Skip to content
This repository has been archived by the owner on Aug 24, 2019. It is now read-only.

Commit

Permalink
Merge pull request #22 from soffes/1.0
Browse files Browse the repository at this point in the history
New class design for performing easy keychain queries
  • Loading branch information
soffes committed Mar 21, 2013
2 parents 755da38 + fbc5c43 commit d754956
Show file tree
Hide file tree
Showing 13 changed files with 386 additions and 674 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
language: objective-c
before_install: "sudo gem update --system && bundle install"
before_install: "sudo gem update --system && sudo gem install bundler && bundle install"
script: bundle exec rake test --trace
13 changes: 11 additions & 2 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
desc 'Run the tests'
task :test do
system 'xcodebuild -project Tests/SSKeychain.xcodeproj -scheme SSKeychainTests TEST_AFTER_BUILD=YES'
system 'xcodebuild -project Tests/SSKeychain.xcodeproj -scheme SSKeychainTestsARC TEST_AFTER_BUILD=YES'
command = 'xcodebuild -project Tests/SSKeychain.xcodeproj -scheme SSKeychainTests TEST_AFTER_BUILD=YES 2>&1'
IO.popen(command) do |io|
while line = io.gets do
puts line
if line == "** BUILD SUCCEEDED **\n"
exit 0
elsif line == "** BUILD FAILED **\n"
exit 1
end
end
end
end

task :default => :test
Expand Down
10 changes: 5 additions & 5 deletions Readme.markdown
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
# SSKeychain

SSKeychain is a simple wrapper for accessing accounts, getting passwords, setting passwords, and deleting passwords using the system Keychain on Mac OS X and iOS. SSKeychain works in ARC and non-ARC projects.
SSKeychain is a 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).

## Adding to your project

1. Add `Security.framework` to your target
2. Add `SSKeychain.h` and `SSKeychain.m` to your project.
2. Add `SSKeychain.h`, `SSKeychain.m`, `SSKeychainQuery.h`, and `SSKeychainQuery.m` to your project.

You don't need to do anything regarding ARC. SSKeychain will detect if you're not using ARC and add the required memory management code.
SSKeychain requires ARC.

Note: Currently SSKeychain does not support Mac OS 10.6.

