blob: 240c32067bcf147858e21746affbe2883cd3d171 [file] [log] [blame]
[email protected]b9d3d002012-03-17 12:14:501// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]32d0ef52009-05-26 20:17:502// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]982f1ab2012-08-30 13:03:465#include "crypto/apple_keychain.h"
6
7#import <Foundation/Foundation.h>
[email protected]b9d3d002012-03-17 12:14:508
[email protected]d6e8fe62012-10-03 05:46:459#include "base/synchronization/lock.h"
10#include "crypto/mac_security_services_lock.h"
11
[email protected]b9d3d002012-03-17 12:14:5012namespace crypto {
13
[email protected]982f1ab2012-08-30 13:03:4614AppleKeychain::AppleKeychain() {}
[email protected]b9d3d002012-03-17 12:14:5015
[email protected]982f1ab2012-08-30 13:03:4616AppleKeychain::~AppleKeychain() {}
[email protected]32d0ef52009-05-26 20:17:5017
[email protected]982f1ab2012-08-30 13:03:4618OSStatus AppleKeychain::ItemCopyAttributesAndData(
[email protected]b9d3d002012-03-17 12:14:5019 SecKeychainItemRef itemRef,
20 SecKeychainAttributeInfo* info,
21 SecItemClass* itemClass,
22 SecKeychainAttributeList** attrList,
23 UInt32* length,
24 void** outData) const {
[email protected]d6e8fe62012-10-03 05:46:4525 base::AutoLock lock(GetMacSecurityServicesLock());
[email protected]32d0ef52009-05-26 20:17:5026 return SecKeychainItemCopyAttributesAndData(itemRef, info, itemClass,
27 attrList, length, outData);
28}
29
[email protected]982f1ab2012-08-30 13:03:4630OSStatus AppleKeychain::ItemModifyAttributesAndData(
[email protected]b9d3d002012-03-17 12:14:5031 SecKeychainItemRef itemRef,
32 const SecKeychainAttributeList* attrList,
33 UInt32 length,
34 const void* data) const {
[email protected]d6e8fe62012-10-03 05:46:4535 base::AutoLock lock(GetMacSecurityServicesLock());
[email protected]06139a22009-06-23 16:36:2036 return SecKeychainItemModifyAttributesAndData(itemRef, attrList, length,
37 data);
38}
39
[email protected]982f1ab2012-08-30 13:03:4640OSStatus AppleKeychain::ItemFreeAttributesAndData(
[email protected]b9d3d002012-03-17 12:14:5041 SecKeychainAttributeList* attrList,
42 void* data) const {
[email protected]d6e8fe62012-10-03 05:46:4543 base::AutoLock lock(GetMacSecurityServicesLock());
[email protected]32d0ef52009-05-26 20:17:5044 return SecKeychainItemFreeAttributesAndData(attrList, data);
45}
46
[email protected]982f1ab2012-08-30 13:03:4647OSStatus AppleKeychain::ItemDelete(SecKeychainItemRef itemRef) const {
[email protected]d6e8fe62012-10-03 05:46:4548 base::AutoLock lock(GetMacSecurityServicesLock());
[email protected]0a21fde2009-07-13 23:44:0849 return SecKeychainItemDelete(itemRef);
50}
51
[email protected]982f1ab2012-08-30 13:03:4652OSStatus AppleKeychain::SearchCreateFromAttributes(
[email protected]b9d3d002012-03-17 12:14:5053 CFTypeRef keychainOrArray,
54 SecItemClass itemClass,
55 const SecKeychainAttributeList* attrList,
56 SecKeychainSearchRef* searchRef) const {
[email protected]d6e8fe62012-10-03 05:46:4557 base::AutoLock lock(GetMacSecurityServicesLock());
[email protected]32d0ef52009-05-26 20:17:5058 return SecKeychainSearchCreateFromAttributes(keychainOrArray, itemClass,
59 attrList, searchRef);
60}
61
[email protected]982f1ab2012-08-30 13:03:4662OSStatus AppleKeychain::SearchCopyNext(SecKeychainSearchRef searchRef,
63 SecKeychainItemRef* itemRef) const {
[email protected]d6e8fe62012-10-03 05:46:4564 base::AutoLock lock(GetMacSecurityServicesLock());
[email protected]32d0ef52009-05-26 20:17:5065 return SecKeychainSearchCopyNext(searchRef, itemRef);
66}
67
[email protected]982f1ab2012-08-30 13:03:4668OSStatus AppleKeychain::AddInternetPassword(
[email protected]06139a22009-06-23 16:36:2069 SecKeychainRef keychain,
[email protected]b9d3d002012-03-17 12:14:5070 UInt32 serverNameLength,
71 const char* serverName,
72 UInt32 securityDomainLength,
73 const char* securityDomain,
74 UInt32 accountNameLength,
75 const char* accountName,
76 UInt32 pathLength,
77 const char* path,
78 UInt16 port,
79 SecProtocolType protocol,
[email protected]06139a22009-06-23 16:36:2080 SecAuthenticationType authenticationType,
[email protected]b9d3d002012-03-17 12:14:5081 UInt32 passwordLength,
82 const void* passwordData,
83 SecKeychainItemRef* itemRef) const {
[email protected]d6e8fe62012-10-03 05:46:4584 base::AutoLock lock(GetMacSecurityServicesLock());
[email protected]06139a22009-06-23 16:36:2085 return SecKeychainAddInternetPassword(keychain,
86 serverNameLength, serverName,
87 securityDomainLength, securityDomain,
88 accountNameLength, accountName,
89 pathLength, path,
90 port, protocol, authenticationType,
91 passwordLength, passwordData,
92 itemRef);
93}
94
[email protected]982f1ab2012-08-30 13:03:4695OSStatus AppleKeychain::FindGenericPassword(CFTypeRef keychainOrArray,
96 UInt32 serviceNameLength,
97 const char* serviceName,
98 UInt32 accountNameLength,
99 const char* accountName,
100 UInt32* passwordLength,
101 void** passwordData,
102 SecKeychainItemRef* itemRef) const {
[email protected]d6e8fe62012-10-03 05:46:45103 base::AutoLock lock(GetMacSecurityServicesLock());
[email protected]ecbf2892010-07-16 01:51:45104 return SecKeychainFindGenericPassword(keychainOrArray,
105 serviceNameLength,
106 serviceName,
107 accountNameLength,
108 accountName,
109 passwordLength,
110 passwordData,
111 itemRef);
112}
113
[email protected]982f1ab2012-08-30 13:03:46114OSStatus AppleKeychain::ItemFreeContent(SecKeychainAttributeList* attrList,
115 void* data) const {
[email protected]d6e8fe62012-10-03 05:46:45116 base::AutoLock lock(GetMacSecurityServicesLock());
[email protected]ecbf2892010-07-16 01:51:45117 return SecKeychainItemFreeContent(attrList, data);
118}
119
[email protected]982f1ab2012-08-30 13:03:46120OSStatus 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 {
[email protected]d6e8fe62012-10-03 05:46:45128 base::AutoLock lock(GetMacSecurityServicesLock());
[email protected]ecbf2892010-07-16 01:51:45129 return SecKeychainAddGenericPassword(keychain,
130 serviceNameLength,
131 serviceName,
132 accountNameLength,
133 accountName,
134 passwordLength,
135 passwordData,
136 itemRef);
137}
138
[email protected]982f1ab2012-08-30 13:03:46139void AppleKeychain::Free(CFTypeRef ref) const {
[email protected]b9d3d002012-03-17 12:14:50140 if (ref)
[email protected]32d0ef52009-05-26 20:17:50141 CFRelease(ref);
[email protected]32d0ef52009-05-26 20:17:50142}
[email protected]b9d3d002012-03-17 12:14:50143
144} // namespace crypto