com.amanotes.gdk 0.1.19 → 0.1.21

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/Packages/AmaGDKConfig.unitypackage +0 -0
  3. package/Packages/AmaGDKExample.unitypackage +0 -0
  4. package/Packages/AmaGDKTest.unitypackage +0 -0
  5. package/Packages/AppsFlyerAdapter_v6.5.4.unitypackage +0 -0
  6. package/Packages/FirebaseAnalyticsAdapter_v9.1.0.unitypackage +0 -0
  7. package/Packages/FirebaseRemoteConfigAdapter_v9.1.0.unitypackage +0 -0
  8. package/{Samples~/Example/AmaGDKExample.unity.meta → Packages/FirebaseRemoteConfigAdapter_v9.1.0.unitypackage.meta} +1 -1
  9. package/Packages/IronsourceAdapter_v7.2.6.unitypackage +0 -0
  10. package/Runtime/AmaGDK.Adapters.cs +19 -0
  11. package/Runtime/AmaGDK.Ads.cs +2 -16
  12. package/Runtime/AmaGDK.RemoteConfig.cs +282 -55
  13. package/Runtime/AmaGDK.Utils.cs +42 -13
  14. package/Runtime/AmaGDK.WebUtils.cs +6 -9
  15. package/Runtime/AmaGDK.cs +5 -4
  16. package/package.json +1 -1
  17. package/Packages/AppsflyerAdapter_v6.5.4.unitypackage +0 -0
  18. package/Runtime/AmaPassport/AmaGDK.AmaPassport.cs +0 -444
  19. package/Runtime/AmaPassport/AmaGDK.AmaPassport.cs.meta +0 -11
  20. package/Runtime/AmaPassport/Plugins/Android/AdvertisingIdCallback.java +0 -7
  21. package/Runtime/AmaPassport/Plugins/Android/AdvertisingIdCallback.java.meta +0 -32
  22. package/Runtime/AmaPassport/Plugins/Android/AdvertisingIdFetcher.cs +0 -96
  23. package/Runtime/AmaPassport/Plugins/Android/AdvertisingIdFetcher.cs.meta +0 -11
  24. package/Runtime/AmaPassport/Plugins/Android/AdvertisingIdFetcher.java +0 -79
  25. package/Runtime/AmaPassport/Plugins/Android/AdvertisingIdFetcher.java.meta +0 -32
  26. package/Runtime/AmaPassport/Plugins/Android.meta +0 -8
  27. package/Runtime/AmaPassport/Plugins/iOS/KeyChain.cs +0 -59
  28. package/Runtime/AmaPassport/Plugins/iOS/KeyChain.cs.meta +0 -11
  29. package/Runtime/AmaPassport/Plugins/iOS/KeyChainPlugin.mm +0 -52
  30. package/Runtime/AmaPassport/Plugins/iOS/KeyChainPlugin.mm.meta +0 -33
  31. package/Runtime/AmaPassport/Plugins/iOS/UICKeyChainStore.h +0 -281
  32. package/Runtime/AmaPassport/Plugins/iOS/UICKeyChainStore.h.meta +0 -33
  33. package/Runtime/AmaPassport/Plugins/iOS/UICKeyChainStore.m +0 -1393
  34. package/Runtime/AmaPassport/Plugins/iOS/UICKeyChainStore.m.meta +0 -33
  35. package/Runtime/AmaPassport/Plugins/iOS.meta +0 -8
  36. package/Runtime/AmaPassport/Plugins.meta +0 -8
  37. package/Runtime/AmaPassport.meta +0 -8
  38. package/Samples~/Example/AmaGDKExample.cs +0 -87
  39. package/Samples~/Example/AmaGDKExample.cs.meta +0 -11
  40. package/Samples~/Example/AmaGDKExample.unity +0 -3114
  41. package/Sample~/Example/AmaGDKExample.cs +0 -87
  42. package/Sample~/Example/AmaGDKExample.cs.meta +0 -11
  43. package/Sample~/Example/AmaGDKExample.unity +0 -3114
  44. package/Sample~/Example/AmaGDKExample.unity.meta +0 -7