Expand All @@ -25,7 +25,7 @@ SSKeychain has the following class methods for working with the system keychain:
+ (BOOL)setPassword:(NSString *)password forService:(NSString *)serviceName account:(NSString *)account;
```

Easy as that. (See [SSKeychain.h](https://github.com/samsoffes/sskeychain/blob/master/SSKeychain.h) for all of the methods.)
Easy as that. (See [SSKeychain.h](https://github.com/soffes/sskeychain/blob/master/SSKeychain/SSKeychain.h) and [SSKeychainQuery.h](https://github.com/soffes/sskeychain/blob/master/SSKeychain/SSKeychainQuery.h)) for all of the methods.)

## Documentation

Expand All @@ -35,7 +35,7 @@ Install the documentation into Xcode with the following steps:
2. Choose Downloads
3. Choose the Documentation tab
4. Click the plus button in the bottom right and enter the following URL:

http://docs.samsoff.es/com.samsoffes.sskeychain.atom

5. Click Install next the new row reading "SSKeychain Documentation". (If you don't see it and didn't get an error, try restarting Xcode.)
Expand Down
5 changes: 3 additions & 2 deletions SSKeychain.podspec
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
Pod::Spec.new do |s|
s.name = 'SSKeychain'
s.version = '0.2.1'
s.version = '1.0'
s.summary = 'Simple Cocoa wrapper for the keychain that works on Mac and iOS.'
s.homepage = 'https://github.com/soffes/sskeychain'
s.author = { 'Sam Soffes' => 'sam@soff.es' }
s.source = { :git => 'https://github.com/soffes/sskeychain.git', :tag => '0.2.1' }
s.source = { :git => 'https://github.com/soffes/sskeychain.git', :tag => '1.0' }
s.description = 'SSKeychain is a simple utility class for making the system keychain less sucky.'
s.source_files = 'SSKeychain/*.{h,m}'
s.frameworks = 'Security'
s.requires_arc = true
s.license = { :type => 'MIT', :file => 'LICENSE' }
end
222 changes: 28 additions & 194 deletions SSKeychain/SSKeychain.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,12 @@
// Copyright (c) 2009-2011 Sam Soffes. All rights reserved.
//

#import <Foundation/Foundation.h>
#import <Security/Security.h>

#import "SSKeychainQuery.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.
For codes returned by the operating system, refer to SecBase.h for your
platform.
*/
typedef enum {

Expand All @@ -21,6 +20,7 @@ typedef enum {

} SSKeychainErrorCode;

/** SSKeychain error domain */
extern NSString *const kSSKeychainErrorDomain;

/** Account name. */
Expand Down Expand Up @@ -60,74 +60,7 @@ extern NSString *const kSSKeychainWhereKey;
*/
@interface SSKeychain : NSObject

///-----------------------
/// @name Getting Accounts
///-----------------------

/**
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.
@see allAccounts:
*/
+ (NSArray *)allAccounts;

/**
Returns an array containing the Keychain's accounts, or `nil` if the Keychain doesn't have any
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.
@param error If accessing the accounts fails, upon return contains an error that describes the problem.
@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.
@see allAccounts
*/
+ (NSArray *)allAccounts:(NSError **)error;

/**
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.
@see accountsForService:error:
*/
+ (NSArray *)accountsForService:(NSString *)serviceName;

/**
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.
@param serviceName The service for which to return the corresponding accounts.
@param error If accessing the accounts fails, upon return contains an error that describes the problem.
@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.
@see accountsForService:
*/
+ (NSArray *)accountsForService:(NSString *)serviceName error:(NSError **)error;


///------------------------
/// @name Getting Passwords
///------------------------
#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
Expand All @@ -144,62 +77,6 @@ extern NSString *const kSSKeychainWhereKey;
*/
+ (NSString *)passwordForService:(NSString *)serviceName account:(NSString *)account;

/**
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.
@param error If accessing the password fails, upon return contains an error that describes the problem.
@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.
@see passwordForService:account:
*/
+ (NSString *)passwordForService:(NSString *)serviceName account:(NSString *)account error:(NSError **)error;

/**
Returns the password data for a given account and service, or `nil` if the Keychain doesn't have data
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.
@param error If accessing the password fails, upon return contains an error that describes the problem.
@return Returns a the password data for the given account and service, or `nil` if the Keychain doesn't
have data for the given parameters.
@see passwordDataForService:account:error:
*/
+ (NSData *)passwordDataForService:(NSString *)serviceName account:(NSString *)account;

/**
Returns the password data for a given account and service, or `nil` if the Keychain doesn't have data
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.
@param error If accessing the password fails, upon return contains an error that describes the problem.
@return Returns a the password data for the given account and service, or `nil` if the Keychain doesn't
have a password for the given parameters.
@see passwordDataForService:account:
*/
+ (NSData *)passwordDataForService:(NSString *)serviceName account:(NSString *)account error:(NSError **)error;


///-------------------------
/// @name Deleting Passwords
///-------------------------

/**
Deletes a password from the Keychain.
Expand All @@ -213,26 +90,6 @@ extern NSString *const kSSKeychainWhereKey;
*/
+ (BOOL)deletePasswordForService:(NSString *)serviceName account:(NSString *)account;

/**
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.
@param error If deleting the password fails, upon return contains an error that describes the problem.
@return Returns `YES` on success, or `NO` on failure.
@see deletePasswordForService:account:
*/
+ (BOOL)deletePasswordForService:(NSString *)serviceName account:(NSString *)account error:(NSError **)error;


///------------------------
/// @name Setting Passwords
///------------------------

/**
Sets a password in the Keychain.
Expand All @@ -249,69 +106,44 @@ extern NSString *const kSSKeychainWhereKey;
+ (BOOL)setPassword:(NSString *)password forService:(NSString *)serviceName account:(NSString *)account;

/**
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.
@param error If setting the password fails, upon return contains an error that describes the problem.
@return Returns `YES` on success, or `NO` on failure.
@see setPassword:forService:account:
*/
+ (BOOL)setPassword:(NSString *)password forService:(NSString *)serviceName account:(NSString *)account error:(NSError **)error;

/**
Sets arbirary data in the Keychain.
@param password The data 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.
Returns an array containing the Keychain's accounts, or `nil` if the Keychain has no accounts.
@param error If setting the password fails, upon return contains an error that describes the problem.
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 Returns `YES` on success, or `NO` on failure.
@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.
@see setPasswordData:forService:account:error:
@see allAccounts:
*/
+ (BOOL)setPasswordData:(NSData *)password forService:(NSString *)serviceName account:(NSString *)account;
+ (NSArray *)allAccounts;

/**
Sets arbirary data in the Keychain.
@param password The data to store in the Keychain.
@param serviceName The service for which to set the corresponding password.
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.
@param account The account for which to set the corresponding password.
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 error If setting the password fails, upon return contains an error that describes the problem.
@param serviceName The service for which to return the corresponding accounts.
@return Returns `YES` on success, or `NO` on failure.
@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.
@see setPasswordData:forService:account:
@see accountsForService:error:
*/
+ (BOOL)setPasswordData:(NSData *)password forService:(NSString *)serviceName account:(NSString *)account error:(NSError **)error;

+ (NSArray *)accountsForService:(NSString *)serviceName;

///--------------------
/// @name Configuration
///--------------------
#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.
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 accessibilityType
*/
Expand All @@ -320,8 +152,8 @@ extern NSString *const kSSKeychainWhereKey;
/**
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.
@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.
Expand All @@ -331,3 +163,5 @@ extern NSString *const kSSKeychainWhereKey;
#endif

@end


0 comments on commit d754956

Please sign in to comment.