diff --git a/Sources/Plasma/Apps/plClient/Mac-Cocoa/PLSLoginWindowController.mm b/Sources/Plasma/Apps/plClient/Mac-Cocoa/PLSLoginWindowController.mm index a9c3497319..7a847e8c25 100644 --- a/Sources/Plasma/Apps/plClient/Mac-Cocoa/PLSLoginWindowController.mm +++ b/Sources/Plasma/Apps/plClient/Mac-Cocoa/PLSLoginWindowController.mm @@ -64,6 +64,7 @@ @interface PLSLoginWindowController () #define FAKE_PASS_STRING @"********" static NSOperationQueue* _loginQueue = nil; +static dispatch_queue_t _keychainQueue = dispatch_queue_create(nullptr, DISPATCH_QUEUE_SERIAL); @implementation PLSLoginController @@ -131,11 +132,13 @@ - (void)save ST::string username = [self.username STString]; ST::string password = [self.password STString]; - pfPasswordStore* store = pfPasswordStore::Instance(); - if (self.rememberPassword) - store->SetPassword(username, password); - else - store->SetPassword(username, ST::string()); + dispatch_async(_keychainQueue, ^{ + pfPasswordStore* store = pfPasswordStore::Instance(); + if (self.rememberPassword) + store->SetPassword(username, password); + else + store->SetPassword(username, ST::string()); + }); } } @@ -150,8 +153,10 @@ - (void)load if (self.rememberPassword) { pfPasswordStore* store = pfPasswordStore::Instance(); ST::string username = [self.username STString]; - ST::string password = store->GetPassword(username); - self.password = [NSString stringWithSTString:password]; + dispatch_sync(_keychainQueue, ^{ + ST::string password = store->GetPassword(username); + self.password = [NSString stringWithSTString:password]; + }); } } diff --git a/Sources/Plasma/FeatureLib/pfPasswordStore/pfPasswordStore_Apple.cpp b/Sources/Plasma/FeatureLib/pfPasswordStore/pfPasswordStore_Apple.cpp index 8ecc2e9be6..6846d54ade 100644 --- a/Sources/Plasma/FeatureLib/pfPasswordStore/pfPasswordStore_Apple.cpp +++ b/Sources/Plasma/FeatureLib/pfPasswordStore/pfPasswordStore_Apple.cpp @@ -93,8 +93,8 @@ 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, kSecValueData }; + const void* values[] = { kSecClassGenericPassword, serviceName, accountName, passwordData }; CFDictionaryRef query = CFDictionaryCreate(nullptr, keys, values, 4, nullptr, nullptr); CFAutorelease(query); @@ -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);