forked from calabash/calabash-ios-server
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SSKeychain is a Cocoapods project which provides handy wrappers around the iOS keychain (which has a Core Foundation-based API). This import pulls it in but adjusts all its exported symbols' prefix from "SS" to "LPSS" to avoid duplicate symbols with any projects that want to link Calabash and use SSKeychain themselves.
- Loading branch information
Showing
6 changed files
with
653 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,163 @@ | ||
// | ||
// SSKeychain.h | ||
// SSKeychain | ||
// | ||
// Created by Sam Soffes on 5/19/10. | ||
// Copyright (c) 2010-2013 Sam Soffes. All rights reserved. | ||
// | ||
|
||
#import "LPSSKeychainQuery.h" | ||
|
||
/** | ||
Error code specific to SSKeychain that can be returned in NSError objects. | ||
For codes returned by the operating system, refer to SecBase.h for your | ||
platform. | ||
*/ | ||
typedef enum { | ||
|
||
/** Some of the arguments were invalid. */ | ||
SSKeychainErrorBadArguments = -1001, | ||
|
||
} SSKeychainErrorCode; | ||
|
||
/** SSKeychain error domain */ | ||
extern NSString *const kLPSSKeychainErrorDomain; | ||
|
||
/** Account name. */ | ||
extern NSString *const kLPSSKeychainAccountKey; | ||
|
||
/** | ||
Time the item was created. | ||
The value will be a string. | ||
*/ | ||
extern NSString *const kLPSSKeychainCreatedAtKey; | ||
|
||
/** Item class. */ | ||
extern NSString *const kLPSSKeychainClassKey; | ||
|
||
/** Item description. */ | ||
extern NSString *const kLPSSKeychainDescriptionKey; | ||
|
||
/** Item label. */ | ||
extern NSString *const kLPSSKeychainLabelKey; | ||
|
||
/** Time the item was last modified. | ||
The value will be a string. | ||
*/ | ||
extern NSString *const kLPSSKeychainLastModifiedKey; | ||
|
||
/** Where the item was created. */ | ||
extern NSString *const kLPSSKeychainWhereKey; | ||
|
||
/** | ||
Simple wrapper for accessing accounts, getting passwords, setting passwords, and deleting passwords using the system | ||
Keychain on Mac OS X and iOS. | ||
This was originally inspired by EMKeychain and SDKeychain (both of which are now gone). Thanks to the authors. | ||
SSKeychain has since switched to a simpler implementation that was abstracted from [SSToolkit](http://sstoolk.it). | ||
*/ | ||
@interface LPSSKeychain : NSObject | ||
|
||
#pragma mark - Classic methods | ||
|
||
/** | ||
Returns a string containing the password for a given account and service, or `nil` if the Keychain doesn't have a | ||
password for the given parameters. | ||
@param serviceName The service for which to return the corresponding password. | ||
@param account The account for which to return the corresponding password. | ||
@return Returns a string containing the password for a given account and service, or `nil` if the Keychain doesn't | ||
have a password for the given parameters. | ||
*/ | ||
+ (NSString *)passwordForService:(NSString *)serviceName account:(NSString *)account; | ||
+ (NSString *)passwordForService:(NSString *)serviceName account:(NSString *)account error:(NSError **)error; | ||
|
||
|
||
/** | ||
Deletes a password from the Keychain. | ||
@param serviceName The service for which to delete the corresponding password. | ||
@param account The account for which to delete the corresponding password. | ||
@return Returns `YES` on success, or `NO` on failure. | ||
*/ | ||
+ (BOOL)deletePasswordForService:(NSString *)serviceName account:(NSString *)account; | ||
+ (BOOL)deletePasswordForService:(NSString *)serviceName account:(NSString *)account error:(NSError **)error; | ||
|
||
|
||
/** | ||
Sets a password in the Keychain. | ||
@param password The password to store in the Keychain. | ||
@param serviceName The service for which to set the corresponding password. | ||
@param account The account for which to set the corresponding password. | ||
@return Returns `YES` on success, or `NO` on failure. | ||
*/ | ||
+ (BOOL)setPassword:(NSString *)password forService:(NSString *)serviceName account:(NSString *)account; | ||
+ (BOOL)setPassword:(NSString *)password forService:(NSString *)serviceName account:(NSString *)account error:(NSError **)error; | ||
|
||
|
||
/** | ||
Returns an array containing the Keychain's accounts, or `nil` if the Keychain has no accounts. | ||
See the `NSString` constants declared in SSKeychain.h for a list of keys that can be used when accessing the | ||
dictionaries returned by this method. | ||
@return An array of dictionaries containing the Keychain's accounts, or `nil` if the Keychain doesn't have any | ||
accounts. The order of the objects in the array isn't defined. | ||
*/ | ||
+ (NSArray *)allAccounts; | ||
|
||
|
||
/** | ||
Returns an array containing the Keychain's accounts for a given service, or `nil` if the Keychain doesn't have any | ||
accounts for the given service. | ||
See the `NSString` constants declared in SSKeychain.h for a list of keys that can be used when accessing the | ||
dictionaries returned by this method. | ||
@param serviceName The service for which to return the corresponding accounts. | ||
@return An array of dictionaries containing the Keychain's accountsfor a given `serviceName`, or `nil` if the Keychain | ||
doesn't have any accounts for the given `serviceName`. The order of the objects in the array isn't defined. | ||
*/ | ||
+ (NSArray *)accountsForService:(NSString *)serviceName; | ||
|
||
|
||
#pragma mark - Configuration | ||
|
||
#if __IPHONE_4_0 && TARGET_OS_IPHONE | ||
/** | ||
Returns the accessibility type for all future passwords saved to the Keychain. | ||
@return Returns the accessibility type. | ||
The return value will be `NULL` or one of the "Keychain Item Accessibility | ||
Constants" used for determining when a keychain item should be readable. | ||
@see setAccessibilityType | ||
*/ | ||
+ (CFTypeRef)accessibilityType; | ||
|
||
/** | ||
Sets the accessibility type for all future passwords saved to the Keychain. | ||
@param accessibilityType One of the "Keychain Item Accessibility Constants" | ||
used for determining when a keychain item should be readable. | ||
If the value is `NULL` (the default), the Keychain default will be used. | ||
@see accessibilityType | ||
*/ | ||
+ (void)setAccessibilityType:(CFTypeRef)accessibilityType; | ||
#endif | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
// | ||
// SSKeychain.m | ||
// SSKeychain | ||
// | ||
// Created by Sam Soffes on 5/19/10. | ||
// Copyright (c) 2010-2013 Sam Soffes. All rights reserved. | ||
// | ||
|
||
#import "LPSSKeychain.h" | ||
|
||
NSString *const kLPSSKeychainErrorDomain = @"com.samsoffes.sskeychain"; | ||
NSString *const kLPSSKeychainAccountKey = @"acct"; | ||
NSString *const kLPSSKeychainCreatedAtKey = @"cdat"; | ||
NSString *const kLPSSKeychainClassKey = @"labl"; | ||
NSString *const kLPSSKeychainDescriptionKey = @"desc"; | ||
NSString *const kLPSSKeychainLabelKey = @"labl"; | ||
NSString *const kLPSSKeychainLastModifiedKey = @"mdat"; | ||
NSString *const kLPSSKeychainWhereKey = @"svce"; | ||
|
||
#if __IPHONE_4_0 && TARGET_OS_IPHONE | ||
static CFTypeRef SSKeychainAccessibilityType = NULL; | ||
#endif | ||
|
||
@implementation LPSSKeychain | ||
|
||
+ (NSString *)passwordForService:(NSString *)serviceName account:(NSString *)account { | ||
return [self passwordForService:serviceName account:account error:nil]; | ||
} | ||
|
||
|
||
+ (NSString *)passwordForService:(NSString *)serviceName account:(NSString *)account error:(NSError *__autoreleasing *)error { | ||
LPSSKeychainQuery *query = [[LPSSKeychainQuery alloc] init]; | ||
query.service = serviceName; | ||
query.account = account; | ||
[query fetch:error]; | ||
return query.password; | ||
} | ||
|
||
|
||
+ (BOOL)deletePasswordForService:(NSString *)serviceName account:(NSString *)account { | ||
return [self deletePasswordForService:serviceName account:account error:nil]; | ||
} | ||
|
||
|
||
+ (BOOL)deletePasswordForService:(NSString *)serviceName account:(NSString *)account error:(NSError *__autoreleasing *)error { | ||
LPSSKeychainQuery *query = [[LPSSKeychainQuery alloc] init]; | ||
query.service = serviceName; | ||
query.account = account; | ||
return [query deleteItem:error]; | ||
} | ||
|
||
|
||
+ (BOOL)setPassword:(NSString *)password forService:(NSString *)serviceName account:(NSString *)account { | ||
return [self setPassword:password forService:serviceName account:account error:nil]; | ||
} | ||
|
||
|
||
+ (BOOL)setPassword:(NSString *)password forService:(NSString *)serviceName account:(NSString *)account error:(NSError *__autoreleasing *)error { | ||
LPSSKeychainQuery *query = [[LPSSKeychainQuery alloc] init]; | ||
query.service = serviceName; | ||
query.account = account; | ||
query.password = password; | ||
return [query save:error]; | ||
} | ||
|
||
|
||
+ (NSArray *)allAccounts { | ||
return [self accountsForService:nil]; | ||
} | ||
|
||
|
||
+ (NSArray *)accountsForService:(NSString *)serviceName { | ||
LPSSKeychainQuery *query = [[LPSSKeychainQuery alloc] init]; | ||
query.service = serviceName; | ||
return [query fetchAll:nil]; | ||
} | ||
|
||
|
||
#if __IPHONE_4_0 && TARGET_OS_IPHONE | ||
+ (CFTypeRef)accessibilityType { | ||
return SSKeychainAccessibilityType; | ||
} | ||
|
||
|
||
+ (void)setAccessibilityType:(CFTypeRef)accessibilityType { | ||
CFRetain(accessibilityType); | ||
if (SSKeychainAccessibilityType) { | ||
CFRelease(SSKeychainAccessibilityType); | ||
} | ||
SSKeychainAccessibilityType = accessibilityType; | ||
} | ||
#endif | ||
|
||
@end |
Oops, something went wrong.