Skip to content

Commit

Permalink
Keychain: Set kSecAttrAccessibleAfterFirstUnlockThisDeviceOnly #14 #3
Browse files Browse the repository at this point in the history
  • Loading branch information
guruz committed Apr 20, 2020
1 parent a39f570 commit eea6d06
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,18 +81,26 @@ - (BOOL)storeString:(NSString*)string forKey:(NSString*)key {
} else {
#if TARGET_OS_IPHONE
NSData *stringData = [string dataUsingEncoding:NSUTF8StringEncoding];
NSDictionary *spec = [NSDictionary dictionaryWithObjectsAndKeys:(id)kSecClassGenericPassword, kSecClass,
key, kSecAttrAccount,[self serviceName], kSecAttrService, nil];
NSDictionary *spec = [NSDictionary dictionaryWithObjectsAndKeys:
(id)kSecClassGenericPassword, kSecClass,
key, kSecAttrAccount,
[self serviceName], kSecAttrService,
kSecAttrAccessibleAfterFirstUnlockThisDeviceOnly, kSecAttrAccessible,
nil];

if(!string) {
return !SecItemDelete((CFDictionaryRef)spec);
}else if([self stringForKey:key]) {
NSDictionary *update = [NSDictionary dictionaryWithObject:stringData forKey:(id)kSecValueData];
return !SecItemUpdate((CFDictionaryRef)spec, (CFDictionaryRef)update);
OSStatus s = SecItemUpdate((CFDictionaryRef)spec, (CFDictionaryRef)update);
NSLog(@"Keychain update for %@ gave %d", key, s);
return !s;
}else{
NSMutableDictionary *data = [NSMutableDictionary dictionaryWithDictionary:spec];
[data setObject:stringData forKey:(id)kSecValueData];
return !SecItemAdd((CFDictionaryRef)data, NULL);
OSStatus s = SecItemAdd((CFDictionaryRef)data, NULL);
NSLog(@"Keychain create for %@ gave %d", key, s);
return !s;
}
#else //OSX
SecKeychainItemRef item = NULL;
Expand Down
6 changes: 6 additions & 0 deletions quassel-for-ios/quassel-for-ios/vcs/LoginViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,12 @@ - (void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([segue.identifier isEqualToString:@"ConnectSegue"]) {
PDKeychainBindings *kc = [PDKeychainBindings sharedKeychainBindings];
// Delete first so we can set security to kSecAttrAccessibleAfterFirstUnlockThisDeviceOnly
[kc setObject:nil forKey:@"userName"];
[kc setObject:nil forKey:@"passWord"];
[kc setObject:nil forKey:@"hostName"];
[kc setObject:nil forKey:@"port"];
// Store
[kc setObject:userNameField.text forKey:@"userName"];
[kc setObject:passWordField.text forKey:@"passWord"];
[kc setObject:hostNameField.text forKey:@"hostName"];
Expand Down

0 comments on commit eea6d06

Please sign in to comment.