dickverweij / nl-afas-cordova-plugin-securelocalstorage

Secure (encrypted by keystore/keychain) localstorage access in cordova
MIT License
8 stars 11 forks source link

Crash with iOS Simulator #4

Open ds8k opened 7 years ago

ds8k commented 7 years ago

Getting this crash when attempting to build to the simulator in Xcode 8:

2016-10-11 13:39:03.972 App[99718:5081501] *** Assertion failure in -[KeychainItemWrapper writeToKeychain], KeychainItemWrapper.m:325
2016-10-11 13:39:03.985 App[99718:5081501] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Couldn't add the Keychain Item.'
*** First throw call stack:
(
    0   CoreFoundation                      0x000000010e50f34b __exceptionPreprocess + 171
    1   libobjc.A.dylib                     0x000000010df4721e objc_exception_throw + 48
    2   CoreFoundation                      0x000000010e513442 +[NSException raise:format:arguments:] + 98
    3   Foundation                          0x000000010a37fedd -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 195
    4   App                                0x0000000108c94aaa -[KeychainItemWrapper writeToKeychain] + 970
    5   App                                0x0000000108c93e9a -[KeychainItemWrapper setObject:forKey:] + 218
    6   App                                0x0000000108c9178e -[SecureLocalStorage writeToSecureStorage:] + 270
    7   App                                0x0000000108c9378b __37-[SecureLocalStorage clearIfInvalid:]_block_invoke + 635
    8   libdispatch.dylib                   0x000000010ff90980 _dispatch_call_block_and_release + 12
    9   libdispatch.dylib                   0x000000010ffba0cd _dispatch_client_callout + 8
    10  libdispatch.dylib                   0x000000010ff99366 _dispatch_queue_override_invoke + 1426
    11  libdispatch.dylib                   0x000000010ff9b3b7 _dispatch_root_queue_drain + 720
    12  libdispatch.dylib                   0x000000010ff9b08b _dispatch_worker_thread3 + 123
    13  libsystem_pthread.dylib             0x0000000110334746 _pthread_wqthread + 1299
    14  libsystem_pthread.dylib             0x0000000110334221 start_wqthread + 13
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb) 
dickverweij commented 7 years ago

Hmm.. strange.. we will investigate..

PhilHuot commented 7 years ago

Hi, I have the same issue. I think It's only for iOS10, iOS9 lower work fine.

ds8k commented 7 years ago

I have a crappy work-around:

#if TARGET_IPHONE_SIMULATOR
#else
        // No previous item found; add the new one.
        result = SecItemAdd((__bridge CFDictionaryRef)[self dictionaryToSecItemFormat:keychainItemData], NULL);
        NSAssert( result == noErr, @"Couldn't add the Keychain Item." );
#endif

At the very least this lets me test other features out in the simulator

tabrindle commented 7 years ago

A very slightly less crappy workaround:

#if !TARGET_OS_SIMULATOR
        // No previous item found; add the new one.
        result = SecItemAdd((__bridge CFDictionaryRef)[self dictionaryToSecItemFormat:keychainItemData], NULL);
        NSAssert( result == noErr, @"Couldn't add the Keychain Item." );
#endif

This gets rid of the useless else and uses a non-deprecated macro.

That said, a similar plugin seems to have this working without crashing, but also seems to have a lot of conditional code for simulators: https://github.com/driftyco/cordova-plugin-ios-keychain

EDIT: I did some research on the library you are using KeychainItemWrapper.m and it seems there is an open bug for the iOS 10 simulator - https://forums.developer.apple.com/thread/51071.

It also seems that the workaround is relatively simple for native projects - to enable keychain sharing in Xcode.

It's slightly more complicated for cordova projects - you may need to integrate the entitlement hook from this plugin https://github.com/Telerik-Verified-Plugins/Keychain-Sharing.

dickverweij commented 7 years ago

just went to xcode 8.. so i got to fix this

tabrindle commented 7 years ago

According the the apple forums relating to that keychain library you are using, the easiest way to fix this is to enable keychain sharing. If you can implement this as part of your plugin, I think this would be a decent work around until it is fixed up stream.