Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OSStatus error code -34018

I am using SecItemCopyMatching to access the iOS keychain. About 1 in a hundred times I get a -34018 result code right after relaunching the app from the background. The documentation states:

The assigned error space for Keychain Services is discontinuous: –25240 through –25279 and –25290 through –25329. Keychain Item Services may also return noErr (0) or paramErr (–50), or CSSM result codes

So it seems that -34018 is a 'CSSM result code'. I have followed the suggested link but could not find result codes.

What it the -34018 result code? How can I get more reliable keychain access?

- (NSData *)getKeychainData:(NSString *)key {     NSDictionary *query = @{         (__bridge id)kSecClass:(__bridge id)kSecClassGenericPassword,         (__bridge id)kSecAttrService:SEC_ATTR_SERVICE,         (__bridge id)kSecAttrAccount:key,         (__bridge id)kSecReturnData:@YES     };      CFDataRef result = nil;      OSStatus status = SecItemCopyMatching((__bridge CFDictionaryRef)query, (CFTypeRef *)&result);      if(status == errSecItemNotFound) {         return nil;     }      if(status == noErr) {         return CFBridgingRelease(result);     } else {         [self logError:[NSString stringWithFormat:@"SecItemCopyMatching status %d", (int)status] :nil];         return nil;     } } 
like image 688
Randomblue Avatar asked Apr 20 '15 06:04

Randomblue


People also ask

What is OSStatus error on Mac?

What Causes OSStatus Error 99999 on Mac? If you're downloading the app from a third-party source, you need to make sure that your Mac allows non-App Store applications to be installed in it. You need to enable this in System Preferences. If this is disabled, you will most likely encounter this error.

How do I fix OSStatus error 2003334207?

Please try deleting and re-syncing your music library via iTunes. Our team is still investigating this issue. You can try deleting and re-importing the songs to iTunes.


1 Answers

I've been just researching the same error.

The gist of it is that the security service apple uses in order to communicate with the key chain, in rare cases, when the user's device is low on memory, crashes and taking away the app ability to talk to the keychain which results the dreadful -34018.

This is not happening only while running through Xcode like some may claim.

This is the most recent data regarding the issue taken from the Apple developer forums by one of the Apple staff:

UPDATE: We have finally been able to reproduce the -34018 error on iOS 8.3. This is the first step in identifying the root cause and then coming up with a fix.

As usual, we can't commit to a release timeframe, but this has affected many developers and we really want to get this resolved.

Earlier I suggested adding a small delay in application:didFinishLaunchingWithOptions and applicationDidBecomeActive: before accessing the keychain as a workaround. However, that doesn't actually appear to help. That means that there's no known workaround at this time other than relaunching the app.

The issue appears to be related to memory pressure, so perhaps being more aggressive in handling memory warnings may alleviate the problem.

From Another Apple staff member:

  • Keychain engineering is well aware of how important this issue is.
  • The primary problem has been reproducing the failure here at Apple.
  • We're now able to do that (largely thanks to the work you guys have put in filing and following up on your bug reports).

From Another Apple staff member on Mar 22, 2016:

OK, here’s the latest. This is a complex problem with multiple possible causes: Some instances of the problem are caused by incorrect app signing. You can easily distinguish this case because the problem is 100% reproducible. Some instances of the problem are caused by a bug in how iOS supports app development (r. 23,991,853). Debugging this was complicated by the fact that another bug in the OS (r. 23,770,418) masked its effect, meaning the problem only cropped up when the device was under memory pressure. We believe these problems were resolved in iOS 9.3. We suspect that there may be yet more causes of this problem. So, if you see this problem on a user device (one that hasn’t been talked to by Xcode) that’s running iOS 9.3 or later, please do file a bug report about it. Try to include the device system log in your bug report (I realise that can be tricky when dealing with customer devices; one option is to ask the customer to install Apple Configurator, which lets them view the system log). And if you do file a bug, please post your bug number, just for the record. On behalf of Apple I’d like to thank everyone for their efforts in helping to track down this rather horrid issue. Share and Enjoy

Unfortunately there are no known workarounds and the issue is still not fixed in 9.3.2 Beta 1 (13F51a)

like image 152
Segev Avatar answered Sep 19 '22 08:09

Segev