Restore that

This commit is contained in:
Max Goedjen 2021-01-17 17:36:50 -08:00
parent c5fe36cde1
commit 1e76513d0a
No known key found for this signature in database
GPG Key ID: E58C21DD77B9B8E8
1 changed files with 21 additions and 21 deletions

View File

@ -121,27 +121,27 @@ extension SecureEnclave.Store {
}
private func loadSecrets() {
// let attributes = [
// kSecClass: kSecClassKey,
// kSecAttrKeyType: SecureEnclave.Constants.keyType,
// kSecAttrApplicationTag: SecureEnclave.Constants.keyTag,
// kSecAttrKeyClass: kSecAttrKeyClassPublic,
// kSecReturnRef: true,
// kSecMatchLimit: kSecMatchLimitAll,
// kSecReturnAttributes: true
// ] as CFDictionary
// var untyped: CFTypeRef?
// SecItemCopyMatching(attributes, &untyped)
// guard let typed = untyped as? [[CFString: Any]] else { return }
// let wrapped: [SecureEnclave.Secret] = typed.map {
// let name = $0[kSecAttrLabel] as? String ?? "Unnamed"
// let id = $0[kSecAttrApplicationLabel] as! Data
// let publicKeyRef = $0[kSecValueRef] as! SecKey
// let publicKeyAttributes = SecKeyCopyAttributes(publicKeyRef) as! [CFString: Any]
// let publicKey = publicKeyAttributes[kSecValueData] as! Data
// return SecureEnclave.Secret(id: id, name: name, publicKey: publicKey)
// }
// secrets.append(contentsOf: wrapped)
let attributes = [
kSecClass: kSecClassKey,
kSecAttrKeyType: SecureEnclave.Constants.keyType,
kSecAttrApplicationTag: SecureEnclave.Constants.keyTag,
kSecAttrKeyClass: kSecAttrKeyClassPublic,
kSecReturnRef: true,
kSecMatchLimit: kSecMatchLimitAll,
kSecReturnAttributes: true
] as CFDictionary
var untyped: CFTypeRef?
SecItemCopyMatching(attributes, &untyped)
guard let typed = untyped as? [[CFString: Any]] else { return }
let wrapped: [SecureEnclave.Secret] = typed.map {
let name = $0[kSecAttrLabel] as? String ?? "Unnamed"
let id = $0[kSecAttrApplicationLabel] as! Data
let publicKeyRef = $0[kSecValueRef] as! SecKey
let publicKeyAttributes = SecKeyCopyAttributes(publicKeyRef) as! [CFString: Any]
let publicKey = publicKeyAttributes[kSecValueData] as! Data
return SecureEnclave.Secret(id: id, name: name, publicKey: publicKey)
}
secrets.append(contentsOf: wrapped)
}
private func savePublicKey(_ publicKey: SecKey, name: String) throws {