@@ -1,1393 +0,0 @@
1
- //
2
- // UICKeyChainStore.m
3
- // UICKeyChainStore
4
- //
5
- // Created by Kishikawa Katsumi on 11/11/20.
6
- // Copyright (c) 2011 Kishikawa Katsumi. All rights reserved.
7
- //
8
-
9
- #import "UICKeyChainStore.h"
10
-
11
- NSString * const UICKeyChainStoreErrorDomain = @"com.amanotes.uickeychainstore";
12
-
13
- static NSString *_defaultService;
14
-
15
- @interface UICKeyChainStore ()
16
-
17
- @end
18
-
19
- @implementation UICKeyChainStore
20
-
21
- + (NSString *)defaultService
22
- {
23
- if (!_defaultService) {
24
- _defaultService = [[NSBundle mainBundle] bundleIdentifier] ?: @"";
25
- }
26
-
27
- return _defaultService;
28
- }
29
-
30
- + (void)setDefaultService:(NSString *)defaultService
31
- {
32
- _defaultService = defaultService;
33
- }
34
-
35
- #pragma mark -
36
-
37
- + (UICKeyChainStore *)keyChainStore
38
- {
39
- return [[self alloc] initWithService:nil accessGroup:nil];
40
- }
41
-
42
- + (UICKeyChainStore *)keyChainStoreWithService:(NSString *)service
43
- {
44
- return [[self alloc] initWithService:service accessGroup:nil];
45
- }
46
-
47
- + (UICKeyChainStore *)keyChainStoreWithService:(NSString *)service accessGroup:(NSString *)accessGroup
48
- {
49
- return [[self alloc] initWithService:service accessGroup:accessGroup];
50
- }
51
-
52
- #pragma mark -
53
-
54
- + (UICKeyChainStore *)keyChainStoreWithServer:(NSURL *)server protocolType:(UICKeyChainStoreProtocolType)protocolType
55
- {
56
- return [[self alloc] initWithServer:server protocolType:protocolType authenticationType:UICKeyChainStoreAuthenticationTypeDefault];
57
- }
58
-
59
- + (UICKeyChainStore *)keyChainStoreWithServer:(NSURL *)server protocolType:(UICKeyChainStoreProtocolType)protocolType authenticationType:(UICKeyChainStoreAuthenticationType)authenticationType
60
- {
61
- return [[self alloc] initWithServer:server protocolType:protocolType authenticationType:authenticationType];
62
- }
63
-
64
- #pragma mark -
65
-
66
- - (instancetype)init
67
- {
68
- return [self initWithService:[self.class defaultService] accessGroup:nil];
69
- }
70
-
71
- - (instancetype)initWithService:(NSString *)service
72
- {
73
- return [self initWithService:service accessGroup:nil];
74
- }
75
-
76
- - (instancetype)initWithService:(NSString *)service accessGroup:(NSString *)accessGroup
77
- {
78
- self = [super init];
79
- if (self) {
80
- _itemClass = UICKeyChainStoreItemClassGenericPassword;
81
-
82
- if (!service) {
83
- service = [self.class defaultService];
84
- }
85
- _service = service.copy;
86
- _accessGroup = accessGroup.copy;
87
- [self commonInit];
88
- }
89
-
90
- return self;
91
- }
92
-
93
- #pragma mark -
94
-
95
- - (instancetype)initWithServer:(NSURL *)server protocolType:(UICKeyChainStoreProtocolType)protocolType
96
- {
97
- return [self initWithServer:server protocolType:protocolType authenticationType:UICKeyChainStoreAuthenticationTypeDefault];
98
- }
99
-
100
- - (instancetype)initWithServer:(NSURL *)server protocolType:(UICKeyChainStoreProtocolType)protocolType authenticationType:(UICKeyChainStoreAuthenticationType)authenticationType
101
- {
102
- self = [super init];
103
- if (self) {
104
- _itemClass = UICKeyChainStoreItemClassInternetPassword;
105
-
106
- _server = server.copy;
107
- _protocolType = protocolType;
108
- _authenticationType = authenticationType;
109
-
110
- [self commonInit];
111
- }
112
-
113
- return self;
114
- }
115
-
116
- #pragma mark -
117
-
118
- - (void)commonInit
119
- {
120
- _accessibility = UICKeyChainStoreAccessibilityAfterFirstUnlock;
121
- }
122
-
123
- #pragma mark -
124
-
125
- + (NSString *)stringForKey:(NSString *)key
126
- {
127
- return [self stringForKey:key service:nil accessGroup:nil error:nil];
128
- }
129
-
130
- + (NSString *)stringForKey:(NSString *)key error:(NSError *__autoreleasing *)error
131
- {
132
- return [self stringForKey:key service:nil accessGroup:nil error:error];
133
- }
134
-
135
- + (NSString *)stringForKey:(NSString *)key service:(NSString *)service
136
- {
137
- return [self stringForKey:key service:service accessGroup:nil error:nil];
138
- }
139
-
140
- + (NSString *)stringForKey:(NSString *)key service:(NSString *)service error:(NSError *__autoreleasing *)error
141
- {
142
- return [self stringForKey:key service:service accessGroup:nil error:error];
143
- }
144
-
145
- + (NSString *)stringForKey:(NSString *)key service:(NSString *)service accessGroup:(NSString *)accessGroup
146
- {
147
- return [self stringForKey:key service:service accessGroup:accessGroup error:nil];
148
- }
149
-
150
- + (NSString *)stringForKey:(NSString *)key service:(NSString *)service accessGroup:(NSString *)accessGroup error:(NSError *__autoreleasing *)error
151
- {
152
- if (!key) {
153
- NSError *e = [self argumentError:NSLocalizedString(@"the key must not to be nil", nil)];
154
- if (error) {
155
- *error = e;
156
- }
157
- return nil;
158
- }
159
- if (!service) {
160
- service = [self defaultService];
161
- }
162
-
163
- UICKeyChainStore *keychain = [UICKeyChainStore keyChainStoreWithService:service accessGroup:accessGroup];
164
- return [keychain stringForKey:key error:error];
165
- }
166
-
167
- #pragma mark -
168
-
169
- + (BOOL)setString:(NSString *)value forKey:(NSString *)key
170
- {
171
- return [self setString:value forKey:key service:nil accessGroup:nil genericAttribute:nil error:nil];
172
- }
173
-
174
- + (BOOL)setString:(NSString *)value forKey:(NSString *)key error:(NSError *__autoreleasing *)error
175
- {
176
- return [self setString:value forKey:key service:nil accessGroup:nil genericAttribute:nil error:error];
177
- }
178
-
179
- + (BOOL)setString:(NSString *)value forKey:(NSString *)key genericAttribute:(id)genericAttribute
180
- {
181
- return [self setString:value forKey:key service:nil accessGroup:nil genericAttribute:genericAttribute error:nil];
182
- }
183
-
184
- + (BOOL)setString:(NSString *)value forKey:(NSString *)key genericAttribute:(id)genericAttribute error:(NSError * __autoreleasing *)error
185
- {
186
- return [self setString:value forKey:key service:nil accessGroup:nil genericAttribute:genericAttribute error:error];
187
- }
188
-
189
- + (BOOL)setString:(NSString *)value forKey:(NSString *)key service:(NSString *)service
190
- {
191
- return [self setString:value forKey:key service:service accessGroup:nil genericAttribute:nil error:nil];
192
- }
193
-
194
- + (BOOL)setString:(NSString *)value forKey:(NSString *)key service:(NSString *)service error:(NSError *__autoreleasing *)error
195
- {
196
- return [self setString:value forKey:key service:service accessGroup:nil genericAttribute:nil error:error];
197
- }
198
-
199
- + (BOOL)setString:(NSString *)value forKey:(NSString *)key service:(NSString *)service genericAttribute:(id)genericAttribute
200
- {
201
- return [self setString:value forKey:key service:service accessGroup:nil genericAttribute:genericAttribute error:nil];
202
- }
203
-
204
- + (BOOL)setString:(NSString *)value forKey:(NSString *)key service:(NSString *)service genericAttribute:(id)genericAttribute error:(NSError * __autoreleasing *)error
205
- {
206
- return [self setString:value forKey:key service:service accessGroup:nil genericAttribute:genericAttribute error:error];
207
- }
208
-
209
- + (BOOL)setString:(NSString *)value forKey:(NSString *)key service:(NSString *)service accessGroup:(NSString *)accessGroup
210
- {
211
- return [self setString:value forKey:key service:service accessGroup:accessGroup genericAttribute:nil error:nil];
212
- }
213
-
214
- + (BOOL)setString:(NSString *)value forKey:(NSString *)key service:(NSString *)service accessGroup:(NSString *)accessGroup error:(NSError *__autoreleasing *)error
215
- {
216
- return [self setString:value forKey:key service:service accessGroup:accessGroup genericAttribute:nil error:error];
217
- }
218
-
219
- + (BOOL)setString:(NSString *)value forKey:(NSString *)key service:(NSString *)service accessGroup:(NSString *)accessGroup genericAttribute:(id)genericAttribute
220
- {
221
- return [self setString:value forKey:key service:service accessGroup:accessGroup genericAttribute:genericAttribute error:nil];
222
- }
223
-
224
- + (BOOL)setString:(NSString *)value forKey:(NSString *)key service:(NSString *)service accessGroup:(NSString *)accessGroup genericAttribute:(id)genericAttribute error:(NSError * __autoreleasing *)error
225
- {
226
- if (!value) {
227
- return [self removeItemForKey:key service:service accessGroup:accessGroup error:error];
228
- }
229
- NSData *data = [value dataUsingEncoding:NSUTF8StringEncoding];
230
- if (data) {
231
- return [self setData:data forKey:key service:service accessGroup:accessGroup genericAttribute:genericAttribute error:error];
232
- }
233
- NSError *e = [self conversionError:NSLocalizedString(@"failed to convert string to data", nil)];
234
- if (error) {
235
- *error = e;
236
- }
237
- return NO;
238
- }
239
-
240
- #pragma mark -
241
-
242
- + (NSData *)dataForKey:(NSString *)key
243
- {
244
- return [self dataForKey:key service:nil accessGroup:nil error:nil];
245
- }
246
-
247
- + (NSData *)dataForKey:(NSString *)key error:(NSError *__autoreleasing *)error
248
- {
249
- return [self dataForKey:key service:nil accessGroup:nil error:error];
250
- }
251
-
252
- + (NSData *)dataForKey:(NSString *)key service:(NSString *)service
253
- {
254
- return [self dataForKey:key service:service accessGroup:nil error:nil];
255
- }
256
-
257
- + (NSData *)dataForKey:(NSString *)key service:(NSString *)service error:(NSError *__autoreleasing *)error
258
- {
259
- return [self dataForKey:key service:service accessGroup:nil error:error];
260
- }
261
-
262
- + (NSData *)dataForKey:(NSString *)key service:(NSString *)service accessGroup:(NSString *)accessGroup
263
- {
264
- return [self dataForKey:key service:service accessGroup:accessGroup error:nil];
265
- }
266
-
267
- + (NSData *)dataForKey:(NSString *)key service:(NSString *)service accessGroup:(NSString *)accessGroup error:(NSError *__autoreleasing *)error
268
- {
269
- if (!key) {
270
- NSError *e = [self argumentError:NSLocalizedString(@"the key must not to be nil", nil)];
271
- if (error) {
272
- *error = e;
273
- }
274
- return nil;
275
- }
276
- if (!service) {
277
- service = [self defaultService];
278
- }
279
-
280
- UICKeyChainStore *keychain = [UICKeyChainStore keyChainStoreWithService:service accessGroup:accessGroup];
281
- return [keychain dataForKey:key error:error];
282
- }
283
-
284
- #pragma mark -
285
-
286
- + (BOOL)setData:(NSData *)data forKey:(NSString *)key
287
- {
288
- return [self setData:data forKey:key service:nil accessGroup:nil genericAttribute:nil error:nil];
289
- }
290
-
291
- + (BOOL)setData:(NSData *)data forKey:(NSString *)key error:(NSError *__autoreleasing *)error
292
- {
293
- return [self setData:data forKey:key service:nil accessGroup:nil genericAttribute:nil error:error];
294
- }
295
-
296
- + (BOOL)setData:(NSData *)data forKey:(NSString *)key genericAttribute:(id)genericAttribute
297
- {
298
- return [self setData:data forKey:key service:nil accessGroup:nil genericAttribute:genericAttribute error:nil];
299
- }
300
-
301
- + (BOOL)setData:(NSData *)data forKey:(NSString *)key genericAttribute:(id)genericAttribute error:(NSError * __autoreleasing *)error
302
- {
303
- return [self setData:data forKey:key service:nil accessGroup:nil genericAttribute:genericAttribute error:error];
304
- }
305
-
306
- + (BOOL)setData:(NSData *)data forKey:(NSString *)key service:(NSString *)service
307
- {
308
- return [self setData:data forKey:key service:service accessGroup:nil genericAttribute:nil error:nil];
309
- }
310
-
311
- + (BOOL)setData:(NSData *)data forKey:(NSString *)key service:(NSString *)service error:(NSError *__autoreleasing *)error
312
- {
313
- return [self setData:data forKey:key service:service accessGroup:nil genericAttribute:nil error:error];
314
- }
315
-
316
- + (BOOL)setData:(NSData *)data forKey:(NSString *)key service:(NSString *)service genericAttribute:(id)genericAttribute
317
- {
318
- return [self setData:data forKey:key service:service accessGroup:nil genericAttribute:genericAttribute error:nil];
319
- }
320
-
321
- + (BOOL)setData:(NSData *)data forKey:(NSString *)key service:(NSString *)service genericAttribute:(id)genericAttribute error:(NSError * __autoreleasing *)error
322
- {
323
- return [self setData:data forKey:key service:service accessGroup:nil genericAttribute:genericAttribute error:error];
324
- }
325
-
326
- + (BOOL)setData:(NSData *)data forKey:(NSString *)key service:(NSString *)service accessGroup:(NSString *)accessGroup
327
- {
328
- return [self setData:data forKey:key service:service accessGroup:accessGroup genericAttribute:nil error:nil];
329
- }
330
-
331
- + (BOOL)setData:(NSData *)data forKey:(NSString *)key service:(NSString *)service accessGroup:(NSString *)accessGroup error:(NSError *__autoreleasing *)error
332
- {
333
- return [self setData:data forKey:key service:service accessGroup:accessGroup genericAttribute:nil error:error];
334
- }
335
-
336
- + (BOOL)setData:(NSData *)data forKey:(NSString *)key service:(NSString *)service accessGroup:(NSString *)accessGroup genericAttribute:(id)genericAttribute
337
- {
338
- return [self setData:data forKey:key service:service accessGroup:accessGroup genericAttribute:genericAttribute error:nil];
339
- }
340
-
341
- + (BOOL)setData:(NSData *)data forKey:(NSString *)key service:(NSString *)service accessGroup:(NSString *)accessGroup genericAttribute:(id)genericAttribute error:(NSError * __autoreleasing *)error
342
- {
343
- if (!key) {
344
- NSError *e = [self argumentError:NSLocalizedString(@"the key must not to be nil", nil)];
345
- if (error) {
346
- *error = e;
347
- }
348
- return NO;
349
- }
350
- if (!service) {
351
- service = [self defaultService];
352
- }
353
-
354
- UICKeyChainStore *keychain = [UICKeyChainStore keyChainStoreWithService:service accessGroup:accessGroup];
355
- return [keychain setData:data forKey:key genericAttribute:genericAttribute];
356
- }
357
-
358
- #pragma mark -
359
-
360
- - (BOOL)contains:(NSString *)key
361
- {
362
- NSMutableDictionary *query = [self query];
363
- query[(__bridge __strong id)kSecAttrAccount] = key;
364
-
365
- OSStatus status = SecItemCopyMatching((__bridge CFDictionaryRef)query, NULL);
366
- return status == errSecSuccess;
367
- }
368
-
369
- #pragma mark -
370
-
371
- - (NSString *)stringForKey:(id)key
372
- {
373
- return [self stringForKey:key error:nil];
374
- }
375
-
376
- - (NSString *)stringForKey:(id)key error:(NSError *__autoreleasing *)error
377
- {
378
- NSData *data = [self dataForKey:key error:error];
379
- if (data) {
380
- NSString *string = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
381
- if (string) {
382
- return string;
383
- }
384
- NSError *e = [self.class conversionError:NSLocalizedString(@"failed to convert data to string", nil)];
385
- if (error) {
386
- *error = e;
387
- }
388
- return nil;
389
- }
390
-
391
- return nil;
392
- }
393
-
394
- #pragma mark -
395
-
396
- - (BOOL)setString:(NSString *)string forKey:(NSString *)key
397
- {
398
- return [self setString:string forKey:key genericAttribute:nil label:nil comment:nil error:nil];
399
- }
400
-
401
- - (BOOL)setString:(NSString *)string forKey:(NSString *)key error:(NSError *__autoreleasing *)error
402
- {
403
- return [self setString:string forKey:key genericAttribute:nil label:nil comment:nil error:error];
404
- }
405
-
406
- - (BOOL)setString:(NSString *)string forKey:(NSString *)key genericAttribute:(id)genericAttribute
407
- {
408
- return [self setString:string forKey:key genericAttribute:genericAttribute label:nil comment:nil error:nil];
409
- }
410
-
411
- - (BOOL)setString:(NSString *)string forKey:(NSString *)key genericAttribute:(id)genericAttribute error:(NSError * __autoreleasing *)error
412
- {
413
- return [self setString:string forKey:key genericAttribute:genericAttribute label:nil comment:nil error:error];
414
- }
415
-
416
- - (BOOL)setString:(NSString *)string forKey:(NSString *)key label:(NSString *)label comment:(NSString *)comment
417
- {
418
- return [self setString:string forKey:key genericAttribute:nil label:label comment:comment error:nil];
419
- }
420
-
421
- - (BOOL)setString:(NSString *)string forKey:(NSString *)key label:(NSString *)label comment:(NSString *)comment error:(NSError *__autoreleasing *)error
422
- {
423
- return [self setString:string forKey:key genericAttribute:nil label:label comment:comment error:error];
424
- }
425
-
426
- - (BOOL)setString:(NSString *)string forKey:(NSString *)key genericAttribute:(id)genericAttribute label:(NSString *)label comment:(NSString *)comment error:(NSError *__autoreleasing *)error
427
- {
428
- if (!string) {
429
- return [self removeItemForKey:key error:error];
430
- }
431
- NSData *data = [string dataUsingEncoding:NSUTF8StringEncoding];
432
- if (data) {
433
- return [self setData:data forKey:key genericAttribute:genericAttribute label:label comment:comment error:error];
434
- }
435
- NSError *e = [self.class conversionError:NSLocalizedString(@"failed to convert string to data", nil)];
436
- if (error) {
437
- *error = e;
438
- }
439
- return NO;
440
- }
441
-
442
- #pragma mark -
443
-
444
- - (NSData *)dataForKey:(NSString *)key
445
- {
446
- return [self dataForKey:key error:nil];
447
- }
448
-
449
- - (NSData *)dataForKey:(NSString *)key error:(NSError *__autoreleasing *)error
450
- {
451
- NSMutableDictionary *query = [self query];
452
- query[(__bridge __strong id)kSecMatchLimit] = (__bridge id)kSecMatchLimitOne;
453
- query[(__bridge __strong id)kSecReturnData] = (__bridge id)kCFBooleanTrue;
454
-
455
- query[(__bridge __strong id)kSecAttrAccount] = key;
456
-
457
- CFTypeRef data = nil;
458
- OSStatus status = SecItemCopyMatching((__bridge CFDictionaryRef)query, &data);
459
-
460
- if (status == errSecSuccess) {
461
- NSData *ret = [NSData dataWithData:(__bridge NSData *)data];
462
- if (data) {
463
- CFRelease(data);
464
- return ret;
465
- } else {
466
- NSError *e = [self.class unexpectedError:NSLocalizedString(@"Unexpected error has occurred.", nil)];
467
- if (error) {
468
- *error = e;
469
- }
470
- return nil;
471
- }
472
- } else if (status == errSecItemNotFound) {
473
- return nil;
474
- }
475
-
476
- NSError *e = [self.class securityError:status];
477
- if (error) {
478
- *error = e;
479
- }
480
- return nil;
481
- }
482
-
483
- #pragma mark -
484
-
485
- - (BOOL)setData:(NSData *)data forKey:(NSString *)key
486
- {
487
- return [self setData:data forKey:key genericAttribute:nil label:nil comment:nil error:nil];
488
- }
489
-
490
- - (BOOL)setData:(NSData *)data forKey:(NSString *)key error:(NSError *__autoreleasing *)error
491
- {
492
- return [self setData:data forKey:key genericAttribute:nil label:nil comment:nil error:error];
493
- }
494
-
495
- - (BOOL)setData:(NSData *)data forKey:(NSString *)key genericAttribute:(id)genericAttribute
496
- {
497
- return [self setData:data forKey:key genericAttribute:genericAttribute label:nil comment:nil error:nil];
498
- }
499
-
500
- - (BOOL)setData:(NSData *)data forKey:(NSString *)key genericAttribute:(id)genericAttribute error:(NSError * __autoreleasing *)error
501
- {
502
- return [self setData:data forKey:key genericAttribute:genericAttribute label:nil comment:nil error:error];
503
- }
504
-
505
- - (BOOL)setData:(NSData *)data forKey:(NSString *)key label:(NSString *)label comment:(NSString *)comment
506
- {
507
- return [self setData:data forKey:key genericAttribute:nil label:label comment:comment error:nil];
508
- }
509
-
510
- - (BOOL)setData:(NSData *)data forKey:(NSString *)key label:(NSString *)label comment:(NSString *)comment error:(NSError *__autoreleasing *)error
511
- {
512
- return [self setData:data forKey:key genericAttribute:nil label:label comment:comment error:error];
513
- }
514
-
515
- - (BOOL)setData:(NSData *)data forKey:(NSString *)key genericAttribute:(id)genericAttribute label:(NSString *)label comment:(NSString *)comment error:(NSError *__autoreleasing *)error
516
- {
517
- if (!key) {
518
- NSError *e = [self.class argumentError:NSLocalizedString(@"the key must not to be nil", nil)];
519
- if (error) {
520
- *error = e;
521
- }
522
- return NO;
523
- }
524
- if (!data) {
525
- return [self removeItemForKey:key error:error];
526
- }
527
-
528
- NSMutableDictionary *query = [self query];
529
- query[(__bridge __strong id)kSecAttrAccount] = key;
530
- #if TARGET_OS_IOS
531
- if (floor(NSFoundationVersionNumber) > floor(1144.17)) { // iOS 9+
532
- query[(__bridge __strong id)kSecUseAuthenticationUI] = (__bridge id)kSecUseAuthenticationUIFail;
533
- #if __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_9_0
534
- } else if (floor(NSFoundationVersionNumber) > floor(1047.25)) { // iOS 8+
535
- query[(__bridge __strong id)kSecUseNoAuthenticationUI] = (__bridge id)kCFBooleanTrue;
536
- #endif
537
- }
538
- #elif TARGET_OS_WATCH || TARGET_OS_TV
539
- query[(__bridge __strong id)kSecUseAuthenticationUI] = (__bridge id)kSecUseAuthenticationUIFail;
540
- #endif
541
-
542
- OSStatus status = SecItemCopyMatching((__bridge CFDictionaryRef)query, NULL);
543
- if (status == errSecSuccess || status == errSecInteractionNotAllowed) {
544
- query = [self query];
545
- query[(__bridge __strong id)kSecAttrAccount] = key;
546
-
547
- NSError *unexpectedError = nil;
548
- NSMutableDictionary *attributes = [self attributesWithKey:nil value:data error:&unexpectedError];
549
-
550
- if (genericAttribute) {
551
- attributes[(__bridge __strong id)kSecAttrGeneric] = genericAttribute;
552
- }
553
- if (label) {
554
- attributes[(__bridge __strong id)kSecAttrLabel] = label;
555
- }
556
- if (comment) {
557
- attributes[(__bridge __strong id)kSecAttrComment] = comment;
558
- }
559
-
560
- if (unexpectedError) {
561
- NSLog(@"error: [%@] %@", @(unexpectedError.code), NSLocalizedString(@"Unexpected error has occurred.", nil));
562
- if (error) {
563
- *error = unexpectedError;
564
- }
565
- return NO;
566
- } else {
567
-
568
- if (status == errSecInteractionNotAllowed && floor(NSFoundationVersionNumber) <= floor(1140.11)) { // iOS 8.0.x
569
- if ([self removeItemForKey:key error:error]) {
570
- return [self setData:data forKey:key label:label comment:comment error:error];
571
- }
572
- } else {
573
- status = SecItemUpdate((__bridge CFDictionaryRef)query, (__bridge CFDictionaryRef)attributes);
574
- }
575
- if (status != errSecSuccess) {
576
- NSError *e = [self.class securityError:status];
577
- if (error) {
578
- *error = e;
579
- }
580
- return NO;
581
- }
582
- }
583
- } else if (status == errSecItemNotFound) {
584
- NSError *unexpectedError = nil;
585
- NSMutableDictionary *attributes = [self attributesWithKey:key value:data error:&unexpectedError];
586
-
587
- if (genericAttribute) {
588
- attributes[(__bridge __strong id)kSecAttrGeneric] = genericAttribute;
589
- }
590
- if (label) {
591
- attributes[(__bridge __strong id)kSecAttrLabel] = label;
592
- }
593
- if (comment) {
594
- attributes[(__bridge __strong id)kSecAttrComment] = comment;
595
- }
596
-
597
- if (unexpectedError) {
598
- NSLog(@"error: [%@] %@", @(unexpectedError.code), NSLocalizedString(@"Unexpected error has occurred.", nil));
599
- if (error) {
600
- *error = unexpectedError;
601
- }
602
- return NO;
603
- } else {
604
- status = SecItemAdd((__bridge CFDictionaryRef)attributes, NULL);
605
- if (status != errSecSuccess) {
606
- NSError *e = [self.class securityError:status];
607
- if (error) {
608
- *error = e;
609
- }
610
- return NO;
611
- }
612
- }
613
- } else {
614
- NSError *e = [self.class securityError:status];
615
- if (error) {
616
- *error = e;
617
- }
618
- return NO;
619
- }
620
-
621
- return YES;
622
- }
623
-
624
- #pragma mark -
625
-
626
- + (BOOL)removeItemForKey:(NSString *)key
627
- {
628
- return [self removeItemForKey:key service:nil accessGroup:nil error:nil];
629
- }
630
-
631
- + (BOOL)removeItemForKey:(NSString *)key error:(NSError *__autoreleasing *)error
632
- {
633
- return [self removeItemForKey:key service:nil accessGroup:nil error:error];
634
- }
635
-
636
- + (BOOL)removeItemForKey:(NSString *)key service:(NSString *)service
637
- {
638
- return [self removeItemForKey:key service:service accessGroup:nil error:nil];
639
- }
640
-
641
- + (BOOL)removeItemForKey:(NSString *)key service:(NSString *)service error:(NSError *__autoreleasing *)error
642
- {
643
- return [self removeItemForKey:key service:service accessGroup:nil error:error];
644
- }
645
-
646
- + (BOOL)removeItemForKey:(NSString *)key service:(NSString *)service accessGroup:(NSString *)accessGroup
647
- {
648
- return [self removeItemForKey:key service:service accessGroup:accessGroup error:nil];
649
- }
650
-
651
- + (BOOL)removeItemForKey:(NSString *)key service:(NSString *)service accessGroup:(NSString *)accessGroup error:(NSError *__autoreleasing *)error
652
- {
653
- if (!key) {
654
- NSError *e = [self.class argumentError:NSLocalizedString(@"the key must not to be nil", nil)];
655
- if (error) {
656
- *error = e;
657
- }
658
- return NO;
659
- }
660
- if (!service) {
661
- service = [self defaultService];
662
- }
663
-
664
- UICKeyChainStore *keychain = [UICKeyChainStore keyChainStoreWithService:service accessGroup:accessGroup];
665
- return [keychain removeItemForKey:key error:error];
666
- }
667
-
668
- #pragma mark -
669
-
670
- + (BOOL)removeAllItems
671
- {
672
- return [self removeAllItemsForService:nil accessGroup:nil error:nil];
673
- }
674
-
675
- + (BOOL)removeAllItemsWithError:(NSError *__autoreleasing *)error
676
- {
677
- return [self removeAllItemsForService:nil accessGroup:nil error:error];
678
- }
679
-
680
- + (BOOL)removeAllItemsForService:(NSString *)service
681
- {
682
- return [self removeAllItemsForService:service accessGroup:nil error:nil];
683
- }
684
-
685
- + (BOOL)removeAllItemsForService:(NSString *)service error:(NSError *__autoreleasing *)error
686
- {
687
- return [self removeAllItemsForService:service accessGroup:nil error:error];
688
- }
689
-
690
- + (BOOL)removeAllItemsForService:(NSString *)service accessGroup:(NSString *)accessGroup
691
- {
692
- return [self removeAllItemsForService:service accessGroup:accessGroup error:nil];
693
- }
694
-
695
- + (BOOL)removeAllItemsForService:(NSString *)service accessGroup:(NSString *)accessGroup error:(NSError *__autoreleasing *)error
696
- {
697
- UICKeyChainStore *keychain = [UICKeyChainStore keyChainStoreWithService:service accessGroup:accessGroup];
698
- return [keychain removeAllItemsWithError:error];
699
- }
700
-
701
- #pragma mark -
702
-
703
- - (BOOL)removeItemForKey:(NSString *)key
704
- {
705
- return [self removeItemForKey:key error:nil];
706
- }
707
-
708
- - (BOOL)removeItemForKey:(NSString *)key error:(NSError *__autoreleasing *)error
709
- {
710
- NSMutableDictionary *query = [self query];
711
- query[(__bridge __strong id)kSecAttrAccount] = key;
712
-
713
- OSStatus status = SecItemDelete((__bridge CFDictionaryRef)query);
714
- if (status != errSecSuccess && status != errSecItemNotFound) {
715
- NSError *e = [self.class securityError:status];
716
- if (error) {
717
- *error = e;
718
- }
719
- return NO;
720
- }
721
-
722
- return YES;
723
- }
724
-
725
- #pragma mark -
726
-
727
- - (BOOL)removeAllItems
728
- {
729
- return [self removeAllItemsWithError:nil];
730
- }
731
-
732
- - (BOOL)removeAllItemsWithError:(NSError *__autoreleasing *)error
733
- {
734
- NSMutableDictionary *query = [self query];
735
- #if !TARGET_OS_IPHONE
736
- query[(__bridge id)kSecMatchLimit] = (__bridge id)kSecMatchLimitAll;
737
- #endif
738
-
739
- OSStatus status = SecItemDelete((__bridge CFDictionaryRef)query);
740
- if (status != errSecSuccess && status != errSecItemNotFound) {
741
- NSError *e = [self.class securityError:status];
742
- if (error) {
743
- *error = e;
744
- }
745
- return NO;
746
- }
747
-
748
- return YES;
749
- }
750
-
751
- #pragma mark -
752
-
753
- - (NSString *)objectForKeyedSubscript:(NSString <NSCopying> *)key
754
- {
755
- return [self stringForKey:key];
756
- }
757
-
758
- - (void)setObject:(NSString *)obj forKeyedSubscript:(NSString <NSCopying> *)key
759
- {
760
- if (!obj) {
761
- [self removeItemForKey:key];
762
- } else {
763
- [self setString:obj forKey:key];
764
- }
765
- }
766
-
767
- #pragma mark -
768
-
769
- - (NSArray UIC_KEY_TYPE *)allKeys
770
- {
771
- NSArray *items = [self.class prettify:[self itemClassObject] items:[self items]];
772
- NSMutableArray *keys = [[NSMutableArray alloc] init];
773
- for (NSDictionary *item in items) {
774
- NSString *key = item[@"key"];
775
- if (key) {
776
- [keys addObject:key];
777
- }
778
- }
779
- return keys.copy;
780
- }
781
-
782
- + (NSArray UIC_KEY_TYPE *)allKeysWithItemClass:(UICKeyChainStoreItemClass)itemClass
783
- {
784
- CFTypeRef itemClassObject = kSecClassGenericPassword;
785
- if (itemClass == UICKeyChainStoreItemClassGenericPassword) {
786
- itemClassObject = kSecClassGenericPassword;
787
- } else if (itemClass == UICKeyChainStoreItemClassInternetPassword) {
788
- itemClassObject = kSecClassInternetPassword;
789
- }
790
-
791
- NSMutableDictionary *query = [[NSMutableDictionary alloc] init];
792
- query[(__bridge __strong id)kSecClass] = (__bridge id)itemClassObject;
793
- query[(__bridge __strong id)kSecMatchLimit] = (__bridge id)kSecMatchLimitAll;
794
- query[(__bridge __strong id)kSecReturnAttributes] = (__bridge id)kCFBooleanTrue;
795
-
796
- CFArrayRef result = nil;
797
- CFDictionaryRef cfquery = (CFDictionaryRef)CFBridgingRetain(query);
798
- OSStatus status = SecItemCopyMatching(cfquery, (CFTypeRef *)&result);
799
- CFRelease(cfquery);
800
-
801
- if (status == errSecSuccess) {
802
- NSArray *items = [self prettify:itemClassObject items:(__bridge NSArray *)result];
803
- NSMutableArray *keys = [[NSMutableArray alloc] init];
804
- for (NSDictionary *item in items) {
805
- if (itemClassObject == kSecClassGenericPassword) {
806
- [keys addObject:@{@"service": item[@"service"] ?: @"", @"key": item[@"key"] ?: @""}];
807
- } else if (itemClassObject == kSecClassInternetPassword) {
808
- [keys addObject:@{@"server": item[@"service"] ?: @"", @"key": item[@"key"] ?: @""}];
809
- }
810
- }
811
- return keys.copy;
812
- } else if (status == errSecItemNotFound) {
813
- return @[];
814
- }
815
-
816
- return nil;
817
- }
818
-
819
- + (NSArray *)allItemsWithItemClass:(UICKeyChainStoreItemClass)itemClass
820
- {
821
- CFTypeRef itemClassObject = kSecClassGenericPassword;
822
- if (itemClass == UICKeyChainStoreItemClassGenericPassword) {
823
- itemClassObject = kSecClassGenericPassword;
824
- } else if (itemClass == UICKeyChainStoreItemClassInternetPassword) {
825
- itemClassObject = kSecClassInternetPassword;
826
- }
827
-
828
- NSMutableDictionary *query = [[NSMutableDictionary alloc] init];
829
- query[(__bridge __strong id)kSecClass] = (__bridge id)itemClassObject;
830
- query[(__bridge __strong id)kSecMatchLimit] = (__bridge id)kSecMatchLimitAll;
831
- query[(__bridge __strong id)kSecReturnAttributes] = (__bridge id)kCFBooleanTrue;
832
- #if TARGET_OS_IPHONE
833
- query[(__bridge __strong id)kSecReturnData] = (__bridge id)kCFBooleanTrue;
834
- #endif
835
-
836
- CFArrayRef result = nil;
837
- CFDictionaryRef cfquery = (CFDictionaryRef)CFBridgingRetain(query);
838
- OSStatus status = SecItemCopyMatching(cfquery, (CFTypeRef *)&result);
839
- CFRelease(cfquery);
840
-
841
- if (status == errSecSuccess) {
842
- return [self prettify:itemClassObject items:(__bridge NSArray *)result];
843
- } else if (status == errSecItemNotFound) {
844
- return @[];
845
- }
846
-
847
- return nil;
848
- }
849
-
850
- - (NSArray *)allItems
851
- {
852
- return [self.class prettify:[self itemClassObject] items:[self items]];
853
- }
854
-
855
- - (NSArray *)items
856
- {
857
- NSMutableDictionary *query = [self query];
858
- query[(__bridge __strong id)kSecMatchLimit] = (__bridge id)kSecMatchLimitAll;
859
- query[(__bridge __strong id)kSecReturnAttributes] = (__bridge id)kCFBooleanTrue;
860
- #if TARGET_OS_IPHONE
861
- query[(__bridge __strong id)kSecReturnData] = (__bridge id)kCFBooleanTrue;
862
- #endif
863
-
864
- CFArrayRef result = nil;
865
- OSStatus status = SecItemCopyMatching((__bridge CFDictionaryRef)query,(CFTypeRef *)&result);
866
-
867
- if (status == errSecSuccess) {
868
- return CFBridgingRelease(result);
869
- } else if (status == errSecItemNotFound) {
870
- return @[];
871
- }
872
-
873
- return nil;
874
- }
875
-
876
- + (NSArray *)prettify:(CFTypeRef)itemClass items:(NSArray *)items
877
- {
878
- NSMutableArray *prettified = [[NSMutableArray alloc] init];
879
-
880
- for (NSDictionary *attributes in items) {
881
- NSMutableDictionary *item = [[NSMutableDictionary alloc] init];
882
- if (itemClass == kSecClassGenericPassword) {
883
- item[@"class"] = @"GenericPassword";
884
- id service = attributes[(__bridge id)kSecAttrService];
885
- if (service) {
886
- item[@"service"] = service;
887
- }
888
- id accessGroup = attributes[(__bridge id)kSecAttrAccessGroup];
889
- if (accessGroup) {
890
- item[@"accessGroup"] = accessGroup;
891
- }
892
- } else if (itemClass == kSecClassInternetPassword) {
893
- item[@"class"] = @"InternetPassword";
894
- id server = attributes[(__bridge id)kSecAttrServer];
895
- if (server) {
896
- item[@"server"] = server;
897
- }
898
- id protocolType = attributes[(__bridge id)kSecAttrProtocol];
899
- if (protocolType) {
900
- item[@"protocol"] = protocolType;
901
- }
902
- id authenticationType = attributes[(__bridge id)kSecAttrAuthenticationType];
903
- if (authenticationType) {
904
- item[@"authenticationType"] = authenticationType;
905
- }
906
- }
907
- id key = attributes[(__bridge id)kSecAttrAccount];
908
- if (key) {
909
- item[@"key"] = key;
910
- }
911
- NSData *data = attributes[(__bridge id)kSecValueData];
912
- NSString *string = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
913
- if (string) {
914
- item[@"value"] = string;
915
- } else {
916
- item[@"value"] = data;
917
- }
918
-
919
- id accessible = attributes[(__bridge id)kSecAttrAccessible];
920
- if (accessible) {
921
- item[@"accessibility"] = accessible;
922
- }
923
-
924
- if (floor(NSFoundationVersionNumber) > floor(993.00)) { // iOS 7+
925
- id synchronizable = attributes[(__bridge id)kSecAttrSynchronizable];
926
- if (synchronizable) {
927
- item[@"synchronizable"] = synchronizable;
928
- }
929
- }
930
-
931
- [prettified addObject:item];
932
- }
933
-
934
- return prettified.copy;
935
- }
936
-
937
- #pragma mark -
938
-
939
- - (void)setSynchronizable:(BOOL)synchronizable
940
- {
941
- _synchronizable = synchronizable;
942
- if (_authenticationPolicy) {
943
- NSLog(@"%@", @"Cannot specify both an authenticationPolicy and a synchronizable");
944
- }
945
- }
946
-
947
- - (void)setAccessibility:(UICKeyChainStoreAccessibility)accessibility authenticationPolicy:(UICKeyChainStoreAuthenticationPolicy)authenticationPolicy
948
- {
949
- _accessibility = accessibility;
950
- _authenticationPolicy = authenticationPolicy;
951
- if (_synchronizable) {
952
- NSLog(@"%@", @"Cannot specify both an authenticationPolicy and a synchronizable");
953
- }
954
- }
955
-
956
- #pragma mark -
957
-
958
- #if TARGET_OS_IOS
959
- - (void)sharedPasswordWithCompletion:(void (^)(NSString *account, NSString *password, NSError *error))completion
960
- {
961
- NSString *domain = self.server.host;
962
- if (domain.length > 0) {
963
- [self.class requestSharedWebCredentialForDomain:domain account:nil completion:^(NSArray *credentials, NSError *error) {
964
- NSDictionary *credential = credentials.firstObject;
965
- if (credential) {
966
- NSString *account = credential[@"account"];
967
- NSString *password = credential[@"password"];
968
- if (completion) {
969
- completion(account, password, error);
970
- }
971
- } else {
972
- if (completion) {
973
- completion(nil, nil, error);
974
- }
975
- }
976
- }];
977
- } else {
978
- NSError *error = [self.class argumentError:NSLocalizedString(@"the server property must not to be nil, should use 'keyChainStoreWithServer:protocolType:' initializer to instantiate keychain store", nil)];
979
- if (completion) {
980
- completion(nil, nil, error);
981
- }
982
- }
983
- }
984
-
985
- - (void)sharedPasswordForAccount:(NSString *)account completion:(void (^)(NSString *password, NSError *error))completion
986
- {
987
- NSString *domain = self.server.host;
988
- if (domain.length > 0) {
989
- [self.class requestSharedWebCredentialForDomain:domain account:account completion:^(NSArray *credentials, NSError *error) {
990
- NSDictionary *credential = credentials.firstObject;
991
- if (credential) {
992
- NSString *password = credential[@"password"];
993
- if (completion) {
994
- completion(password, error);
995
- }
996
- } else {
997
- if (completion) {
998
- completion(nil, error);
999
- }
1000
- }
1001
- }];
1002
- } else {
1003
- NSError *error = [self.class argumentError:NSLocalizedString(@"the server property must not to be nil, should use 'keyChainStoreWithServer:protocolType:' initializer to instantiate keychain store", nil)];
1004
- if (completion) {
1005
- completion(nil, error);
1006
- }
1007
- }
1008
- }
1009
-
1010
- - (void)setSharedPassword:(NSString *)password forAccount:(NSString *)account completion:(void (^)(NSError *error))completion
1011
- {
1012
- NSString *domain = self.server.host;
1013
- if (domain.length > 0) {
1014
- SecAddSharedWebCredential((__bridge CFStringRef)domain, (__bridge CFStringRef)account, (__bridge CFStringRef)password, ^(CFErrorRef error) {
1015
- if (completion) {
1016
- completion((__bridge NSError *)error);
1017
- }
1018
- });
1019
- } else {
1020
- NSError *error = [self.class argumentError:NSLocalizedString(@"the server property must not to be nil, should use 'keyChainStoreWithServer:protocolType:' initializer to instantiate keychain store", nil)];
1021
- if (completion) {
1022
- completion(error);
1023
- }
1024
- }
1025
- }
1026
-
1027
- - (void)removeSharedPasswordForAccount:(NSString *)account completion:(void (^)(NSError *error))completion
1028
- {
1029
- [self setSharedPassword:nil forAccount:account completion:completion];
1030
- }
1031
-
1032
- + (void)requestSharedWebCredentialWithCompletion:(void (^)(NSArray UIC_CREDENTIAL_TYPE *credentials, NSError *error))completion
1033
- {
1034
- [self requestSharedWebCredentialForDomain:nil account:nil completion:completion];
1035
- }
1036
-
1037
- + (void)requestSharedWebCredentialForDomain:(NSString *)domain account:(NSString *)account completion:(void (^)(NSArray UIC_CREDENTIAL_TYPE *credentials, NSError *error))completion
1038
- {
1039
- SecRequestSharedWebCredential((__bridge CFStringRef)domain, (__bridge CFStringRef)account, ^(CFArrayRef credentials, CFErrorRef error) {
1040
- if (error) {
1041
- NSError *e = (__bridge NSError *)error;
1042
- if (e.code != errSecItemNotFound) {
1043
- NSLog(@"error: [%@] %@", @(e.code), e.localizedDescription);
1044
- }
1045
- }
1046
-
1047
- NSMutableArray *sharedCredentials = [[NSMutableArray alloc] init];
1048
- for (NSDictionary *credential in (__bridge NSArray *)credentials) {
1049
- NSMutableDictionary *sharedCredential = [[NSMutableDictionary alloc] init];
1050
- NSString *server = credential[(__bridge __strong id)kSecAttrServer];
1051
- if (server) {
1052
- sharedCredential[@"server"] = server;
1053
- }
1054
- NSString *account = credential[(__bridge __strong id)kSecAttrAccount];
1055
- if (account) {
1056
- sharedCredential[@"account"] = account;
1057
- }
1058
- NSString *password = credential[(__bridge __strong id)kSecSharedPassword];
1059
- if (password) {
1060
- sharedCredential[@"password"] = password;
1061
- }
1062
- [sharedCredentials addObject:sharedCredential];
1063
- }
1064
-
1065
- if (completion) {
1066
- completion(sharedCredentials.copy, (__bridge NSError *)error);
1067
- }
1068
- });
1069
- }
1070
-
1071
- + (NSString *)generatePassword
1072
- {
1073
- return (NSString *)CFBridgingRelease(SecCreateSharedWebCredentialPassword());
1074
- }
1075
-
1076
- #endif
1077
-
1078
- #pragma mark -
1079
-
1080
- - (NSString *)description
1081
- {
1082
- NSArray *items = [self allItems];
1083
- if (items.count == 0) {
1084
- return @"()";
1085
- }
1086
- NSMutableString *description = [[NSMutableString alloc] initWithString:@"(\n"];
1087
- for (NSDictionary *item in items) {
1088
- [description appendFormat:@" %@", item];
1089
- }
1090
- [description appendString:@")"];
1091
- return description.copy;
1092
- }
1093
-
1094
- - (NSString *)debugDescription
1095
- {
1096
- return [NSString stringWithFormat:@"%@", [self items]];
1097
- }
1098
-
1099
- #pragma mark -
1100
-
1101
- - (NSMutableDictionary *)query
1102
- {
1103
- NSMutableDictionary *query = [[NSMutableDictionary alloc] init];
1104
-
1105
- CFTypeRef itemClass = [self itemClassObject];
1106
- query[(__bridge __strong id)kSecClass] =(__bridge id)itemClass;
1107
- if (floor(NSFoundationVersionNumber) > floor(993.00)) { // iOS 7+ (NSFoundationVersionNumber_iOS_6_1)
1108
- query[(__bridge __strong id)kSecAttrSynchronizable] = (__bridge id)kSecAttrSynchronizableAny;
1109
- }
1110
-
1111
- if (itemClass == kSecClassGenericPassword) {
1112
- query[(__bridge __strong id)(kSecAttrService)] = _service;
1113
- #if !TARGET_OS_SIMULATOR
1114
- if (_accessGroup) {
1115
- query[(__bridge __strong id)kSecAttrAccessGroup] = _accessGroup;
1116
- }
1117
- #endif
1118
- } else {
1119
- if (_server.host) {
1120
- query[(__bridge __strong id)kSecAttrServer] = _server.host;
1121
- }
1122
- if (_server.port) {
1123
- query[(__bridge __strong id)kSecAttrPort] = _server.port;
1124
- }
1125
- CFTypeRef protocolTypeObject = [self protocolTypeObject];
1126
- if (protocolTypeObject) {
1127
- query[(__bridge __strong id)kSecAttrProtocol] = (__bridge id)protocolTypeObject;
1128
- }
1129
- CFTypeRef authenticationTypeObject = [self authenticationTypeObject];
1130
- if (authenticationTypeObject) {
1131
- query[(__bridge __strong id)kSecAttrAuthenticationType] = (__bridge id)authenticationTypeObject;
1132
- }
1133
- }
1134
-
1135
- #if TARGET_OS_IOS
1136
- if (_authenticationPrompt) {
1137
- if (floor(NSFoundationVersionNumber) > floor(1047.25)) { // iOS 8+ (NSFoundationVersionNumber_iOS_7_1)
1138
- query[(__bridge __strong id)kSecUseOperationPrompt] = _authenticationPrompt;
1139
- } else {
1140
- NSLog(@"%@", @"Unavailable 'authenticationPrompt' attribute on iOS versions prior to 8.0.");
1141
- }
1142
- }
1143
- #endif
1144
-
1145
- return query;
1146
- }
1147
-
1148
- - (NSMutableDictionary *)attributesWithKey:(NSString *)key value:(NSData *)value error:(NSError *__autoreleasing *)error
1149
- {
1150
- NSMutableDictionary *attributes;
1151
-
1152
- if (key) {
1153
- attributes = [self query];
1154
- attributes[(__bridge __strong id)kSecAttrAccount] = key;
1155
- } else {
1156
- attributes = [[NSMutableDictionary alloc] init];
1157
- }
1158
-
1159
- attributes[(__bridge __strong id)kSecValueData] = value;
1160
-
1161
- #if TARGET_OS_IOS
1162
- double iOS_7_1_or_10_9_2 = 1047.25; // NSFoundationVersionNumber_iOS_7_1
1163
- #else
1164
- double iOS_7_1_or_10_9_2 = 1056.13; // NSFoundationVersionNumber10_9_2
1165
- #endif
1166
- CFTypeRef accessibilityObject = [self accessibilityObject];
1167
- if (_authenticationPolicy && accessibilityObject) {
1168
- if (floor(NSFoundationVersionNumber) > floor(iOS_7_1_or_10_9_2)) { // iOS 8+ or OS X 10.10+
1169
- CFErrorRef securityError = NULL;
1170
- SecAccessControlRef accessControl = SecAccessControlCreateWithFlags(kCFAllocatorDefault, accessibilityObject, (SecAccessControlCreateFlags)_authenticationPolicy, &securityError);
1171
- if (securityError) {
1172
- NSError *e = (__bridge NSError *)securityError;
1173
- NSLog(@"error: [%@] %@", @(e.code), e.localizedDescription);
1174
- if (error) {
1175
- *error = e;
1176
- CFRelease(accessControl);
1177
- return nil;
1178
- }
1179
- }
1180
- if (!accessControl) {
1181
- NSString *message = NSLocalizedString(@"Unexpected error has occurred.", nil);
1182
- NSError *e = [self.class unexpectedError:message];
1183
- if (error) {
1184
- *error = e;
1185
- }
1186
- return nil;
1187
- }
1188
- attributes[(__bridge __strong id)kSecAttrAccessControl] = (__bridge_transfer id)accessControl;
1189
- } else {
1190
- #if TARGET_OS_IOS
1191
- NSLog(@"%@", @"Unavailable 'Touch ID integration' on iOS versions prior to 8.0.");
1192
- #else
1193
- NSLog(@"%@", @"Unavailable 'Touch ID integration' on OS X versions prior to 10.10.");
1194
- #endif
1195
- }
1196
- } else {
1197
- if (floor(NSFoundationVersionNumber) <= floor(iOS_7_1_or_10_9_2) && _accessibility == UICKeyChainStoreAccessibilityWhenPasscodeSetThisDeviceOnly) {
1198
- #if TARGET_OS_IOS
1199
- NSLog(@"%@", @"Unavailable 'UICKeyChainStoreAccessibilityWhenPasscodeSetThisDeviceOnly' attribute on iOS versions prior to 8.0.");
1200
- #else
1201
- NSLog(@"%@", @"Unavailable 'UICKeyChainStoreAccessibilityWhenPasscodeSetThisDeviceOnly' attribute on OS X versions prior to 10.10.");
1202
- #endif
1203
- } else {
1204
- if (accessibilityObject) {
1205
- attributes[(__bridge __strong id)kSecAttrAccessible] = (__bridge id)accessibilityObject;
1206
- }
1207
- }
1208
- }
1209
-
1210
- if (floor(NSFoundationVersionNumber) > floor(993.00)) { // iOS 7+
1211
- attributes[(__bridge __strong id)kSecAttrSynchronizable] = @(_synchronizable);
1212
- }
1213
-
1214
- return attributes;
1215
- }
1216
-
1217
- #pragma mark -
1218
-
1219
- - (CFTypeRef)itemClassObject
1220
- {
1221
- switch (_itemClass) {
1222
- case UICKeyChainStoreItemClassGenericPassword:
1223
- return kSecClassGenericPassword;
1224
- case UICKeyChainStoreItemClassInternetPassword:
1225
- return kSecClassInternetPassword;
1226
- default:
1227
- return nil;
1228
- }
1229
- }
1230
-
1231
- - (CFTypeRef)protocolTypeObject
1232
- {
1233
- switch (_protocolType) {
1234
- case UICKeyChainStoreProtocolTypeFTP:
1235
- return kSecAttrProtocolFTP;
1236
- case UICKeyChainStoreProtocolTypeFTPAccount:
1237
- return kSecAttrProtocolFTPAccount;
1238
- case UICKeyChainStoreProtocolTypeHTTP:
1239
- return kSecAttrProtocolHTTP;
1240
- case UICKeyChainStoreProtocolTypeIRC:
1241
- return kSecAttrProtocolIRC;
1242
- case UICKeyChainStoreProtocolTypeNNTP:
1243
- return kSecAttrProtocolNNTP;
1244
- case UICKeyChainStoreProtocolTypePOP3:
1245
- return kSecAttrProtocolPOP3;
1246
- case UICKeyChainStoreProtocolTypeSMTP:
1247
- return kSecAttrProtocolSMTP;
1248
- case UICKeyChainStoreProtocolTypeSOCKS:
1249
- return kSecAttrProtocolSOCKS;
1250
- case UICKeyChainStoreProtocolTypeIMAP:
1251
- return kSecAttrProtocolIMAP;
1252
- case UICKeyChainStoreProtocolTypeLDAP:
1253
- return kSecAttrProtocolLDAP;
1254
- case UICKeyChainStoreProtocolTypeAppleTalk:
1255
- return kSecAttrProtocolAppleTalk;
1256
- case UICKeyChainStoreProtocolTypeAFP:
1257
- return kSecAttrProtocolAFP;
1258
- case UICKeyChainStoreProtocolTypeTelnet:
1259
- return kSecAttrProtocolTelnet;
1260
- case UICKeyChainStoreProtocolTypeSSH:
1261
- return kSecAttrProtocolSSH;
1262
- case UICKeyChainStoreProtocolTypeFTPS:
1263
- return kSecAttrProtocolFTPS;
1264
- case UICKeyChainStoreProtocolTypeHTTPS:
1265
- return kSecAttrProtocolHTTPS;
1266
- case UICKeyChainStoreProtocolTypeHTTPProxy:
1267
- return kSecAttrProtocolHTTPProxy;
1268
- case UICKeyChainStoreProtocolTypeHTTPSProxy:
1269
- return kSecAttrProtocolHTTPSProxy;
1270
- case UICKeyChainStoreProtocolTypeFTPProxy:
1271
- return kSecAttrProtocolFTPProxy;
1272
- case UICKeyChainStoreProtocolTypeSMB:
1273
- return kSecAttrProtocolSMB;
1274
- case UICKeyChainStoreProtocolTypeRTSP:
1275
- return kSecAttrProtocolRTSP;
1276
- case UICKeyChainStoreProtocolTypeRTSPProxy:
1277
- return kSecAttrProtocolRTSPProxy;
1278
- case UICKeyChainStoreProtocolTypeDAAP:
1279
- return kSecAttrProtocolDAAP;
1280
- case UICKeyChainStoreProtocolTypeEPPC:
1281
- return kSecAttrProtocolEPPC;
1282
- case UICKeyChainStoreProtocolTypeNNTPS:
1283
- return kSecAttrProtocolNNTPS;
1284
- case UICKeyChainStoreProtocolTypeLDAPS:
1285
- return kSecAttrProtocolLDAPS;
1286
- case UICKeyChainStoreProtocolTypeTelnetS:
1287
- return kSecAttrProtocolTelnetS;
1288
- case UICKeyChainStoreProtocolTypeIRCS:
1289
- return kSecAttrProtocolIRCS;
1290
- case UICKeyChainStoreProtocolTypePOP3S:
1291
- return kSecAttrProtocolPOP3S;
1292
- default:
1293
- return nil;
1294
- }
1295
- }
1296
-
1297
- - (CFTypeRef)authenticationTypeObject
1298
- {
1299
- switch (_authenticationType) {
1300
- case UICKeyChainStoreAuthenticationTypeNTLM:
1301
- return kSecAttrAuthenticationTypeNTLM;
1302
- case UICKeyChainStoreAuthenticationTypeMSN:
1303
- return kSecAttrAuthenticationTypeMSN;
1304
- case UICKeyChainStoreAuthenticationTypeDPA:
1305
- return kSecAttrAuthenticationTypeDPA;
1306
- case UICKeyChainStoreAuthenticationTypeRPA:
1307
- return kSecAttrAuthenticationTypeRPA;
1308
- case UICKeyChainStoreAuthenticationTypeHTTPBasic:
1309
- return kSecAttrAuthenticationTypeHTTPBasic;
1310
- case UICKeyChainStoreAuthenticationTypeHTTPDigest:
1311
- return kSecAttrAuthenticationTypeHTTPDigest;
1312
- case UICKeyChainStoreAuthenticationTypeHTMLForm:
1313
- return kSecAttrAuthenticationTypeHTMLForm;
1314
- case UICKeyChainStoreAuthenticationTypeDefault:
1315
- return kSecAttrAuthenticationTypeDefault;
1316
- default:
1317
- return nil;
1318
- }
1319
- }
1320
-
1321
- - (CFTypeRef)accessibilityObject
1322
- {
1323
- switch (_accessibility) {
1324
- case UICKeyChainStoreAccessibilityWhenUnlocked:
1325
- return kSecAttrAccessibleWhenUnlocked;
1326
- case UICKeyChainStoreAccessibilityAfterFirstUnlock:
1327
- return kSecAttrAccessibleAfterFirstUnlock;
1328
- case UICKeyChainStoreAccessibilityAlways:
1329
- return kSecAttrAccessibleAlways;
1330
- case UICKeyChainStoreAccessibilityWhenPasscodeSetThisDeviceOnly:
1331
- return kSecAttrAccessibleWhenPasscodeSetThisDeviceOnly;
1332
- case UICKeyChainStoreAccessibilityWhenUnlockedThisDeviceOnly:
1333
- return kSecAttrAccessibleWhenUnlockedThisDeviceOnly;
1334
- case UICKeyChainStoreAccessibilityAfterFirstUnlockThisDeviceOnly:
1335
- return kSecAttrAccessibleAfterFirstUnlockThisDeviceOnly;
1336
- case UICKeyChainStoreAccessibilityAlwaysThisDeviceOnly:
1337
- return kSecAttrAccessibleAlwaysThisDeviceOnly;
1338
- default:
1339
- return nil;
1340
- }
1341
- }
1342
-
1343
- + (NSError *)argumentError:(NSString *)message
1344
- {
1345
- NSError *error = [NSError errorWithDomain:UICKeyChainStoreErrorDomain code:UICKeyChainStoreErrorInvalidArguments userInfo:@{NSLocalizedDescriptionKey: message}];
1346
- NSLog(@"error: [%@] %@", @(error.code), error.localizedDescription);
1347
- return error;
1348
- }
1349
-
1350
- + (NSError *)conversionError:(NSString *)message
1351
- {
1352
- NSError *error = [NSError errorWithDomain:UICKeyChainStoreErrorDomain code:-67594 userInfo:@{NSLocalizedDescriptionKey: message}];
1353
- NSLog(@"error: [%@] %@", @(error.code), error.localizedDescription);
1354
- return error;
1355
- }
1356
-
1357
- + (NSError *)securityError:(OSStatus)status
1358
- {
1359
- NSString *message = @"Security error has occurred.";
1360
- #if TARGET_OS_MAC && !TARGET_OS_IPHONE
1361
- CFStringRef description = SecCopyErrorMessageString(status, NULL);
1362
- if (description) {
1363
- message = (__bridge_transfer NSString *)description;
1364
- }
1365
- #endif
1366
- NSError *error = [NSError errorWithDomain:UICKeyChainStoreErrorDomain code:status userInfo:@{NSLocalizedDescriptionKey: message}];
1367
- NSLog(@"OSStatus error: [%@] %@", @(error.code), error.localizedDescription);
1368
- return error;
1369
- }
1370
-
1371
- + (NSError *)unexpectedError:(NSString *)message
1372
- {
1373
- NSError *error = [NSError errorWithDomain:UICKeyChainStoreErrorDomain code:-99999 userInfo:@{NSLocalizedDescriptionKey: message}];
1374
- NSLog(@"error: [%@] %@", @(error.code), error.localizedDescription);
1375
- return error;
1376
- }
1377
-
1378
- @end
1379
-
1380
- @implementation UICKeyChainStore (Deprecation)
1381
-
1382
- - (void)synchronize
1383
- {
1384
- // Deprecated, calling this method is no longer required
1385
- }
1386
-
1387
- - (BOOL)synchronizeWithError:(NSError *__autoreleasing *)error
1388
- {
1389
- // Deprecated, calling this method is no longer required
1390
- return true;
1391
- }
1392
-
1393
- @end