EOSIO / eosio-swift-vault

Utility library for managing keys and signing with Apple's Keychain and Secure Enclave
https://eosio.github.io/eosio-swift-vault/
MIT License
12 stars 8 forks source link

newVaultKey throws KeyManagementError: PUB_R1_5LfLBzXdsHCd1WqTF9a7VrCoxintemEDSKK4i63UiCC7rx9fiD not found #53

Closed ismyhc closed 4 years ago

ismyhc commented 4 years ago

When trying to generate a new key via keychain, I get an error thrown.

KeyManagementError: PUB_R1_5LfLBzXdsHCd1WqTF9a7VrCoxintemEDSKK4i63UiCC7rx9fiD not found

let secKey = try keychain.createEllipticCurveSecKey(secureEnclave: secureEnclave, tag: tag, label: nil, protection: protection, accessFlag: accessFlag)
guard let eosioPublicKey = secKey.publicKey?.externalRepresentation?.compressedPublicKey?.toEosioR1PublicKey else {
       throw EosioError(.keyManagementError, reason: "Unable to create public key")
}
var vaultKey = try getVaultKey(eosioPublicKey: eosioPublicKey)

As you can see the newVaultKey function creates the key, then tries to retrieve it from keychain without it actually being added to the keychain first. I could see a case where you might actually not want the key to be saved to keychain upon generation. For instance, you generate a key and the user doesn't follow throw with creating an account, etc. This could create abandoned keys in the keychain.

ismyhc commented 4 years ago

This was a simulator issue. Closing now as its not something that can be fixed by the library.