| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "crypto/apple_keychain.h" | 5 #include "crypto/apple_keychain.h" |
| 6 | 6 |
| 7 #import <Foundation/Foundation.h> | 7 #import <Foundation/Foundation.h> |
| 8 | 8 |
| 9 #include "base/synchronization/lock.h" |
| 10 #include "crypto/mac_security_services_lock.h" |
| 11 |
| 9 namespace crypto { | 12 namespace crypto { |
| 10 | 13 |
| 11 AppleKeychain::AppleKeychain() {} | 14 AppleKeychain::AppleKeychain() {} |
| 12 | 15 |
| 13 AppleKeychain::~AppleKeychain() {} | 16 AppleKeychain::~AppleKeychain() {} |
| 14 | 17 |
| 15 OSStatus AppleKeychain::ItemCopyAttributesAndData( | 18 OSStatus AppleKeychain::ItemCopyAttributesAndData( |
| 16 SecKeychainItemRef itemRef, | 19 SecKeychainItemRef itemRef, |
| 17 SecKeychainAttributeInfo* info, | 20 SecKeychainAttributeInfo* info, |
| 18 SecItemClass* itemClass, | 21 SecItemClass* itemClass, |
| 19 SecKeychainAttributeList** attrList, | 22 SecKeychainAttributeList** attrList, |
| 20 UInt32* length, | 23 UInt32* length, |
| 21 void** outData) const { | 24 void** outData) const { |
| 25 base::AutoLock lock(GetMacSecurityServicesLock()); |
| 22 return SecKeychainItemCopyAttributesAndData(itemRef, info, itemClass, | 26 return SecKeychainItemCopyAttributesAndData(itemRef, info, itemClass, |
| 23 attrList, length, outData); | 27 attrList, length, outData); |
| 24 } | 28 } |
| 25 | 29 |
| 26 OSStatus AppleKeychain::ItemModifyAttributesAndData( | 30 OSStatus AppleKeychain::ItemModifyAttributesAndData( |
| 27 SecKeychainItemRef itemRef, | 31 SecKeychainItemRef itemRef, |
| 28 const SecKeychainAttributeList* attrList, | 32 const SecKeychainAttributeList* attrList, |
| 29 UInt32 length, | 33 UInt32 length, |
| 30 const void* data) const { | 34 const void* data) const { |
| 35 base::AutoLock lock(GetMacSecurityServicesLock()); |
| 31 return SecKeychainItemModifyAttributesAndData(itemRef, attrList, length, | 36 return SecKeychainItemModifyAttributesAndData(itemRef, attrList, length, |
| 32 data); | 37 data); |
| 33 } | 38 } |
| 34 | 39 |
| 35 OSStatus AppleKeychain::ItemFreeAttributesAndData( | 40 OSStatus AppleKeychain::ItemFreeAttributesAndData( |
| 36 SecKeychainAttributeList* attrList, | 41 SecKeychainAttributeList* attrList, |
| 37 void* data) const { | 42 void* data) const { |
| 43 base::AutoLock lock(GetMacSecurityServicesLock()); |
| 38 return SecKeychainItemFreeAttributesAndData(attrList, data); | 44 return SecKeychainItemFreeAttributesAndData(attrList, data); |
| 39 } | 45 } |
| 40 | 46 |
| 41 OSStatus AppleKeychain::ItemDelete(SecKeychainItemRef itemRef) const { | 47 OSStatus AppleKeychain::ItemDelete(SecKeychainItemRef itemRef) const { |
| 48 base::AutoLock lock(GetMacSecurityServicesLock()); |
| 42 return SecKeychainItemDelete(itemRef); | 49 return SecKeychainItemDelete(itemRef); |
| 43 } | 50 } |
| 44 | 51 |
| 45 OSStatus AppleKeychain::SearchCreateFromAttributes( | 52 OSStatus AppleKeychain::SearchCreateFromAttributes( |
| 46 CFTypeRef keychainOrArray, | 53 CFTypeRef keychainOrArray, |
| 47 SecItemClass itemClass, | 54 SecItemClass itemClass, |
| 48 const SecKeychainAttributeList* attrList, | 55 const SecKeychainAttributeList* attrList, |
| 49 SecKeychainSearchRef* searchRef) const { | 56 SecKeychainSearchRef* searchRef) const { |
| 57 base::AutoLock lock(GetMacSecurityServicesLock()); |
| 50 return SecKeychainSearchCreateFromAttributes(keychainOrArray, itemClass, | 58 return SecKeychainSearchCreateFromAttributes(keychainOrArray, itemClass, |
| 51 attrList, searchRef); | 59 attrList, searchRef); |
| 52 } | 60 } |
| 53 | 61 |
| 54 OSStatus AppleKeychain::SearchCopyNext(SecKeychainSearchRef searchRef, | 62 OSStatus AppleKeychain::SearchCopyNext(SecKeychainSearchRef searchRef, |
| 55 SecKeychainItemRef* itemRef) const { | 63 SecKeychainItemRef* itemRef) const { |
| 64 base::AutoLock lock(GetMacSecurityServicesLock()); |
| 56 return SecKeychainSearchCopyNext(searchRef, itemRef); | 65 return SecKeychainSearchCopyNext(searchRef, itemRef); |
| 57 } | 66 } |
| 58 | 67 |
| 59 OSStatus AppleKeychain::AddInternetPassword( | 68 OSStatus AppleKeychain::AddInternetPassword( |
| 60 SecKeychainRef keychain, | 69 SecKeychainRef keychain, |
| 61 UInt32 serverNameLength, | 70 UInt32 serverNameLength, |
| 62 const char* serverName, | 71 const char* serverName, |
| 63 UInt32 securityDomainLength, | 72 UInt32 securityDomainLength, |
| 64 const char* securityDomain, | 73 const char* securityDomain, |
| 65 UInt32 accountNameLength, | 74 UInt32 accountNameLength, |
| 66 const char* accountName, | 75 const char* accountName, |
| 67 UInt32 pathLength, | 76 UInt32 pathLength, |
| 68 const char* path, | 77 const char* path, |
| 69 UInt16 port, | 78 UInt16 port, |
| 70 SecProtocolType protocol, | 79 SecProtocolType protocol, |
| 71 SecAuthenticationType authenticationType, | 80 SecAuthenticationType authenticationType, |
| 72 UInt32 passwordLength, | 81 UInt32 passwordLength, |
| 73 const void* passwordData, | 82 const void* passwordData, |
| 74 SecKeychainItemRef* itemRef) const { | 83 SecKeychainItemRef* itemRef) const { |
| 84 base::AutoLock lock(GetMacSecurityServicesLock()); |
| 75 return SecKeychainAddInternetPassword(keychain, | 85 return SecKeychainAddInternetPassword(keychain, |
| 76 serverNameLength, serverName, | 86 serverNameLength, serverName, |
| 77 securityDomainLength, securityDomain, | 87 securityDomainLength, securityDomain, |
| 78 accountNameLength, accountName, | 88 accountNameLength, accountName, |
| 79 pathLength, path, | 89 pathLength, path, |
| 80 port, protocol, authenticationType, | 90 port, protocol, authenticationType, |
| 81 passwordLength, passwordData, | 91 passwordLength, passwordData, |
| 82 itemRef); | 92 itemRef); |
| 83 } | 93 } |
| 84 | 94 |
| 85 OSStatus AppleKeychain::FindGenericPassword(CFTypeRef keychainOrArray, | 95 OSStatus AppleKeychain::FindGenericPassword(CFTypeRef keychainOrArray, |
| 86 UInt32 serviceNameLength, | 96 UInt32 serviceNameLength, |
| 87 const char* serviceName, | 97 const char* serviceName, |
| 88 UInt32 accountNameLength, | 98 UInt32 accountNameLength, |
| 89 const char* accountName, | 99 const char* accountName, |
| 90 UInt32* passwordLength, | 100 UInt32* passwordLength, |
| 91 void** passwordData, | 101 void** passwordData, |
| 92 SecKeychainItemRef* itemRef) const { | 102 SecKeychainItemRef* itemRef) const { |
| 103 base::AutoLock lock(GetMacSecurityServicesLock()); |
| 93 return SecKeychainFindGenericPassword(keychainOrArray, | 104 return SecKeychainFindGenericPassword(keychainOrArray, |
| 94 serviceNameLength, | 105 serviceNameLength, |
| 95 serviceName, | 106 serviceName, |
| 96 accountNameLength, | 107 accountNameLength, |
| 97 accountName, | 108 accountName, |
| 98 passwordLength, | 109 passwordLength, |
| 99 passwordData, | 110 passwordData, |
| 100 itemRef); | 111 itemRef); |
| 101 } | 112 } |
| 102 | 113 |
| 103 OSStatus AppleKeychain::ItemFreeContent(SecKeychainAttributeList* attrList, | 114 OSStatus AppleKeychain::ItemFreeContent(SecKeychainAttributeList* attrList, |
| 104 void* data) const { | 115 void* data) const { |
| 116 base::AutoLock lock(GetMacSecurityServicesLock()); |
| 105 return SecKeychainItemFreeContent(attrList, data); | 117 return SecKeychainItemFreeContent(attrList, data); |
| 106 } | 118 } |
| 107 | 119 |
| 108 OSStatus AppleKeychain::AddGenericPassword(SecKeychainRef keychain, | 120 OSStatus AppleKeychain::AddGenericPassword(SecKeychainRef keychain, |
| 109 UInt32 serviceNameLength, | 121 UInt32 serviceNameLength, |
| 110 const char* serviceName, | 122 const char* serviceName, |
| 111 UInt32 accountNameLength, | 123 UInt32 accountNameLength, |
| 112 const char* accountName, | 124 const char* accountName, |
| 113 UInt32 passwordLength, | 125 UInt32 passwordLength, |
| 114 const void* passwordData, | 126 const void* passwordData, |
| 115 SecKeychainItemRef* itemRef) const { | 127 SecKeychainItemRef* itemRef) const { |
| 128 base::AutoLock lock(GetMacSecurityServicesLock()); |
| 116 return SecKeychainAddGenericPassword(keychain, | 129 return SecKeychainAddGenericPassword(keychain, |
| 117 serviceNameLength, | 130 serviceNameLength, |
| 118 serviceName, | 131 serviceName, |
| 119 accountNameLength, | 132 accountNameLength, |
| 120 accountName, | 133 accountName, |
| 121 passwordLength, | 134 passwordLength, |
| 122 passwordData, | 135 passwordData, |
| 123 itemRef); | 136 itemRef); |
| 124 } | 137 } |
| 125 | 138 |
| 126 void AppleKeychain::Free(CFTypeRef ref) const { | 139 void AppleKeychain::Free(CFTypeRef ref) const { |
| 127 if (ref) | 140 if (ref) |
| 128 CFRelease(ref); | 141 CFRelease(ref); |
| 129 } | 142 } |
| 130 | 143 |
| 131 } // namespace crypto | 144 } // namespace crypto |
| OLD | NEW |