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

Add accessibility type to inidivdual items #77

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion SSKeychain/SSKeychain.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ extern NSString *const kSSKeychainWhereKey;

#pragma mark - Configuration

#if __IPHONE_4_0 && TARGET_OS_IPHONE
#ifdef SSKEYCHAIN_ACCESSIBLE_AVAILABLE
/**
Returns the accessibility type for all future passwords saved to the Keychain.

Expand Down
4 changes: 2 additions & 2 deletions SSKeychain/SSKeychain.m
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
NSString *const kSSKeychainLastModifiedKey = @"mdat";
NSString *const kSSKeychainWhereKey = @"svce";

#if __IPHONE_4_0 && TARGET_OS_IPHONE
#ifdef SSKEYCHAIN_ACCESSIBLE_AVAILABLE
static CFTypeRef SSKeychainAccessibilityType = NULL;
#endif

Expand Down Expand Up @@ -76,7 +76,7 @@ + (NSArray *)accountsForService:(NSString *)serviceName {
}


#if __IPHONE_4_0 && TARGET_OS_IPHONE
#ifdef SSKEYCHAIN_ACCESSIBLE_AVAILABLE
+ (CFTypeRef)accessibilityType {
return SSKeychainAccessibilityType;
}
Expand Down
24 changes: 22 additions & 2 deletions SSKeychain/SSKeychainQuery.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,15 @@ typedef NS_ENUM(NSUInteger, SSKeychainQuerySynchronizationMode) {
};
#endif

#if __IPHONE_4_0 || __MAC_10_9
#define SSKEYCHAIN_ACCESSIBLE_AVAILABLE 1
#endif

#if __IPHONE_3_0 || __MAC_10_9
#define SSKEYCHAIN_ACCESSGROUP_AVAILABLE 1
#endif


/**
Simple interface for querying or modifying keychain items.
*/
Expand All @@ -36,8 +45,19 @@ typedef NS_ENUM(NSUInteger, SSKeychainQuerySynchronizationMode) {
/** kSecAttrLabel */
@property (nonatomic, copy) NSString *label;

#if __IPHONE_3_0 && TARGET_OS_IPHONE
/** kSecAttrAccessGroup (only used on iOS) */
/** kSecAttrComment **/
@property (nonatomic, copy) NSString *comment;

#ifdef SSKEYCHAIN_ACCESSIBLE_AVAILABLE
/**
kSecAttrAccessible
Sets the accessibility type for an individual item. If set, this overrides +[SSKeychain accessibilityType].
*/
@property (nonatomic, copy) __attribute__((NSObject)) CFTypeRef accessibilityType;
#endif

#if SSKEYCHAIN_ACCESSGROUP_AVAILABLE
/** kSecAttrAccessGroup */
@property (nonatomic, copy) NSString *accessGroup;
#endif

Expand Down
13 changes: 9 additions & 4 deletions SSKeychain/SSKeychainQuery.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ @implementation SSKeychainQuery
@synthesize label = _label;
@synthesize passwordData = _passwordData;

#if __IPHONE_3_0 && TARGET_OS_IPHONE
#if SSKEYCHAIN_ACCESSGROUP_AVAILABLE
@synthesize accessGroup = _accessGroup;
#endif

Expand All @@ -42,8 +42,13 @@ - (BOOL)save:(NSError *__autoreleasing *)error {
if (self.label) {
[query setObject:self.label forKey:(__bridge id)kSecAttrLabel];
}
#if __IPHONE_4_0 && TARGET_OS_IPHONE
CFTypeRef accessibilityType = [SSKeychain accessibilityType];

if (self.comment) {
[query setObject:self.comment forKey:(__bridge id)kSecAttrComment];
}

#ifdef SSKEYCHAIN_ACCESSIBLE_AVAILABLE
CFTypeRef accessibilityType = self.accessibilityType ?: [SSKeychain accessibilityType];
if (accessibilityType) {
[query setObject:(__bridge id)accessibilityType forKey:(__bridge id)kSecAttrAccessible];
}
Expand Down Expand Up @@ -187,7 +192,7 @@ - (NSMutableDictionary *)query {
[dictionary setObject:self.account forKey:(__bridge id)kSecAttrAccount];
}

#if __IPHONE_3_0 && TARGET_OS_IPHONE && !TARGET_IPHONE_SIMULATOR
#if SSKEYCHAIN_ACCESSGROUP_AVAILABLE && !TARGET_IPHONE_SIMULATOR
if (self.accessGroup) {
[dictionary setObject:self.accessGroup forKey:(__bridge id)kSecAttrAccessGroup];
}
Expand Down
2 changes: 1 addition & 1 deletion Tests/SSKeychainTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ - (void)testSSKeychain {
XCTAssertTrue([SSKeychain setPassword:kSSKeychainPassword forService:kSSKeychainServiceName account:kSSKeychainAccountName], @"Unable to save item");
XCTAssertTrue([SSKeychain deletePasswordForService:kSSKeychainServiceName account:kSSKeychainAccountName], @"Unable to delete password");

#if __IPHONE_4_0 && TARGET_OS_IPHONE
#ifdef SSKEYCHAIN_ACCESSIBLE_AVAILABLE
[SSKeychain setAccessibilityType:kSecAttrAccessibleWhenUnlockedThisDeviceOnly];
XCTAssertTrue([SSKeychain accessibilityType] == kSecAttrAccessibleWhenUnlockedThisDeviceOnly, @"Unable to verify accessibilityType");
#endif
Expand Down