poliveira
poliveira

Reputation: 147

Keychain unlock inside app, is this approach safe?

I'm using Keychain to permit login through TouchID in a remote app. My concern is about an attacker setting a breakpoint in a jailbreak device and recovering the username and password, I tried this approach to let the info the less time possible on memory.

I'd like to know if I need this level of paranoia and if I'm using the right approach.

KeychainItemWrapper *keychainItem = [[KeychainItemWrapper alloc] 
                                    initWithIdentifier:@"MyAppLogin" accessGroup:nil];
NSString *password = [keychainItem objectForKey:(__bridge id)(kSecValueData)];
NSString *username = [keychainItem objectForKey:(__bridge id)(kSecAttrAccount)];
if (!username || !password) {
    self.layoutState = kLayoutStateNormal;
    return;
}
// forget everything you know about my password
keychainItem = nil;
password = nil;
username = nil;

Upvotes: 2

Views: 73

Answers (1)

zaph
zaph

Reputation: 112857

Setting NSString instances to nil will not remove the contents from memory, will not zero the contents, will just remove the pointer. The contents will continue to exist until that memory is re-used.

If you use "C" strings (char arrays) you can clear them. But you may need NSString due to the usage of the username and password in your code.

It is very hard to impossible to keep information on an iDevice from the owner/user. The best that can be dome is to increase the work factor to obtain the information.

Upvotes: 1

Related Questions