mirror of
https://github.com/maxgoedjen/secretive.git
synced 2024-11-25 06:57:07 +00:00
refactoring savePublicKey move in kSecPublicKeyAttrs
This commit is contained in:
parent
fd7a9c2f7a
commit
23b3297fee
@ -54,21 +54,21 @@ extension SecureEnclave {
|
|||||||
kSecAttrKeyType: Constants.keyType,
|
kSecAttrKeyType: Constants.keyType,
|
||||||
kSecAttrTokenID: kSecAttrTokenIDSecureEnclave,
|
kSecAttrTokenID: kSecAttrTokenIDSecureEnclave,
|
||||||
kSecAttrApplicationTag: Constants.keyTag,
|
kSecAttrApplicationTag: Constants.keyTag,
|
||||||
|
kSecAttrIsPermanent: true,
|
||||||
kSecPrivateKeyAttrs: [
|
kSecPrivateKeyAttrs: [
|
||||||
kSecAttrIsPermanent: true,
|
kSecAttrKeyClass: kSecAttrKeyClassPrivate,
|
||||||
kSecAttrAccessControl: access
|
kSecAttrAccessControl: access
|
||||||
|
],
|
||||||
|
kSecPublicKeyAttrs: [
|
||||||
|
kSecAttrKeyClass: kSecAttrKeyClassPublic
|
||||||
]
|
]
|
||||||
]
|
]
|
||||||
|
|
||||||
var createKeyError: SecurityError?
|
var createKeyError: SecurityError?
|
||||||
let keypair = SecKeyCreateRandomKey(attributes, &createKeyError)
|
SecKeyCreateRandomKey(attributes, &createKeyError)
|
||||||
if let error = createKeyError {
|
if let error = createKeyError {
|
||||||
throw error.takeRetainedValue() as Error
|
throw error.takeRetainedValue() as Error
|
||||||
}
|
}
|
||||||
guard let keypair = keypair, let publicKey = SecKeyCopyPublicKey(keypair) else {
|
|
||||||
throw KeychainError(statusCode: nil)
|
|
||||||
}
|
|
||||||
try savePublicKey(publicKey, name: name)
|
|
||||||
reloadSecretsInternal()
|
reloadSecretsInternal()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -278,26 +278,6 @@ extension SecureEnclave.Store {
|
|||||||
secrets.append(contentsOf: wrapped)
|
secrets.append(contentsOf: wrapped)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Saves a public key.
|
|
||||||
/// - Parameters:
|
|
||||||
/// - publicKey: The public key to save.
|
|
||||||
/// - name: A user-facing name for the key.
|
|
||||||
private func savePublicKey(_ publicKey: SecKey, name: String) throws {
|
|
||||||
let attributes : NSDictionary = [
|
|
||||||
kSecClass: kSecClassKey,
|
|
||||||
kSecAttrKeyType: SecureEnclave.Constants.keyType,
|
|
||||||
kSecAttrKeyClass: kSecAttrKeyClassPublic,
|
|
||||||
kSecAttrApplicationTag: SecureEnclave.Constants.keyTag,
|
|
||||||
kSecValueRef: publicKey,
|
|
||||||
kSecAttrIsPermanent: true,
|
|
||||||
kSecReturnData: true,
|
|
||||||
kSecAttrLabel: name
|
|
||||||
]
|
|
||||||
let status = SecItemAdd(attributes, nil)
|
|
||||||
if status != errSecSuccess {
|
|
||||||
throw KeychainError(statusCode: status)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user