Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cant find privateKey in keychain, but doesBiometryKeyExist return true #275

Open
majloj123 opened this issue Jan 23, 2024 · 0 comments
Open

Comments

@majloj123
Copy link

majloj123 commented Jan 23, 2024

Hi, i am using this package that generate privateKey for generating signature. Im working on native module (and then also extension) in swift and i need to create signature there too. I know its possible but i need that private Key. I created keys with package and function is also returning true on if BiometricKeyExist, but when i try to create query and find the key in my swift code/module...i am always getting errSecItemNotFound (code: -25300). How that can be possible? That private key should be stored in keychain and to find it, package use code like this:

- (BOOL) doesBiometricKeyExist {
  NSData *biometricKeyTag = [self getBiometricKeyTag];
  NSDictionary *searchQuery = @{
                                (id)kSecClass: (id)kSecClassKey,
                                (id)kSecAttrApplicationTag: biometricKeyTag,
                                (id)kSecAttrKeyType: (id)kSecAttrKeyTypeRSA,
                                (id)kSecUseAuthenticationUI:    (id)kSecUseAuthenticationUIFail
                                };

  OSStatus status = SecItemCopyMatching((__bridge CFDictionaryRef)searchQuery, nil);
  return status == errSecSuccess || status == errSecInteractionNotAllowed;
} 

My function in swift looks something like this (i am trying to find that private key and return, but for simplicity i will only write code to find that key...it doesnt work already in that stage):

@objc
  func getPrivateKey(_ promise: @escaping RCTPromiseResolveBlock, rejector reject: RCTPromiseRejectBlock) -> Void {

    guard let biometricKeyTag = "com.rnbiometrics.biometricKey".data(using: .utf8) else {
      return promise("Error")
    }
   
    let query = [
            kSecClass: kSecClassKey,
            kSecAttrApplicationTag: biometricKeyTag,
            kSecAttrKeyType: kSecAttrKeyTypeRSA,
            kSecAttrAccessible: kSecAttrAccessibleWhenUnlocked,
            kSecUseAuthenticationUI: kSecUseAuthenticationUIFail,
        ] as CFDictionary
   
     let status = SecItemCopyMatching(query, nil)
     guard status == errSecSuccess else {
            return promise("Error")
      }
    
    return promise("Success")
  } 
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant