Skip to content

Commit

Permalink
Update to v2.0.0
Browse files Browse the repository at this point in the history
- Add support for storing internet password (kSecClassInternetPassword)
- Add `contains` method to check if the key has specific value
- Add support for `label` and `comment` attributes
- Add `allKeys` and `allItems` methods
- Deprecated `synchronize` method, no longer required calling this method (no-op)
  • Loading branch information
kishikawakatsumi committed Jan 12, 2015
1 parent a75bc37 commit 23ef336
Show file tree
Hide file tree
Showing 3 changed files with 819 additions and 410 deletions.
109 changes: 100 additions & 9 deletions Lib/UICKeyChainStore.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,103 @@ typedef NS_ENUM(NSInteger, UICKeyChainStoreErrorCode) {
UICKeyChainStoreErrorInvalidArguments = 1,
};

typedef NS_ENUM(NSInteger, UICKeyChainStoreItemClass) {
UICKeyChainStoreItemClassGenericPassword = 1,
UICKeyChainStoreItemClassInternetPassword,
};

typedef NS_ENUM(NSInteger, UICKeyChainStoreProtocolType) {
UICKeyChainStoreProtocolTypeFTP = 1,
UICKeyChainStoreProtocolTypeFTPAccount,
UICKeyChainStoreProtocolTypeHTTP,
UICKeyChainStoreProtocolTypeIRC,
UICKeyChainStoreProtocolTypeNNTP,
UICKeyChainStoreProtocolTypePOP3,
UICKeyChainStoreProtocolTypeSMTP,
UICKeyChainStoreProtocolTypeSOCKS,
UICKeyChainStoreProtocolTypeIMAP,
UICKeyChainStoreProtocolTypeLDAP,
UICKeyChainStoreProtocolTypeAppleTalk,
UICKeyChainStoreProtocolTypeAFP,
UICKeyChainStoreProtocolTypeTelnet,
UICKeyChainStoreProtocolTypeSSH,
UICKeyChainStoreProtocolTypeFTPS,
UICKeyChainStoreProtocolTypeHTTPS,
UICKeyChainStoreProtocolTypeHTTPProxy,
UICKeyChainStoreProtocolTypeHTTPSProxy,
UICKeyChainStoreProtocolTypeFTPProxy,
UICKeyChainStoreProtocolTypeSMB,
UICKeyChainStoreProtocolTypeRTSP,
UICKeyChainStoreProtocolTypeRTSPProxy,
UICKeyChainStoreProtocolTypeDAAP,
UICKeyChainStoreProtocolTypeEPPC,
UICKeyChainStoreProtocolTypeNNTPS,
UICKeyChainStoreProtocolTypeLDAPS,
UICKeyChainStoreProtocolTypeTelnetS,
UICKeyChainStoreProtocolTypeIRCS,
UICKeyChainStoreProtocolTypePOP3S,
};

typedef NS_ENUM(NSInteger, UICKeyChainStoreAuthenticationType) {
UICKeyChainStoreAuthenticationTypeNTLM = 1,
UICKeyChainStoreAuthenticationTypeMSN,
UICKeyChainStoreAuthenticationTypeDPA,
UICKeyChainStoreAuthenticationTypeRPA,
UICKeyChainStoreAuthenticationTypeHTTPBasic,
UICKeyChainStoreAuthenticationTypeHTTPDigest,
UICKeyChainStoreAuthenticationTypeHTMLForm,
UICKeyChainStoreAuthenticationTypeDefault,
};

typedef NS_ENUM(NSInteger, UICKeyChainStoreAccessibility) {
UICKeyChainStoreAccessibilityWhenUnlocked = 1,
UICKeyChainStoreAccessibilityAfterFirstUnlock,
UICKeyChainStoreAccessibilityAlways,
UICKeyChainStoreAccessibilityWhenPasscodeSetThisDeviceOnly,
UICKeyChainStoreAccessibilityWhenUnlockedThisDeviceOnly,
UICKeyChainStoreAccessibilityAfterFirstUnlockThisDeviceOnly,
UICKeyChainStoreAccessibilityAlwaysThisDeviceOnly,
};

typedef NS_ENUM(NSInteger, UICKeyChainStoreAuthenticationPolicy) {
UICKeyChainStoreAuthenticationPolicyUserPresence = kSecAccessControlUserPresence,
};

@interface UICKeyChainStore : NSObject

@property (nonatomic, readonly) UICKeyChainStoreItemClass itemClass;

@property (nonatomic, readonly) NSString *service;
@property (nonatomic, readonly) NSString *accessGroup;

@property (nonatomic, readonly) NSURL *server;
@property (nonatomic, readonly) UICKeyChainStoreProtocolType protocolType;
@property (nonatomic, readonly) UICKeyChainStoreAuthenticationType authenticationType;

@property (nonatomic, readonly) UICKeyChainStoreAccessibility accessibility;
@property (nonatomic, readonly) UICKeyChainStoreAuthenticationPolicy authenticationPolicy;

@property (nonatomic, readonly) BOOL synchronizable;

@property (nonatomic, readonly) NSString *authenticationPrompt;

+ (NSString *)defaultService;
+ (void)setDefaultService:(NSString *)defaultService;

+ (UICKeyChainStore *)keyChainStore;
+ (UICKeyChainStore *)keyChainStoreWithService:(NSString *)service;
+ (UICKeyChainStore *)keyChainStoreWithService:(NSString *)service accessGroup:(NSString *)accessGroup;

+ (UICKeyChainStore *)keyChainStoreWithServer:(NSURL *)server protocolType:(UICKeyChainStoreProtocolType)protocolType;
+ (UICKeyChainStore *)keyChainStoreWithServer:(NSURL *)server protocolType:(UICKeyChainStoreProtocolType)protocolType authenticationType:(UICKeyChainStoreAuthenticationType)authenticationType;

- (instancetype)init;
- (instancetype)initWithService:(NSString *)service;
- (instancetype)initWithService:(NSString *)service accessGroup:(NSString *)accessGroup;

- (instancetype)initWithServer:(NSURL *)server protocolType:(UICKeyChainStoreProtocolType)protocolType;
- (instancetype)initWithServer:(NSURL *)server protocolType:(UICKeyChainStoreProtocolType)protocolType authenticationType:(UICKeyChainStoreAuthenticationType)authenticationType;

+ (NSString *)stringForKey:(NSString *)key;
+ (NSString *)stringForKey:(NSString *)key error:(NSError * __autoreleasing *)error;
+ (NSString *)stringForKey:(NSString *)key service:(NSString *)service;
Expand All @@ -56,13 +137,19 @@ typedef NS_ENUM(NSInteger, UICKeyChainStoreErrorCode) {
+ (BOOL)setData:(NSData *)data forKey:(NSString *)key service:(NSString *)service accessGroup:(NSString *)accessGroup;
+ (BOOL)setData:(NSData *)data forKey:(NSString *)key service:(NSString *)service accessGroup:(NSString *)accessGroup error:(NSError * __autoreleasing *)error;

- (void)setString:(NSString *)string forKey:(NSString *)key;
- (BOOL)contains:(NSString *)key;

- (BOOL)setString:(NSString *)string forKey:(NSString *)key;
- (BOOL)setString:(NSString *)string forKey:(NSString *)key error:(NSError * __autoreleasing *)error;
- (BOOL)setString:(NSString *)string forKey:(NSString *)key label:(NSString *)label comment:(NSString *)comment;
- (BOOL)setString:(NSString *)string forKey:(NSString *)key label:(NSString *)label comment:(NSString *)comment error:(NSError * __autoreleasing *)error;
- (NSString *)stringForKey:(NSString *)key;
- (NSString *)stringForKey:(NSString *)key error:(NSError * __autoreleasing *)error;

- (void)setData:(NSData *)data forKey:(NSString *)key;
- (BOOL)setData:(NSData *)data forKey:(NSString *)key;
- (BOOL)setData:(NSData *)data forKey:(NSString *)key error:(NSError * __autoreleasing *)error;
- (BOOL)setData:(NSData *)data forKey:(NSString *)key label:(NSString *)label comment:(NSString *)comment;
- (BOOL)setData:(NSData *)data forKey:(NSString *)key label:(NSString *)label comment:(NSString *)comment error:(NSError * __autoreleasing *)error;
- (NSData *)dataForKey:(NSString *)key;
- (NSData *)dataForKey:(NSString *)key error:(NSError * __autoreleasing *)error;

Expand All @@ -79,17 +166,21 @@ typedef NS_ENUM(NSInteger, UICKeyChainStoreErrorCode) {
+ (BOOL)removeAllItemsForService:(NSString *)service accessGroup:(NSString *)accessGroup;
+ (BOOL)removeAllItemsForService:(NSString *)service accessGroup:(NSString *)accessGroup error:(NSError * __autoreleasing *)error;

- (void)removeItemForKey:(NSString *)key;
- (BOOL)removeItemForKey:(NSString *)key;
- (BOOL)removeItemForKey:(NSString *)key error:(NSError * __autoreleasing *)error;
- (void)removeAllItems;
- (BOOL)removeAllItems;
- (BOOL)removeAllItemsWithError:(NSError * __autoreleasing *)error;

- (void)synchronize;
- (BOOL)synchronizeWithError:(NSError *__autoreleasing *)error;

// object subscripting

- (NSString *)objectForKeyedSubscript:(NSString <NSCopying> *)key;
- (void)setObject:(NSString *)obj forKeyedSubscript:(NSString <NSCopying> *)key;

+ (NSArray *)allKeysWithItemClass:(CFTypeRef)itemClass;
- (NSArray *)allKeys;

+ (NSArray *)allItemsWithItemClass:(CFTypeRef)itemClass;
- (NSArray *)allItems;

- (void)synchronize __attribute__((deprecated("calling this method is no longer required")));
- (BOOL)synchronizeWithError:(NSError *__autoreleasing *)error __attribute__((deprecated("calling this method is no longer required")));

@end

0 comments on commit 23ef336

Please sign in to comment.