Skip to content

Commit 288a5b5

Browse files
Added SecItemDelete for app keychain items
1 parent a562220 commit 288a5b5

1 file changed

Lines changed: 10 additions & 3 deletions

File tree

AppBox/Common/KeychainHandler/KeychainHandler.m

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,19 @@ + (void)removeAllStoredCredentials{
7272
// Also delete all stored cookies!
7373
NSHTTPCookieStorage *cookieStorage = [NSHTTPCookieStorage sharedHTTPCookieStorage];
7474
NSArray *cookies = [cookieStorage cookies];
75-
id cookie;
76-
for (cookie in cookies) {
75+
for (NSHTTPCookie *cookie in cookies) {
7776
[cookieStorage deleteCookie:cookie];
7877
}
7978

79+
// Remove app-specific keychain items
80+
NSDictionary *keychainQuery = @{
81+
(__bridge id)kSecClass: (__bridge id)kSecClassGenericPassword
82+
};
83+
OSStatus keychainStatus = SecItemDelete((__bridge CFDictionaryRef)keychainQuery);
84+
if (keychainStatus != errSecSuccess && keychainStatus != errSecItemNotFound) {
85+
DDLogWarn(@"Failed to clear keychain items: %@", [self errorMessageForStatus:keychainStatus]);
86+
}
87+
8088
NSDictionary *credentialsDict = [[NSURLCredentialStorage sharedCredentialStorage] allCredentials];
8189
if ([credentialsDict count] > 0) {
8290
// the credentialsDict has NSURLProtectionSpace objs as keys and dicts of userName => NSURLCredential
@@ -89,7 +97,6 @@ + (void)removeAllStoredCredentials{
8997
// iterate over all usernames for this protectionspace, which are the keys for the actual NSURLCredentials
9098
while (userName = [userNameEnumerator nextObject]) {
9199
NSURLCredential *cred = [[credentialsDict objectForKey:urlProtectionSpace] objectForKey:userName];
92-
//NSLog(@"credentials to be removed: %@", cred);
93100
[[NSURLCredentialStorage sharedCredentialStorage] removeCredential:cred forProtectionSpace:urlProtectionSpace];
94101
}
95102
}

0 commit comments

Comments
 (0)