Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SecItemAdd() returning errSecInteractionNotAllowed (-25308)

Any attempts I make to store a value to the keychain fails with the error code errSecInteractionNotAllowed (-25308). I have been playing around with Touch ID and the keychain so I may have changed a permission that I wasn't aware of, but I can't figure out anything what I could have changed that could cause this issue.

I was able to successfully store a value to the keychain prior to my fiddling with the keychain, so it is likely a setting somewhere in the device. If it is a setting, I would like some help discovering what I need to change to save data in the keychain again. Also I would like some suggestions to ensure I have access to save to the keychain before I try.

static NSString *serviceName = @"myServiceName";

- (void) createTouchIdKeyChain:(NSString *)identifier password:(NSString*)password{
CFErrorRef error = nil;
SecAccessControlRef sacObject =
SecAccessControlCreateWithFlags( kCFAllocatorDefault,
                                kSecAttrAccessibleWhenPasscodeSetThisDeviceOnly,
                                kSecAccessControlUserPresence,  &error);

NSData* secret = [password dataUsingEncoding:NSUTF8StringEncoding];

NSDictionary* attributes = @{
                             (__bridge id)kSecClass: (__bridge id)kSecClassGenericPassword,
                             (__bridge id)kSecAttrService: serviceName,
                             (__bridge id)kSecAttrAccount: identifier,
                             (__bridge id)kSecValueData: secret,
                             (__bridge id)kSecAttrAccessControl: (__bridge id)sacObject,
                             (__bridge id)kSecUseOperationPrompt: @"create password test"
                             };
OSStatus status = SecItemAdd((__bridge CFDictionaryRef) attributes, nil);
ODLog(@"done");
}
like image 690
KWilk Avatar asked Mar 29 '26 18:03

KWilk


1 Answers

In my case if you try to store two items with the same identifier to the keychain, the second attempt will fail at error code -25308. Try to delete the first one and try again.

like image 187
Summer Avatar answered Mar 31 '26 13:03

Summer



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!