Skip to content

Commit

Permalink
Fixes for keychain storage. Existing keychain code was baulking at so…
Browse files Browse the repository at this point in the history
…me queries.
  • Loading branch information
colincornaby committed Oct 1, 2023
1 parent 9c23884 commit 85404f1
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions Sources/Plasma/FeatureLib/pfPasswordStore/pfPasswordStore_Apple.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,27 +92,27 @@ bool pfApplePasswordStore::SetPassword(const ST::string& username, const ST::str
CFAutorelease(accountName);
CFAutorelease(serviceName);
CFAutorelease(passwordData);

const void* keys[] = { kSecClass, kSecAttrService, kSecReturnData, kSecValueData };
const void* values[] = { kSecClassGenericPassword, serviceName, kCFBooleanTrue, passwordData };

const void* keys[] = { kSecClass, kSecAttrService, kSecAttrAccount, kSecValueData };
const void* values[] = { kSecClassGenericPassword, serviceName, accountName, passwordData };
CFDictionaryRef query = CFDictionaryCreate(nullptr, keys, values, 4, nullptr, nullptr);
CFAutorelease(query);

OSStatus err = SecItemAdd(query, nullptr);

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);

CFRelease(attributes);
Expand Down

0 comments on commit 85404f1

Please sign in to comment.