Skip to content

Commit

Permalink
Fix signing.
Browse files Browse the repository at this point in the history
  • Loading branch information
yspreen committed Apr 26, 2021
1 parent 9978ff5 commit a2deb95
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
5 changes: 0 additions & 5 deletions DGCAVerifier/Services/Enclave.swift
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ struct Enclave {
else {
return (nil, error?.takeRetainedValue().localizedDescription)
}
error?.release()
return (privateKey, nil)
}

Expand Down Expand Up @@ -117,7 +116,6 @@ struct Enclave {
&error
) as Data?
let err = error?.takeRetainedValue().localizedDescription
error?.release()
return (cipherData, err)
}

Expand All @@ -140,7 +138,6 @@ struct Enclave {
&error
) as Data?
let err = error?.takeRetainedValue().localizedDescription
error?.release()
return (clearData, err)
}

Expand All @@ -160,7 +157,6 @@ struct Enclave {
&error
)
let err = error?.takeRetainedValue().localizedDescription
error?.release()
return (isValid, err)
}

Expand All @@ -183,7 +179,6 @@ struct Enclave {
&error
) as Data?
let err = error?.takeRetainedValue().localizedDescription
error?.release()
return (signature, err)
}
}
17 changes: 16 additions & 1 deletion DGCAVerifier/Services/SecureStorage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,21 @@ struct SecureStorage {
static let documents: URL! = try? FileManager.default.url(for: .documentDirectory, in: .userDomainMask, appropriateFor: nil, create: true)
static let path: URL! = URL(string: documents.absoluteString + "secure.db")

/**
Loads encrypted db and overrides it with an empty one if that fails.
*/
public static func loadOverride(completion: ((Bool) -> Void)? = nil) {
load { success in
if success {
completion?(true)
return
}
save { _ in
load(completion: completion)
}
}
}

public static func load(completion: ((Bool) -> Void)? = nil) {
if !FileManager.default.fileExists(atPath: path.path) {
save()
Expand Down Expand Up @@ -79,7 +94,7 @@ struct SecureStorage {
completion?(false)
return
}
Enclave.sign(data: data, with: key) { signature, err in
Enclave.sign(data: encrypted, with: key) { signature, err in
guard
let signature = signature,
err == nil
Expand Down
2 changes: 1 addition & 1 deletion DGCAVerifier/ViewControllers/Home.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class HomeVC: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()

SecureStorage.load { [weak self] success in
SecureStorage.loadOverride { [weak self] success in
guard success else {
return
}
Expand Down

0 comments on commit a2deb95

Please sign in to comment.