Aucune description

AWSUICKeyChainStore.h 16KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  1. //
  2. // UICKeyChainStore.h
  3. // UICKeyChainStore
  4. //
  5. // Created by Kishikawa Katsumi on 11/11/20.
  6. // Copyright (c) 2011 Kishikawa Katsumi. All rights reserved.
  7. //
  8. #import <Foundation/Foundation.h>
  9. #if !__has_feature(nullability)
  10. #define NS_ASSUME_NONNULL_BEGIN
  11. #define NS_ASSUME_NONNULL_END
  12. #define nullable
  13. #define nonnull
  14. #define null_unspecified
  15. #define null_resettable
  16. #define __nullable
  17. #define __nonnull
  18. #define __null_unspecified
  19. #endif
  20. #if __has_extension(objc_generics)
  21. #define UIC_KEY_TYPE <NSString *>
  22. #define UIC_CREDENTIAL_TYPE <NSDictionary <NSString *, NSString *>*>
  23. #else
  24. #define UIC_KEY_TYPE
  25. #define UIC_CREDENTIAL_TYPE
  26. #endif
  27. NS_ASSUME_NONNULL_BEGIN
  28. extern NSString * const AWSUICKeyChainStoreErrorDomain;
  29. typedef NS_ENUM(NSInteger, AWSUICKeyChainStoreErrorCode) {
  30. AWSUICKeyChainStoreErrorInvalidArguments = 1,
  31. };
  32. typedef NS_ENUM(NSInteger, AWSUICKeyChainStoreItemClass) {
  33. AWSUICKeyChainStoreItemClassGenericPassword = 1,
  34. AWSUICKeyChainStoreItemClassInternetPassword,
  35. };
  36. typedef NS_ENUM(NSInteger, AWSUICKeyChainStoreProtocolType) {
  37. AWSUICKeyChainStoreProtocolTypeFTP = 1,
  38. AWSUICKeyChainStoreProtocolTypeFTPAccount,
  39. AWSUICKeyChainStoreProtocolTypeHTTP,
  40. AWSUICKeyChainStoreProtocolTypeIRC,
  41. AWSUICKeyChainStoreProtocolTypeNNTP,
  42. AWSUICKeyChainStoreProtocolTypePOP3,
  43. AWSUICKeyChainStoreProtocolTypeSMTP,
  44. AWSUICKeyChainStoreProtocolTypeSOCKS,
  45. AWSUICKeyChainStoreProtocolTypeIMAP,
  46. AWSUICKeyChainStoreProtocolTypeLDAP,
  47. AWSUICKeyChainStoreProtocolTypeAppleTalk,
  48. AWSUICKeyChainStoreProtocolTypeAFP,
  49. AWSUICKeyChainStoreProtocolTypeTelnet,
  50. AWSUICKeyChainStoreProtocolTypeSSH,
  51. AWSUICKeyChainStoreProtocolTypeFTPS,
  52. AWSUICKeyChainStoreProtocolTypeHTTPS,
  53. AWSUICKeyChainStoreProtocolTypeHTTPProxy,
  54. AWSUICKeyChainStoreProtocolTypeHTTPSProxy,
  55. AWSUICKeyChainStoreProtocolTypeFTPProxy,
  56. AWSUICKeyChainStoreProtocolTypeSMB,
  57. AWSUICKeyChainStoreProtocolTypeRTSP,
  58. AWSUICKeyChainStoreProtocolTypeRTSPProxy,
  59. AWSUICKeyChainStoreProtocolTypeDAAP,
  60. AWSUICKeyChainStoreProtocolTypeEPPC,
  61. AWSUICKeyChainStoreProtocolTypeNNTPS,
  62. AWSUICKeyChainStoreProtocolTypeLDAPS,
  63. AWSUICKeyChainStoreProtocolTypeTelnetS,
  64. AWSUICKeyChainStoreProtocolTypeIRCS,
  65. AWSUICKeyChainStoreProtocolTypePOP3S,
  66. };
  67. typedef NS_ENUM(NSInteger, AWSUICKeyChainStoreAuthenticationType) {
  68. AWSUICKeyChainStoreAuthenticationTypeNTLM = 1,
  69. AWSUICKeyChainStoreAuthenticationTypeMSN,
  70. AWSUICKeyChainStoreAuthenticationTypeDPA,
  71. AWSUICKeyChainStoreAuthenticationTypeRPA,
  72. AWSUICKeyChainStoreAuthenticationTypeHTTPBasic,
  73. AWSUICKeyChainStoreAuthenticationTypeHTTPDigest,
  74. AWSUICKeyChainStoreAuthenticationTypeHTMLForm,
  75. AWSUICKeyChainStoreAuthenticationTypeDefault,
  76. };
  77. typedef NS_ENUM(NSInteger, AWSUICKeyChainStoreAccessibility) {
  78. AWSUICKeyChainStoreAccessibilityWhenUnlocked = 1,
  79. AWSUICKeyChainStoreAccessibilityAfterFirstUnlock,
  80. AWSUICKeyChainStoreAccessibilityAlways,
  81. AWSUICKeyChainStoreAccessibilityWhenPasscodeSetThisDeviceOnly
  82. __OSX_AVAILABLE_STARTING(__MAC_10_10, __IPHONE_8_0),
  83. AWSUICKeyChainStoreAccessibilityWhenUnlockedThisDeviceOnly,
  84. AWSUICKeyChainStoreAccessibilityAfterFirstUnlockThisDeviceOnly,
  85. AWSUICKeyChainStoreAccessibilityAlwaysThisDeviceOnly,
  86. }
  87. __OSX_AVAILABLE_STARTING(__MAC_10_9, __IPHONE_4_0);
  88. typedef NS_ENUM(NSInteger, AWSUICKeyChainStoreAuthenticationPolicy) {
  89. AWSUICKeyChainStoreAuthenticationPolicyUserPresence = kSecAccessControlUserPresence,
  90. };
  91. @interface AWSUICKeyChainStore : NSObject
  92. @property (nonatomic, readonly) AWSUICKeyChainStoreItemClass itemClass;
  93. @property (nonatomic, readonly, nullable) NSString *service;
  94. @property (nonatomic, readonly, nullable) NSString *accessGroup;
  95. @property (nonatomic, readonly, nullable) NSURL *server;
  96. @property (nonatomic, readonly) AWSUICKeyChainStoreProtocolType protocolType;
  97. @property (nonatomic, readonly) AWSUICKeyChainStoreAuthenticationType authenticationType;
  98. @property (nonatomic) AWSUICKeyChainStoreAccessibility accessibility;
  99. @property (nonatomic, readonly) AWSUICKeyChainStoreAuthenticationPolicy authenticationPolicy
  100. __OSX_AVAILABLE_STARTING(__MAC_10_10, __IPHONE_8_0);
  101. @property (nonatomic) BOOL synchronizable;
  102. @property (nonatomic, nullable) NSString *authenticationPrompt
  103. __OSX_AVAILABLE_STARTING(__MAC_NA, __IPHONE_8_0);
  104. @property (nonatomic, readonly, nullable) NSArray UIC_KEY_TYPE *allKeys;
  105. @property (nonatomic, readonly, nullable) NSArray *allItems;
  106. + (NSString *)defaultService;
  107. + (void)setDefaultService:(NSString *)defaultService;
  108. + (AWSUICKeyChainStore *)keyChainStore;
  109. + (AWSUICKeyChainStore *)keyChainStoreWithService:(nullable NSString *)service;
  110. + (AWSUICKeyChainStore *)keyChainStoreWithService:(nullable NSString *)service accessGroup:(nullable NSString *)accessGroup;
  111. + (AWSUICKeyChainStore *)keyChainStoreWithServer:(NSURL *)server protocolType:(AWSUICKeyChainStoreProtocolType)protocolType;
  112. + (AWSUICKeyChainStore *)keyChainStoreWithServer:(NSURL *)server protocolType:(AWSUICKeyChainStoreProtocolType)protocolType authenticationType:(AWSUICKeyChainStoreAuthenticationType)authenticationType;
  113. - (instancetype)init;
  114. - (instancetype)initWithService:(nullable NSString *)service;
  115. - (instancetype)initWithService:(nullable NSString *)service accessGroup:(nullable NSString *)accessGroup;
  116. - (instancetype)initWithServer:(NSURL *)server protocolType:(AWSUICKeyChainStoreProtocolType)protocolType;
  117. - (instancetype)initWithServer:(NSURL *)server protocolType:(AWSUICKeyChainStoreProtocolType)protocolType authenticationType:(AWSUICKeyChainStoreAuthenticationType)authenticationType;
  118. + (nullable NSString *)stringForKey:(NSString *)key;
  119. + (nullable NSString *)stringForKey:(NSString *)key service:(nullable NSString *)service;
  120. + (nullable NSString *)stringForKey:(NSString *)key service:(nullable NSString *)service accessGroup:(nullable NSString *)accessGroup;
  121. + (BOOL)setString:(nullable NSString *)value forKey:(NSString *)key;
  122. + (BOOL)setString:(nullable NSString *)value forKey:(NSString *)key service:(nullable NSString *)service;
  123. + (BOOL)setString:(nullable NSString *)value forKey:(NSString *)key service:(nullable NSString *)service accessGroup:(nullable NSString *)accessGroup;
  124. + (nullable NSData *)dataForKey:(NSString *)key;
  125. + (nullable NSData *)dataForKey:(NSString *)key service:(nullable NSString *)service;
  126. + (nullable NSData *)dataForKey:(NSString *)key service:(nullable NSString *)service accessGroup:(nullable NSString *)accessGroup;
  127. + (BOOL)setData:(nullable NSData *)data forKey:(NSString *)key;
  128. + (BOOL)setData:(nullable NSData *)data forKey:(NSString *)key service:(nullable NSString *)service;
  129. + (BOOL)setData:(nullable NSData *)data forKey:(NSString *)key service:(nullable NSString *)service accessGroup:(nullable NSString *)accessGroup;
  130. - (BOOL)contains:(nullable NSString *)key;
  131. - (BOOL)setString:(nullable NSString *)string forKey:(nullable NSString *)key;
  132. - (BOOL)setString:(nullable NSString *)string forKey:(nullable NSString *)key label:(nullable NSString *)label comment:(nullable NSString *)comment;
  133. - (nullable NSString *)stringForKey:(NSString *)key;
  134. - (BOOL)setData:(nullable NSData *)data forKey:(NSString *)key;
  135. - (BOOL)setData:(nullable NSData *)data forKey:(NSString *)key label:(nullable NSString *)label comment:(nullable NSString *)comment;
  136. - (nullable NSData *)dataForKey:(NSString *)key;
  137. + (BOOL)removeItemForKey:(NSString *)key;
  138. + (BOOL)removeItemForKey:(NSString *)key service:(nullable NSString *)service;
  139. + (BOOL)removeItemForKey:(NSString *)key service:(nullable NSString *)service accessGroup:(nullable NSString *)accessGroup;
  140. + (BOOL)removeAllItems;
  141. + (BOOL)removeAllItemsForService:(nullable NSString *)service;
  142. + (BOOL)removeAllItemsForService:(nullable NSString *)service accessGroup:(nullable NSString *)accessGroup;
  143. - (BOOL)removeItemForKey:(NSString *)key;
  144. - (BOOL)removeAllItems;
  145. - (nullable NSString *)objectForKeyedSubscript:(NSString<NSCopying> *)key;
  146. - (void)setObject:(nullable NSString *)obj forKeyedSubscript:(NSString<NSCopying> *)key;
  147. + (nullable NSArray UIC_KEY_TYPE *)allKeysWithItemClass:(AWSUICKeyChainStoreItemClass)itemClass;
  148. - (nullable NSArray UIC_KEY_TYPE *)allKeys;
  149. + (nullable NSArray *)allItemsWithItemClass:(AWSUICKeyChainStoreItemClass)itemClass;
  150. - (nullable NSArray *)allItems;
  151. - (void)setAccessibility:(AWSUICKeyChainStoreAccessibility)accessibility authenticationPolicy:(AWSUICKeyChainStoreAuthenticationPolicy)authenticationPolicy
  152. __OSX_AVAILABLE_STARTING(__MAC_10_10, __IPHONE_8_0);
  153. #if TARGET_OS_IOS
  154. - (void)sharedPasswordWithCompletion:(nullable void (^)(NSString * __nullable account, NSString * __nullable password, NSError * __nullable error))completion;
  155. - (void)sharedPasswordForAccount:(NSString *)account completion:(nullable void (^)(NSString * __nullable password, NSError * __nullable error))completion;
  156. - (void)setSharedPassword:(nullable NSString *)password forAccount:(NSString *)account completion:(nullable void (^)(NSError * __nullable error))completion;
  157. - (void)removeSharedPasswordForAccount:(NSString *)account completion:(nullable void (^)(NSError * __nullable error))completion;
  158. + (void)requestSharedWebCredentialWithCompletion:(nullable void (^)(NSArray UIC_CREDENTIAL_TYPE *credentials, NSError * __nullable error))completion;
  159. + (void)requestSharedWebCredentialForDomain:(nullable NSString *)domain account:(nullable NSString *)account completion:(nullable void (^)(NSArray UIC_CREDENTIAL_TYPE *credentials, NSError * __nullable error))completion;
  160. + (NSString *)generatePassword;
  161. #endif
  162. @end
  163. @interface AWSUICKeyChainStore (ErrorHandling)
  164. + (nullable NSString *)stringForKey:(NSString *)key error:(NSError * __nullable __autoreleasing * __nullable)error;
  165. + (nullable NSString *)stringForKey:(NSString *)key service:(nullable NSString *)service error:(NSError * __nullable __autoreleasing * __nullable)error;
  166. + (nullable NSString *)stringForKey:(NSString *)key service:(nullable NSString *)service accessGroup:(nullable NSString *)accessGroup error:(NSError * __nullable __autoreleasing * __nullable)error;
  167. + (BOOL)setString:(nullable NSString *)value forKey:(NSString *)key error:(NSError * __nullable __autoreleasing * __nullable)error;
  168. + (BOOL)setString:(nullable NSString *)value forKey:(NSString *)key service:(nullable NSString *)service error:(NSError * __nullable __autoreleasing * __nullable)error;
  169. + (BOOL)setString:(nullable NSString *)value forKey:(NSString *)key service:(nullable NSString *)service accessGroup:(nullable NSString *)accessGroup error:(NSError * __nullable __autoreleasing * __nullable)error;
  170. + (nullable NSData *)dataForKey:(NSString *)key error:(NSError * __nullable __autoreleasing * __nullable)error;
  171. + (nullable NSData *)dataForKey:(NSString *)key service:(nullable NSString *)service error:(NSError * __nullable __autoreleasing * __nullable)error;
  172. + (nullable NSData *)dataForKey:(NSString *)key service:(nullable NSString *)service accessGroup:(nullable NSString *)accessGroup error:(NSError * __nullable __autoreleasing * __nullable)error;
  173. + (BOOL)setData:(nullable NSData *)data forKey:(NSString *)key error:(NSError * __nullable __autoreleasing * __nullable)error;
  174. + (BOOL)setData:(nullable NSData *)data forKey:(NSString *)key service:(nullable NSString *)service error:(NSError * __nullable __autoreleasing * __nullable)error;
  175. + (BOOL)setData:(nullable NSData *)data forKey:(NSString *)key service:(nullable NSString *)service accessGroup:(nullable NSString *)accessGroup error:(NSError * __nullable __autoreleasing * __nullable)error;
  176. - (BOOL)setString:(nullable NSString *)string forKey:(NSString * )key error:(NSError * __nullable __autoreleasing * __nullable)error;
  177. - (BOOL)setString:(nullable NSString *)string forKey:(NSString * )key label:(nullable NSString *)label comment:(nullable NSString *)comment error:(NSError * __nullable __autoreleasing * __nullable)error;
  178. - (BOOL)setData:(nullable NSData *)data forKey:(NSString *)key error:(NSError * __nullable __autoreleasing * __nullable)error;
  179. - (BOOL)setData:(nullable NSData *)data forKey:(NSString *)key label:(nullable NSString *)label comment:(nullable NSString *)comment error:(NSError * __nullable __autoreleasing * __nullable)error;
  180. - (nullable NSString *)stringForKey:(NSString *)key error:(NSError * __nullable __autoreleasing * __nullable)error;
  181. - (nullable NSData *)dataForKey:(NSString *)key error:(NSError * __nullable __autoreleasing * __nullable)error;
  182. + (BOOL)removeItemForKey:(NSString *)key error:(NSError * __nullable __autoreleasing * __nullable)error;
  183. + (BOOL)removeItemForKey:(NSString *)key service:(nullable NSString *)service error:(NSError * __nullable __autoreleasing * __nullable)error;
  184. + (BOOL)removeItemForKey:(NSString *)key service:(nullable NSString *)service accessGroup:(nullable NSString *)accessGroup error:(NSError * __nullable __autoreleasing * __nullable)error;
  185. + (BOOL)removeAllItemsWithError:(NSError * __nullable __autoreleasing * __nullable)error;
  186. + (BOOL)removeAllItemsForService:(nullable NSString *)service error:(NSError * __nullable __autoreleasing * __nullable)error;
  187. + (BOOL)removeAllItemsForService:(nullable NSString *)service accessGroup:(nullable NSString *)accessGroup error:(NSError * __nullable __autoreleasing * __nullable)error;
  188. - (BOOL)removeItemForKey:(NSString *)key error:(NSError * __nullable __autoreleasing * __nullable)error;
  189. - (BOOL)removeAllItemsWithError:(NSError * __nullable __autoreleasing * __nullable)error;
  190. @end
  191. @interface AWSUICKeyChainStore (ForwardCompatibility)
  192. + (BOOL)setString:(nullable NSString *)value forKey:(NSString *)key genericAttribute:(nullable id)genericAttribute;
  193. + (BOOL)setString:(nullable NSString *)value forKey:(NSString *)key genericAttribute:(nullable id)genericAttribute error:(NSError * __nullable __autoreleasing * __nullable)error;
  194. + (BOOL)setString:(nullable NSString *)value forKey:(NSString *)key service:(nullable NSString *)service genericAttribute:(nullable id)genericAttribute;
  195. + (BOOL)setString:(nullable NSString *)value forKey:(NSString *)key service:(nullable NSString *)service genericAttribute:(nullable id)genericAttribute error:(NSError * __nullable __autoreleasing * __nullable)error;
  196. + (BOOL)setString:(nullable NSString *)value forKey:(NSString *)key service:(nullable NSString *)service accessGroup:(nullable NSString *)accessGroup genericAttribute:(nullable id)genericAttribute;
  197. + (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;
  198. + (BOOL)setData:(nullable NSData *)data forKey:(NSString *)key genericAttribute:(nullable id)genericAttribute;
  199. + (BOOL)setData:(nullable NSData *)data forKey:(NSString *)key genericAttribute:(nullable id)genericAttribute error:(NSError * __nullable __autoreleasing * __nullable)error;
  200. + (BOOL)setData:(nullable NSData *)data forKey:(NSString *)key service:(nullable NSString *)service genericAttribute:(nullable id)genericAttribute;
  201. + (BOOL)setData:(nullable NSData *)data forKey:(NSString *)key service:(nullable NSString *)service genericAttribute:(nullable id)genericAttribute error:(NSError * __nullable __autoreleasing * __nullable)error;
  202. + (BOOL)setData:(nullable NSData *)data forKey:(NSString *)key service:(nullable NSString *)service accessGroup:(nullable NSString *)accessGroup genericAttribute:(nullable id)genericAttribute;
  203. + (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;
  204. - (BOOL)setString:(nullable NSString *)string forKey:(NSString *)key genericAttribute:(nullable id)genericAttribute;
  205. - (BOOL)setString:(nullable NSString *)string forKey:(NSString *)key genericAttribute:(nullable id)genericAttribute error:(NSError * __nullable __autoreleasing * __nullable)error;
  206. - (BOOL)setData:(nullable NSData *)data forKey:(NSString *)key genericAttribute:(nullable id)genericAttribute;
  207. - (BOOL)setData:(nullable NSData *)data forKey:(NSString *)key genericAttribute:(nullable id)genericAttribute error:(NSError * __nullable __autoreleasing * __nullable)error;
  208. @end
  209. NS_ASSUME_NONNULL_END