1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "crypto/apple_keychain.h"
7 #import <Foundation/Foundation.h>
9 #include "base/synchronization/lock.h"
10 #include "crypto/mac_security_services_lock.h"
14 AppleKeychain::AppleKeychain() {}
16 AppleKeychain::~AppleKeychain() {}
18 OSStatus AppleKeychain::ItemCopyAttributesAndData(
19 SecKeychainItemRef itemRef,
20 SecKeychainAttributeInfo* info,
21 SecItemClass* itemClass,
22 SecKeychainAttributeList** attrList,
24 void** outData) const {
25 base::AutoLock lock(GetMacSecurityServicesLock());
26 return SecKeychainItemCopyAttributesAndData(itemRef, info, itemClass,
27 attrList, length, outData);
30 OSStatus AppleKeychain::ItemModifyAttributesAndData(
31 SecKeychainItemRef itemRef,
32 const SecKeychainAttributeList* attrList,
34 const void* data) const {
35 base::AutoLock lock(GetMacSecurityServicesLock());
36 return SecKeychainItemModifyAttributesAndData(itemRef, attrList, length,
40 OSStatus AppleKeychain::ItemFreeAttributesAndData(
41 SecKeychainAttributeList* attrList,
43 base::AutoLock lock(GetMacSecurityServicesLock());
44 return SecKeychainItemFreeAttributesAndData(attrList, data);
47 OSStatus AppleKeychain::ItemDelete(SecKeychainItemRef itemRef) const {
48 base::AutoLock lock(GetMacSecurityServicesLock());
49 return SecKeychainItemDelete(itemRef);
52 OSStatus AppleKeychain::SearchCreateFromAttributes(
53 CFTypeRef keychainOrArray,
54 SecItemClass itemClass,
55 const SecKeychainAttributeList* attrList,
56 SecKeychainSearchRef* searchRef) const {
57 base::AutoLock lock(GetMacSecurityServicesLock());
58 return SecKeychainSearchCreateFromAttributes(keychainOrArray, itemClass,
62 OSStatus AppleKeychain::SearchCopyNext(SecKeychainSearchRef searchRef,
63 SecKeychainItemRef* itemRef) const {
64 base::AutoLock lock(GetMacSecurityServicesLock());
65 return SecKeychainSearchCopyNext(searchRef, itemRef);
68 OSStatus AppleKeychain::AddInternetPassword(
69 SecKeychainRef keychain,
70 UInt32 serverNameLength,
71 const char* serverName,
72 UInt32 securityDomainLength,
73 const char* securityDomain,
74 UInt32 accountNameLength,
75 const char* accountName,
79 SecProtocolType protocol,
80 SecAuthenticationType authenticationType,
81 UInt32 passwordLength,
82 const void* passwordData,
83 SecKeychainItemRef* itemRef) const {
84 base::AutoLock lock(GetMacSecurityServicesLock());
85 return SecKeychainAddInternetPassword(keychain,
86 serverNameLength, serverName,
87 securityDomainLength, securityDomain,
88 accountNameLength, accountName,
90 port, protocol, authenticationType,
91 passwordLength, passwordData,
95 OSStatus AppleKeychain::FindGenericPassword(CFTypeRef keychainOrArray,
96 UInt32 serviceNameLength,
97 const char* serviceName,
98 UInt32 accountNameLength,
99 const char* accountName,
100 UInt32* passwordLength,
102 SecKeychainItemRef* itemRef) const {
103 base::AutoLock lock(GetMacSecurityServicesLock());
104 return SecKeychainFindGenericPassword(keychainOrArray,
114 OSStatus AppleKeychain::ItemFreeContent(SecKeychainAttributeList* attrList,
116 base::AutoLock lock(GetMacSecurityServicesLock());
117 return SecKeychainItemFreeContent(attrList, data);
120 OSStatus AppleKeychain::AddGenericPassword(SecKeychainRef keychain,
121 UInt32 serviceNameLength,
122 const char* serviceName,
123 UInt32 accountNameLength,
124 const char* accountName,
125 UInt32 passwordLength,
126 const void* passwordData,
127 SecKeychainItemRef* itemRef) const {
128 base::AutoLock lock(GetMacSecurityServicesLock());
129 return SecKeychainAddGenericPassword(keychain,
139 void AppleKeychain::Free(CFTypeRef ref) const {
144 } // namespace crypto