Permalink
Browse files

Removing old keychain stuff. Use SSKeychain.

  • Loading branch information...
1 parent 93a67d7 commit cbee6bbd640614506bccdef2028b4ed91bcba505 @gabriel committed Jun 2, 2012
View
94 Classes/GHKeychainStore.h
@@ -1,94 +0,0 @@
-//
-// GHKeychainStore.h
-// GHKit
-//
-// Copyright 2008 Gabriel Handford
-//
-// Permission is hereby granted, free of charge, to any person
-// obtaining a copy of this software and associated documentation
-// files (the "Software"), to deal in the Software without
-// restriction, including without limitation the rights to use,
-// copy, modify, merge, publish, distribute, sublicense, and/or sell
-// copies of the Software, and to permit persons to whom the
-// Software is furnished to do so, subject to the following
-// conditions:
-//
-// The above copyright notice and this permission notice shall be
-// included in all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
-// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
-// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
-// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-// OTHER DEALINGS IN THE SOFTWARE.
-//
-
-#import <Foundation/Foundation.h>
-
-extern NSString *const GHEMKeychainStoreErrorDomain;
-
-typedef enum {
- GHEMKeychainStoreErrorCodeInvalidSecret = 1
-} GHEMKeychainStoreErrorCode;
-
-/*!
- Protocol for keychain storage.
- */
-@protocol GHKeychainStore <NSObject>
-
-/*!
- Get secret from keychain.
-
- @param serviceName Service name
- @param key Key
- @param error Out error
- @result Secret
- */
-- (NSString *)secretFromKeychainForServiceName:(NSString *)serviceName key:(NSString *)key error:(NSError **)error;
-
-/*!
- Save secret to keychain.
-
- @param serviceName Service name
- @param key Key
- @param secret Secret
- @param error Out error
- @result NO if there was an error, YES otherwise
- */
-- (BOOL)saveToKeychainWithServiceName:(NSString *)serviceName key:(NSString *)key secret:(NSString *)secret error:(NSError **)error;
-
-@end
-
-/*!
- Keychain store adapter which works on both iOS and Mac OS X.
-
- Forwards to:
-
- - GHEMKeychainStore for Mac OS X.
- - GHSFHFKeychainStore for iPhone.
-
-
- Secret from keychain:
-
- GHKeychainStore *keyChainStore = [[GHKeychainStore alloc] init];
- NSError *error = nil;
- NSString *secret = [keyChainStore secretFromKeychainForServiceName:@"MyApp" key:"password" error:&error];
- if (!secret) NSLog(@"Error: %@", [error localizedDescription];
-
- Save to keychain:
-
- GHKeychainStore *keyChainStore = [[GHKeychainStore alloc] init];
- NSError *error = nil;
- BOOL saved = [keyChainStore saveToKeychainWithServiceName:@"MyApp" key:"password" secret:"12345" error:&error];
- if (!saved) NSLog(@"Error: %@", [error localizedDescription];
-
- */
-@interface GHKeychainStore : NSObject <GHKeychainStore> {
- id<GHKeychainStore> _keychainStore;
-}
-
-@end
-
View
148 Classes/GHKeychainStore.m
@@ -1,148 +0,0 @@
-//
-// GHKeychainStore.m
-// GHKit
-//
-// Copyright 2008 Gabriel Handford
-//
-// Permission is hereby granted, free of charge, to any person
-// obtaining a copy of this software and associated documentation
-// files (the "Software"), to deal in the Software without
-// restriction, including without limitation the rights to use,
-// copy, modify, merge, publish, distribute, sublicense, and/or sell
-// copies of the Software, and to permit persons to whom the
-// Software is furnished to do so, subject to the following
-// conditions:
-//
-// The above copyright notice and this permission notice shall be
-// included in all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
-// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
-// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
-// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-// OTHER DEALINGS IN THE SOFTWARE.
-//
-
-#import "GHKeychainStore.h"
-
-#import "GHNSError+Utils.h"
-
-NSString *const GHEMKeychainStoreErrorDomain = @"GHEMKeychainStoreErrorDomain";
-
-// Uses SFHFKeychainUtils (iPhone)
-@interface GHSFHFKeychainStore : NSObject <GHKeychainStore> {}
-@end
-
-// Uses EMKeychainProxy (Cocoa)
-@interface GHEMKeychainStore : NSObject <GHKeychainStore> {}
-@end
-
-@implementation GHKeychainStore
-
-- (id)init {
- if ((self = [super init])) {
-#if TARGET_OS_IPHONE
- _keychainStore = [[GHSFHFKeychainStore alloc] init];
-#else
- _keychainStore = [[GHEMKeychainStore alloc] init];
-#endif
- }
- return self;
-}
-
-- (void)dealloc {
- [_keychainStore release];
- [super dealloc];
-}
-
-- (NSString *)secretFromKeychainForServiceName:(NSString *)serviceName key:(NSString *)key error:(NSError **)error {
- return [_keychainStore secretFromKeychainForServiceName:serviceName key:key error:error];
-}
-
-- (BOOL)saveToKeychainWithServiceName:(NSString *)serviceName key:(NSString *)key secret:(NSString *)secret error:(NSError **)error {
- return [_keychainStore saveToKeychainWithServiceName:serviceName key:key secret:secret error:error];
-}
-
-
-@end
-
-
-#if !TARGET_OS_IPHONE
-
-#import "EMKeychainProxy.h"
-
-@implementation GHEMKeychainStore
-
-- (NSString *)secretFromKeychainForServiceName:(NSString *)serviceName key:(NSString *)key error:(NSError **)error {
- // TODO: Set error on failure modes from EMGenericKeychainItem (which doesn't have any)
- EMGenericKeychainItem *keychainItem = [[EMKeychainProxy sharedProxy] genericKeychainItemForService:serviceName withUsername:key];
- return [keychainItem password];
-}
-
-- (BOOL)saveToKeychainWithServiceName:(NSString *)serviceName key:(NSString *)key secret:(NSString *)secret error:(NSError **)error {
- if (!secret) {
- if (error) *error = [NSError gh_errorWithDomain:GHEMKeychainStoreErrorDomain code:GHEMKeychainStoreErrorCodeInvalidSecret localizedDescription:@"Invalid secret"];
- return NO;
- }
- EMGenericKeychainItem *keychainItem = [[EMKeychainProxy sharedProxy] genericKeychainItemForService:serviceName withUsername:key];
- if (!keychainItem) {
- [[EMKeychainProxy sharedProxy] addGenericKeychainItemForService:serviceName withUsername:key password:secret];
- } else
- [keychainItem setPassword:secret];
-
- return YES;
-}
-
-@end
-
-#endif
-
-
-#if TARGET_OS_IPHONE
-
-@protocol GHKit_SFHFKeychainUtils
-+ (NSString *)getPasswordForUsername:(NSString *)username andServiceName:(NSString *)serviceName error:(NSError **)error;
-+ (void) storeUsername:(NSString *)username andPassword:(NSString *)password forServiceName:(NSString *)serviceName updateExisting:(BOOL)updateExisting error:(NSError **) error;
-@end
-
-@implementation GHSFHFKeychainStore
-
-- (Class)keychainUtilsClass {
- Class keychainUtilsClass = NSClassFromString(@"SFHFKeychainUtils");
- if (keychainUtilsClass == NULL)
- [NSException raise:NSDestinationInvalidException format:@"Must import SFHFKeychainUtils to use the keychain store"];
- return keychainUtilsClass;
-}
-
-- (NSString *)secretFromKeychainForServiceName:(NSString *)serviceName key:(NSString *)key error:(NSError **)error {
-
- if (!error) {
- NSError *errorTmp = nil;
- error = &errorTmp;
- }
-
- return [[self keychainUtilsClass] getPasswordForUsername:key andServiceName:serviceName error:error];
-}
-
-- (BOOL)saveToKeychainWithServiceName:(NSString *)serviceName key:(NSString *)key secret:(NSString *)secret error:(NSError **)error {
- if (!secret) {
- if (error) *error = [NSError gh_errorWithDomain:GHEMKeychainStoreErrorDomain code:GHEMKeychainStoreErrorCodeInvalidSecret localizedDescription:@"Invalid secret"];
- return NO;
- }
-
- if (!error) {
- NSError *errorTmp = nil;
- error = &errorTmp;
- }
-
- [[self keychainUtilsClass] storeUsername:key andPassword:secret forServiceName:serviceName updateExisting:YES error:error];
- if (error && *error) return NO;
- return YES;
-}
-
-@end
-
-#endif
View
56 GHKit.xcodeproj/project.pbxproj
@@ -12,10 +12,6 @@
00D022EA154DF226003BAAC3 /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 00D022E9154DF226003BAAC3 /* Cocoa.framework */; };
00D022FC154DF30E003BAAC3 /* GHCGUtils.h in Headers */ = {isa = PBXBuildFile; fileRef = 00D0227B154DF1C5003BAAC3 /* GHCGUtils.h */; settings = {ATTRIBUTES = (Public, ); }; };
00D022FD154DF30F003BAAC3 /* GHCGUtils.h in Headers */ = {isa = PBXBuildFile; fileRef = 00D0227B154DF1C5003BAAC3 /* GHCGUtils.h */; settings = {ATTRIBUTES = (Public, ); }; };
- 00D022FE154DF316003BAAC3 /* GHKeychainStore.h in Headers */ = {isa = PBXBuildFile; fileRef = 00D0227D154DF1C5003BAAC3 /* GHKeychainStore.h */; settings = {ATTRIBUTES = (Public, ); }; };
- 00D022FF154DF316003BAAC3 /* GHKeychainStore.h in Headers */ = {isa = PBXBuildFile; fileRef = 00D0227D154DF1C5003BAAC3 /* GHKeychainStore.h */; settings = {ATTRIBUTES = (Public, ); }; };
- 00D02300154DF324003BAAC3 /* GHKeychainStore.m in Sources */ = {isa = PBXBuildFile; fileRef = 00D0227E154DF1C5003BAAC3 /* GHKeychainStore.m */; };
- 00D02301154DF324003BAAC3 /* GHKeychainStore.m in Sources */ = {isa = PBXBuildFile; fileRef = 00D0227E154DF1C5003BAAC3 /* GHKeychainStore.m */; };
00D02302154DF328003BAAC3 /* GHCGUtils.m in Sources */ = {isa = PBXBuildFile; fileRef = 00D0227C154DF1C5003BAAC3 /* GHCGUtils.m */; };
00D02303154DF328003BAAC3 /* GHCGUtils.m in Sources */ = {isa = PBXBuildFile; fileRef = 00D0227C154DF1C5003BAAC3 /* GHCGUtils.m */; };
00D02304154DF32C003BAAC3 /* GHKit.h in Headers */ = {isa = PBXBuildFile; fileRef = 00D0227F154DF1C5003BAAC3 /* GHKit.h */; settings = {ATTRIBUTES = (Public, ); }; };
@@ -162,7 +158,6 @@
00D02398154DF67D003BAAC3 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 00D022D7154DF1EB003BAAC3 /* Foundation.framework */; };
00D0239A154DF67D003BAAC3 /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 00D02399154DF67D003BAAC3 /* CoreGraphics.framework */; };
00D023A2154DF67E003BAAC3 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 00D023A1154DF67E003BAAC3 /* main.m */; };
- 00D023B3154DF89A003BAAC3 /* GHEMKeychainStoreTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 00D023AC154DF89A003BAAC3 /* GHEMKeychainStoreTest.m */; };
00D023B4154DF89A003BAAC3 /* GHNSStringEnumeratorTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 00D023AD154DF89A003BAAC3 /* GHNSStringEnumeratorTest.m */; };
00D023B5154DF89A003BAAC3 /* GHNSStringXMLTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 00D023AE154DF89A003BAAC3 /* GHNSStringXMLTest.m */; };
00D023B6154DF89A003BAAC3 /* GHReversableDictionaryTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 00D023AF154DF89A003BAAC3 /* GHReversableDictionaryTest.m */; };
@@ -186,7 +181,6 @@
00D023DB154DF8A5003BAAC3 /* NSURLUtilsTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 00D023C9154DF8A5003BAAC3 /* NSURLUtilsTest.m */; };
00D023DC154DF8A5003BAAC3 /* ReadonlyCopyTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 00D023CA154DF8A5003BAAC3 /* ReadonlyCopyTest.m */; };
00D023DD154DF8BC003BAAC3 /* GHCGUtils.m in Sources */ = {isa = PBXBuildFile; fileRef = 00D0227C154DF1C5003BAAC3 /* GHCGUtils.m */; };
- 00D023DE154DF8BD003BAAC3 /* GHKeychainStore.m in Sources */ = {isa = PBXBuildFile; fileRef = 00D0227E154DF1C5003BAAC3 /* GHKeychainStore.m */; };
00D023DF154DF8C0003BAAC3 /* GHNSArray+Utils.m in Sources */ = {isa = PBXBuildFile; fileRef = 00D02283154DF1C5003BAAC3 /* GHNSArray+Utils.m */; };
00D023E0154DF8C2003BAAC3 /* GHNSBundle+Utils.m in Sources */ = {isa = PBXBuildFile; fileRef = 00D02285154DF1C5003BAAC3 /* GHNSBundle+Utils.m */; };
00D023E1154DF8C4003BAAC3 /* GHNSDate+Formatters.m in Sources */ = {isa = PBXBuildFile; fileRef = 00D02287154DF1C5003BAAC3 /* GHNSDate+Formatters.m */; };
@@ -221,7 +215,6 @@
00D023FE154DF905003BAAC3 /* GHNSObject+Swizzle.m in Sources */ = {isa = PBXBuildFile; fileRef = 00D022CE154DF1C5003BAAC3 /* GHNSObject+Swizzle.m */; };
00D02400154DF93F003BAAC3 /* GHUnitIOS.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 00D023FF154DF93F003BAAC3 /* GHUnitIOS.framework */; };
00D02405154DFA2B003BAAC3 /* GTMBase64.m in Sources */ = {isa = PBXBuildFile; fileRef = 00D02403154DFA2B003BAAC3 /* GTMBase64.m */; };
- 00D02409154DFA55003BAAC3 /* SFHFKeychainUtils.m in Sources */ = {isa = PBXBuildFile; fileRef = 00D02408154DFA55003BAAC3 /* SFHFKeychainUtils.m */; };
00D0240B154DFA69003BAAC3 /* Security.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 00D0240A154DFA67003BAAC3 /* Security.framework */; };
00D0240E154DFA87003BAAC3 /* GTMRegex.m in Sources */ = {isa = PBXBuildFile; fileRef = 00D0240D154DFA87003BAAC3 /* GTMRegex.m */; };
00D02410154DFAC0003BAAC3 /* test.file in Resources */ = {isa = PBXBuildFile; fileRef = 00D0240F154DFABF003BAAC3 /* test.file */; };
@@ -230,7 +223,6 @@
00D0242E154DFB82003BAAC3 /* GHUnit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 00D0242D154DFB82003BAAC3 /* GHUnit.framework */; };
00D02430154DFBD6003BAAC3 /* GHUnit.framework in CopyFiles */ = {isa = PBXBuildFile; fileRef = 00D0242D154DFB82003BAAC3 /* GHUnit.framework */; };
00D02431154DFC82003BAAC3 /* GHCGUtils.m in Sources */ = {isa = PBXBuildFile; fileRef = 00D0227C154DF1C5003BAAC3 /* GHCGUtils.m */; };
- 00D02432154DFC84003BAAC3 /* GHKeychainStore.m in Sources */ = {isa = PBXBuildFile; fileRef = 00D0227E154DF1C5003BAAC3 /* GHKeychainStore.m */; };
00D02433154DFC87003BAAC3 /* GHNSArray+Utils.m in Sources */ = {isa = PBXBuildFile; fileRef = 00D02283154DF1C5003BAAC3 /* GHNSArray+Utils.m */; };
00D02434154DFC89003BAAC3 /* GHNSBundle+Utils.m in Sources */ = {isa = PBXBuildFile; fileRef = 00D02285154DF1C5003BAAC3 /* GHNSBundle+Utils.m */; };
00D02435154DFC8B003BAAC3 /* GHNSDate+Formatters.m in Sources */ = {isa = PBXBuildFile; fileRef = 00D02287154DF1C5003BAAC3 /* GHNSDate+Formatters.m */; };
@@ -267,8 +259,6 @@
00D02454154DFCDC003BAAC3 /* sha1.c in Sources */ = {isa = PBXBuildFile; fileRef = 00D022CA154DF1C5003BAAC3 /* sha1.c */; };
00D02455154DFCDF003BAAC3 /* GHNSObject+Swizzle.m in Sources */ = {isa = PBXBuildFile; fileRef = 00D022CE154DF1C5003BAAC3 /* GHNSObject+Swizzle.m */; };
00D02457154DFD36003BAAC3 /* GHNSAttributedStringTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 00D02456154DFD36003BAAC3 /* GHNSAttributedStringTest.m */; };
- 00D0245D154DFD66003BAAC3 /* EMKeychainItem.m in Sources */ = {isa = PBXBuildFile; fileRef = 00D0245A154DFD66003BAAC3 /* EMKeychainItem.m */; };
- 00D0245E154DFD66003BAAC3 /* EMKeychainProxy.m in Sources */ = {isa = PBXBuildFile; fileRef = 00D0245C154DFD66003BAAC3 /* EMKeychainProxy.m */; };
00D02460154DFD95003BAAC3 /* Security.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 00D0245F154DFD92003BAAC3 /* Security.framework */; };
00D02461154DFDA3003BAAC3 /* NSArrayUtilsTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 00D023B9154DF8A4003BAAC3 /* NSArrayUtilsTest.m */; };
00D02462154DFDA6003BAAC3 /* NSDateParsingTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 00D023BA154DF8A4003BAAC3 /* NSDateParsingTest.m */; };
@@ -287,7 +277,6 @@
00D0246F154DFDC1003BAAC3 /* NSStringUtilsTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 00D023C8154DF8A5003BAAC3 /* NSStringUtilsTest.m */; };
00D02470154DFDC3003BAAC3 /* NSURLUtilsTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 00D023C9154DF8A5003BAAC3 /* NSURLUtilsTest.m */; };
00D02471154DFDC5003BAAC3 /* ReadonlyCopyTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 00D023CA154DF8A5003BAAC3 /* ReadonlyCopyTest.m */; };
- 00D02472154DFDC7003BAAC3 /* GHEMKeychainStoreTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 00D023AC154DF89A003BAAC3 /* GHEMKeychainStoreTest.m */; };
00D02473154DFDC9003BAAC3 /* GHNSStringEnumeratorTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 00D023AD154DF89A003BAAC3 /* GHNSStringEnumeratorTest.m */; };
00D02474154DFDCB003BAAC3 /* GHNSStringXMLTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 00D023AE154DF89A003BAAC3 /* GHNSStringXMLTest.m */; };
00D02475154DFDCD003BAAC3 /* GHReversableDictionaryTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 00D023AF154DF89A003BAAC3 /* GHReversableDictionaryTest.m */; };
@@ -314,8 +303,6 @@
007DA669154E055C008574F9 /* GHKit-Prefix.pch */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "GHKit-Prefix.pch"; sourceTree = "<group>"; };
00D0227B154DF1C5003BAAC3 /* GHCGUtils.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GHCGUtils.h; sourceTree = "<group>"; };
00D0227C154DF1C5003BAAC3 /* GHCGUtils.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = GHCGUtils.m; sourceTree = "<group>"; };
- 00D0227D154DF1C5003BAAC3 /* GHKeychainStore.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GHKeychainStore.h; sourceTree = "<group>"; };
- 00D0227E154DF1C5003BAAC3 /* GHKeychainStore.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = GHKeychainStore.m; sourceTree = "<group>"; };
00D0227F154DF1C5003BAAC3 /* GHKit.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GHKit.h; sourceTree = "<group>"; };
00D02280154DF1C5003BAAC3 /* GHKitDefines.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GHKitDefines.h; sourceTree = "<group>"; };
00D02281154DF1C5003BAAC3 /* GHKitIOS.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GHKitIOS.h; sourceTree = "<group>"; };
@@ -406,7 +393,6 @@
00D0239D154DF67E003BAAC3 /* Tests-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "Tests-Info.plist"; sourceTree = "<group>"; };
00D023A1154DF67E003BAAC3 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = "<group>"; };
00D023A3154DF67E003BAAC3 /* Tests-Prefix.pch */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "Tests-Prefix.pch"; sourceTree = "<group>"; };
- 00D023AC154DF89A003BAAC3 /* GHEMKeychainStoreTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GHEMKeychainStoreTest.m; sourceTree = "<group>"; };
00D023AD154DF89A003BAAC3 /* GHNSStringEnumeratorTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GHNSStringEnumeratorTest.m; sourceTree = "<group>"; };
00D023AE154DF89A003BAAC3 /* GHNSStringXMLTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GHNSStringXMLTest.m; sourceTree = "<group>"; };
00D023AF154DF89A003BAAC3 /* GHReversableDictionaryTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GHReversableDictionaryTest.m; sourceTree = "<group>"; };
@@ -433,8 +419,6 @@
00D02402154DFA2B003BAAC3 /* GTMBase64.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GTMBase64.h; sourceTree = "<group>"; };
00D02403154DFA2B003BAAC3 /* GTMBase64.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GTMBase64.m; sourceTree = "<group>"; };
00D02404154DFA2B003BAAC3 /* GTMDefines.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GTMDefines.h; sourceTree = "<group>"; };
- 00D02407154DFA55003BAAC3 /* SFHFKeychainUtils.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SFHFKeychainUtils.h; sourceTree = "<group>"; };
- 00D02408154DFA55003BAAC3 /* SFHFKeychainUtils.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SFHFKeychainUtils.m; sourceTree = "<group>"; };
00D0240A154DFA67003BAAC3 /* Security.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Security.framework; path = Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.1.sdk/System/Library/Frameworks/Security.framework; sourceTree = DEVELOPER_DIR; };
00D0240C154DFA87003BAAC3 /* GTMRegex.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GTMRegex.h; sourceTree = "<group>"; };
00D0240D154DFA87003BAAC3 /* GTMRegex.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GTMRegex.m; sourceTree = "<group>"; };
@@ -445,10 +429,6 @@
00D02420154DFB0D003BAAC3 /* TestsFramework-Prefix.pch */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "TestsFramework-Prefix.pch"; sourceTree = "<group>"; };
00D0242D154DFB82003BAAC3 /* GHUnit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = GHUnit.framework; path = Frameworks/GHUnit.framework; sourceTree = "<group>"; };
00D02456154DFD36003BAAC3 /* GHNSAttributedStringTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GHNSAttributedStringTest.m; sourceTree = "<group>"; };
- 00D02459154DFD66003BAAC3 /* EMKeychainItem.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = EMKeychainItem.h; sourceTree = "<group>"; };
- 00D0245A154DFD66003BAAC3 /* EMKeychainItem.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = EMKeychainItem.m; sourceTree = "<group>"; };
- 00D0245B154DFD66003BAAC3 /* EMKeychainProxy.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = EMKeychainProxy.h; sourceTree = "<group>"; };
- 00D0245C154DFD66003BAAC3 /* EMKeychainProxy.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = EMKeychainProxy.m; sourceTree = "<group>"; };
00D0245F154DFD92003BAAC3 /* Security.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Security.framework; path = Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.7.sdk/System/Library/Frameworks/Security.framework; sourceTree = DEVELOPER_DIR; };
00D0247A154DFE94003BAAC3 /* README.md */ = {isa = PBXFileReference; lastKnownFileType = text; path = README.md; sourceTree = "<group>"; };
/* End PBXFileReference section */
@@ -512,8 +492,6 @@
children = (
00D0227B154DF1C5003BAAC3 /* GHCGUtils.h */,
00D0227C154DF1C5003BAAC3 /* GHCGUtils.m */,
- 00D0227D154DF1C5003BAAC3 /* GHKeychainStore.h */,
- 00D0227E154DF1C5003BAAC3 /* GHKeychainStore.m */,
00D0227F154DF1C5003BAAC3 /* GHKit.h */,
00D02280154DF1C5003BAAC3 /* GHKitDefines.h */,
00D02281154DF1C5003BAAC3 /* GHKitIOS.h */,
@@ -660,7 +638,6 @@
00D0239B154DF67D003BAAC3 /* Tests */ = {
isa = PBXGroup;
children = (
- 00D02406154DFA55003BAAC3 /* SFHF */,
00D02401154DFA2B003BAAC3 /* GTM */,
00D023B9154DF8A4003BAAC3 /* NSArrayUtilsTest.m */,
00D023BA154DF8A4003BAAC3 /* NSDateParsingTest.m */,
@@ -679,7 +656,6 @@
00D023C8154DF8A5003BAAC3 /* NSStringUtilsTest.m */,
00D023C9154DF8A5003BAAC3 /* NSURLUtilsTest.m */,
00D023CA154DF8A5003BAAC3 /* ReadonlyCopyTest.m */,
- 00D023AC154DF89A003BAAC3 /* GHEMKeychainStoreTest.m */,
00D023AD154DF89A003BAAC3 /* GHNSStringEnumeratorTest.m */,
00D023AE154DF89A003BAAC3 /* GHNSStringXMLTest.m */,
00D023AF154DF89A003BAAC3 /* GHReversableDictionaryTest.m */,
@@ -721,19 +697,9 @@
path = GTM;
sourceTree = "<group>";
};
- 00D02406154DFA55003BAAC3 /* SFHF */ = {
- isa = PBXGroup;
- children = (
- 00D02407154DFA55003BAAC3 /* SFHFKeychainUtils.h */,
- 00D02408154DFA55003BAAC3 /* SFHFKeychainUtils.m */,
- );
- path = SFHF;
- sourceTree = "<group>";
- };
00D02418154DFB0C003BAAC3 /* TestsFramework */ = {
isa = PBXGroup;
children = (
- 00D02458154DFD65003BAAC3 /* ExtendMac */,
00D02456154DFD36003BAAC3 /* GHNSAttributedStringTest.m */,
00D02419154DFB0D003BAAC3 /* Supporting Files */,
);
@@ -750,17 +716,6 @@
name = "Supporting Files";
sourceTree = "<group>";
};
- 00D02458154DFD65003BAAC3 /* ExtendMac */ = {
- isa = PBXGroup;
- children = (
- 00D02459154DFD66003BAAC3 /* EMKeychainItem.h */,
- 00D0245A154DFD66003BAAC3 /* EMKeychainItem.m */,
- 00D0245B154DFD66003BAAC3 /* EMKeychainProxy.h */,
- 00D0245C154DFD66003BAAC3 /* EMKeychainProxy.m */,
- );
- path = ExtendMac;
- sourceTree = "<group>";
- };
/* End PBXGroup section */
/* Begin PBXHeadersBuildPhase section */
@@ -769,7 +724,6 @@
buildActionMask = 2147483647;
files = (
00D022FC154DF30E003BAAC3 /* GHCGUtils.h in Headers */,
- 00D022FE154DF316003BAAC3 /* GHKeychainStore.h in Headers */,
00D02304154DF32C003BAAC3 /* GHKit.h in Headers */,
00D02306154DF333003BAAC3 /* GHKitDefines.h in Headers */,
00D02308154DF339003BAAC3 /* GHKitIOS.h in Headers */,
@@ -814,7 +768,6 @@
buildActionMask = 2147483647;
files = (
00D022FD154DF30F003BAAC3 /* GHCGUtils.h in Headers */,
- 00D022FF154DF316003BAAC3 /* GHKeychainStore.h in Headers */,
00D02305154DF32C003BAAC3 /* GHKit.h in Headers */,
00D02307154DF334003BAAC3 /* GHKitDefines.h in Headers */,
00D02309154DF339003BAAC3 /* GHKitIOS.h in Headers */,
@@ -990,7 +943,6 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
- 00D02300154DF324003BAAC3 /* GHKeychainStore.m in Sources */,
00D02302154DF328003BAAC3 /* GHCGUtils.m in Sources */,
00D0230C154DF356003BAAC3 /* GHNSArray+Utils.m in Sources */,
00D02310154DF35D003BAAC3 /* GHNSBundle+Utils.m in Sources */,
@@ -1031,7 +983,6 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
- 00D02301154DF324003BAAC3 /* GHKeychainStore.m in Sources */,
00D02303154DF328003BAAC3 /* GHCGUtils.m in Sources */,
00D0230D154DF356003BAAC3 /* GHNSArray+Utils.m in Sources */,
00D02311154DF35D003BAAC3 /* GHNSBundle+Utils.m in Sources */,
@@ -1076,7 +1027,6 @@
buildActionMask = 2147483647;
files = (
00D023A2154DF67E003BAAC3 /* main.m in Sources */,
- 00D023B3154DF89A003BAAC3 /* GHEMKeychainStoreTest.m in Sources */,
00D023B4154DF89A003BAAC3 /* GHNSStringEnumeratorTest.m in Sources */,
00D023B5154DF89A003BAAC3 /* GHNSStringXMLTest.m in Sources */,
00D023B6154DF89A003BAAC3 /* GHReversableDictionaryTest.m in Sources */,
@@ -1100,7 +1050,6 @@
00D023DB154DF8A5003BAAC3 /* NSURLUtilsTest.m in Sources */,
00D023DC154DF8A5003BAAC3 /* ReadonlyCopyTest.m in Sources */,
00D023DD154DF8BC003BAAC3 /* GHCGUtils.m in Sources */,
- 00D023DE154DF8BD003BAAC3 /* GHKeychainStore.m in Sources */,
00D023DF154DF8C0003BAAC3 /* GHNSArray+Utils.m in Sources */,
00D023E0154DF8C2003BAAC3 /* GHNSBundle+Utils.m in Sources */,
00D023E1154DF8C4003BAAC3 /* GHNSDate+Formatters.m in Sources */,
@@ -1134,7 +1083,6 @@
00D023FD154DF902003BAAC3 /* sha1.c in Sources */,
00D023FE154DF905003BAAC3 /* GHNSObject+Swizzle.m in Sources */,
00D02405154DFA2B003BAAC3 /* GTMBase64.m in Sources */,
- 00D02409154DFA55003BAAC3 /* SFHFKeychainUtils.m in Sources */,
00D0240E154DFA87003BAAC3 /* GTMRegex.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
@@ -1145,7 +1093,6 @@
files = (
00D0241F154DFB0D003BAAC3 /* main.m in Sources */,
00D02431154DFC82003BAAC3 /* GHCGUtils.m in Sources */,
- 00D02432154DFC84003BAAC3 /* GHKeychainStore.m in Sources */,
00D02433154DFC87003BAAC3 /* GHNSArray+Utils.m in Sources */,
00D02434154DFC89003BAAC3 /* GHNSBundle+Utils.m in Sources */,
00D02435154DFC8B003BAAC3 /* GHNSDate+Formatters.m in Sources */,
@@ -1182,8 +1129,6 @@
00D02454154DFCDC003BAAC3 /* sha1.c in Sources */,
00D02455154DFCDF003BAAC3 /* GHNSObject+Swizzle.m in Sources */,
00D02457154DFD36003BAAC3 /* GHNSAttributedStringTest.m in Sources */,
- 00D0245D154DFD66003BAAC3 /* EMKeychainItem.m in Sources */,
- 00D0245E154DFD66003BAAC3 /* EMKeychainProxy.m in Sources */,
00D02461154DFDA3003BAAC3 /* NSArrayUtilsTest.m in Sources */,
00D02462154DFDA6003BAAC3 /* NSDateParsingTest.m in Sources */,
00D02463154DFDA8003BAAC3 /* NSDateUtilsTest.m in Sources */,
@@ -1201,7 +1146,6 @@
00D0246F154DFDC1003BAAC3 /* NSStringUtilsTest.m in Sources */,
00D02470154DFDC3003BAAC3 /* NSURLUtilsTest.m in Sources */,
00D02471154DFDC5003BAAC3 /* ReadonlyCopyTest.m in Sources */,
- 00D02472154DFDC7003BAAC3 /* GHEMKeychainStoreTest.m in Sources */,
00D02473154DFDC9003BAAC3 /* GHNSStringEnumeratorTest.m in Sources */,
00D02474154DFDCB003BAAC3 /* GHNSStringXMLTest.m in Sources */,
00D02475154DFDCD003BAAC3 /* GHReversableDictionaryTest.m in Sources */,
View
53 Tests/GHEMKeychainStoreTest.m
@@ -1,53 +0,0 @@
-//
-// GHEMKeychainStoreTest.m
-// GHKit
-//
-// Created by Gabriel Handford on 9/12/09.
-// Copyright 2009. All rights reserved.
-//
-
-#import "GHKeychainStore.h"
-
-@interface GHKeychainStoreTest : GHTestCase { }
-@end
-
-
-@implementation GHKeychainStoreTest
-
-- (void)testSave {
-
- GHKeychainStore *keychainStore = [[GHKeychainStore alloc] init];
- BOOL saved = [keychainStore saveToKeychainWithServiceName:@"GHEMKeychainStoreTest" key:@"TestKey" secret:@"TestSecret" error:nil];
- GHAssertTrue(saved, nil); // Jesus saves, I spend
-
- NSString *secret = [keychainStore secretFromKeychainForServiceName:@"GHEMKeychainStoreTest" key:@"TestKey" error:nil];
- GHAssertEqualStrings(secret, @"TestSecret", nil);
-
- [keychainStore release];
-
-}
-
-- (void)testErrorInvalidSecret {
-
- GHKeychainStore *keychainStore = [[GHKeychainStore alloc] init];
- NSError *error = nil;
- BOOL saved = [keychainStore saveToKeychainWithServiceName:@"GHEMKeychainStoreTest" key:@"TestKey" secret:nil error:&error];
- GHAssertFalse(saved, nil);
- GHAssertNotNil(error, nil);
- GHAssertTrue([error code] == 1, nil);
-
- [keychainStore release];
-}
-
-- (void)testSaveEmpty {
-
- GHKeychainStore *keychainStore = [[GHKeychainStore alloc] init];
- NSError *error = nil;
- BOOL saved = [keychainStore saveToKeychainWithServiceName:@"GHEMKeychainStoreTest" key:@"TestKey" secret:@"" error:&error];
- GHAssertTrue(saved, nil);
-
- [keychainStore release];
-}
-
-
-@end
View
41 Tests/SFHF/SFHFKeychainUtils.h
@@ -1,41 +0,0 @@
-//
-// SFHFKeychainUtils.h
-//
-// Created by Buzz Andersen on 10/20/08.
-// Based partly on code by Jonathan Wight, Jon Crosby, and Mike Malone.
-// Copyright 2008 Sci-Fi Hi-Fi. All rights reserved.
-//
-// Permission is hereby granted, free of charge, to any person
-// obtaining a copy of this software and associated documentation
-// files (the "Software"), to deal in the Software without
-// restriction, including without limitation the rights to use,
-// copy, modify, merge, publish, distribute, sublicense, and/or sell
-// copies of the Software, and to permit persons to whom the
-// Software is furnished to do so, subject to the following
-// conditions:
-//
-// The above copyright notice and this permission notice shall be
-// included in all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
-// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
-// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
-// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-// OTHER DEALINGS IN THE SOFTWARE.
-//
-
-#import <UIKit/UIKit.h>
-
-
-@interface SFHFKeychainUtils : NSObject {
-
-}
-
-+ (NSString *) getPasswordForUsername: (NSString *) username andServiceName: (NSString *) serviceName error: (NSError **) error;
-+ (void) storeUsername: (NSString *) username andPassword: (NSString *) password forServiceName: (NSString *) serviceName updateExisting: (BOOL) updateExisting error: (NSError **) error;
-+ (void) deleteItemForUsername: (NSString *) username andServiceName: (NSString *) serviceName error: (NSError **) error;
-
-@end
View
384 Tests/SFHF/SFHFKeychainUtils.m
@@ -1,384 +0,0 @@
-//
-// SFHFKeychainUtils.m
-//
-// Created by Buzz Andersen on 10/20/08.
-// Based partly on code by Jonathan Wight, Jon Crosby, and Mike Malone.
-// Copyright 2008 Sci-Fi Hi-Fi. All rights reserved.
-//
-// Permission is hereby granted, free of charge, to any person
-// obtaining a copy of this software and associated documentation
-// files (the "Software"), to deal in the Software without
-// restriction, including without limitation the rights to use,
-// copy, modify, merge, publish, distribute, sublicense, and/or sell
-// copies of the Software, and to permit persons to whom the
-// Software is furnished to do so, subject to the following
-// conditions:
-//
-// The above copyright notice and this permission notice shall be
-// included in all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
-// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
-// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
-// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-// OTHER DEALINGS IN THE SOFTWARE.
-//
-
-#import "SFHFKeychainUtils.h"
-#import <Security/Security.h>
-
-static NSString *SFHFKeychainUtilsErrorDomain = @"SFHFKeychainUtilsErrorDomain";
-
-#if __IPHONE_OS_VERSION_MIN_REQUIRED < 30000 && TARGET_IPHONE_SIMULATOR
-@interface SFHFKeychainUtils (PrivateMethods)
-+ (SecKeychainItemRef) getKeychainItemReferenceForUsername: (NSString *) username andServiceName: (NSString *) serviceName error: (NSError **) error;
-@end
-#endif
-
-@implementation SFHFKeychainUtils
-
-#if __IPHONE_OS_VERSION_MIN_REQUIRED < 30000 && TARGET_IPHONE_SIMULATOR
-
-+ (NSString *) getPasswordForUsername: (NSString *) username andServiceName: (NSString *) serviceName error: (NSError **) error {
- if (!username || !serviceName) {
- *error = [NSError errorWithDomain: SFHFKeychainUtilsErrorDomain code: -2000 userInfo: nil];
- return nil;
- }
-
- SecKeychainItemRef item = [SFHFKeychainUtils getKeychainItemReferenceForUsername: username andServiceName: serviceName error: error];
-
- if (*error || !item) {
- return nil;
- }
-
- // from Advanced Mac OS X Programming, ch. 16
- UInt32 length;
- char *password;
- SecKeychainAttribute attributes[8];
- SecKeychainAttributeList list;
-
- attributes[0].tag = kSecAccountItemAttr;
- attributes[1].tag = kSecDescriptionItemAttr;
- attributes[2].tag = kSecLabelItemAttr;
- attributes[3].tag = kSecModDateItemAttr;
-
- list.count = 4;
- list.attr = attributes;
-
- OSStatus status = SecKeychainItemCopyContent(item, NULL, &list, &length, (void **)&password);
-
- if (status != noErr) {
- *error = [NSError errorWithDomain: SFHFKeychainUtilsErrorDomain code: status userInfo: nil];
- return nil;
- }
-
- NSString *passwordString = nil;
-
- if (password != NULL) {
- char passwordBuffer[1024];
-
- if (length > 1023) {
- length = 1023;
- }
- strncpy(passwordBuffer, password, length);
-
- passwordBuffer[length] = '\0';
- passwordString = [NSString stringWithCString:passwordBuffer];
- }
-
- SecKeychainItemFreeContent(&list, password);
-
- CFRelease(item);
-
- return passwordString;
-}
-
-+ (void) storeUsername: (NSString *) username andPassword: (NSString *) password forServiceName: (NSString *) serviceName updateExisting: (BOOL) updateExisting error: (NSError **) error {
- if (!username || !password || !serviceName) {
- *error = [NSError errorWithDomain: SFHFKeychainUtilsErrorDomain code: -2000 userInfo: nil];
- return;
- }
-
- OSStatus status = noErr;
-
- SecKeychainItemRef item = [SFHFKeychainUtils getKeychainItemReferenceForUsername: username andServiceName: serviceName error: error];
-
- if (*error && [*error code] != noErr) {
- return;
- }
-
- *error = nil;
-
- if (item) {
- status = SecKeychainItemModifyAttributesAndData(item,
- NULL,
- strlen([password UTF8String]),
- [password UTF8String]);
-
- CFRelease(item);
- }
- else {
- status = SecKeychainAddGenericPassword(NULL,
- strlen([serviceName UTF8String]),
- [serviceName UTF8String],
- strlen([username UTF8String]),
- [username UTF8String],
- strlen([password UTF8String]),
- [password UTF8String],
- NULL);
- }
-
- if (status != noErr) {
- *error = [NSError errorWithDomain: SFHFKeychainUtilsErrorDomain code: status userInfo: nil];
- }
-}
-
-+ (void) deleteItemForUsername: (NSString *) username andServiceName: (NSString *) serviceName error: (NSError **) error {
- if (!username || !serviceName) {
- *error = [NSError errorWithDomain: SFHFKeychainUtilsErrorDomain code: 2000 userInfo: nil];
- return;
- }
-
- *error = nil;
-
- SecKeychainItemRef item = [SFHFKeychainUtils getKeychainItemReferenceForUsername: username andServiceName: serviceName error: error];
-
- if (*error && [*error code] != noErr) {
- return;
- }
-
- OSStatus status;
-
- if (item) {
- status = SecKeychainItemDelete(item);
-
- CFRelease(item);
- }
-
- if (status != noErr) {
- *error = [NSError errorWithDomain: SFHFKeychainUtilsErrorDomain code: status userInfo: nil];
- }
-}
-
-+ (SecKeychainItemRef) getKeychainItemReferenceForUsername: (NSString *) username andServiceName: (NSString *) serviceName error: (NSError **) error {
- if (!username || !serviceName) {
- *error = [NSError errorWithDomain: SFHFKeychainUtilsErrorDomain code: -2000 userInfo: nil];
- return nil;
- }
-
- *error = nil;
-
- SecKeychainItemRef item;
-
- OSStatus status = SecKeychainFindGenericPassword(NULL,
- strlen([serviceName UTF8String]),
- [serviceName UTF8String],
- strlen([username UTF8String]),
- [username UTF8String],
- NULL,
- NULL,
- &item);
-
- if (status != noErr) {
- if (status != errSecItemNotFound) {
- *error = [NSError errorWithDomain: SFHFKeychainUtilsErrorDomain code: status userInfo: nil];
- }
-
- return nil;
- }
-
- return item;
-}
-
-#else
-
-+ (NSString *) getPasswordForUsername: (NSString *) username andServiceName: (NSString *) serviceName error: (NSError **) error {
- if (!username || !serviceName) {
- *error = [NSError errorWithDomain: SFHFKeychainUtilsErrorDomain code: -2000 userInfo: nil];
- return nil;
- }
-
- *error = nil;
-
- // Set up a query dictionary with the base query attributes: item type (generic), username, and service
-
- NSArray *keys = [[[NSArray alloc] initWithObjects: (NSString *) kSecClass, kSecAttrAccount, kSecAttrService, nil] autorelease];
- NSArray *objects = [[[NSArray alloc] initWithObjects: (NSString *) kSecClassGenericPassword, username, serviceName, nil] autorelease];
-
- NSMutableDictionary *query = [[[NSMutableDictionary alloc] initWithObjects: objects forKeys: keys] autorelease];
-
- // First do a query for attributes, in case we already have a Keychain item with no password data set.
- // One likely way such an incorrect item could have come about is due to the previous (incorrect)
- // version of this code (which set the password as a generic attribute instead of password data).
-
- NSDictionary *attributeResult = NULL;
- NSMutableDictionary *attributeQuery = [query mutableCopy];
- [attributeQuery setObject: (id) kCFBooleanTrue forKey:(id) kSecReturnAttributes];
- OSStatus status = SecItemCopyMatching((CFDictionaryRef) attributeQuery, (CFTypeRef *) &attributeResult);
-
- [attributeResult release];
- [attributeQuery release];
-
- if (status != noErr) {
- // No existing item found--simply return nil for the password
- if (status != errSecItemNotFound) {
- //Only return an error if a real exception happened--not simply for "not found."
- *error = [NSError errorWithDomain: SFHFKeychainUtilsErrorDomain code: status userInfo: nil];
- }
-
- return nil;
- }
-
- // We have an existing item, now query for the password data associated with it.
-
- NSData *resultData = nil;
- NSMutableDictionary *passwordQuery = [query mutableCopy];
- [passwordQuery setObject: (id) kCFBooleanTrue forKey: (id) kSecReturnData];
-
- status = SecItemCopyMatching((CFDictionaryRef) passwordQuery, (CFTypeRef *) &resultData);
-
- [resultData autorelease];
- [passwordQuery release];
-
- if (status != noErr) {
- if (status == errSecItemNotFound) {
- // We found attributes for the item previously, but no password now, so return a special error.
- // Users of this API will probably want to detect this error and prompt the user to
- // re-enter their credentials. When you attempt to store the re-entered credentials
- // using storeUsername:andPassword:forServiceName:updateExisting:error
- // the old, incorrect entry will be deleted and a new one with a properly encrypted
- // password will be added.
- *error = [NSError errorWithDomain: SFHFKeychainUtilsErrorDomain code: -1999 userInfo: nil];
- }
- else {
- // Something else went wrong. Simply return the normal Keychain API error code.
- *error = [NSError errorWithDomain: SFHFKeychainUtilsErrorDomain code: status userInfo: nil];
- }
-
- return nil;
- }
-
- NSString *password = nil;
-
- if (resultData) {
- password = [[NSString alloc] initWithData: resultData encoding: NSUTF8StringEncoding];
- }
- else {
- // There is an existing item, but we weren't able to get password data for it for some reason,
- // Possibly as a result of an item being incorrectly entered by the previous code.
- // Set the -1999 error so the code above us can prompt the user again.
- *error = [NSError errorWithDomain: SFHFKeychainUtilsErrorDomain code: -1999 userInfo: nil];
- }
-
- return [password autorelease];
-}
-
-+ (void) storeUsername: (NSString *) username andPassword: (NSString *) password forServiceName: (NSString *) serviceName updateExisting: (BOOL) updateExisting error: (NSError **) error {
- if (!username || !password || !serviceName) {
- *error = [NSError errorWithDomain: SFHFKeychainUtilsErrorDomain code: -2000 userInfo: nil];
- return;
- }
-
- // See if we already have a password entered for these credentials.
-
- NSString *existingPassword = [SFHFKeychainUtils getPasswordForUsername: username andServiceName: serviceName error: error];
-
- if ([*error code] == -1999) {
- // There is an existing entry without a password properly stored (possibly as a result of the previous incorrect version of this code.
- // Delete the existing item before moving on entering a correct one.
-
- *error = nil;
-
- [self deleteItemForUsername: username andServiceName: serviceName error: error];
-
- if ([*error code] != noErr) {
- return;
- }
- }
- else if ([*error code] != noErr) {
- return;
- }
-
- *error = nil;
-
- OSStatus status = noErr;
-
- if (existingPassword) {
- // We have an existing, properly entered item with a password.
- // Update the existing item.
-
- if ((existingPassword != password) && updateExisting) {
- //Only update if we're allowed to update existing. If not, simply do nothing.
-
- NSArray *keys = [[[NSArray alloc] initWithObjects: (NSString *) kSecClass,
- kSecAttrService,
- kSecAttrLabel,
- kSecAttrAccount,
- nil] autorelease];
-
- NSArray *objects = [[[NSArray alloc] initWithObjects: (NSString *) kSecClassGenericPassword,
- serviceName,
- serviceName,
- username,
- nil] autorelease];
-
- NSDictionary *query = [[[NSDictionary alloc] initWithObjects: objects forKeys: keys] autorelease];
-
- status = SecItemUpdate((CFDictionaryRef) query, (CFDictionaryRef) [NSDictionary dictionaryWithObject: [password dataUsingEncoding: NSUTF8StringEncoding] forKey: (NSString *) kSecValueData]);
- }
- }
- else {
- // No existing entry (or an existing, improperly entered, and therefore now
- // deleted, entry). Create a new entry.
-
- NSArray *keys = [[[NSArray alloc] initWithObjects: (NSString *) kSecClass,
- kSecAttrService,
- kSecAttrLabel,
- kSecAttrAccount,
- kSecValueData,
- nil] autorelease];
-
- NSArray *objects = [[[NSArray alloc] initWithObjects: (NSString *) kSecClassGenericPassword,
- serviceName,
- serviceName,
- username,
- [password dataUsingEncoding: NSUTF8StringEncoding],
- nil] autorelease];
-
- NSDictionary *query = [[[NSDictionary alloc] initWithObjects: objects forKeys: keys] autorelease];
-
- status = SecItemAdd((CFDictionaryRef) query, NULL);
- }
-
- if (status != noErr) {
- // Something went wrong with adding the new item. Return the Keychain error code.
- *error = [NSError errorWithDomain: SFHFKeychainUtilsErrorDomain code: status userInfo: nil];
- }
-}
-
-+ (void) deleteItemForUsername: (NSString *) username andServiceName: (NSString *) serviceName error: (NSError **) error {
- if (!username || !serviceName) {
- *error = [NSError errorWithDomain: SFHFKeychainUtilsErrorDomain code: -2000 userInfo: nil];
- return;
- }
-
- *error = nil;
-
- NSArray *keys = [[[NSArray alloc] initWithObjects: (NSString *) kSecClass, kSecAttrAccount, kSecAttrService, kSecReturnAttributes, nil] autorelease];
- NSArray *objects = [[[NSArray alloc] initWithObjects: (NSString *) kSecClassGenericPassword, username, serviceName, kCFBooleanTrue, nil] autorelease];
-
- NSDictionary *query = [[[NSDictionary alloc] initWithObjects: objects forKeys: keys] autorelease];
-
- OSStatus status = SecItemDelete((CFDictionaryRef) query);
-
- if (status != noErr) {
- *error = [NSError errorWithDomain: SFHFKeychainUtilsErrorDomain code: status userInfo: nil];
- }
-}
-
-#endif
-
-@end
View
52 TestsFramework/ExtendMac/EMKeychainItem.h
@@ -1,52 +0,0 @@
-/*Copyright (c) 2007 Extendmac, LLC. <support@extendmac.com>
-
- Permission is hereby granted, free of charge, to any person
- obtaining a copy of this software and associated documentation
- files (the "Software"), to deal in the Software without
- restriction, including without limitation the rights to use,
- copy, modify, merge, publish, distribute, sublicense, and/or sell
- copies of the Software, and to permit persons to whom the
- Software is furnished to do so, subject to the following
- conditions:
-
- The above copyright notice and this permission notice shall be
- included in all copies or substantial portions of the Software.
-
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
- OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
- HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
- WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
- OTHER DEALINGS IN THE SOFTWARE.
- */
-
-#import <Security/Security.h>
-
-@interface EMKeychainItem : NSObject {
- NSString *myPassword;
- NSString *myUsername;
- NSString *myLabel;
- SecKeychainItemRef coreKeychainItem;
-}
-- (NSString *)password;
-- (NSString *)username;
-- (NSString *)label;
-- (BOOL)setPassword:(NSString *)newPassword;
-- (BOOL)setUsername:(NSString *)newUsername;
-- (BOOL)setLabel:(NSString *)newLabel;
-@end
-
-@interface EMKeychainItem (Private)
-- (BOOL)modifyAttributeWithTag:(SecItemAttr)attributeTag toBeString:(NSString *)newStringValue;
-@end
-
-@interface EMGenericKeychainItem : EMKeychainItem
-{
- NSString *myServiceName;
-}
-+ (id)genericKeychainItem:(SecKeychainItemRef)item forServiceName:(NSString *)serviceName username:(NSString *)username password:(NSString *)password;
-- (NSString *)serviceName;
-- (BOOL)setServiceName:(NSString *)newServiceName;
-@end
View
133 TestsFramework/ExtendMac/EMKeychainItem.m
@@ -1,133 +0,0 @@
-/*Copyright (c) 2007 Extendmac, LLC. <support@extendmac.com>
-
- Permission is hereby granted, free of charge, to any person
- obtaining a copy of this software and associated documentation
- files (the "Software"), to deal in the Software without
- restriction, including without limitation the rights to use,
- copy, modify, merge, publish, distribute, sublicense, and/or sell
- copies of the Software, and to permit persons to whom the
- Software is furnished to do so, subject to the following
- conditions:
-
- The above copyright notice and this permission notice shall be
- included in all copies or substantial portions of the Software.
-
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
- OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
- HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
- WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
- OTHER DEALINGS IN THE SOFTWARE.
- */
-
-#import "EMKeychainItem.h"
-
-@implementation EMKeychainItem
-- (id)initWithCoreKeychainItem:(SecKeychainItemRef)item username:(NSString *)username password:(NSString *)password
-{
- if ((self = [super init]))
- {
- coreKeychainItem = item;
- [self setValue:username forKey:@"myUsername"];
- [self setValue:password forKey:@"myPassword"];
- return self;
- }
- return nil;
-}
-- (NSString *)password
-{
- return myPassword;
-}
-- (NSString *)username
-{
- return myUsername;
-}
-- (NSString *)label
-{
- return myLabel;
-}
-
-- (BOOL)setPassword:(NSString *)newPasswordString
-{
- if (!newPasswordString)
- {
- return NO;
- }
- [self willChangeValueForKey:@"password"];
- [myPassword autorelease];
- myPassword = [newPasswordString copy];
- [self didChangeValueForKey:@"password"];
-
- const char *newPassword = [newPasswordString UTF8String];
- OSStatus returnStatus = SecKeychainItemModifyAttributesAndData(coreKeychainItem, NULL, (UInt32)strlen(newPassword), (void *)newPassword);
- return (returnStatus == noErr);
-}
-- (BOOL)setUsername:(NSString *)newUsername
-{
- [self willChangeValueForKey:@"username"];
- [myUsername autorelease];
- myUsername = [newUsername copy];
- [self didChangeValueForKey:@"username"];
-
- return [self modifyAttributeWithTag:kSecAccountItemAttr toBeString:newUsername];
-}
-- (BOOL)setLabel:(NSString *)newLabel
-{
- [self willChangeValueForKey:@"label"];
- [myLabel autorelease];
- myLabel = [newLabel copy];
- [self didChangeValueForKey:@"label"];
-
- return [self modifyAttributeWithTag:kSecLabelItemAttr toBeString:newLabel];
-}
-@end
-
-@implementation EMKeychainItem (Private)
-- (BOOL)modifyAttributeWithTag:(SecItemAttr)attributeTag toBeString:(NSString *)newStringValue
-{
- const char *newValue = [newStringValue UTF8String];
- SecKeychainAttribute attributes[1];
- attributes[0].tag = attributeTag;
- attributes[0].length = (UInt32)strlen(newValue);
- attributes[0].data = (void *)newValue;
-
- SecKeychainAttributeList list;
- list.count = 1;
- list.attr = attributes;
-
- OSStatus returnStatus = SecKeychainItemModifyAttributesAndData(coreKeychainItem, &list, 0, NULL);
- return (returnStatus == noErr);
-}
-@end
-
-@implementation EMGenericKeychainItem
-- (id)initWithCoreKeychainItem:(SecKeychainItemRef)item serviceName:(NSString *)serviceName username:(NSString *)username password:(NSString *)password
-{
- if ((self = [super initWithCoreKeychainItem:item username:username password:password]))
- {
- [self setValue:serviceName forKey:@"myServiceName"];
- return self;
- }
- return nil;
-}
-+ (id)genericKeychainItem:(SecKeychainItemRef)item forServiceName:(NSString *)serviceName username:(NSString *)username password:(NSString *)password
-{
- return [[[EMGenericKeychainItem alloc] initWithCoreKeychainItem:item serviceName:serviceName username:username password:password] autorelease];
-}
-- (NSString *)serviceName
-{
- return myServiceName;
-}
-
-- (BOOL)setServiceName:(NSString *)newServiceName
-{
- [self willChangeValueForKey:@"serviceName"];
- [myServiceName autorelease];
- myServiceName = [newServiceName copy];
- [self didChangeValueForKey:@"serviceName"];
-
- return [self modifyAttributeWithTag:kSecServiceItemAttr toBeString:newServiceName];
-}
-@end
View
42 TestsFramework/ExtendMac/EMKeychainProxy.h
@@ -1,42 +0,0 @@
-/*Copyright (c) 2007 Extendmac, LLC. <support@extendmac.com>
-
-Permission is hereby granted, free of charge, to any person
-obtaining a copy of this software and associated documentation
-files (the "Software"), to deal in the Software without
-restriction, including without limitation the rights to use,
-copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the
-Software is furnished to do so, subject to the following
-conditions:
-
-The above copyright notice and this permission notice shall be
-included in all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
-OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
-HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
-WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-OTHER DEALINGS IN THE SOFTWARE.
-*/
-
-//Last Changed on 2/07/08. Version 0.14
-
-#import <Security/Security.h>
-
-#import "EMKeychainItem.h"
-
-@interface EMKeychainProxy : NSObject {
- BOOL _logErrors;
-}
-+ (id)sharedProxy;
-- (void)lockKeychain;
-- (void)unlockKeychain;
-- (void)setLogsErrors:(BOOL)flag;
-
-- (EMGenericKeychainItem *)genericKeychainItemForService:(NSString *)serviceNameString withUsername:(NSString *)usernameString;
-- (EMGenericKeychainItem *)addGenericKeychainItemForService:(NSString *)serviceNameString withUsername:(NSString *)usernameString password:(NSString *)passwordString;
-
-@end
View
118 TestsFramework/ExtendMac/EMKeychainProxy.m
@@ -1,118 +0,0 @@
-/*Copyright (c) 2007 Extendmac, LLC. <support@extendmac.com>
-
- Permission is hereby granted, free of charge, to any person
- obtaining a copy of this software and associated documentation
- files (the "Software"), to deal in the Software without
- restriction, including without limitation the rights to use,
- copy, modify, merge, publish, distribute, sublicense, and/or sell
- copies of the Software, and to permit persons to whom the
- Software is furnished to do so, subject to the following
- conditions:
-
- The above copyright notice and this permission notice shall be
- included in all copies or substantial portions of the Software.
-
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
- OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
- HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
- WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
- OTHER DEALINGS IN THE SOFTWARE.
- */
-
-#import "EMKeychainProxy.h"
-
-@implementation EMKeychainProxy
-
-static EMKeychainProxy* sharedProxy;
-
-+ (id)sharedProxy
-{
- if (!sharedProxy)
- {
- sharedProxy = [[EMKeychainProxy alloc] init];
- }
- return sharedProxy;
-}
-- (void)lockKeychain
-{
- SecKeychainLock(NULL);
-}
-- (void)unlockKeychain
-{
- SecKeychainUnlock(NULL, 0, NULL, NO);
-}
-- (void)setLogsErrors:(BOOL)flag
-{
- _logErrors = flag;
-}
-
-#pragma mark -
-#pragma mark Getting Keychain Items
-- (EMGenericKeychainItem *)genericKeychainItemForService:(NSString *)serviceNameString withUsername:(NSString *)usernameString
-{
- if (!usernameString || [usernameString length] == 0)
- {
- return nil;
- }
-
- const char *serviceName = [serviceNameString UTF8String];
- const char *username = [usernameString UTF8String];
-
- UInt32 passwordLength = 0;
- char *password = nil;
-
- SecKeychainItemRef item = nil;
- OSStatus returnStatus = SecKeychainFindGenericPassword(NULL, (UInt32)strlen(serviceName), serviceName, (UInt32)strlen(username), username, &passwordLength, (void **)&password, &item);
- if (returnStatus != noErr || !item)
- {
- if (_logErrors)
- {
-#if !TARGET_OS_IPHONE
- NSLog(@"Error (%@) - %s", NSStringFromSelector(_cmd), GetMacOSStatusErrorString(returnStatus));
-#endif
- }
- return nil;
- }
-
- NSString *passwordString = nil;
-
- if (password != NULL) {
- char passwordBuffer[1024];
- if (passwordLength > 1023) passwordLength = 1023; // Ensure room for the NULL character.
- strncpy(passwordBuffer, password, passwordLength);
- passwordBuffer[passwordLength] = '\0';
- passwordString = [NSString stringWithUTF8String:passwordBuffer];
- }
-
- return [EMGenericKeychainItem genericKeychainItem:item forServiceName:serviceNameString username:usernameString password:passwordString];
-}
-
-#pragma mark -
-#pragma mark Saving Passwords
-- (EMGenericKeychainItem *)addGenericKeychainItemForService:(NSString *)serviceNameString withUsername:(NSString *)usernameString password:(NSString *)passwordString
-{
- if (!usernameString || [usernameString length] == 0 || !serviceNameString || [serviceNameString length] == 0)
- {
- return nil;
- }
- const char *serviceName = [serviceNameString UTF8String];
- const char *username = [usernameString UTF8String];
- const char *password = [passwordString UTF8String];
-
- SecKeychainItemRef item = nil;
- OSStatus returnStatus = SecKeychainAddGenericPassword(NULL, (UInt32)strlen(serviceName), serviceName, (UInt32)strlen(username), username, (UInt32)strlen(password), (void *)password, &item);
-
- if (returnStatus != noErr || !item)
- {
-#ifndef TARGET_OS_IPHONE
- NSLog(@"Error (%@) - %s", NSStringFromSelector(_cmd), GetMacOSStatusErrorString(returnStatus));
-#endif
- return nil;
- }
- return [EMGenericKeychainItem genericKeychainItem:item forServiceName:serviceNameString username:usernameString password:passwordString];
-}
-
-@end

0 comments on commit cbee6bb

Please sign in to comment.