-
-
Notifications
You must be signed in to change notification settings - Fork 522
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adds getAllInternetPasswordServers method for iOS #473
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -301,6 +301,37 @@ - (OSStatus)deleteCredentialsForServer:(NSString *)server | |||||
return services; | ||||||
} | ||||||
|
||||||
-(NSArray<NSString*>*)getAllServersForInternetPasswords | ||||||
{ | ||||||
NSMutableDictionary *query = [NSMutableDictionary dictionaryWithObjectsAndKeys: | ||||||
(__bridge id)kCFBooleanTrue, (__bridge id)kSecReturnAttributes, | ||||||
(__bridge id)kSecMatchLimitAll, (__bridge id)kSecMatchLimit, | ||||||
nil]; | ||||||
NSMutableArray<NSString*> *servers = [NSMutableArray<NSString*> new]; | ||||||
|
||||||
[query setObject:(__bridge id)kSecClassInternetPassword forKey:(__bridge id)kSecClass]; | ||||||
NSArray *result = nil; | ||||||
CFTypeRef resultRef = NULL; | ||||||
OSStatus osStatus = SecItemCopyMatching((__bridge CFDictionaryRef)query, (CFTypeRef*)&resultRef); | ||||||
if (osStatus != noErr && osStatus != errSecItemNotFound) { | ||||||
NSError *error = [NSError errorWithDomain:NSOSStatusErrorDomain code:osStatus userInfo:nil]; | ||||||
@throw error; | ||||||
} else if (osStatus != errSecItemNotFound) { | ||||||
result = (__bridge NSArray*)(resultRef); | ||||||
if (result != NULL) { | ||||||
for (id entry in result) { | ||||||
NSMutableData *serverData = [entry objectForKey:(__bridge NSString *)kSecAttrServer]; | ||||||
if (serverData != NULL) { | ||||||
NSString *server = [[NSString alloc] initWithData:serverData encoding:NSUTF8StringEncoding]; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this line is not needed There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
[servers addObject:server]; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
} | ||||||
} | ||||||
} | ||||||
} | ||||||
|
||||||
return servers; | ||||||
} | ||||||
|
||||||
#pragma mark - RNKeychain | ||||||
|
||||||
#if TARGET_OS_IOS | ||||||
|
@@ -594,4 +625,14 @@ - (OSStatus)deleteCredentialsForServer:(NSString *)server | |||||
} | ||||||
} | ||||||
|
||||||
RCT_EXPORT_METHOD(getAllInternetPasswordServers:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) | ||||||
{ | ||||||
@try { | ||||||
NSArray *servers = [self getAllServersForInternetPasswords]; | ||||||
return resolve(servers); | ||||||
} @catch (NSError *nsError) { | ||||||
return rejectWithError(reject, nsError); | ||||||
} | ||||||
} | ||||||
|
||||||
@end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.