Skip to content

Commit

Permalink
Move and rename key.
Browse files Browse the repository at this point in the history
  • Loading branch information
yspreen committed Apr 28, 2021
1 parent c2617aa commit 3bdb0e9
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
1 change: 0 additions & 1 deletion DGCAVerifier/Services/Enclave.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import Foundation
struct Enclave {
static let encryptAlg = SecKeyAlgorithm.eciesEncryptionCofactorVariableIVX963SHA256AESGCM
static let signAlg = SecKeyAlgorithm.ecdsaSignatureMessageX962SHA512
static let symmetricKey = generateOrLoadKey(with: "symmetricKey")

static func tag(for name: String) -> Data {
"\(Bundle.main.bundleIdentifier ?? "app").\(name)".data(using: .utf8)!
Expand Down
5 changes: 3 additions & 2 deletions DGCAVerifier/Services/SecureStorage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ struct SecureDB: Codable {
struct SecureStorage<T: Codable> {
let documents: URL! = try? FileManager.default.url(for: .documentDirectory, in: .userDomainMask, appropriateFor: nil, create: true)
var path: URL! { URL(string: documents.absoluteString + "secure.db") }
let secureStorageKey = Enclave.generateOrLoadKey(with: "secureStorageKey")

/**
Loads encrypted db and overrides it with an empty one if that fails.
Expand All @@ -60,7 +61,7 @@ struct SecureStorage<T: Codable> {

guard
let (data, signature) = read(),
let key = Enclave.symmetricKey,
let key = secureStorageKey,
Enclave.verify(data: data, signature: signature, with: key).0
else {
completion?(nil)
Expand All @@ -82,7 +83,7 @@ struct SecureStorage<T: Codable> {
public func save(_ instance: T, completion: ((Bool) -> Void)? = nil) {
guard
let data = try? JSONEncoder().encode(instance),
let key = Enclave.symmetricKey,
let key = secureStorageKey,
let encrypted = Enclave.encrypt(data: data, with: key).0
else {
completion?(false)
Expand Down

0 comments on commit 3bdb0e9

Please sign in to comment.