From b095eefb2365c6b829c2da2e0af3ae80be4d4c91 Mon Sep 17 00:00:00 2001 From: Colin Cornaby Date: Sat, 30 Sep 2023 16:11:18 -0700 Subject: [PATCH] Fixes for keychain storage. Existing keychain code was baulking at some queries. --- .../pfPasswordStore/pfPasswordStore_Apple.cpp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/Sources/Plasma/FeatureLib/pfPasswordStore/pfPasswordStore_Apple.cpp b/Sources/Plasma/FeatureLib/pfPasswordStore/pfPasswordStore_Apple.cpp index 2bdab4a239..76e5216d05 100644 --- a/Sources/Plasma/FeatureLib/pfPasswordStore/pfPasswordStore_Apple.cpp +++ b/Sources/Plasma/FeatureLib/pfPasswordStore/pfPasswordStore_Apple.cpp @@ -93,10 +93,10 @@ bool pfApplePasswordStore::SetPassword(const ST::string& username, const ST::str CFAutorelease(serviceName); CFAutorelease(passwordData); - const void* keys[] = { kSecClass, kSecAttrService, kSecReturnData, kSecValueData }; - const void* values[] = { kSecClassGenericPassword, serviceName, kCFBooleanTrue, passwordData }; + const void* keys[] = { kSecClass, kSecAttrService, kSecAttrAccount, kSecReturnData, kSecValueData }; + const void* values[] = { kSecClassGenericPassword, serviceName, accountName, kCFBooleanTrue, passwordData }; - CFDictionaryRef query = CFDictionaryCreate(nullptr, keys, values, 4, nullptr, nullptr); + CFDictionaryRef query = CFDictionaryCreate(nullptr, keys, values, 5, nullptr, nullptr); CFAutorelease(query); OSStatus err = SecItemAdd(query, nullptr); @@ -104,14 +104,14 @@ bool pfApplePasswordStore::SetPassword(const ST::string& username, const ST::str if (err == errSecDuplicateItem) { // the keychain item already exists, update it - const void* queryKeys[2] = { kSecClass, kSecAttrService }; - const void* queryValues[2] = { kSecClassGenericPassword, serviceName }; - CFDictionaryRef updateQuery = CFDictionaryCreate(nullptr, queryKeys, queryValues, 2, nullptr, nullptr); + const void* queryKeys[] = { kSecClass, kSecAttrService, kSecAttrAccount }; + const void* queryValues[] = { kSecClassGenericPassword, serviceName, accountName }; + CFDictionaryRef updateQuery = CFDictionaryCreate(nullptr, queryKeys, queryValues, 3, nullptr, nullptr); CFAutorelease(updateQuery); - const void* attributeKeys[2] = { kSecAttrAccount, kSecValueData }; - const void* attributeValues[2] = { accountName, passwordData }; - CFDictionaryRef attributes = CFDictionaryCreate(nullptr, attributeKeys, attributeValues, 2, nullptr, nullptr); + const void* attributeKeys[1] = { kSecValueData }; + const void* attributeValues[1] = { passwordData }; + CFDictionaryRef attributes = CFDictionaryCreate(nullptr, attributeKeys, attributeValues, 1, nullptr, nullptr); err = SecItemUpdate(updateQuery, attributes);