EddyVerbruggen / nativescript-secure-storage

:closed_lock_with_key: NativeScript plugin for secure local storage of fi. passwords
MIT License
111 stars 26 forks source link

Not working in iOS simulator. Gives "found no keychain client entitlements" #10

Closed sserdyuk closed 7 years ago

sserdyuk commented 7 years ago

It can't write. Any idea how to avoid it? From looking into Facebook SDK, it appears that they detect simulator based on defined target type, and replace all keychain calls with a non-secure ones. Here's the log from the demo app. It errors on write, and then it reads null as it wasn't assigned.

Jun 30 12:32:36 mini securityd[80251]: found no keychain client entitlements. task=demo[84130]/1#0 LF=0 procid=org.nativescript.demo cs_flags=0x02000201
CONSOLE LOG file:///app/main-view-model.js:31:24: NSErrorWrapper: Refer to SecBase.h for description
CONSOLE LOG file:///app/main-view-model.js:17:24: Value: null
Jun 30 12:32:57 mini securityd[80251]: found no keychain client entitlements. task=demo[84130]/1#0 LF=0 procid=org.nativescript.demo cs_flags=0x02000201
CONSOLE LOG file:///app/main-view-model.js:31:24: NSErrorWrapper: Refer to SecBase.h for description
CONSOLE LOG file:///app/main-view-model.js:17:24: Value: null
Jun 30 12:33:04 mini securityd[80251]: found no keychain client entitlements. task=demo[84130]/1#0 LF=0 procid=org.nativescript.demo cs_flags=0x02000201
CONSOLE LOG file:///app/main-view-model.js:39:24: Successfully removed a value? 
EddyVerbruggen commented 7 years ago

Saw this too. Started this week for me.

sserdyuk commented 7 years ago

Good to know it's not just me, as I couldn't find anything on the issue on the web. Here's the FB SDK file I have mentioned. The have preprocessor condition on both set and get. platforms/ios/Pods/FBSDKCoreKit/FBSDKCoreKit/FBSDKCoreKit/Internal/TokenCaching/FBSDKKeychainStore.m

- (BOOL)setData:(NSData *)value forKey:(NSString *)key accessibility:(CFTypeRef)accessibility
{
    if (!key) {
        return NO;
    }

#if TARGET_OS_SIMULATOR
    NSLog(@"Falling back to storing access token in NSUserDefaults because of simulator bug");
    [[NSUserDefaults standardUserDefaults] setObject:value forKey:key];

    return [[NSUserDefaults standardUserDefaults] synchronize];
#else
    NSMutableDictionary *query = [self queryForKey:key];

    OSStatus status;
    if (value) {
        NSMutableDictionary *attributesToUpdate = [NSMutableDictionary dictionary];
        [attributesToUpdate setObject:value forKey:[FBSDKDynamicFrameworkLoader loadkSecValueData]];

        status = fbsdkdfl_SecItemUpdate((__bridge CFDictionaryRef)query, (__bridge CFDictionaryRef)attributesToUpdate);
        if (status == errSecItemNotFound) {
#if TARGET_OS_IPHONE || (defined(MAC_OS_X_VERSION_10_9) && MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_9)
            if (accessibility) {
                [query setObject:(__bridge id)(accessibility) forKey:[FBSDKDynamicFrameworkLoader loadkSecAttrAccessible]];
            }
#endif
            [query setObject:value forKey:[FBSDKDynamicFrameworkLoader loadkSecValueData]];

            status = fbsdkdfl_SecItemAdd((__bridge CFDictionaryRef)query, NULL);
        }
    } else {
        status = fbsdkdfl_SecItemDelete((__bridge CFDictionaryRef)query);
        if (status == errSecItemNotFound) {
            status = errSecSuccess;
        }
    }

    return (status == errSecSuccess);
#endif
}
EddyVerbruggen commented 7 years ago

Thanks for the pointers. I can't use those macro's in NativeScript, but I've found another good solution on SO which is compatible with any iOS version.

Available in version 2.1.1.

sserdyuk commented 7 years ago

Thank you