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

Fix accessibity #202

Open
wants to merge 2 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
5 changes: 3 additions & 2 deletions Sources/SAMKeychain.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
#import <Foundation/Foundation.h>
#endif

#import <SAMKeychain/SAMKeychainQuery.h>

NS_ASSUME_NONNULL_BEGIN

/**
Expand Down Expand Up @@ -167,7 +169,7 @@ extern NSString *const kSAMKeychainWhereKey;

#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 Expand Up @@ -200,4 +202,3 @@ extern NSString *const kSAMKeychainWhereKey;

NS_ASSUME_NONNULL_END

#import <SAMKeychain/SAMKeychainQuery.h>
4 changes: 2 additions & 2 deletions Sources/SAMKeychain.m
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
NSString *const kSAMKeychainLastModifiedKey = @"mdat";
NSString *const kSAMKeychainWhereKey = @"svce";

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

Expand Down Expand Up @@ -112,7 +112,7 @@ + (nullable NSArray *)accountsForService:(nullable NSString *)serviceName error:
}


#if __IPHONE_4_0 && TARGET_OS_IPHONE
#ifdef SSKEYCHAIN_ACCESSIBLE_AVAILABLE
+ (CFTypeRef)accessibilityType {
return SAMKeychainAccessibilityType;
}
Expand Down
24 changes: 16 additions & 8 deletions Sources/SAMKeychainQuery.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,13 @@

NS_ASSUME_NONNULL_BEGIN

#if __IPHONE_7_0 || __MAC_10_9
// Keychain synchronization available at compile time
#define SAMKEYCHAIN_SYNCHRONIZATION_AVAILABLE 1
#endif
#define SSKEYCHAIN_ACCESSIBLE_AVAILABLE 1

#if __IPHONE_3_0 || __MAC_10_9
// Keychain access group available at compile time
#define SAMKEYCHAIN_ACCESS_GROUP_AVAILABLE 1
#endif
// Keychain synchronization available at compile time
#define SAMKEYCHAIN_SYNCHRONIZATION_AVAILABLE 1

// Keychain access group available at compile time
#define SAMKEYCHAIN_ACCESS_GROUP_AVAILABLE 1

#ifdef SAMKEYCHAIN_SYNCHRONIZATION_AVAILABLE
typedef NS_ENUM(NSUInteger, SAMKeychainQuerySynchronizationMode) {
Expand All @@ -48,6 +46,16 @@ typedef NS_ENUM(NSUInteger, SAMKeychainQuerySynchronizationMode) {
/** kSecAttrLabel */
@property (nonatomic, copy, nullable) NSString *label;

/** kSecAttrComment **/
@property (nonatomic, copy) NSString *comment;

#ifdef SSKEYCHAIN_ACCESSIBLE_AVAILABLE
/**
kSecAttrAccessible
Sets the accessibility type for an individual item. If set, this overrides +[SAMKeychain accessibilityType].
*/
@property (nonatomic, copy) __attribute__((NSObject)) CFTypeRef accessibilityType;
#endif
#ifdef SAMKEYCHAIN_ACCESS_GROUP_AVAILABLE
/** kSecAttrAccessGroup (only used on iOS) */
@property (nonatomic, copy, nullable) NSString *accessGroup;
Expand Down
19 changes: 13 additions & 6 deletions Sources/SAMKeychainQuery.m
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,13 @@ - (BOOL)save:(NSError *__autoreleasing *)error {
if (status == errSecSuccess) {//item already exists, update it!
query = [[NSMutableDictionary alloc]init];
[query setObject:self.passwordData forKey:(__bridge id)kSecValueData];
#if __IPHONE_4_0 && TARGET_OS_IPHONE
CFTypeRef accessibilityType = [SAMKeychain accessibilityType];

if (self.comment) {
[query setObject:self.comment forKey:(__bridge id)kSecAttrComment];
}
#ifdef SSKEYCHAIN_ACCESSIBLE_AVAILABLE
CFTypeRef accessibilityType = self.accessibilityType ?: [SAMKeychain accessibilityType];

if (accessibilityType) {
[query setObject:(__bridge id)accessibilityType forKey:(__bridge id)kSecAttrAccessible];
}
Expand All @@ -53,8 +58,8 @@ - (BOOL)save:(NSError *__autoreleasing *)error {
[query setObject:self.label forKey:(__bridge id)kSecAttrLabel];
}
[query setObject:self.passwordData forKey:(__bridge id)kSecValueData];
#if __IPHONE_4_0 && TARGET_OS_IPHONE
CFTypeRef accessibilityType = [SAMKeychain accessibilityType];
#if SSKEYCHAIN_ACCESSIBLE_AVAILABLE
CFTypeRef accessibilityType = self.accessibilityType ?: [SAMKeychain accessibilityType];
if (accessibilityType) {
[query setObject:(__bridge id)accessibilityType forKey:(__bridge id)kSecAttrAccessible];
}
Expand Down Expand Up @@ -110,8 +115,10 @@ - (nullable NSArray *)fetchAll:(NSError *__autoreleasing *)error {
NSMutableDictionary *query = [self query];
[query setObject:@YES forKey:(__bridge id)kSecReturnAttributes];
[query setObject:(__bridge id)kSecMatchLimitAll forKey:(__bridge id)kSecMatchLimit];
#if __IPHONE_4_0 && TARGET_OS_IPHONE
CFTypeRef accessibilityType = [SAMKeychain accessibilityType];

#if SSKEYCHAIN_ACCESSIBLE_AVAILABLE
CFTypeRef accessibilityType = self.accessibilityType ?: [SAMKeychain accessibilityType];

if (accessibilityType) {
[query setObject:(__bridge id)accessibilityType forKey:(__bridge id)kSecAttrAccessible];
}
Expand Down