Skip to content

Commit 97b6c9e

Browse files
authored
fix(core): update keychain setter for macOS (#3174)
* fix(core): update keychain setter for macOS * chore(core): update per review comments * chore(core): update per review comments * chore(core): remove code comment
1 parent d4f0ca6 commit 97b6c9e

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

AmplifyPlugins/Core/AWSPluginsCore/Keychain/KeychainStore.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,14 +148,18 @@ public struct KeychainStore: KeychainStoreBehavior {
148148
let fetchStatus = SecItemCopyMatching(getQuery as CFDictionary, nil)
149149
switch fetchStatus {
150150
case errSecSuccess:
151-
151+
#if os(macOS)
152+
SecItemDelete(getQuery as CFDictionary)
153+
fallthrough
154+
#else
152155
var attributesToUpdate = [String: Any]()
153156
attributesToUpdate[Constants.ValueData] = value
154157

155158
let updateStatus = SecItemUpdate(getQuery as CFDictionary, attributesToUpdate as CFDictionary)
156159
if updateStatus != errSecSuccess {
157160
throw KeychainStoreError.securityError(updateStatus)
158161
}
162+
#endif
159163
case errSecItemNotFound:
160164
var attributesToSet = attributes.defaultSetQuery()
161165
attributesToSet[Constants.AttributeAccount] = key

AmplifyPlugins/Core/AWSPluginsCore/Keychain/KeychainStoreAttributes.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,10 @@ extension KeychainStoreAttributes {
2020
func defaultGetQuery() -> [String: Any] {
2121
var query: [String: Any] = [
2222
KeychainStore.Constants.Class: itemClass,
23-
KeychainStore.Constants.AttributeService: service
23+
KeychainStore.Constants.AttributeService: service,
24+
KeychainStore.Constants.UseDataProtectionKeyChain: kCFBooleanTrue
2425
]
26+
2527
if let accessGroup = accessGroup {
2628
query[KeychainStore.Constants.AttributeAccessGroup] = accessGroup
2729
}

0 commit comments

Comments
 (0)