commit | author | age
|
655e66
|
1 |
/* |
H |
2 |
* Copyright (C) 2017 Twitter, Inc. |
|
3 |
* |
|
4 |
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
5 |
* you may not use this file except in compliance with the License. |
|
6 |
* You may obtain a copy of the License at |
|
7 |
* |
|
8 |
* http://www.apache.org/licenses/LICENSE-2.0 |
|
9 |
* |
|
10 |
* Unless required by applicable law or agreed to in writing, software |
|
11 |
* distributed under the License is distributed on an "AS IS" BASIS, |
|
12 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
13 |
* See the License for the specific language governing permissions and |
|
14 |
* limitations under the License. |
|
15 |
* |
|
16 |
*/ |
|
17 |
|
|
18 |
/** |
|
19 |
This header is private to the Twitter Core SDK and not exposed for public SDK consumption |
|
20 |
*/ |
a0a843
|
21 |
|
H |
22 |
#import <Foundation/Foundation.h> |
|
23 |
|
|
24 |
NS_ASSUME_NONNULL_BEGIN |
|
25 |
|
|
26 |
extern NSString *const TWTRGenericKeychainItemErrorDomain; |
|
27 |
|
|
28 |
/** |
|
29 |
* The TWTRGenericKeychainQuery provides an simple model object |
|
30 |
* that can be used in conjuction with TWTRGenericKeychainItem to |
|
31 |
* retrieve items in the keychain. |
|
32 |
*/ |
|
33 |
@interface TWTRGenericKeychainQuery : NSObject |
|
34 |
|
|
35 |
/** |
|
36 |
* The name of the service corresponding with kSecAttrService. |
|
37 |
* If this value is specified the genericValue and accessGroup values are ignored. |
|
38 |
*/ |
|
39 |
@property (nonatomic, copy, readonly, nullable) NSString *service; |
|
40 |
|
|
41 |
/** |
|
42 |
* The name of the account corresponding with kSecAttrAccount. |
|
43 |
* If this value is specified the genericValue and accessGroup values are ignored. |
|
44 |
*/ |
|
45 |
@property (nonatomic, copy, readonly, nullable) NSString *account; |
|
46 |
|
|
47 |
/** |
|
48 |
* A generic value corresponding with kSecAttrGeneric. |
|
49 |
*/ |
|
50 |
@property (nonatomic, copy, readonly, nullable) NSString *genericValue; |
|
51 |
|
|
52 |
/** |
|
53 |
* The access group corresponding with kSecAttrAccessGroup. |
|
54 |
* This value is not used in equality checks. |
|
55 |
* Note: This value is ignored in the simulator. |
|
56 |
*/ |
|
57 |
@property (nonatomic, copy, readonly, nullable) NSString *accessGroup; |
|
58 |
|
|
59 |
/** |
|
60 |
* A query that will return all the items in the keychain. |
|
61 |
*/ |
|
62 |
+ (instancetype)queryForAllItems; |
|
63 |
|
|
64 |
/** |
|
65 |
* A query that will return all items with the given service. |
|
66 |
*/ |
|
67 |
+ (instancetype)queryForService:(NSString *)service; |
|
68 |
|
|
69 |
/** |
|
70 |
* A query that will return all items with the given account. |
|
71 |
*/ |
|
72 |
+ (instancetype)queryForAccount:(NSString *)account; |
|
73 |
|
|
74 |
/** |
|
75 |
* A query that will match all items that contain both the service and account. |
|
76 |
*/ |
|
77 |
+ (instancetype)queryForService:(NSString *)service account:(NSString *)account; |
|
78 |
|
|
79 |
/** |
|
80 |
* A query that will return all items with the given generic value. |
|
81 |
*/ |
|
82 |
+ (instancetype)queryForGenericValue:(NSString *)genericValue; |
|
83 |
|
|
84 |
/** |
|
85 |
* A query that will return all items with the given access group. |
|
86 |
*/ |
|
87 |
+ (instancetype)queryForAccessGroup:(NSString *)accessGroup; |
|
88 |
|
|
89 |
@end |
|
90 |
|
|
91 |
/** |
|
92 |
* The TWTRGenericKeychainItem provides a convenience wrapper |
|
93 |
* around the security framework's keychain access. All of |
|
94 |
* the items stored using this class will be stored as |
|
95 |
* kSecClassGenericPassword objects. |
|
96 |
*/ |
|
97 |
@interface TWTRGenericKeychainItem : NSObject |
|
98 |
|
|
99 |
/** |
|
100 |
* A value which specifies the item's service attribute. This |
|
101 |
* value represents the service associated with this item. |
|
102 |
*/ |
|
103 |
@property (nonatomic, copy, readonly) NSString *service; |
|
104 |
|
|
105 |
/** |
|
106 |
* A value which represents the items account name. |
|
107 |
*/ |
|
108 |
@property (nonatomic, copy, readonly) NSString *account; |
|
109 |
|
|
110 |
/** |
|
111 |
* The item that is intended to be kept secret. This may be |
|
112 |
* something like a password for an account or an oauth token. |
|
113 |
* |
|
114 |
* @warning If this data is too large it will fail to save. The size |
|
115 |
* should be smaller than ~2mb but can change from device to device. |
|
116 |
*/ |
|
117 |
@property (nonatomic, copy, readonly) NSData *secret; |
|
118 |
|
|
119 |
/** |
|
120 |
* An optional value that can be set on the item. |
|
121 |
*/ |
|
122 |
@property (nonatomic, copy, readonly, nullable) NSString *genericValue; |
|
123 |
|
|
124 |
/** |
|
125 |
* Returns the date that the item was last saved to the store. This value |
|
126 |
* is nil until the item is actually saved. |
|
127 |
*/ |
|
128 |
@property (nonatomic, copy, readonly, nullable) NSDate *lastSavedDate; |
|
129 |
|
|
130 |
/** |
|
131 |
* An optional value that can be used to specify the items accesss group. |
|
132 |
* If this value is not set the default access group which is only |
|
133 |
* accessible from the calling application will be used. |
|
134 |
* |
|
135 |
* Refer to 'Keychain Services Programming Guide' for more information |
|
136 |
* regarding access groups. Most of the time you will |
|
137 |
* want to leave this value empty. |
|
138 |
* |
|
139 |
* This value may not be empty upon fetch even if it is empty when it is saved. This |
|
140 |
* is because the security framework will fill it with the default value which |
|
141 |
* is not specified. |
|
142 |
*/ |
|
143 |
@property (nonatomic, copy, readonly, nullable) NSString *accessGroup; |
|
144 |
|
|
145 |
/** |
|
146 |
* Fetches all of the stored items for the given query. |
|
147 |
* If the returned array is nil it indicates that an error |
|
148 |
* has occurred and the error parameter will be set. If no |
|
149 |
* items are found an empty array will be returned. |
|
150 |
* |
|
151 |
* The query results will depend on the specificity of the query |
|
152 |
* object as described in its documetation. |
|
153 |
*/ |
|
154 |
+ (NSArray *)storedItemsMatchingQuery:(TWTRGenericKeychainQuery *)query error:(NSError **)error; |
|
155 |
|
|
156 |
/** |
|
157 |
* Removes all the items matching the given query. |
|
158 |
*/ |
|
159 |
+ (BOOL)removeAllItemsForQuery:(TWTRGenericKeychainQuery *)query error:(NSError **)error; |
|
160 |
|
|
161 |
/** |
|
162 |
* Initializes a TWTRGenericKeychainItem object with the given values. |
|
163 |
* This does not automatically save the object, you must call -[TWTRGenericKeychainItem storeInKeychain:] |
|
164 |
to actually save the object. |
|
165 |
* |
|
166 |
* A keychain item is uniquely constrained by the service/account combination. Any action performed |
|
167 |
* with the keychain item will override any existing keychain items with the given service/account |
|
168 |
* combination. |
|
169 |
* |
|
170 |
* @param service the service for this item. |
|
171 |
* @param account the account associated with this item. |
|
172 |
* @param secret the secret value to store. |
|
173 |
* @param genericValue an additional value to associate with this item. |
|
174 |
* @param accessGroup the access group for this item. If empty uses the default access group. * |
|
175 |
*/ |
|
176 |
- (instancetype)initWithService:(NSString *)service account:(NSString *)account secret:(NSData *)secret; |
|
177 |
- (instancetype)initWithService:(NSString *)service account:(NSString *)account secret:(NSData *)secret genericValue:(nullable NSString *)genericValue; |
|
178 |
- (instancetype)initWithService:(NSString *)service account:(NSString *)account secret:(NSData *)secret genericValue:(nullable NSString *)genericValue accessGroup:(nullable NSString *)accessGroup; |
|
179 |
|
|
180 |
/** |
|
181 |
* Call this method to store the keychain item in the store. |
|
182 |
* |
|
183 |
* A TWTRGenericKeychainItem is only unique based on the account |
|
184 |
* and the service specified. If the item exists and the replaceExisting parameter |
|
185 |
* is YES the value will be replaced. If this parameter is NO the operation will |
|
186 |
* fail. |
|
187 |
* |
|
188 |
* @param replacesExisting whether an existing value should be replaced, Default = YES |
|
189 |
* @param error an optional error that will be set if the operation fails. |
|
190 |
* @return a value representing if the operation was successful |
|
191 |
*/ |
|
192 |
- (BOOL)storeInKeychain:(NSError **)error; |
|
193 |
- (BOOL)storeInKeychainReplacingExisting:(BOOL)replaceExisting error:(NSError **)error; |
|
194 |
|
|
195 |
/** |
|
196 |
* Attempts to remove the wrapper from the keychain. |
|
197 |
* |
|
198 |
* The keychain item is only unique based on the service/account |
|
199 |
* pair. So a value that is created with the same service/account |
|
200 |
* but different secret will remove the existing value. |
|
201 |
* |
|
202 |
* @return a value representing if the operation was successful |
|
203 |
*/ |
|
204 |
- (BOOL)removeFromKeychain:(NSError **)error; |
|
205 |
|
|
206 |
@end |
|
207 |
|
|
208 |
NS_ASSUME_NONNULL_END |