IOS keychain: SecItemUpdate returns -50 (paramErr) when updating kSecAttrAccessible

I need to update kSecAttrAccessible entries in a keychain. I do not need to update the actual data, just an accessibility attribute.

First, I try to find an element to make sure my query dictionary is good:

sanityCheck = SecItemCopyMatching((__bridge CFDictionaryRef)(queryPrivateKey), (void *)&privateKeyRef);

This line successfully finds me the item I'm looking for (return code is 0).

Then I update the kSecAttrAccessible attribute using the same request:

if (sanityCheck == noErr && privateKeyRef != nil) {
    // found it, update accessibility
    NSMutableDictionary *updatedAttributes = [[NSMutableDictionary alloc] init];
    updatedAttributes[(__bridge id)kSecAttrAccessible] = (__bridge id)kSecAttrAccessibleAlways;
    OSStatus updateItemStatus = SecItemUpdate((__bridge CFDictionaryRef)queryPrivateKey, (__bridge CFDictionaryRef)updatedAttributes);
}

At this point, updateItemStatus is set to -50 (paramErr).

: kSecAttrAccessable Keychain? . -50, kSecValueData updatedAttributes. , , kSecValueData iOS 4 . iOS 7 , .

- , ? .

+4
1

, keychain SecItemCopyMatching, , keychain.

:

[queryPrivateKey setObject:(__bridge id)kSecClassKey forKey:(__bridge id)kSecClass];
[queryPrivateKey setObject:(__bridge id)kSecAttrKeyTypeRSA forKey:(__bridge id)kSecAttrKeyType];
[queryPrivateKey setObject:[NSNumber numberWithBool:YES] forKey:(__bridge id)kSecReturnRef];
[queryPrivateKey setObject:[EncryptionHelper privateKeyTag:JWT_KEYPAIR_TAG] forKey:(__bridge id<NSCopying>)(kSecAttrApplicationTag)];

sanityCheck = SecItemCopyMatching((__bridge CFDictionaryRef)(queryPrivateKey), (void *)&privateKeyef);

, , :

[queryPrivateKey removeObjectForKey:(__bridge id)kSecReturnRef];

:

OSStatus updateItemStatus = SecItemUpdate((__bridge CFDictionaryRef)queryPrivateKey,(__bridge CFDictionaryRef)updatedAttributes);

, kSecReturnRef SecItemUpdate. SecItemUpdate Apple. SecItemUpdate , , , , , kSecClass .. - doc, , , , , SecItemUpdate.

, , kSecAttrAccessible: , kSecAttrAccessibleWhenUnlocked, , kSecAttrAccessibleAlways, , , . , , .

+3

Source: https://habr.com/ru/post/1588890/


All Articles