Skip to content

Commit

Permalink
iOS: clear Keychain data on uninstall
Browse files Browse the repository at this point in the history
  • Loading branch information
kaloudis committed Mar 25, 2023
1 parent 735d777 commit f576ced
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions ios/zeus/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,31 @@ static void InitializeFlipper(UIApplication *application) {
}
#endif

/**
Deletes all Keychain items accessible by this app if this is the first time the user launches the app
*/
static void ClearKeychainIfNecessary() {
// Checks whether or not this is the first time the app is run
if ([[NSUserDefaults standardUserDefaults] boolForKey:@"HAS_RUN_BEFORE"] == NO) {
// Set the appropriate value so we don't clear next time the app is launched
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"HAS_RUN_BEFORE"];

NSArray *secItemClasses = @[
(__bridge id)kSecClassGenericPassword,
(__bridge id)kSecClassInternetPassword,
(__bridge id)kSecClassCertificate,
(__bridge id)kSecClassKey,
(__bridge id)kSecClassIdentity
];

// Maps through all Keychain classes and deletes all items that match
for (id secItemClass in secItemClasses) {
NSDictionary *spec = @{(__bridge id)kSecClass: secItemClass};
SecItemDelete((__bridge CFDictionaryRef)spec);
}
}
}

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application
Expand All @@ -39,6 +64,9 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
InitializeFlipper(application);
#endif

// Add this line to call the above function
ClearKeychainIfNecessary();

RCTBridge *bridge = [[RCTBridge alloc] initWithDelegate:self launchOptions:launchOptions];
RCTRootView *rootView = [[RCTRootView alloc] initWithBridge:bridge
moduleName:@"zeus"
Expand Down

0 comments on commit f576ced

Please sign in to comment.