[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] | b9d3d00 | 2012-03-17 12:14:50 | [diff] [blame^] | 5 | #include "crypto/keychain_mac.h" |
| 6 | |
| 7 | namespace crypto { |
| 8 | |
| 9 | MacKeychain::MacKeychain() {} |
| 10 | |
| 11 | MacKeychain::~MacKeychain() {} |
[email protected] | 32d0ef5 | 2009-05-26 20:17:50 | [diff] [blame] | 12 | |
| 13 | OSStatus MacKeychain::ItemCopyAttributesAndData( |
[email protected] | b9d3d00 | 2012-03-17 12:14:50 | [diff] [blame^] | 14 | SecKeychainItemRef itemRef, |
| 15 | SecKeychainAttributeInfo* info, |
| 16 | SecItemClass* itemClass, |
| 17 | SecKeychainAttributeList** attrList, |
| 18 | UInt32* length, |
| 19 | void** outData) const { |
[email protected] | 32d0ef5 | 2009-05-26 20:17:50 | [diff] [blame] | 20 | return SecKeychainItemCopyAttributesAndData(itemRef, info, itemClass, |
| 21 | attrList, length, outData); |
| 22 | } |
| 23 | |
[email protected] | 06139a2 | 2009-06-23 16:36:20 | [diff] [blame] | 24 | OSStatus MacKeychain::ItemModifyAttributesAndData( |
[email protected] | b9d3d00 | 2012-03-17 12:14:50 | [diff] [blame^] | 25 | SecKeychainItemRef itemRef, |
| 26 | const SecKeychainAttributeList* attrList, |
| 27 | UInt32 length, |
| 28 | const void* data) const { |
[email protected] | 06139a2 | 2009-06-23 16:36:20 | [diff] [blame] | 29 | return SecKeychainItemModifyAttributesAndData(itemRef, attrList, length, |
| 30 | data); |
| 31 | } |
| 32 | |
[email protected] | 32d0ef5 | 2009-05-26 20:17:50 | [diff] [blame] | 33 | OSStatus MacKeychain::ItemFreeAttributesAndData( |
[email protected] | b9d3d00 | 2012-03-17 12:14:50 | [diff] [blame^] | 34 | SecKeychainAttributeList* attrList, |
| 35 | void* data) const { |
[email protected] | 32d0ef5 | 2009-05-26 20:17:50 | [diff] [blame] | 36 | return SecKeychainItemFreeAttributesAndData(attrList, data); |
| 37 | } |
| 38 | |
[email protected] | 0a21fde | 2009-07-13 23:44:08 | [diff] [blame] | 39 | OSStatus MacKeychain::ItemDelete(SecKeychainItemRef itemRef) const { |
| 40 | return SecKeychainItemDelete(itemRef); |
| 41 | } |
| 42 | |
[email protected] | 32d0ef5 | 2009-05-26 20:17:50 | [diff] [blame] | 43 | OSStatus MacKeychain::SearchCreateFromAttributes( |
[email protected] | b9d3d00 | 2012-03-17 12:14:50 | [diff] [blame^] | 44 | CFTypeRef keychainOrArray, |
| 45 | SecItemClass itemClass, |
| 46 | const SecKeychainAttributeList* attrList, |
| 47 | SecKeychainSearchRef* searchRef) const { |
[email protected] | 32d0ef5 | 2009-05-26 20:17:50 | [diff] [blame] | 48 | return SecKeychainSearchCreateFromAttributes(keychainOrArray, itemClass, |
| 49 | attrList, searchRef); |
| 50 | } |
| 51 | |
| 52 | OSStatus MacKeychain::SearchCopyNext(SecKeychainSearchRef searchRef, |
[email protected] | b9d3d00 | 2012-03-17 12:14:50 | [diff] [blame^] | 53 | SecKeychainItemRef* itemRef) const { |
[email protected] | 32d0ef5 | 2009-05-26 20:17:50 | [diff] [blame] | 54 | return SecKeychainSearchCopyNext(searchRef, itemRef); |
| 55 | } |
| 56 | |
[email protected] | 06139a2 | 2009-06-23 16:36:20 | [diff] [blame] | 57 | OSStatus MacKeychain::AddInternetPassword( |
| 58 | SecKeychainRef keychain, |
[email protected] | b9d3d00 | 2012-03-17 12:14:50 | [diff] [blame^] | 59 | UInt32 serverNameLength, |
| 60 | const char* serverName, |
| 61 | UInt32 securityDomainLength, |
| 62 | const char* securityDomain, |
| 63 | UInt32 accountNameLength, |
| 64 | const char* accountName, |
| 65 | UInt32 pathLength, |
| 66 | const char* path, |
| 67 | UInt16 port, |
| 68 | SecProtocolType protocol, |
[email protected] | 06139a2 | 2009-06-23 16:36:20 | [diff] [blame] | 69 | SecAuthenticationType authenticationType, |
[email protected] | b9d3d00 | 2012-03-17 12:14:50 | [diff] [blame^] | 70 | UInt32 passwordLength, |
| 71 | const void* passwordData, |
| 72 | SecKeychainItemRef* itemRef) const { |
[email protected] | 06139a2 | 2009-06-23 16:36:20 | [diff] [blame] | 73 | return SecKeychainAddInternetPassword(keychain, |
| 74 | serverNameLength, serverName, |
| 75 | securityDomainLength, securityDomain, |
| 76 | accountNameLength, accountName, |
| 77 | pathLength, path, |
| 78 | port, protocol, authenticationType, |
| 79 | passwordLength, passwordData, |
| 80 | itemRef); |
| 81 | } |
| 82 | |
[email protected] | ecbf289 | 2010-07-16 01:51:45 | [diff] [blame] | 83 | OSStatus MacKeychain::FindGenericPassword(CFTypeRef keychainOrArray, |
| 84 | UInt32 serviceNameLength, |
[email protected] | b9d3d00 | 2012-03-17 12:14:50 | [diff] [blame^] | 85 | const char* serviceName, |
[email protected] | ecbf289 | 2010-07-16 01:51:45 | [diff] [blame] | 86 | UInt32 accountNameLength, |
[email protected] | b9d3d00 | 2012-03-17 12:14:50 | [diff] [blame^] | 87 | const char* accountName, |
| 88 | UInt32* passwordLength, |
| 89 | void** passwordData, |
| 90 | SecKeychainItemRef* itemRef) const { |
[email protected] | ecbf289 | 2010-07-16 01:51:45 | [diff] [blame] | 91 | return SecKeychainFindGenericPassword(keychainOrArray, |
| 92 | serviceNameLength, |
| 93 | serviceName, |
| 94 | accountNameLength, |
| 95 | accountName, |
| 96 | passwordLength, |
| 97 | passwordData, |
| 98 | itemRef); |
| 99 | } |
| 100 | |
[email protected] | b9d3d00 | 2012-03-17 12:14:50 | [diff] [blame^] | 101 | OSStatus MacKeychain::ItemFreeContent(SecKeychainAttributeList* attrList, |
| 102 | void* data) const { |
[email protected] | ecbf289 | 2010-07-16 01:51:45 | [diff] [blame] | 103 | return SecKeychainItemFreeContent(attrList, data); |
| 104 | } |
| 105 | |
| 106 | OSStatus MacKeychain::AddGenericPassword(SecKeychainRef keychain, |
| 107 | UInt32 serviceNameLength, |
[email protected] | b9d3d00 | 2012-03-17 12:14:50 | [diff] [blame^] | 108 | const char* serviceName, |
[email protected] | ecbf289 | 2010-07-16 01:51:45 | [diff] [blame] | 109 | UInt32 accountNameLength, |
[email protected] | b9d3d00 | 2012-03-17 12:14:50 | [diff] [blame^] | 110 | const char* accountName, |
[email protected] | ecbf289 | 2010-07-16 01:51:45 | [diff] [blame] | 111 | UInt32 passwordLength, |
[email protected] | b9d3d00 | 2012-03-17 12:14:50 | [diff] [blame^] | 112 | const void* passwordData, |
| 113 | SecKeychainItemRef* itemRef) const { |
[email protected] | ecbf289 | 2010-07-16 01:51:45 | [diff] [blame] | 114 | return SecKeychainAddGenericPassword(keychain, |
| 115 | serviceNameLength, |
| 116 | serviceName, |
| 117 | accountNameLength, |
| 118 | accountName, |
| 119 | passwordLength, |
| 120 | passwordData, |
| 121 | itemRef); |
| 122 | } |
| 123 | |
[email protected] | 32d0ef5 | 2009-05-26 20:17:50 | [diff] [blame] | 124 | void MacKeychain::Free(CFTypeRef ref) const { |
[email protected] | b9d3d00 | 2012-03-17 12:14:50 | [diff] [blame^] | 125 | if (ref) |
[email protected] | 32d0ef5 | 2009-05-26 20:17:50 | [diff] [blame] | 126 | CFRelease(ref); |
[email protected] | 32d0ef5 | 2009-05-26 20:17:50 | [diff] [blame] | 127 | } |
[email protected] | b9d3d00 | 2012-03-17 12:14:50 | [diff] [blame^] | 128 | |
| 129 | } // namespace crypto |