Skip to content

Commit df71568

Browse files
authored
fix: default to setting use data protection to false for macOS Keychain (#398)
* fix: default to setting use data protection to false for macOS Keychain * fix * Update .codecov.yml
1 parent ed74494 commit df71568

File tree

6 files changed

+47
-8
lines changed

6 files changed

+47
-8
lines changed

.codecov.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ coverage:
66
status:
77
patch:
88
default:
9-
target: auto
9+
target: 83
1010
changes: false
1111
project:
1212
default:

CHANGELOG.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
# Parse-Swift Changelog
22

33
### main
4-
[Full Changelog](https://github.com/parse-community/Parse-Swift/compare/4.9.2...main)
4+
[Full Changelog](https://github.com/parse-community/Parse-Swift/compare/4.9.3...main)
55
* _Contributing to this repo? Add info about your change here to be included in the next release_
66

7+
### 4.9.3
8+
[Full Changelog](https://github.com/parse-community/Parse-Swift/compare/4.9.2...4.9.3)
9+
__Fixes__
10+
- Default to not setting kSecUseDataProtectionKeychain to true as this can cause issues with querying the Keychain in Swift Playgrounds or other apps that cannot setup the Keychain on macOS. This behavior can be changed by setting usingDataProtectionKeychain to true when initializing the SDK ([#398](https://github.com/parse-community/Parse-Swift/pull/398)), thanks to [Corey Baker](https://github.com/cbaker6).
11+
712
### 4.9.2
813
[Full Changelog](https://github.com/parse-community/Parse-Swift/compare/4.9.1...4.9.2)
914

ParseSwift.playground/Sources/Common.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@ public func initializeParse(customObjectId: Bool = false) {
77
masterKey: "masterKey",
88
serverURL: URL(string: "http://localhost:1337/1")!,
99
allowingCustomObjectIds: customObjectId,
10-
usingEqualQueryConstraint: false)
10+
usingEqualQueryConstraint: false,
11+
usingDataProtectionKeychain: false)
1112
}

Sources/ParseSwift/Parse.swift

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ internal func initialize(applicationId: String,
2626
cacheMemoryCapacity: Int = 512_000,
2727
cacheDiskCapacity: Int = 10_000_000,
2828
migratingFromObjcSDK: Bool = false,
29+
usingDataProtectionKeychain: Bool = false,
2930
deletingKeychainIfNeeded: Bool = false,
3031
httpAdditionalHeaders: [AnyHashable: Any]? = nil,
3132
maxConnectionAttempts: Int = 5,
@@ -46,6 +47,7 @@ internal func initialize(applicationId: String,
4647
requestCachePolicy: requestCachePolicy,
4748
cacheMemoryCapacity: cacheMemoryCapacity,
4849
cacheDiskCapacity: cacheDiskCapacity,
50+
usingDataProtectionKeychain: usingDataProtectionKeychain,
4951
deletingKeychainIfNeeded: deletingKeychainIfNeeded,
5052
httpAdditionalHeaders: httpAdditionalHeaders,
5153
maxConnectionAttempts: maxConnectionAttempts,
@@ -191,6 +193,8 @@ public func initialize(configuration: ParseConfiguration) {
191193
for more info.
192194
- parameter cacheMemoryCapacity: The memory capacity of the cache, in bytes. Defaults to 512KB.
193195
- parameter cacheDiskCapacity: The disk capacity of the cache, in bytes. Defaults to 10MB.
196+
- parameter usingDataProtectionKeychain: Sets `kSecUseDataProtectionKeychain` to **true**. See Apple's [documentation](https://developer.apple.com/documentation/security/ksecusedataprotectionkeychain)
197+
for more info. Defaults to **false**.
194198
- parameter deletingKeychainIfNeeded: Deletes the Parse Keychain when the app is running for the first time.
195199
Defaults to **false**.
196200
- parameter httpAdditionalHeaders: A dictionary of additional headers to send with requests. See Apple's
@@ -201,9 +205,11 @@ public func initialize(configuration: ParseConfiguration) {
201205
It should have the following argument signature: `(challenge: URLAuthenticationChallenge,
202206
completionHandler: (URLSession.AuthChallengeDisposition, URLCredential?) -> Void) -> Void`.
203207
See Apple's [documentation](https://developer.apple.com/documentation/foundation/urlsessiontaskdelegate/1411595-urlsession) for more for details.
204-
- warning: `usingTransactions` is experimental.
205208
- warning: It is recomended to only specify `masterKey` when using the SDK on a server. Do not use this key on the client.
209+
- warning: `usingTransactions` is experimental.
206210
- warning: Setting `usingPostForQuery` to **true** will require all queries to access the server instead of following the `requestCachePolicy`.
211+
- warning: Setting `usingDataProtectionKeychain` to **true** is known to cause issues in Playgrounds or in
212+
situtations when apps do not have credentials to setup a Keychain.
207213
*/
208214
public func initialize(
209215
applicationId: String,
@@ -219,6 +225,7 @@ public func initialize(
219225
requestCachePolicy: URLRequest.CachePolicy = .useProtocolCachePolicy,
220226
cacheMemoryCapacity: Int = 512_000,
221227
cacheDiskCapacity: Int = 10_000_000,
228+
usingDataProtectionKeychain: Bool = false,
222229
deletingKeychainIfNeeded: Bool = false,
223230
httpAdditionalHeaders: [AnyHashable: Any]? = nil,
224231
maxConnectionAttempts: Int = 5,
@@ -239,6 +246,7 @@ public func initialize(
239246
requestCachePolicy: requestCachePolicy,
240247
cacheMemoryCapacity: cacheMemoryCapacity,
241248
cacheDiskCapacity: cacheDiskCapacity,
249+
usingDataProtectionKeychain: usingDataProtectionKeychain,
242250
deletingKeychainIfNeeded: deletingKeychainIfNeeded,
243251
httpAdditionalHeaders: httpAdditionalHeaders,
244252
maxConnectionAttempts: maxConnectionAttempts,
@@ -272,6 +280,8 @@ public func initialize(
272280
- parameter cacheDiskCapacity: The disk capacity of the cache, in bytes. Defaults to 10MB.
273281
- parameter migratingFromObjcSDK: If your app previously used the iOS Objective-C SDK, setting this value
274282
to **true** will attempt to migrate relevant data stored in the Keychain to ParseSwift. Defaults to **false**.
283+
- parameter usingDataProtectionKeychain: Sets `kSecUseDataProtectionKeychain` to **true**. See Apple's [documentation](https://developer.apple.com/documentation/security/ksecusedataprotectionkeychain)
284+
for more info. Defaults to **false**.
275285
- parameter deletingKeychainIfNeeded: Deletes the Parse Keychain when the app is running for the first time.
276286
Defaults to **false**.
277287
- parameter httpAdditionalHeaders: A dictionary of additional headers to send with requests. See Apple's
@@ -282,9 +292,11 @@ public func initialize(
282292
It should have the following argument signature: `(challenge: URLAuthenticationChallenge,
283293
completionHandler: (URLSession.AuthChallengeDisposition, URLCredential?) -> Void) -> Void`.
284294
See Apple's [documentation](https://developer.apple.com/documentation/foundation/urlsessiontaskdelegate/1411595-urlsession) for more for details.
285-
- warning: `usingTransactions` is experimental.
286295
- warning: It is recomended to only specify `masterKey` when using the SDK on a server. Do not use this key on the client.
296+
- warning: `usingTransactions` is experimental.
287297
- warning: Setting `usingPostForQuery` to **true** will require all queries to access the server instead of following the `requestCachePolicy`.
298+
- warning: Setting `usingDataProtectionKeychain` to **true** is known to cause issues in Playgrounds or in
299+
situtations when apps do not have credentials to setup a Keychain.
288300
*/
289301
@available(*, deprecated, message: "Remove the migratingFromObjcSDK argument")
290302
public func initialize(
@@ -302,6 +314,7 @@ public func initialize(
302314
cacheMemoryCapacity: Int = 512_000,
303315
cacheDiskCapacity: Int = 10_000_000,
304316
migratingFromObjcSDK: Bool = false,
317+
usingDataProtectionKeychain: Bool = false,
305318
deletingKeychainIfNeeded: Bool = false,
306319
httpAdditionalHeaders: [AnyHashable: Any]? = nil,
307320
maxConnectionAttempts: Int = 5,
@@ -322,6 +335,7 @@ public func initialize(
322335
requestCachePolicy: requestCachePolicy,
323336
cacheMemoryCapacity: cacheMemoryCapacity,
324337
cacheDiskCapacity: cacheDiskCapacity,
338+
usingDataProtectionKeychain: usingDataProtectionKeychain,
325339
deletingKeychainIfNeeded: deletingKeychainIfNeeded,
326340
httpAdditionalHeaders: httpAdditionalHeaders,
327341
maxConnectionAttempts: maxConnectionAttempts,

Sources/ParseSwift/Storage/KeychainStore.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ struct KeychainStore: SecureStorage {
130130
query[kSecAttrAccessible as String] = kSecAttrAccessibleAfterFirstUnlockThisDeviceOnly as String
131131
}
132132
#if os(macOS)
133-
if !Parse.configuration.isTestingSDK {
133+
if Parse.configuration.isUsingDataProtectionKeychain {
134134
query[kSecUseDataProtectionKeychain as String] = kCFBooleanTrue
135135
}
136136
#endif

Sources/ParseSwift/Types/ParseConfiguration.swift

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,13 @@ public struct ParseConfiguration {
7777
/// Defaults to **false**.
7878
public internal(set) var isDeletingKeychainIfNeeded: Bool = false
7979

80+
/// Sets `kSecUseDataProtectionKeychain` to **true**. See Apple's [documentation](https://developer.apple.com/documentation/security/ksecusedataprotectionkeychain)
81+
/// for more info.
82+
/// Defaults to **false**.
83+
/// - warning: This is known to cause issues in Playgrounds or in situtations when
84+
/// apps do not have credentials to setup a Keychain.
85+
public internal(set) var isUsingDataProtectionKeychain: Bool = false
86+
8087
/// Maximum number of times to try to connect to Parse Server.
8188
/// Defaults to 5.
8289
public internal(set) var maxConnectionAttempts: Int = 5
@@ -115,6 +122,8 @@ public struct ParseConfiguration {
115122
- parameter cacheDiskCapacity: The disk capacity of the cache, in bytes. Defaults to 10MB.
116123
- parameter migratingFromObjcSDK: If your app previously used the iOS Objective-C SDK, setting this value
117124
to **true** will attempt to migrate relevant data stored in the Keychain to ParseSwift. Defaults to **false**.
125+
- parameter usingDataProtectionKeychain: Sets `kSecUseDataProtectionKeychain` to **true**. See Apple's [documentation](https://developer.apple.com/documentation/security/ksecusedataprotectionkeychain)
126+
for more info. Defaults to **false**.
118127
- parameter deletingKeychainIfNeeded: Deletes the Parse Keychain when the app is running for the first time.
119128
Defaults to **false**.
120129
- parameter httpAdditionalHeaders: A dictionary of additional headers to send with requests. See Apple's
@@ -127,9 +136,11 @@ public struct ParseConfiguration {
127136
It should have the following argument signature: `(challenge: URLAuthenticationChallenge,
128137
completionHandler: (URLSession.AuthChallengeDisposition, URLCredential?) -> Void) -> Void`.
129138
See Apple's [documentation](https://developer.apple.com/documentation/foundation/urlsessiontaskdelegate/1411595-urlsession) for more for details.
130-
- warning: `usingTransactions` is experimental.
131139
- warning: It is recomended to only specify `masterKey` when using the SDK on a server. Do not use this key on the client.
140+
- warning: `usingTransactions` is experimental.
132141
- warning: Setting `usingPostForQuery` to **true** will require all queries to access the server instead of following the `requestCachePolicy`.
142+
- warning: Setting `usingDataProtectionKeychain` to **true** is known to cause issues in Playgrounds or in
143+
situtations when apps do not have credentials to setup a Keychain.
133144
*/
134145
public init(applicationId: String,
135146
clientKey: String? = nil,
@@ -145,6 +156,7 @@ public struct ParseConfiguration {
145156
requestCachePolicy: URLRequest.CachePolicy = .useProtocolCachePolicy,
146157
cacheMemoryCapacity: Int = 512_000,
147158
cacheDiskCapacity: Int = 10_000_000,
159+
usingDataProtectionKeychain: Bool = false,
148160
deletingKeychainIfNeeded: Bool = false,
149161
httpAdditionalHeaders: [AnyHashable: Any]? = nil,
150162
maxConnectionAttempts: Int = 5,
@@ -167,6 +179,7 @@ public struct ParseConfiguration {
167179
self.requestCachePolicy = requestCachePolicy
168180
self.cacheMemoryCapacity = cacheMemoryCapacity
169181
self.cacheDiskCapacity = cacheDiskCapacity
182+
self.isUsingDataProtectionKeychain = usingDataProtectionKeychain
170183
self.isDeletingKeychainIfNeeded = deletingKeychainIfNeeded
171184
self.httpAdditionalHeaders = httpAdditionalHeaders
172185
self.maxConnectionAttempts = maxConnectionAttempts
@@ -198,6 +211,8 @@ public struct ParseConfiguration {
198211
- parameter cacheDiskCapacity: The disk capacity of the cache, in bytes. Defaults to 10MB.
199212
- parameter migratingFromObjcSDK: If your app previously used the iOS Objective-C SDK, setting this value
200213
to **true** will attempt to migrate relevant data stored in the Keychain to ParseSwift. Defaults to **false**.
214+
- parameter usingDataProtectionKeychain: Sets `kSecUseDataProtectionKeychain` to **true**. See Apple's [documentation](https://developer.apple.com/documentation/security/ksecusedataprotectionkeychain)
215+
for more info. Defaults to **false**.
201216
- parameter deletingKeychainIfNeeded: Deletes the Parse Keychain when the app is running for the first time.
202217
Defaults to **false**.
203218
- parameter httpAdditionalHeaders: A dictionary of additional headers to send with requests. See Apple's
@@ -210,9 +225,11 @@ public struct ParseConfiguration {
210225
It should have the following argument signature: `(challenge: URLAuthenticationChallenge,
211226
completionHandler: (URLSession.AuthChallengeDisposition, URLCredential?) -> Void) -> Void`.
212227
See Apple's [documentation](https://developer.apple.com/documentation/foundation/urlsessiontaskdelegate/1411595-urlsession) for more for details.
213-
- warning: `usingTransactions` is experimental.
214228
- warning: It is recomended to only specify `masterKey` when using the SDK on a server. Do not use this key on the client.
229+
- warning: `usingTransactions` is experimental.
215230
- warning: Setting `usingPostForQuery` to **true** will require all queries to access the server instead of following the `requestCachePolicy`.
231+
- warning: Setting `usingDataProtectionKeychain` to **true** is known to cause issues in Playgrounds or in
232+
situtations when apps do not have credentials to setup a Keychain.
216233
*/
217234
@available(*, deprecated, message: "Remove the migratingFromObjcSDK argument")
218235
public init(applicationId: String,
@@ -230,6 +247,7 @@ public struct ParseConfiguration {
230247
cacheMemoryCapacity: Int = 512_000,
231248
cacheDiskCapacity: Int = 10_000_000,
232249
migratingFromObjcSDK: Bool = false,
250+
usingDataProtectionKeychain: Bool = false,
233251
deletingKeychainIfNeeded: Bool = false,
234252
httpAdditionalHeaders: [AnyHashable: Any]? = nil,
235253
maxConnectionAttempts: Int = 5,
@@ -250,6 +268,7 @@ public struct ParseConfiguration {
250268
requestCachePolicy: requestCachePolicy,
251269
cacheMemoryCapacity: cacheMemoryCapacity,
252270
cacheDiskCapacity: cacheDiskCapacity,
271+
usingDataProtectionKeychain: usingDataProtectionKeychain,
253272
deletingKeychainIfNeeded: deletingKeychainIfNeeded,
254273
httpAdditionalHeaders: httpAdditionalHeaders,
255274
maxConnectionAttempts: maxConnectionAttempts,

0 commit comments

Comments
 (0)