[email protected] | b9d3d00 | 2012-03-17 12:14:50 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | 32d0ef5 | 2009-05-26 20:17:50 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
[email protected] | 982f1ab | 2012-08-30 13:03:46 | [diff] [blame] | 5 | #include "crypto/apple_keychain.h" |
| 6 | |
| 7 | #import <Foundation/Foundation.h> |
[email protected] | b9d3d00 | 2012-03-17 12:14:50 | [diff] [blame] | 8 | |
[email protected] | d6e8fe6 | 2012-10-03 05:46:45 | [diff] [blame] | 9 | #include "base/synchronization/lock.h" |
| 10 | #include "crypto/mac_security_services_lock.h" |
| 11 | |
[email protected] | b9d3d00 | 2012-03-17 12:14:50 | [diff] [blame] | 12 | namespace crypto { |
| 13 | |
[email protected] | 982f1ab | 2012-08-30 13:03:46 | [diff] [blame] | 14 | AppleKeychain::AppleKeychain() {} |
[email protected] | b9d3d00 | 2012-03-17 12:14:50 | [diff] [blame] | 15 | |
[email protected] | 982f1ab | 2012-08-30 13:03:46 | [diff] [blame] | 16 | AppleKeychain::~AppleKeychain() {} |
[email protected] | 32d0ef5 | 2009-05-26 20:17:50 | [diff] [blame] | 17 | |
Justin Cohen | 2db1569 | 2018-06-06 16:54:03 | [diff] [blame] | 18 | OSStatus AppleKeychain::ItemDelete(AppleSecKeychainItemRef itemRef) const { |
[email protected] | d6e8fe6 | 2012-10-03 05:46:45 | [diff] [blame] | 19 | base::AutoLock lock(GetMacSecurityServicesLock()); |
[email protected] | 0a21fde | 2009-07-13 23:44:08 | [diff] [blame] | 20 | return SecKeychainItemDelete(itemRef); |
| 21 | } |
| 22 | |
Justin Cohen | 2db1569 | 2018-06-06 16:54:03 | [diff] [blame] | 23 | OSStatus AppleKeychain::FindGenericPassword( |
| 24 | UInt32 serviceNameLength, |
| 25 | const char* serviceName, |
| 26 | UInt32 accountNameLength, |
| 27 | const char* accountName, |
| 28 | UInt32* passwordLength, |
| 29 | void** passwordData, |
| 30 | AppleSecKeychainItemRef* itemRef) const { |
[email protected] | d6e8fe6 | 2012-10-03 05:46:45 | [diff] [blame] | 31 | base::AutoLock lock(GetMacSecurityServicesLock()); |
Justin Cohen | 2db1569 | 2018-06-06 16:54:03 | [diff] [blame] | 32 | return SecKeychainFindGenericPassword(nullptr, serviceNameLength, serviceName, |
| 33 | accountNameLength, accountName, |
| 34 | passwordLength, passwordData, itemRef); |
[email protected] | ecbf289 | 2010-07-16 01:51:45 | [diff] [blame] | 35 | } |
| 36 | |
Justin Cohen | 2db1569 | 2018-06-06 16:54:03 | [diff] [blame] | 37 | OSStatus AppleKeychain::ItemFreeContent(void* data) const { |
[email protected] | d6e8fe6 | 2012-10-03 05:46:45 | [diff] [blame] | 38 | base::AutoLock lock(GetMacSecurityServicesLock()); |
Justin Cohen | 2db1569 | 2018-06-06 16:54:03 | [diff] [blame] | 39 | return SecKeychainItemFreeContent(nullptr, data); |
[email protected] | ecbf289 | 2010-07-16 01:51:45 | [diff] [blame] | 40 | } |
| 41 | |
Justin Cohen | 2db1569 | 2018-06-06 16:54:03 | [diff] [blame] | 42 | OSStatus AppleKeychain::AddGenericPassword( |
| 43 | UInt32 serviceNameLength, |
| 44 | const char* serviceName, |
| 45 | UInt32 accountNameLength, |
| 46 | const char* accountName, |
| 47 | UInt32 passwordLength, |
| 48 | const void* passwordData, |
| 49 | AppleSecKeychainItemRef* itemRef) const { |
[email protected] | d6e8fe6 | 2012-10-03 05:46:45 | [diff] [blame] | 50 | base::AutoLock lock(GetMacSecurityServicesLock()); |
Justin Cohen | 2db1569 | 2018-06-06 16:54:03 | [diff] [blame] | 51 | return SecKeychainAddGenericPassword(nullptr, serviceNameLength, serviceName, |
| 52 | accountNameLength, accountName, |
| 53 | passwordLength, passwordData, itemRef); |
[email protected] | ecbf289 | 2010-07-16 01:51:45 | [diff] [blame] | 54 | } |
| 55 | |
[email protected] | b9d3d00 | 2012-03-17 12:14:50 | [diff] [blame] | 56 | } // namespace crypto |