Skip to content

Commit

Permalink
Import SSKeychain.
Browse files Browse the repository at this point in the history
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
hydhknn committed Feb 18, 2014
1 parent 5e3ed97 commit bf1c991
Show file tree
Hide file tree
Showing 6 changed files with 653 additions and 0 deletions.
26 changes: 26 additions & 0 deletions calabash.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@
/* End PBXAggregateTarget section */

/* Begin PBXBuildFile section */
52AB9FB718AFF46E00FA3C67 /* LPSSKeychain.h in Headers */ = {isa = PBXBuildFile; fileRef = 52AB9FB318AFF46E00FA3C67 /* LPSSKeychain.h */; };
52AB9FB818AFF46E00FA3C67 /* LPSSKeychain.m in Sources */ = {isa = PBXBuildFile; fileRef = 52AB9FB418AFF46E00FA3C67 /* LPSSKeychain.m */; };
52AB9FB918AFF46E00FA3C67 /* LPSSKeychainQuery.h in Headers */ = {isa = PBXBuildFile; fileRef = 52AB9FB518AFF46E00FA3C67 /* LPSSKeychainQuery.h */; };
52AB9FBA18AFF46E00FA3C67 /* LPSSKeychainQuery.m in Sources */ = {isa = PBXBuildFile; fileRef = 52AB9FB618AFF46E00FA3C67 /* LPSSKeychainQuery.m */; };
692D77A01657010000DE3E53 /* LPExitRoute.h in Headers */ = {isa = PBXBuildFile; fileRef = 692D779E1657010000DE3E53 /* LPExitRoute.h */; };
692D77A11657010000DE3E53 /* LPExitRoute.m in Sources */ = {isa = PBXBuildFile; fileRef = 692D779F1657010000DE3E53 /* LPExitRoute.m */; };
B12179A8165D613100B6DA43 /* LPScreenshotRoute2.h in Headers */ = {isa = PBXBuildFile; fileRef = B12179A6165D613100B6DA43 /* LPScreenshotRoute2.h */; };
Expand Down Expand Up @@ -141,6 +145,11 @@
/* End PBXCopyFilesBuildPhase section */

/* Begin PBXFileReference section */
52AB9FB318AFF46E00FA3C67 /* LPSSKeychain.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LPSSKeychain.h; sourceTree = "<group>"; };
52AB9FB418AFF46E00FA3C67 /* LPSSKeychain.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LPSSKeychain.m; sourceTree = "<group>"; };
52AB9FB518AFF46E00FA3C67 /* LPSSKeychainQuery.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LPSSKeychainQuery.h; sourceTree = "<group>"; };
52AB9FB618AFF46E00FA3C67 /* LPSSKeychainQuery.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LPSSKeychainQuery.m; sourceTree = "<group>"; };
52AB9FBB18AFF47C00FA3C67 /* SSKeychain.LICENSE */ = {isa = PBXFileReference; lastKnownFileType = text; path = SSKeychain.LICENSE; sourceTree = "<group>"; };
692D779E1657010000DE3E53 /* LPExitRoute.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LPExitRoute.h; sourceTree = "<group>"; };
692D779F1657010000DE3E53 /* LPExitRoute.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LPExitRoute.m; sourceTree = "<group>"; };
B111321514D5837900982BBC /* LPAsyncPlaybackRoute.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LPAsyncPlaybackRoute.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -329,6 +338,18 @@
/* End PBXFrameworksBuildPhase section */

/* Begin PBXGroup section */
52AB9FB218AFF45F00FA3C67 /* SSKeychain */ = {
isa = PBXGroup;
children = (
52AB9FB318AFF46E00FA3C67 /* LPSSKeychain.h */,
52AB9FB418AFF46E00FA3C67 /* LPSSKeychain.m */,
52AB9FB518AFF46E00FA3C67 /* LPSSKeychainQuery.h */,
52AB9FB618AFF46E00FA3C67 /* LPSSKeychainQuery.m */,
52AB9FBB18AFF47C00FA3C67 /* SSKeychain.LICENSE */,
);
name = SSKeychain;
sourceTree = "<group>";
};
B116C98214E5214600663205 /* Categories */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -648,6 +669,7 @@
B184FE0B14B6DB2B002A744C /* Utils */ = {
isa = PBXGroup;
children = (
52AB9FB218AFF45F00FA3C67 /* SSKeychain */,
B1F279AD183D5B3000A922BC /* LPUIAChannel.h */,
B1F279AE183D5B3000A922BC /* LPUIAChannel.m */,
B1DDE6D115C0701D00BBE2BE /* UIAutomation.h */,
Expand Down Expand Up @@ -706,6 +728,7 @@
B12DCD87189A998400F8DF87 /* LPDebugRoute.h in Headers */,
B1F279AF183D5B3000A922BC /* LPUIAChannel.h in Headers */,
F5CAC06C180D499600E23F03 /* LPSliderOperation.h in Headers */,
52AB9FB718AFF46E00FA3C67 /* LPSSKeychain.h in Headers */,
B12DCD75189A82DF00F8DF87 /* LPEnv.h in Headers */,
B17E75B615D436100066550B /* CalabashServer.h in Headers */,
B1296FC015DC1F4B005DDF5C /* LPReflectUtils.h in Headers */,
Expand All @@ -714,6 +737,7 @@
B12179A8165D613100B6DA43 /* LPScreenshotRoute2.h in Headers */,
B12DCD79189A833000F8DF87 /* LPLog.h in Headers */,
B1CED0FD183E9562004793B9 /* LPLocationRoute.h in Headers */,
52AB9FB918AFF46E00FA3C67 /* LPSSKeychainQuery.h in Headers */,
B1B19DC816D162CF00D3D80B /* UIScriptASTVisibility.h in Headers */,
B1EBF08816EE63A000AE4D40 /* LPAppPropertyRoute.h in Headers */,
B1EBF08A16EE63A000AE4D40 /* LPQueryLogRoute.h in Headers */,
Expand Down Expand Up @@ -859,6 +883,7 @@
B17E758915D4357F0066550B /* LPHTTPRedirectResponse.m in Sources */,
B17E758A15D4357F0066550B /* LPRouter.m in Sources */,
B17E758B15D4357F0066550B /* LPQueryAllOperation.m in Sources */,
52AB9FBA18AFF46E00FA3C67 /* LPSSKeychainQuery.m in Sources */,
B17E758C15D4357F0066550B /* LPOperation.m in Sources */,
B17E758D15D4357F0066550B /* LPQueryOperation.m in Sources */,
B17E758E15D4357F0066550B /* LPScrollOperation.m in Sources */,
Expand All @@ -874,6 +899,7 @@
B17E759715D4357F0066550B /* LPInterpolateRoute.m in Sources */,
B17E759915D4357F0066550B /* LPRecordRoute.m in Sources */,
B17E759A15D4357F0066550B /* LPMapRoute.m in Sources */,
52AB9FB818AFF46E00FA3C67 /* LPSSKeychain.m in Sources */,
B17E759B15D4357F0066550B /* LPNoContentResponse.m in Sources */,
B17E759C15D4357F0066550B /* LPScreenshotRoute.m in Sources */,
B17E759D15D4357F0066550B /* LPAsyncPlaybackRoute.m in Sources */,
Expand Down
163 changes: 163 additions & 0 deletions calabash/Classes/Utils/LPSSKeychain.h
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
94 changes: 94 additions & 0 deletions calabash/Classes/Utils/LPSSKeychain.m
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
Loading

0 comments on commit bf1c991

Please sign in to comment.