Skip to content

Commit

Permalink
fix: default to setting use data protection to false for macOS Keycha…
Browse files Browse the repository at this point in the history
…in (#398)

* fix: default to setting use data protection to false for macOS Keychain

* fix

* Update .codecov.yml
  • Loading branch information
cbaker6 authored Sep 2, 2022
1 parent ed74494 commit df71568
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ coverage:
status:
patch:
default:
target: auto
target: 83
changes: false
project:
default:
Expand Down
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
# Parse-Swift Changelog

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

### 4.9.3
[Full Changelog](https://github.com/parse-community/Parse-Swift/compare/4.9.2...4.9.3)
__Fixes__
- 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).

### 4.9.2
[Full Changelog](https://github.com/parse-community/Parse-Swift/compare/4.9.1...4.9.2)

Expand Down
3 changes: 2 additions & 1 deletion ParseSwift.playground/Sources/Common.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ public func initializeParse(customObjectId: Bool = false) {
masterKey: "masterKey",
serverURL: URL(string: "http://localhost:1337/1")!,
allowingCustomObjectIds: customObjectId,
usingEqualQueryConstraint: false)
usingEqualQueryConstraint: false,
usingDataProtectionKeychain: false)
}
18 changes: 16 additions & 2 deletions Sources/ParseSwift/Parse.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ internal func initialize(applicationId: String,
cacheMemoryCapacity: Int = 512_000,
cacheDiskCapacity: Int = 10_000_000,
migratingFromObjcSDK: Bool = false,
usingDataProtectionKeychain: Bool = false,
deletingKeychainIfNeeded: Bool = false,
httpAdditionalHeaders: [AnyHashable: Any]? = nil,
maxConnectionAttempts: Int = 5,
Expand All @@ -46,6 +47,7 @@ internal func initialize(applicationId: String,
requestCachePolicy: requestCachePolicy,
cacheMemoryCapacity: cacheMemoryCapacity,
cacheDiskCapacity: cacheDiskCapacity,
usingDataProtectionKeychain: usingDataProtectionKeychain,
deletingKeychainIfNeeded: deletingKeychainIfNeeded,
httpAdditionalHeaders: httpAdditionalHeaders,
maxConnectionAttempts: maxConnectionAttempts,
Expand Down Expand Up @@ -191,6 +193,8 @@ public func initialize(configuration: ParseConfiguration) {
for more info.
- parameter cacheMemoryCapacity: The memory capacity of the cache, in bytes. Defaults to 512KB.
- parameter cacheDiskCapacity: The disk capacity of the cache, in bytes. Defaults to 10MB.
- parameter usingDataProtectionKeychain: Sets `kSecUseDataProtectionKeychain` to **true**. See Apple's [documentation](https://developer.apple.com/documentation/security/ksecusedataprotectionkeychain)
for more info. Defaults to **false**.
- parameter deletingKeychainIfNeeded: Deletes the Parse Keychain when the app is running for the first time.
Defaults to **false**.
- parameter httpAdditionalHeaders: A dictionary of additional headers to send with requests. See Apple's
Expand All @@ -201,9 +205,11 @@ public func initialize(configuration: ParseConfiguration) {
It should have the following argument signature: `(challenge: URLAuthenticationChallenge,
completionHandler: (URLSession.AuthChallengeDisposition, URLCredential?) -> Void) -> Void`.
See Apple's [documentation](https://developer.apple.com/documentation/foundation/urlsessiontaskdelegate/1411595-urlsession) for more for details.
- warning: `usingTransactions` is experimental.
- warning: It is recomended to only specify `masterKey` when using the SDK on a server. Do not use this key on the client.
- warning: `usingTransactions` is experimental.
- warning: Setting `usingPostForQuery` to **true** will require all queries to access the server instead of following the `requestCachePolicy`.
- warning: Setting `usingDataProtectionKeychain` to **true** is known to cause issues in Playgrounds or in
situtations when apps do not have credentials to setup a Keychain.
*/
public func initialize(
applicationId: String,
Expand All @@ -219,6 +225,7 @@ public func initialize(
requestCachePolicy: URLRequest.CachePolicy = .useProtocolCachePolicy,
cacheMemoryCapacity: Int = 512_000,
cacheDiskCapacity: Int = 10_000_000,
usingDataProtectionKeychain: Bool = false,
deletingKeychainIfNeeded: Bool = false,
httpAdditionalHeaders: [AnyHashable: Any]? = nil,
maxConnectionAttempts: Int = 5,
Expand All @@ -239,6 +246,7 @@ public func initialize(
requestCachePolicy: requestCachePolicy,
cacheMemoryCapacity: cacheMemoryCapacity,
cacheDiskCapacity: cacheDiskCapacity,
usingDataProtectionKeychain: usingDataProtectionKeychain,
deletingKeychainIfNeeded: deletingKeychainIfNeeded,
httpAdditionalHeaders: httpAdditionalHeaders,
maxConnectionAttempts: maxConnectionAttempts,
Expand Down Expand Up @@ -272,6 +280,8 @@ public func initialize(
- parameter cacheDiskCapacity: The disk capacity of the cache, in bytes. Defaults to 10MB.
- parameter migratingFromObjcSDK: If your app previously used the iOS Objective-C SDK, setting this value
to **true** will attempt to migrate relevant data stored in the Keychain to ParseSwift. Defaults to **false**.
- parameter usingDataProtectionKeychain: Sets `kSecUseDataProtectionKeychain` to **true**. See Apple's [documentation](https://developer.apple.com/documentation/security/ksecusedataprotectionkeychain)
for more info. Defaults to **false**.
- parameter deletingKeychainIfNeeded: Deletes the Parse Keychain when the app is running for the first time.
Defaults to **false**.
- parameter httpAdditionalHeaders: A dictionary of additional headers to send with requests. See Apple's
Expand All @@ -282,9 +292,11 @@ public func initialize(
It should have the following argument signature: `(challenge: URLAuthenticationChallenge,
completionHandler: (URLSession.AuthChallengeDisposition, URLCredential?) -> Void) -> Void`.
See Apple's [documentation](https://developer.apple.com/documentation/foundation/urlsessiontaskdelegate/1411595-urlsession) for more for details.
- warning: `usingTransactions` is experimental.
- warning: It is recomended to only specify `masterKey` when using the SDK on a server. Do not use this key on the client.
- warning: `usingTransactions` is experimental.
- warning: Setting `usingPostForQuery` to **true** will require all queries to access the server instead of following the `requestCachePolicy`.
- warning: Setting `usingDataProtectionKeychain` to **true** is known to cause issues in Playgrounds or in
situtations when apps do not have credentials to setup a Keychain.
*/
@available(*, deprecated, message: "Remove the migratingFromObjcSDK argument")
public func initialize(
Expand All @@ -302,6 +314,7 @@ public func initialize(
cacheMemoryCapacity: Int = 512_000,
cacheDiskCapacity: Int = 10_000_000,
migratingFromObjcSDK: Bool = false,
usingDataProtectionKeychain: Bool = false,
deletingKeychainIfNeeded: Bool = false,
httpAdditionalHeaders: [AnyHashable: Any]? = nil,
maxConnectionAttempts: Int = 5,
Expand All @@ -322,6 +335,7 @@ public func initialize(
requestCachePolicy: requestCachePolicy,
cacheMemoryCapacity: cacheMemoryCapacity,
cacheDiskCapacity: cacheDiskCapacity,
usingDataProtectionKeychain: usingDataProtectionKeychain,
deletingKeychainIfNeeded: deletingKeychainIfNeeded,
httpAdditionalHeaders: httpAdditionalHeaders,
maxConnectionAttempts: maxConnectionAttempts,
Expand Down
2 changes: 1 addition & 1 deletion Sources/ParseSwift/Storage/KeychainStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ struct KeychainStore: SecureStorage {
query[kSecAttrAccessible as String] = kSecAttrAccessibleAfterFirstUnlockThisDeviceOnly as String
}
#if os(macOS)
if !Parse.configuration.isTestingSDK {
if Parse.configuration.isUsingDataProtectionKeychain {
query[kSecUseDataProtectionKeychain as String] = kCFBooleanTrue
}
#endif
Expand Down
23 changes: 21 additions & 2 deletions Sources/ParseSwift/Types/ParseConfiguration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,13 @@ public struct ParseConfiguration {
/// Defaults to **false**.
public internal(set) var isDeletingKeychainIfNeeded: Bool = false

/// Sets `kSecUseDataProtectionKeychain` to **true**. See Apple's [documentation](https://developer.apple.com/documentation/security/ksecusedataprotectionkeychain)
/// for more info.
/// Defaults to **false**.
/// - warning: This is known to cause issues in Playgrounds or in situtations when
/// apps do not have credentials to setup a Keychain.
public internal(set) var isUsingDataProtectionKeychain: Bool = false

/// Maximum number of times to try to connect to Parse Server.
/// Defaults to 5.
public internal(set) var maxConnectionAttempts: Int = 5
Expand Down Expand Up @@ -115,6 +122,8 @@ public struct ParseConfiguration {
- parameter cacheDiskCapacity: The disk capacity of the cache, in bytes. Defaults to 10MB.
- parameter migratingFromObjcSDK: If your app previously used the iOS Objective-C SDK, setting this value
to **true** will attempt to migrate relevant data stored in the Keychain to ParseSwift. Defaults to **false**.
- parameter usingDataProtectionKeychain: Sets `kSecUseDataProtectionKeychain` to **true**. See Apple's [documentation](https://developer.apple.com/documentation/security/ksecusedataprotectionkeychain)
for more info. Defaults to **false**.
- parameter deletingKeychainIfNeeded: Deletes the Parse Keychain when the app is running for the first time.
Defaults to **false**.
- parameter httpAdditionalHeaders: A dictionary of additional headers to send with requests. See Apple's
Expand All @@ -127,9 +136,11 @@ public struct ParseConfiguration {
It should have the following argument signature: `(challenge: URLAuthenticationChallenge,
completionHandler: (URLSession.AuthChallengeDisposition, URLCredential?) -> Void) -> Void`.
See Apple's [documentation](https://developer.apple.com/documentation/foundation/urlsessiontaskdelegate/1411595-urlsession) for more for details.
- warning: `usingTransactions` is experimental.
- warning: It is recomended to only specify `masterKey` when using the SDK on a server. Do not use this key on the client.
- warning: `usingTransactions` is experimental.
- warning: Setting `usingPostForQuery` to **true** will require all queries to access the server instead of following the `requestCachePolicy`.
- warning: Setting `usingDataProtectionKeychain` to **true** is known to cause issues in Playgrounds or in
situtations when apps do not have credentials to setup a Keychain.
*/
public init(applicationId: String,
clientKey: String? = nil,
Expand All @@ -145,6 +156,7 @@ public struct ParseConfiguration {
requestCachePolicy: URLRequest.CachePolicy = .useProtocolCachePolicy,
cacheMemoryCapacity: Int = 512_000,
cacheDiskCapacity: Int = 10_000_000,
usingDataProtectionKeychain: Bool = false,
deletingKeychainIfNeeded: Bool = false,
httpAdditionalHeaders: [AnyHashable: Any]? = nil,
maxConnectionAttempts: Int = 5,
Expand All @@ -167,6 +179,7 @@ public struct ParseConfiguration {
self.requestCachePolicy = requestCachePolicy
self.cacheMemoryCapacity = cacheMemoryCapacity
self.cacheDiskCapacity = cacheDiskCapacity
self.isUsingDataProtectionKeychain = usingDataProtectionKeychain
self.isDeletingKeychainIfNeeded = deletingKeychainIfNeeded
self.httpAdditionalHeaders = httpAdditionalHeaders
self.maxConnectionAttempts = maxConnectionAttempts
Expand Down Expand Up @@ -198,6 +211,8 @@ public struct ParseConfiguration {
- parameter cacheDiskCapacity: The disk capacity of the cache, in bytes. Defaults to 10MB.
- parameter migratingFromObjcSDK: If your app previously used the iOS Objective-C SDK, setting this value
to **true** will attempt to migrate relevant data stored in the Keychain to ParseSwift. Defaults to **false**.
- parameter usingDataProtectionKeychain: Sets `kSecUseDataProtectionKeychain` to **true**. See Apple's [documentation](https://developer.apple.com/documentation/security/ksecusedataprotectionkeychain)
for more info. Defaults to **false**.
- parameter deletingKeychainIfNeeded: Deletes the Parse Keychain when the app is running for the first time.
Defaults to **false**.
- parameter httpAdditionalHeaders: A dictionary of additional headers to send with requests. See Apple's
Expand All @@ -210,9 +225,11 @@ public struct ParseConfiguration {
It should have the following argument signature: `(challenge: URLAuthenticationChallenge,
completionHandler: (URLSession.AuthChallengeDisposition, URLCredential?) -> Void) -> Void`.
See Apple's [documentation](https://developer.apple.com/documentation/foundation/urlsessiontaskdelegate/1411595-urlsession) for more for details.
- warning: `usingTransactions` is experimental.
- warning: It is recomended to only specify `masterKey` when using the SDK on a server. Do not use this key on the client.
- warning: `usingTransactions` is experimental.
- warning: Setting `usingPostForQuery` to **true** will require all queries to access the server instead of following the `requestCachePolicy`.
- warning: Setting `usingDataProtectionKeychain` to **true** is known to cause issues in Playgrounds or in
situtations when apps do not have credentials to setup a Keychain.
*/
@available(*, deprecated, message: "Remove the migratingFromObjcSDK argument")
public init(applicationId: String,
Expand All @@ -230,6 +247,7 @@ public struct ParseConfiguration {
cacheMemoryCapacity: Int = 512_000,
cacheDiskCapacity: Int = 10_000_000,
migratingFromObjcSDK: Bool = false,
usingDataProtectionKeychain: Bool = false,
deletingKeychainIfNeeded: Bool = false,
httpAdditionalHeaders: [AnyHashable: Any]? = nil,
maxConnectionAttempts: Int = 5,
Expand All @@ -250,6 +268,7 @@ public struct ParseConfiguration {
requestCachePolicy: requestCachePolicy,
cacheMemoryCapacity: cacheMemoryCapacity,
cacheDiskCapacity: cacheDiskCapacity,
usingDataProtectionKeychain: usingDataProtectionKeychain,
deletingKeychainIfNeeded: deletingKeychainIfNeeded,
httpAdditionalHeaders: httpAdditionalHeaders,
maxConnectionAttempts: maxConnectionAttempts,
Expand Down

0 comments on commit df71568

Please sign in to comment.