修改读取存储keychain的方法
This commit is contained in:
parent
721814c93b
commit
5a4d4e2afd
21
Classes_cocos/DataManager.h
Normal file
21
Classes_cocos/DataManager.h
Normal file
@ -0,0 +1,21 @@
|
||||
//
|
||||
// DataManager.h
|
||||
// Unity-iPhone
|
||||
//
|
||||
// Created by zhl on 2022/11/23.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
typedef NS_ENUM(NSUInteger, InitType) {
|
||||
SynLock,
|
||||
GCD,
|
||||
};
|
||||
|
||||
@interface DataManager : NSObject
|
||||
|
||||
+ (instancetype)sharedInstanceWith:(InitType)type;
|
||||
-(void)saveKey:(NSString *) account key:(NSString *) key;
|
||||
-(NSString *)loadKey:(NSString *) account;
|
||||
|
||||
@end
|
87
Classes_cocos/DataManager.m
Normal file
87
Classes_cocos/DataManager.m
Normal file
@ -0,0 +1,87 @@
|
||||
//
|
||||
// DataManager.m
|
||||
// Unity-iPhone
|
||||
//
|
||||
// Created by zhl on 2022/11/23.
|
||||
//
|
||||
|
||||
#import "DataManager.h"
|
||||
#import "UICKeyChainStore.h"
|
||||
|
||||
|
||||
@interface DataManager () <NSCopying>
|
||||
|
||||
@end
|
||||
|
||||
static NSString * const cebgWalletService = @"com.cebg.wallet";
|
||||
//global var
|
||||
static id _instance;
|
||||
|
||||
UICKeyChainStore *keychain;
|
||||
|
||||
InitType _instanceInitType;
|
||||
|
||||
@implementation DataManager
|
||||
|
||||
+ (instancetype)sharedInstanceWith:(InitType)type {
|
||||
_instanceInitType = type;
|
||||
if (type == SynLock) {
|
||||
@synchronized (self) {
|
||||
if (_instance == nil) {
|
||||
_instance = [[self alloc] init];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
else {
|
||||
static dispatch_once_t onceToken;
|
||||
dispatch_once(&onceToken, ^{
|
||||
_instance = [[self alloc] init];
|
||||
});
|
||||
}
|
||||
return _instance;
|
||||
}
|
||||
|
||||
+ (instancetype)allocWithZone:(struct _NSZone *)zone {
|
||||
if (_instanceInitType == SynLock) {
|
||||
@synchronized (self) {
|
||||
if (_instance == nil) {
|
||||
_instance = [super allocWithZone:zone];
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
static dispatch_once_t onceToken;
|
||||
dispatch_once(&onceToken, ^{
|
||||
_instance = [super allocWithZone:zone];
|
||||
});
|
||||
}
|
||||
return _instance;
|
||||
}
|
||||
|
||||
- (id)copyWithZone:(nullable NSZone *)zone {
|
||||
return _instance;
|
||||
}
|
||||
|
||||
-(void)saveKey:(NSString *) account key:(NSString *) key {
|
||||
if (keychain == nil ){
|
||||
keychain = [UICKeyChainStore keyChainStoreWithService:cebgWalletService];
|
||||
keychain.synchronizable = YES;
|
||||
}
|
||||
keychain[account] = key;
|
||||
}
|
||||
|
||||
-(NSString *)loadKey:(NSString *) account {
|
||||
if (keychain == nil ){
|
||||
keychain = [UICKeyChainStore keyChainStoreWithService:cebgWalletService];
|
||||
keychain.synchronizable = YES;
|
||||
}
|
||||
NSError *error;
|
||||
NSString * result = [keychain stringForKey:account error:&error];
|
||||
if (error) {
|
||||
NSLog(@"%@", error.localizedDescription);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@end
|
@ -1,357 +0,0 @@
|
||||
//
|
||||
// SSKeychain.h
|
||||
// SSToolkit
|
||||
//
|
||||
// Created by Sam Soffes on 5/19/10.
|
||||
// Copyright (c) 2009-2011 Sam Soffes. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import <Security/Security.h>
|
||||
|
||||
/** Error codes that can be returned in NSError objects. */
|
||||
typedef enum {
|
||||
/** No error. */
|
||||
SSKeychainErrorNone = noErr,
|
||||
|
||||
/** Some of the arguments were invalid. */
|
||||
SSKeychainErrorBadArguments = -1001,
|
||||
|
||||
/** There was no password. */
|
||||
SSKeychainErrorNoPassword = -1002,
|
||||
|
||||
/** One or more parameters passed internally were not valid. */
|
||||
SSKeychainErrorInvalidParameter = errSecParam,
|
||||
|
||||
/** Failed to allocate memory. */
|
||||
SSKeychainErrorFailedToAllocated = errSecAllocate,
|
||||
|
||||
/** No trust results are available. */
|
||||
SSKeychainErrorNotAvailable = errSecNotAvailable,
|
||||
|
||||
/** Authorization/Authentication failed. */
|
||||
SSKeychainErrorAuthorizationFailed = errSecAuthFailed,
|
||||
|
||||
/** The item already exists. */
|
||||
SSKeychainErrorDuplicatedItem = errSecDuplicateItem,
|
||||
|
||||
/** The item cannot be found.*/
|
||||
SSKeychainErrorNotFound = errSecItemNotFound,
|
||||
|
||||
/** Interaction with the Security Server is not allowed. */
|
||||
SSKeychainErrorInteractionNotAllowed = errSecInteractionNotAllowed,
|
||||
|
||||
/** Unable to decode the provided data. */
|
||||
SSKeychainErrorFailedToDecode = errSecDecode
|
||||
} SSKeychainErrorCode;
|
||||
|
||||
extern NSString *const kSSKeychainErrorDomain;
|
||||
|
||||
/** Account name. */
|
||||
extern NSString *const kSSKeychainAccountKey;
|
||||
|
||||
/**
|
||||
Time the item was created.
|
||||
|
||||
The value will be a string.
|
||||
*/
|
||||
extern NSString *const kSSKeychainCreatedAtKey;
|
||||
|
||||
/** Item class. */
|
||||
extern NSString *const kSSKeychainClassKey;
|
||||
|
||||
/** Item description. */
|
||||
extern NSString *const kSSKeychainDescriptionKey;
|
||||
|
||||
/** Item label. */
|
||||
extern NSString *const kSSKeychainLabelKey;
|
||||
|
||||
/** Time the item was last modified.
|
||||
|
||||
The value will be a string.
|
||||
*/
|
||||
extern NSString *const kSSKeychainLastModifiedKey;
|
||||
|
||||
/** Where the item was created. */
|
||||
extern NSString *const kSSKeychainWhereKey;
|
||||
|
||||
/**
|
||||
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).
|
||||
*/
|
||||
@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
|
||||
///------------------------
|
||||
|
||||
/**
|
||||
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.
|
||||
|
||||
@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:error:
|
||||
*/
|
||||
+ (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.
|
||||
|
||||
@param serviceName The service for which to delete the corresponding password.
|
||||
|
||||
@param account The account for which to delete the corresponding password.
|
||||
|
||||
@return Returns `YES` on success, or `NO` on failure.
|
||||
|
||||
@see deletePasswordForService:account:error:
|
||||
*/
|
||||
+ (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.
|
||||
|
||||
@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.
|
||||
|
||||
@return Returns `YES` on success, or `NO` on failure.
|
||||
|
||||
@see setPassword:forService:account:error:
|
||||
*/
|
||||
+ (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.
|
||||
|
||||
@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 setPasswordData:forService:account:error:
|
||||
*/
|
||||
+ (BOOL)setPasswordData:(NSData *)password forService:(NSString *)serviceName account:(NSString *)account;
|
||||
|
||||
/**
|
||||
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.
|
||||
|
||||
@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 setPasswordData:forService:account:
|
||||
*/
|
||||
+ (BOOL)setPasswordData:(NSData *)password forService:(NSString *)serviceName account:(NSString *)account error:(NSError **)error;
|
||||
|
||||
|
||||
///--------------------
|
||||
/// @name 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.
|
||||
|
||||
@see accessibilityType
|
||||
*/
|
||||
+ (CFTypeRef)accessibilityType;
|
||||
|
||||
/**
|
||||
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.
|
||||
|
||||
If the value is `NULL` (the default), the Keychain default will be used.
|
||||
|
||||
@see accessibilityType
|
||||
*/
|
||||
+ (void)setAccessibilityType:(CFTypeRef)accessibilityType;
|
||||
#endif
|
||||
|
||||
@end
|
@ -1,262 +0,0 @@
|
||||
//
|
||||
// SSKeychain.m
|
||||
// SSToolkit
|
||||
//
|
||||
// Created by Sam Soffes on 5/19/10.
|
||||
// Copyright (c) 2009-2011 Sam Soffes. All rights reserved.
|
||||
//
|
||||
|
||||
#import "SSKeychain.h"
|
||||
|
||||
NSString *const kSSKeychainErrorDomain = @"com.samsoffes.sskeychain";
|
||||
|
||||
NSString *const kSSKeychainAccountKey = @"acct";
|
||||
NSString *const kSSKeychainCreatedAtKey = @"cdat";
|
||||
NSString *const kSSKeychainClassKey = @"labl";
|
||||
NSString *const kSSKeychainDescriptionKey = @"desc";
|
||||
NSString *const kSSKeychainLabelKey = @"labl";
|
||||
NSString *const kSSKeychainLastModifiedKey = @"mdat";
|
||||
NSString *const kSSKeychainWhereKey = @"svce";
|
||||
|
||||
#if __IPHONE_4_0 && TARGET_OS_IPHONE
|
||||
CFTypeRef SSKeychainAccessibilityType = NULL;
|
||||
#endif
|
||||
|
||||
@interface SSKeychain ()
|
||||
+ (NSMutableDictionary *)_queryForService:(NSString *)service account:(NSString *)account;
|
||||
@end
|
||||
|
||||
@implementation SSKeychain
|
||||
|
||||
#pragma mark - Getting Accounts
|
||||
|
||||
+ (NSArray *)allAccounts {
|
||||
return [self accountsForService:nil error:nil];
|
||||
}
|
||||
|
||||
|
||||
+ (NSArray *)allAccounts:(NSError **)error {
|
||||
return [self accountsForService:nil error:error];
|
||||
}
|
||||
|
||||
|
||||
+ (NSArray *)accountsForService:(NSString *)service {
|
||||
return [self accountsForService:service error:nil];
|
||||
}
|
||||
|
||||
|
||||
+ (NSArray *)accountsForService:(NSString *)service error:(NSError **)error {
|
||||
OSStatus status = SSKeychainErrorBadArguments;
|
||||
NSMutableDictionary *query = [self _queryForService:service account:nil];
|
||||
#if __has_feature(objc_arc)
|
||||
[query setObject:(__bridge id)kCFBooleanTrue forKey:(__bridge id)kSecReturnAttributes];
|
||||
[query setObject:(__bridge id)kSecMatchLimitAll forKey:(__bridge id)kSecMatchLimit];
|
||||
#else
|
||||
[query setObject:(id)kCFBooleanTrue forKey:(id)kSecReturnAttributes];
|
||||
[query setObject:(id)kSecMatchLimitAll forKey:(id)kSecMatchLimit];
|
||||
#endif
|
||||
|
||||
CFTypeRef result = NULL;
|
||||
#if __has_feature(objc_arc)
|
||||
status = SecItemCopyMatching((__bridge CFDictionaryRef)query, &result);
|
||||
#else
|
||||
status = SecItemCopyMatching((CFDictionaryRef)query, &result);
|
||||
#endif
|
||||
if (status != noErr && error != NULL) {
|
||||
*error = [NSError errorWithDomain:kSSKeychainErrorDomain code:status userInfo:nil];
|
||||
return nil;
|
||||
}
|
||||
|
||||
#if __has_feature(objc_arc)
|
||||
return (__bridge_transfer NSArray *)result;
|
||||
#else
|
||||
return [(NSArray *)result autorelease];
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
#pragma mark - Getting Passwords
|
||||
|
||||
+ (NSString *)passwordForService:(NSString *)service account:(NSString *)account {
|
||||
return [self passwordForService:service account:account error:nil];
|
||||
}
|
||||
|
||||
|
||||
+ (NSString *)passwordForService:(NSString *)service account:(NSString *)account error:(NSError **)error {
|
||||
NSData *data = [self passwordDataForService:service account:account error:error];
|
||||
if (data.length > 0) {
|
||||
NSString *string = [[NSString alloc] initWithData:(NSData *)data encoding:NSUTF8StringEncoding];
|
||||
#if !__has_feature(objc_arc)
|
||||
[string autorelease];
|
||||
#endif
|
||||
return string;
|
||||
}
|
||||
|
||||
return nil;
|
||||
}
|
||||
|
||||
|
||||
+ (NSData *)passwordDataForService:(NSString *)service account:(NSString *)account {
|
||||
return [self passwordDataForService:service account:account error:nil];
|
||||
}
|
||||
|
||||
|
||||
+ (NSData *)passwordDataForService:(NSString *)service account:(NSString *)account error:(NSError **)error {
|
||||
OSStatus status = SSKeychainErrorBadArguments;
|
||||
if (!service || !account) {
|
||||
if (error) {
|
||||
*error = [NSError errorWithDomain:kSSKeychainErrorDomain code:status userInfo:nil];
|
||||
}
|
||||
return nil;
|
||||
}
|
||||
|
||||
CFTypeRef result = NULL;
|
||||
NSMutableDictionary *query = [self _queryForService:service account:account];
|
||||
#if __has_feature(objc_arc)
|
||||
[query setObject:(__bridge id)kCFBooleanTrue forKey:(__bridge id)kSecReturnData];
|
||||
[query setObject:(__bridge id)kSecMatchLimitOne forKey:(__bridge id)kSecMatchLimit];
|
||||
status = SecItemCopyMatching((__bridge CFDictionaryRef)query, &result);
|
||||
#else
|
||||
[query setObject:(id)kCFBooleanTrue forKey:(id)kSecReturnData];
|
||||
[query setObject:(id)kSecMatchLimitOne forKey:(id)kSecMatchLimit];
|
||||
status = SecItemCopyMatching((CFDictionaryRef)query, &result);
|
||||
#endif
|
||||
|
||||
if (status != noErr && error != NULL) {
|
||||
*error = [NSError errorWithDomain:kSSKeychainErrorDomain code:status userInfo:nil];
|
||||
return nil;
|
||||
}
|
||||
|
||||
#if __has_feature(objc_arc)
|
||||
return (__bridge_transfer NSData *)result;
|
||||
#else
|
||||
return [(NSData *)result autorelease];
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
#pragma mark - Deleting Passwords
|
||||
|
||||
+ (BOOL)deletePasswordForService:(NSString *)service account:(NSString *)account {
|
||||
return [self deletePasswordForService:service account:account error:nil];
|
||||
}
|
||||
|
||||
|
||||
+ (BOOL)deletePasswordForService:(NSString *)service account:(NSString *)account error:(NSError **)error {
|
||||
OSStatus status = SSKeychainErrorBadArguments;
|
||||
if (service && account) {
|
||||
NSMutableDictionary *query = [self _queryForService:service account:account];
|
||||
#if __has_feature(objc_arc)
|
||||
status = SecItemDelete((__bridge CFDictionaryRef)query);
|
||||
#else
|
||||
status = SecItemDelete((CFDictionaryRef)query);
|
||||
#endif
|
||||
}
|
||||
if (status != noErr && error != NULL) {
|
||||
*error = [NSError errorWithDomain:kSSKeychainErrorDomain code:status userInfo:nil];
|
||||
}
|
||||
return (status == noErr);
|
||||
|
||||
}
|
||||
|
||||
|
||||
#pragma mark - Setting Passwords
|
||||
|
||||
+ (BOOL)setPassword:(NSString *)password forService:(NSString *)service account:(NSString *)account {
|
||||
return [self setPassword:password forService:service account:account error:nil];
|
||||
}
|
||||
|
||||
|
||||
+ (BOOL)setPassword:(NSString *)password forService:(NSString *)service account:(NSString *)account error:(NSError **)error {
|
||||
NSData *data = [password dataUsingEncoding:NSUTF8StringEncoding];
|
||||
return [self setPasswordData:data forService:service account:account error:error];
|
||||
}
|
||||
|
||||
|
||||
+ (BOOL)setPasswordData:(NSData *)password forService:(NSString *)service account:(NSString *)account {
|
||||
return [self setPasswordData:password forService:service account:account error:nil];
|
||||
}
|
||||
|
||||
|
||||
+ (BOOL)setPasswordData:(NSData *)password forService:(NSString *)service account:(NSString *)account error:(NSError **)error {
|
||||
OSStatus status = SSKeychainErrorBadArguments;
|
||||
if (password && service && account) {
|
||||
[self deletePasswordForService:service account:account];
|
||||
NSMutableDictionary *query = [self _queryForService:service account:account];
|
||||
#if __has_feature(objc_arc)
|
||||
[query setObject:password forKey:(__bridge id)kSecValueData];
|
||||
#else
|
||||
[query setObject:password forKey:(id)kSecValueData];
|
||||
#endif
|
||||
|
||||
#if __IPHONE_4_0 && TARGET_OS_IPHONE
|
||||
if (SSKeychainAccessibilityType) {
|
||||
#if __has_feature(objc_arc)
|
||||
[query setObject:(id)[self accessibilityType] forKey:(__bridge id)kSecAttrAccessible];
|
||||
#else
|
||||
[query setObject:(id)[self accessibilityType] forKey:(id)kSecAttrAccessible];
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
#if __has_feature(objc_arc)
|
||||
status = SecItemAdd((__bridge CFDictionaryRef)query, NULL);
|
||||
#else
|
||||
status = SecItemAdd((CFDictionaryRef)query, NULL);
|
||||
#endif
|
||||
}
|
||||
if (status != noErr && error != NULL) {
|
||||
*error = [NSError errorWithDomain:kSSKeychainErrorDomain code:status userInfo:nil];
|
||||
}
|
||||
return (status == noErr);
|
||||
}
|
||||
|
||||
|
||||
#pragma mark - Configuration
|
||||
|
||||
#if __IPHONE_4_0 && TARGET_OS_IPHONE
|
||||
+ (CFTypeRef)accessibilityType {
|
||||
return SSKeychainAccessibilityType;
|
||||
}
|
||||
|
||||
|
||||
+ (void)setAccessibilityType:(CFTypeRef)accessibilityType {
|
||||
CFRetain(accessibilityType);
|
||||
if (SSKeychainAccessibilityType) {
|
||||
CFRelease(SSKeychainAccessibilityType);
|
||||
}
|
||||
SSKeychainAccessibilityType = accessibilityType;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#pragma mark - Private
|
||||
|
||||
+ (NSMutableDictionary *)_queryForService:(NSString *)service account:(NSString *)account {
|
||||
NSMutableDictionary *dictionary = [NSMutableDictionary dictionaryWithCapacity:3];
|
||||
#if __has_feature(objc_arc)
|
||||
[dictionary setObject:(__bridge id)kSecClassGenericPassword forKey:(__bridge id)kSecClass];
|
||||
#else
|
||||
[dictionary setObject:(id)kSecClassGenericPassword forKey:(id)kSecClass];
|
||||
#endif
|
||||
|
||||
if (service) {
|
||||
#if __has_feature(objc_arc)
|
||||
[dictionary setObject:service forKey:(__bridge id)kSecAttrService];
|
||||
#else
|
||||
[dictionary setObject:service forKey:(id)kSecAttrService];
|
||||
#endif
|
||||
}
|
||||
|
||||
if (account) {
|
||||
#if __has_feature(objc_arc)
|
||||
[dictionary setObject:account forKey:(__bridge id)kSecAttrAccount];
|
||||
#else
|
||||
[dictionary setObject:account forKey:(id)kSecAttrAccount];
|
||||
#endif
|
||||
}
|
||||
|
||||
return dictionary;
|
||||
}
|
||||
|
||||
@end
|
289
Classes_cocos/UICKeyChainStore.h
Normal file
289
Classes_cocos/UICKeyChainStore.h
Normal file
@ -0,0 +1,289 @@
|
||||
//
|
||||
// UICKeyChainStore.h
|
||||
// UICKeyChainStore
|
||||
//
|
||||
// Created by Kishikawa Katsumi on 11/11/20.
|
||||
// Copyright (c) 2011 Kishikawa Katsumi. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
#if !__has_feature(nullability)
|
||||
#define NS_ASSUME_NONNULL_BEGIN
|
||||
#define NS_ASSUME_NONNULL_END
|
||||
#define nullable
|
||||
#define nonnull
|
||||
#define null_unspecified
|
||||
#define null_resettable
|
||||
#define __nullable
|
||||
#define __nonnull
|
||||
#define __null_unspecified
|
||||
#endif
|
||||
|
||||
#if __has_extension(objc_generics)
|
||||
#define UIC_KEY_TYPE <NSString *>
|
||||
#define UIC_CREDENTIAL_TYPE <NSDictionary <NSString *, NSString *>*>
|
||||
#else
|
||||
#define UIC_KEY_TYPE
|
||||
#define UIC_CREDENTIAL_TYPE
|
||||
#endif
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
extern NSString * const UICKeyChainStoreErrorDomain;
|
||||
|
||||
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
|
||||
__OSX_AVAILABLE_STARTING(__MAC_10_10, __IPHONE_8_0),
|
||||
UICKeyChainStoreAccessibilityWhenUnlockedThisDeviceOnly,
|
||||
UICKeyChainStoreAccessibilityAfterFirstUnlockThisDeviceOnly,
|
||||
UICKeyChainStoreAccessibilityAlwaysThisDeviceOnly,
|
||||
}
|
||||
__OSX_AVAILABLE_STARTING(__MAC_10_9, __IPHONE_4_0);
|
||||
|
||||
typedef NS_ENUM(unsigned long, UICKeyChainStoreAuthenticationPolicy) {
|
||||
UICKeyChainStoreAuthenticationPolicyUserPresence = 1 << 0,
|
||||
UICKeyChainStoreAuthenticationPolicyTouchIDAny NS_ENUM_AVAILABLE(10_12_1, 9_0) = 1u << 1,
|
||||
UICKeyChainStoreAuthenticationPolicyTouchIDCurrentSet NS_ENUM_AVAILABLE(10_12_1, 9_0) = 1u << 3,
|
||||
UICKeyChainStoreAuthenticationPolicyDevicePasscode NS_ENUM_AVAILABLE(10_11, 9_0) = 1u << 4,
|
||||
UICKeyChainStoreAuthenticationPolicyControlOr NS_ENUM_AVAILABLE(10_12_1, 9_0) = 1u << 14,
|
||||
UICKeyChainStoreAuthenticationPolicyControlAnd NS_ENUM_AVAILABLE(10_12_1, 9_0) = 1u << 15,
|
||||
UICKeyChainStoreAuthenticationPolicyPrivateKeyUsage NS_ENUM_AVAILABLE(10_12_1, 9_0) = 1u << 30,
|
||||
UICKeyChainStoreAuthenticationPolicyApplicationPassword NS_ENUM_AVAILABLE(10_12_1, 9_0) = 1u << 31,
|
||||
}__OSX_AVAILABLE_STARTING(__MAC_10_10, __IPHONE_8_0);
|
||||
|
||||
@interface UICKeyChainStore : NSObject
|
||||
|
||||
@property (nonatomic, readonly) UICKeyChainStoreItemClass itemClass;
|
||||
|
||||
@property (nonatomic, readonly, nullable) NSString *service;
|
||||
@property (nonatomic, readonly, nullable) NSString *accessGroup;
|
||||
|
||||
@property (nonatomic, readonly, nullable) NSURL *server;
|
||||
@property (nonatomic, readonly) UICKeyChainStoreProtocolType protocolType;
|
||||
@property (nonatomic, readonly) UICKeyChainStoreAuthenticationType authenticationType;
|
||||
|
||||
@property (nonatomic) UICKeyChainStoreAccessibility accessibility;
|
||||
@property (nonatomic, readonly) UICKeyChainStoreAuthenticationPolicy authenticationPolicy
|
||||
__OSX_AVAILABLE_STARTING(__MAC_10_10, __IPHONE_8_0);
|
||||
@property (nonatomic) BOOL useAuthenticationUI;
|
||||
|
||||
@property (nonatomic) BOOL synchronizable;
|
||||
|
||||
@property (nonatomic, nullable) NSString *authenticationPrompt
|
||||
__OSX_AVAILABLE_STARTING(__MAC_NA, __IPHONE_8_0);
|
||||
|
||||
@property (nonatomic, readonly, nullable) NSArray UIC_KEY_TYPE *allKeys;
|
||||
@property (nonatomic, readonly, nullable) NSArray *allItems;
|
||||
|
||||
+ (NSString *)defaultService;
|
||||
+ (void)setDefaultService:(NSString *)defaultService;
|
||||
|
||||
+ (UICKeyChainStore *)keyChainStore;
|
||||
+ (UICKeyChainStore *)keyChainStoreWithService:(nullable NSString *)service;
|
||||
+ (UICKeyChainStore *)keyChainStoreWithService:(nullable NSString *)service accessGroup:(nullable NSString *)accessGroup;
|
||||
|
||||
+ (UICKeyChainStore *)keyChainStoreWithServer:(NSURL *)server protocolType:(UICKeyChainStoreProtocolType)protocolType;
|
||||
+ (UICKeyChainStore *)keyChainStoreWithServer:(NSURL *)server protocolType:(UICKeyChainStoreProtocolType)protocolType authenticationType:(UICKeyChainStoreAuthenticationType)authenticationType;
|
||||
|
||||
- (instancetype)init;
|
||||
- (instancetype)initWithService:(nullable NSString *)service;
|
||||
- (instancetype)initWithService:(nullable NSString *)service accessGroup:(nullable NSString *)accessGroup;
|
||||
|
||||
- (instancetype)initWithServer:(NSURL *)server protocolType:(UICKeyChainStoreProtocolType)protocolType;
|
||||
- (instancetype)initWithServer:(NSURL *)server protocolType:(UICKeyChainStoreProtocolType)protocolType authenticationType:(UICKeyChainStoreAuthenticationType)authenticationType;
|
||||
|
||||
+ (nullable NSString *)stringForKey:(NSString *)key;
|
||||
+ (nullable NSString *)stringForKey:(NSString *)key service:(nullable NSString *)service;
|
||||
+ (nullable NSString *)stringForKey:(NSString *)key service:(nullable NSString *)service accessGroup:(nullable NSString *)accessGroup;
|
||||
+ (BOOL)setString:(nullable NSString *)value forKey:(NSString *)key;
|
||||
+ (BOOL)setString:(nullable NSString *)value forKey:(NSString *)key service:(nullable NSString *)service;
|
||||
+ (BOOL)setString:(nullable NSString *)value forKey:(NSString *)key service:(nullable NSString *)service accessGroup:(nullable NSString *)accessGroup;
|
||||
|
||||
+ (nullable NSData *)dataForKey:(NSString *)key;
|
||||
+ (nullable NSData *)dataForKey:(NSString *)key service:(nullable NSString *)service;
|
||||
+ (nullable NSData *)dataForKey:(NSString *)key service:(nullable NSString *)service accessGroup:(nullable NSString *)accessGroup;
|
||||
+ (BOOL)setData:(nullable NSData *)data forKey:(NSString *)key;
|
||||
+ (BOOL)setData:(nullable NSData *)data forKey:(NSString *)key service:(nullable NSString *)service;
|
||||
+ (BOOL)setData:(nullable NSData *)data forKey:(NSString *)key service:(nullable NSString *)service accessGroup:(nullable NSString *)accessGroup;
|
||||
|
||||
- (BOOL)contains:(nullable NSString *)key;
|
||||
|
||||
- (BOOL)setString:(nullable NSString *)string forKey:(nullable NSString *)key;
|
||||
- (BOOL)setString:(nullable NSString *)string forKey:(nullable NSString *)key label:(nullable NSString *)label comment:(nullable NSString *)comment;
|
||||
- (nullable NSString *)stringForKey:(NSString *)key;
|
||||
|
||||
- (BOOL)setData:(nullable NSData *)data forKey:(NSString *)key;
|
||||
- (BOOL)setData:(nullable NSData *)data forKey:(NSString *)key label:(nullable NSString *)label comment:(nullable NSString *)comment;
|
||||
- (nullable NSData *)dataForKey:(NSString *)key;
|
||||
|
||||
+ (BOOL)removeItemForKey:(NSString *)key;
|
||||
+ (BOOL)removeItemForKey:(NSString *)key service:(nullable NSString *)service;
|
||||
+ (BOOL)removeItemForKey:(NSString *)key service:(nullable NSString *)service accessGroup:(nullable NSString *)accessGroup;
|
||||
|
||||
+ (BOOL)removeAllItems;
|
||||
+ (BOOL)removeAllItemsForService:(nullable NSString *)service;
|
||||
+ (BOOL)removeAllItemsForService:(nullable NSString *)service accessGroup:(nullable NSString *)accessGroup;
|
||||
|
||||
- (BOOL)removeItemForKey:(NSString *)key;
|
||||
|
||||
- (BOOL)removeAllItems;
|
||||
|
||||
- (nullable NSString *)objectForKeyedSubscript:(NSString<NSCopying> *)key;
|
||||
- (void)setObject:(nullable NSString *)obj forKeyedSubscript:(NSString<NSCopying> *)key;
|
||||
|
||||
+ (nullable NSArray UIC_KEY_TYPE *)allKeysWithItemClass:(UICKeyChainStoreItemClass)itemClass;
|
||||
- (nullable NSArray UIC_KEY_TYPE *)allKeys;
|
||||
|
||||
+ (nullable NSArray *)allItemsWithItemClass:(UICKeyChainStoreItemClass)itemClass;
|
||||
- (nullable NSArray *)allItems;
|
||||
|
||||
- (void)setAccessibility:(UICKeyChainStoreAccessibility)accessibility authenticationPolicy:(UICKeyChainStoreAuthenticationPolicy)authenticationPolicy
|
||||
__OSX_AVAILABLE_STARTING(__MAC_10_10, __IPHONE_8_0);
|
||||
|
||||
#if TARGET_OS_IOS
|
||||
- (void)sharedPasswordWithCompletion:(nullable void (^)(NSString * __nullable account, NSString * __nullable password, NSError * __nullable error))completion;
|
||||
- (void)sharedPasswordForAccount:(NSString *)account completion:(nullable void (^)(NSString * __nullable password, NSError * __nullable error))completion;
|
||||
|
||||
- (void)setSharedPassword:(nullable NSString *)password forAccount:(NSString *)account completion:(nullable void (^)(NSError * __nullable error))completion;
|
||||
- (void)removeSharedPasswordForAccount:(NSString *)account completion:(nullable void (^)(NSError * __nullable error))completion;
|
||||
|
||||
+ (void)requestSharedWebCredentialWithCompletion:(nullable void (^)(NSArray UIC_CREDENTIAL_TYPE *credentials, NSError * __nullable error))completion;
|
||||
+ (void)requestSharedWebCredentialForDomain:(nullable NSString *)domain account:(nullable NSString *)account completion:(nullable void (^)(NSArray UIC_CREDENTIAL_TYPE *credentials, NSError * __nullable error))completion;
|
||||
|
||||
+ (NSString *)generatePassword;
|
||||
#endif
|
||||
|
||||
@end
|
||||
|
||||
@interface UICKeyChainStore (ErrorHandling)
|
||||
|
||||
+ (nullable NSString *)stringForKey:(NSString *)key error:(NSError * __nullable __autoreleasing * __nullable)error;
|
||||
+ (nullable NSString *)stringForKey:(NSString *)key service:(nullable NSString *)service error:(NSError * __nullable __autoreleasing * __nullable)error;
|
||||
+ (nullable NSString *)stringForKey:(NSString *)key service:(nullable NSString *)service accessGroup:(nullable NSString *)accessGroup error:(NSError * __nullable __autoreleasing * __nullable)error;
|
||||
|
||||
+ (BOOL)setString:(nullable NSString *)value forKey:(NSString *)key error:(NSError * __nullable __autoreleasing * __nullable)error;
|
||||
+ (BOOL)setString:(nullable NSString *)value forKey:(NSString *)key service:(nullable NSString *)service error:(NSError * __nullable __autoreleasing * __nullable)error;
|
||||
+ (BOOL)setString:(nullable NSString *)value forKey:(NSString *)key service:(nullable NSString *)service accessGroup:(nullable NSString *)accessGroup error:(NSError * __nullable __autoreleasing * __nullable)error;
|
||||
|
||||
+ (nullable NSData *)dataForKey:(NSString *)key error:(NSError * __nullable __autoreleasing * __nullable)error;
|
||||
+ (nullable NSData *)dataForKey:(NSString *)key service:(nullable NSString *)service error:(NSError * __nullable __autoreleasing * __nullable)error;
|
||||
+ (nullable NSData *)dataForKey:(NSString *)key service:(nullable NSString *)service accessGroup:(nullable NSString *)accessGroup error:(NSError * __nullable __autoreleasing * __nullable)error;
|
||||
|
||||
+ (BOOL)setData:(nullable NSData *)data forKey:(NSString *)key error:(NSError * __nullable __autoreleasing * __nullable)error;
|
||||
+ (BOOL)setData:(nullable NSData *)data forKey:(NSString *)key service:(nullable NSString *)service error:(NSError * __nullable __autoreleasing * __nullable)error;
|
||||
+ (BOOL)setData:(nullable NSData *)data forKey:(NSString *)key service:(nullable NSString *)service accessGroup:(nullable NSString *)accessGroup error:(NSError * __nullable __autoreleasing * __nullable)error;
|
||||
|
||||
- (BOOL)setString:(nullable NSString *)string forKey:(NSString * )key error:(NSError * __nullable __autoreleasing * __nullable)error;
|
||||
- (BOOL)setString:(nullable NSString *)string forKey:(NSString * )key label:(nullable NSString *)label comment:(nullable NSString *)comment error:(NSError * __nullable __autoreleasing * __nullable)error;
|
||||
|
||||
- (BOOL)setData:(nullable NSData *)data forKey:(NSString *)key error:(NSError * __nullable __autoreleasing * __nullable)error;
|
||||
- (BOOL)setData:(nullable NSData *)data forKey:(NSString *)key label:(nullable NSString *)label comment:(nullable NSString *)comment error:(NSError * __nullable __autoreleasing * __nullable)error;
|
||||
|
||||
- (nullable NSString *)stringForKey:(NSString *)key error:(NSError * __nullable __autoreleasing * __nullable)error;
|
||||
- (nullable NSData *)dataForKey:(NSString *)key error:(NSError * __nullable __autoreleasing * __nullable)error;
|
||||
|
||||
+ (BOOL)removeItemForKey:(NSString *)key error:(NSError * __nullable __autoreleasing * __nullable)error;
|
||||
+ (BOOL)removeItemForKey:(NSString *)key service:(nullable NSString *)service error:(NSError * __nullable __autoreleasing * __nullable)error;
|
||||
+ (BOOL)removeItemForKey:(NSString *)key service:(nullable NSString *)service accessGroup:(nullable NSString *)accessGroup error:(NSError * __nullable __autoreleasing * __nullable)error;
|
||||
|
||||
+ (BOOL)removeAllItemsWithError:(NSError * __nullable __autoreleasing * __nullable)error;
|
||||
+ (BOOL)removeAllItemsForService:(nullable NSString *)service error:(NSError * __nullable __autoreleasing * __nullable)error;
|
||||
+ (BOOL)removeAllItemsForService:(nullable NSString *)service accessGroup:(nullable NSString *)accessGroup error:(NSError * __nullable __autoreleasing * __nullable)error;
|
||||
|
||||
- (BOOL)removeItemForKey:(NSString *)key error:(NSError * __nullable __autoreleasing * __nullable)error;
|
||||
- (BOOL)removeAllItemsWithError:(NSError * __nullable __autoreleasing * __nullable)error;
|
||||
|
||||
@end
|
||||
|
||||
@interface UICKeyChainStore (ForwardCompatibility)
|
||||
|
||||
+ (BOOL)setString:(nullable NSString *)value forKey:(NSString *)key genericAttribute:(nullable id)genericAttribute;
|
||||
+ (BOOL)setString:(nullable NSString *)value forKey:(NSString *)key genericAttribute:(nullable id)genericAttribute error:(NSError * __nullable __autoreleasing * __nullable)error;
|
||||
|
||||
+ (BOOL)setString:(nullable NSString *)value forKey:(NSString *)key service:(nullable NSString *)service genericAttribute:(nullable id)genericAttribute;
|
||||
+ (BOOL)setString:(nullable NSString *)value forKey:(NSString *)key service:(nullable NSString *)service genericAttribute:(nullable id)genericAttribute error:(NSError * __nullable __autoreleasing * __nullable)error;
|
||||
|
||||
+ (BOOL)setString:(nullable NSString *)value forKey:(NSString *)key service:(nullable NSString *)service accessGroup:(nullable NSString *)accessGroup genericAttribute:(nullable id)genericAttribute;
|
||||
+ (BOOL)setString:(nullable NSString *)value forKey:(NSString *)key service:(nullable NSString *)service accessGroup:(nullable NSString *)accessGroup genericAttribute:(nullable id)genericAttribute error:(NSError * __nullable __autoreleasing * __nullable)error;
|
||||
|
||||
+ (BOOL)setData:(nullable NSData *)data forKey:(NSString *)key genericAttribute:(nullable id)genericAttribute;
|
||||
+ (BOOL)setData:(nullable NSData *)data forKey:(NSString *)key genericAttribute:(nullable id)genericAttribute error:(NSError * __nullable __autoreleasing * __nullable)error;
|
||||
|
||||
+ (BOOL)setData:(nullable NSData *)data forKey:(NSString *)key service:(nullable NSString *)service genericAttribute:(nullable id)genericAttribute;
|
||||
+ (BOOL)setData:(nullable NSData *)data forKey:(NSString *)key service:(nullable NSString *)service genericAttribute:(nullable id)genericAttribute error:(NSError * __nullable __autoreleasing * __nullable)error;
|
||||
|
||||
+ (BOOL)setData:(nullable NSData *)data forKey:(NSString *)key service:(nullable NSString *)service accessGroup:(nullable NSString *)accessGroup genericAttribute:(nullable id)genericAttribute;
|
||||
+ (BOOL)setData:(nullable NSData *)data forKey:(NSString *)key service:(nullable NSString *)service accessGroup:(nullable NSString *)accessGroup genericAttribute:(nullable id)genericAttribute error:(NSError * __nullable __autoreleasing * __nullable)error;
|
||||
|
||||
- (BOOL)setString:(nullable NSString *)string forKey:(NSString *)key genericAttribute:(nullable id)genericAttribute;
|
||||
- (BOOL)setString:(nullable NSString *)string forKey:(NSString *)key genericAttribute:(nullable id)genericAttribute error:(NSError * __nullable __autoreleasing * __nullable)error;
|
||||
|
||||
- (BOOL)setData:(nullable NSData *)data forKey:(NSString *)key genericAttribute:(nullable id)genericAttribute;
|
||||
- (BOOL)setData:(nullable NSData *)data forKey:(NSString *)key genericAttribute:(nullable id)genericAttribute error:(NSError * __nullable __autoreleasing * __nullable)error;
|
||||
|
||||
@end
|
||||
|
||||
@interface UICKeyChainStore (Deprecation)
|
||||
|
||||
- (void)synchronize __attribute__((deprecated("calling this method is no longer required")));
|
||||
- (BOOL)synchronizeWithError:(NSError * __nullable __autoreleasing * __nullable)error __attribute__((deprecated("calling this method is no longer required")));
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
1407
Classes_cocos/UICKeyChainStore.m
Normal file
1407
Classes_cocos/UICKeyChainStore.m
Normal file
File diff suppressed because it is too large
Load Diff
@ -13,12 +13,12 @@
|
||||
#include "WalletEvent.h"
|
||||
#include "JcWallet.h"
|
||||
#import <GoogleSignIn/GoogleSignIn.h>
|
||||
#include "SSKeychain.h"
|
||||
#include "DataManager.h"
|
||||
|
||||
@import GoogleSignIn;
|
||||
|
||||
static NSString * const kClientID =
|
||||
@"53206975661-0d6q9pqljn84n9l63gm0to1ulap9cbk4.apps.googleusercontent.com";
|
||||
static NSString * const cebgWalletService = @"CEBG-wallet";
|
||||
|
||||
@implementation UIViewController (Wallet)
|
||||
|
||||
@ -35,20 +35,11 @@ static NSString * const cebgWalletService = @"CEBG-wallet";
|
||||
}
|
||||
-(void)saveKey:(NSString *) account key:(NSString *) key {
|
||||
NSLog(@"saveKey::account:%@, key: %@", account, key);
|
||||
[SSKeychain setPassword:key forService:cebgWalletService account:account];
|
||||
[SSKeychain setAccessibilityType:kSecAttrAccessibleWhenUnlocked];
|
||||
[[DataManager sharedInstanceWith: SynLock] saveKey: account key: key];
|
||||
}
|
||||
-(NSString *)loadKey:(NSString *) account {
|
||||
NSLog(@"loadKey::account:%@", account);
|
||||
NSError *error = nil;
|
||||
NSString *password = [SSKeychain passwordForService:cebgWalletService account:account error:&error];
|
||||
if ([error code] == SSKeychainErrorNotFound) {
|
||||
NSLog(@"password not found, account: %@", account);
|
||||
return @"";
|
||||
} else {
|
||||
NSLog(@"password for %@ is %@", account, password);
|
||||
return password;
|
||||
}
|
||||
return [[DataManager sharedInstanceWith: SynLock] loadKey: account];
|
||||
}
|
||||
|
||||
-(void)scanQRCode:(NSString *)funid title:(NSString *) title{
|
||||
|
@ -81,7 +81,8 @@
|
||||
D5538BA5287E9908000BDFB6 /* WalletEvent.cpp in Sources */ = {isa = PBXBuildFile; fileRef = D5538BA3287E9908000BDFB6 /* WalletEvent.cpp */; };
|
||||
D589C9BB28B62D93002CAA34 /* cacert.pem in Resources */ = {isa = PBXBuildFile; fileRef = D589C9B928B62D93002CAA34 /* cacert.pem */; };
|
||||
D59AB424292DBACE00714392 /* CloudKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D59AB423292DBACE00714392 /* CloudKit.framework */; };
|
||||
D59AB427292DD91D00714392 /* SSKeychain.m in Sources */ = {isa = PBXBuildFile; fileRef = D59AB426292DD91D00714392 /* SSKeychain.m */; };
|
||||
D59AB42F292E250500714392 /* UICKeyChainStore.m in Sources */ = {isa = PBXBuildFile; fileRef = D59AB42E292E250500714392 /* UICKeyChainStore.m */; };
|
||||
D59AB433292E26CE00714392 /* DataManager.m in Sources */ = {isa = PBXBuildFile; fileRef = D59AB432292E26CE00714392 /* DataManager.m */; };
|
||||
D5AB1D3328BF782300AA6AFA /* QRToggleTorchButton.m in Sources */ = {isa = PBXBuildFile; fileRef = D5AB1D2928BF782200AA6AFA /* QRToggleTorchButton.m */; };
|
||||
D5AB1D3428BF782300AA6AFA /* QRCameraSwitchButton.m in Sources */ = {isa = PBXBuildFile; fileRef = D5AB1D2B28BF782200AA6AFA /* QRCameraSwitchButton.m */; };
|
||||
D5AB1D3528BF782300AA6AFA /* QRCodeReaderViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = D5AB1D2D28BF782200AA6AFA /* QRCodeReaderViewController.m */; };
|
||||
@ -366,8 +367,10 @@
|
||||
D589C9B928B62D93002CAA34 /* cacert.pem */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = cacert.pem; sourceTree = "<group>"; };
|
||||
D59AB422292DBABA00714392 /* Unity-iPhone.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; name = "Unity-iPhone.entitlements"; path = "Unity-iPhone/Unity-iPhone.entitlements"; sourceTree = "<group>"; };
|
||||
D59AB423292DBACE00714392 /* CloudKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CloudKit.framework; path = System/Library/Frameworks/CloudKit.framework; sourceTree = SDKROOT; };
|
||||
D59AB425292DD8E500714392 /* SSKeychain.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SSKeychain.h; sourceTree = "<group>"; };
|
||||
D59AB426292DD91D00714392 /* SSKeychain.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SSKeychain.m; sourceTree = "<group>"; };
|
||||
D59AB42C292E24DD00714392 /* UICKeyChainStore.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = UICKeyChainStore.h; sourceTree = "<group>"; };
|
||||
D59AB42E292E250500714392 /* UICKeyChainStore.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = UICKeyChainStore.m; sourceTree = "<group>"; };
|
||||
D59AB431292E26B600714392 /* DataManager.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = DataManager.h; sourceTree = "<group>"; };
|
||||
D59AB432292E26CE00714392 /* DataManager.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = DataManager.m; sourceTree = "<group>"; };
|
||||
D5AB1D2828BF782200AA6AFA /* QRCodeReaderView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = QRCodeReaderView.h; sourceTree = "<group>"; };
|
||||
D5AB1D2928BF782200AA6AFA /* QRToggleTorchButton.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = QRToggleTorchButton.m; sourceTree = "<group>"; };
|
||||
D5AB1D2A28BF782200AA6AFA /* QRCodeReaderDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = QRCodeReaderDelegate.h; sourceTree = "<group>"; };
|
||||
@ -899,8 +902,10 @@
|
||||
D5F2D104287C12DD003C2B62 /* JcWallet.mm */,
|
||||
D5538BA4287E9908000BDFB6 /* WalletEvent.h */,
|
||||
D5538BA3287E9908000BDFB6 /* WalletEvent.cpp */,
|
||||
D59AB425292DD8E500714392 /* SSKeychain.h */,
|
||||
D59AB426292DD91D00714392 /* SSKeychain.m */,
|
||||
D59AB42C292E24DD00714392 /* UICKeyChainStore.h */,
|
||||
D59AB42E292E250500714392 /* UICKeyChainStore.m */,
|
||||
D59AB431292E26B600714392 /* DataManager.h */,
|
||||
D59AB432292E26CE00714392 /* DataManager.m */,
|
||||
);
|
||||
path = Classes_cocos;
|
||||
sourceTree = "<group>";
|
||||
@ -1212,6 +1217,7 @@
|
||||
D5F2CF75287BEC0D003C2B62 /* Il2CppCompilerCalculateTypeValues_21Table.cpp in Sources */,
|
||||
D5F2CF43287BEC0D003C2B62 /* Bulk_Generics_2.cpp in Sources */,
|
||||
D5F2CF6F287BEC0D003C2B62 /* Il2CppCompilerCalculateTypeValues_4Table.cpp in Sources */,
|
||||
D59AB433292E26CE00714392 /* DataManager.m in Sources */,
|
||||
8A142DC61636943E00DD87CA /* Keyboard.mm in Sources */,
|
||||
8A0FED491649699200E9727D /* EAGLContextHelper.mm in Sources */,
|
||||
D5F2CF57287BEC0D003C2B62 /* Bulk_System.Xml_0.cpp in Sources */,
|
||||
@ -1254,6 +1260,7 @@
|
||||
D5F2CF8A287BEC0D003C2B62 /* Bulk_UnityEngine.CoreModule_0.cpp in Sources */,
|
||||
4E090A341F27885B0077B28D /* StoreReview.m in Sources */,
|
||||
8AC74A9519B47FEF00019D38 /* AVCapture.mm in Sources */,
|
||||
D59AB42F292E250500714392 /* UICKeyChainStore.m in Sources */,
|
||||
D5F2CF90287BEC0D003C2B62 /* Il2CppCompilerCalculateTypeValues_6Table.cpp in Sources */,
|
||||
D5F2CFA8287BEC0D003C2B62 /* Il2CppCompilerCalculateTypeValues_13Table.cpp in Sources */,
|
||||
D5F2CF5C287BEC0D003C2B62 /* Bulk_Generics_7.cpp in Sources */,
|
||||
@ -1279,7 +1286,6 @@
|
||||
D5F2D106287C12DD003C2B62 /* JcWallet.mm in Sources */,
|
||||
D5F2CF8B287BEC0D003C2B62 /* Bulk_System.Diagnostics.StackTrace_0.cpp in Sources */,
|
||||
D5F2CF63287BEC0D003C2B62 /* Il2CppCompilerCalculateTypeValues_10Table.cpp in Sources */,
|
||||
D59AB427292DD91D00714392 /* SSKeychain.m in Sources */,
|
||||
D5F2CF88287BEC0D003C2B62 /* Bulk_UnityEngine.UIModule_0.cpp in Sources */,
|
||||
D5F2CF5E287BEC0D003C2B62 /* GenericMethods3.cpp in Sources */,
|
||||
D5F2CF72287BEC0D003C2B62 /* Bulk_mscorlib_2.cpp in Sources */,
|
||||
|
Binary file not shown.
@ -14,8 +14,8 @@
|
||||
filePath = "Classes_cocos/UIViewController+Wallet.mm"
|
||||
startingColumnNumber = "9"
|
||||
endingColumnNumber = "9"
|
||||
startingLineNumber = "134"
|
||||
endingLineNumber = "134"
|
||||
startingLineNumber = "133"
|
||||
endingLineNumber = "133"
|
||||
landmarkName = "-refreshTokenID:funid:"
|
||||
landmarkType = "7">
|
||||
</BreakpointContent>
|
||||
@ -30,8 +30,8 @@
|
||||
filePath = "Classes_cocos/UIViewController+Wallet.mm"
|
||||
startingColumnNumber = "9223372036854775807"
|
||||
endingColumnNumber = "9223372036854775807"
|
||||
startingLineNumber = "140"
|
||||
endingLineNumber = "140"
|
||||
startingLineNumber = "131"
|
||||
endingLineNumber = "131"
|
||||
landmarkName = "-refreshTokenID:funid:"
|
||||
landmarkType = "7">
|
||||
</BreakpointContent>
|
||||
@ -46,8 +46,8 @@
|
||||
filePath = "Classes_cocos/UIViewController+Wallet.mm"
|
||||
startingColumnNumber = "9223372036854775807"
|
||||
endingColumnNumber = "9223372036854775807"
|
||||
startingLineNumber = "142"
|
||||
endingLineNumber = "142"
|
||||
startingLineNumber = "133"
|
||||
endingLineNumber = "133"
|
||||
landmarkName = "-refreshTokenID:funid:"
|
||||
landmarkType = "7">
|
||||
</BreakpointContent>
|
||||
@ -78,8 +78,8 @@
|
||||
filePath = "Classes_cocos/UIViewController+Wallet.mm"
|
||||
startingColumnNumber = "9223372036854775807"
|
||||
endingColumnNumber = "9223372036854775807"
|
||||
startingLineNumber = "141"
|
||||
endingLineNumber = "141"
|
||||
startingLineNumber = "132"
|
||||
endingLineNumber = "132"
|
||||
landmarkName = "-refreshTokenID:funid:"
|
||||
landmarkType = "7">
|
||||
</BreakpointContent>
|
||||
@ -94,8 +94,8 @@
|
||||
filePath = "Classes_cocos/UIViewController+Wallet.mm"
|
||||
startingColumnNumber = "9223372036854775807"
|
||||
endingColumnNumber = "9223372036854775807"
|
||||
startingLineNumber = "147"
|
||||
endingLineNumber = "147"
|
||||
startingLineNumber = "138"
|
||||
endingLineNumber = "138"
|
||||
landmarkName = "-signWithGoogle:"
|
||||
landmarkType = "7">
|
||||
</BreakpointContent>
|
||||
@ -116,5 +116,21 @@
|
||||
landmarkType = "7">
|
||||
</BreakpointContent>
|
||||
</BreakpointProxy>
|
||||
<BreakpointProxy
|
||||
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
|
||||
<BreakpointContent
|
||||
uuid = "401F3BC0-AE8F-418C-9ADB-17A8CE6E71FF"
|
||||
shouldBeEnabled = "No"
|
||||
ignoreCount = "0"
|
||||
continueAfterRunningActions = "No"
|
||||
filePath = "../../../../cocos/cocos2d-x/cocos/platform/ios/CCApplication-ios.mm"
|
||||
startingColumnNumber = "9223372036854775807"
|
||||
endingColumnNumber = "9223372036854775807"
|
||||
startingLineNumber = "359"
|
||||
endingLineNumber = "359"
|
||||
landmarkName = "Application::loadKeyLocal(account, outItem)"
|
||||
landmarkType = "7">
|
||||
</BreakpointContent>
|
||||
</BreakpointProxy>
|
||||
</Breakpoints>
|
||||
</Bucket>
|
||||
|
@ -23,5 +23,9 @@
|
||||
</array>
|
||||
<key>com.apple.developer.ubiquity-kvstore-identifier</key>
|
||||
<string>$(TeamIdentifierPrefix)$(CFBundleIdentifier)</string>
|
||||
<key>keychain-access-groups</key>
|
||||
<array>
|
||||
<string>$(AppIdentifierPrefix)com.jc.tebg</string>
|
||||
</array>
|
||||
</dict>
|
||||
</plist>
|
||||
|
Loading…
x
Reference in New Issue
Block a user