Skip to content

Commit

Permalink
Added wipe function allowing deleting all keychain items (#73)
Browse files Browse the repository at this point in the history
Co-authored-by: Michael Neuwert <mn@neuwert-media.com>
  • Loading branch information
mneuwert and Michael Neuwert authored Nov 17, 2020
1 parent 732c63e commit 3c40553
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
1 change: 1 addition & 0 deletions ownCloudSDK/Security/OCKeychain.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ NS_ASSUME_NONNULL_BEGIN
- (nullable NSData *)readDataFromKeychainItemForAccount:(NSString *)account path:(NSString *)path;
- (nullable NSError *)writeData:(nullable NSData *)data toKeychainItemForAccount:(NSString *)account path:(NSString *)path;
- (nullable NSError *)removeKeychainItemForAccount:(NSString *)account path:(NSString *)path;
- (BOOL)wipe;

#pragma mark - Object interface
- (nullable id)readObjectFromKeychainItemForAccount:(NSString *)account path:(NSString *)path allowedClasses:(NSSet<Class> *)allowedClasses rootClass:(Class)rootClass error:(NSError * _Nullable * _Nullable)outError;
Expand Down
15 changes: 15 additions & 0 deletions ownCloudSDK/Security/OCKeychain.m
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,21 @@ - (NSError *)removeKeychainItemForAccount:(NSString *)account path:(NSString *)p
return ([self writeData:nil toKeychainItemForAccount:account path:path]);
}

- (BOOL)wipe
{
OSStatus status = errSecSuccess;
NSMutableDictionary <NSString *, id> *queryDict;

if ((queryDict = [self _queryType:NULL dictForAccount:nil path:nil]) != nil)
{
status = SecItemDelete((CFDictionaryRef)queryDict);

OCTLogDebug(@[@"Delete"], @"Delete all items, status=%d", status);
}

return (status == errSecSuccess);
}

- (id)readObjectFromKeychainItemForAccount:(NSString *)account path:(NSString *)path allowedClasses:(NSSet<Class> *)allowedClasses rootClass:(Class)rootClass error:(NSError **)outError
{
NSData *data;
Expand Down

0 comments on commit 3c40553

Please sign in to comment.