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 #ifndef CRYPTO_KEYCHAIN_MAC_H_
6 #define CRYPTO_KEYCHAIN_MAC_H_
8 #include <Security/Security.h>
10 #include "base/basictypes.h"
11 #include "crypto/crypto_export.h"
15 // Wraps the KeychainServices API in a very thin layer, to allow it to be
16 // mocked out for testing.
18 // See Keychain Services documentation for function documentation, as these call
19 // through directly to their Keychain Services equivalents (Foo ->
20 // SecKeychainFoo). The only exception is Free, which should be used for
21 // anything returned from this class that would normally be freed with
22 // CFRelease (to aid in testing).
23 class CRYPTO_EXPORT MacKeychain
{
26 virtual ~MacKeychain();
28 virtual OSStatus
ItemCopyAttributesAndData(
29 SecKeychainItemRef itemRef
,
30 SecKeychainAttributeInfo
* info
,
31 SecItemClass
* itemClass
,
32 SecKeychainAttributeList
** attrList
,
34 void** outData
) const;
36 virtual OSStatus
ItemModifyAttributesAndData(
37 SecKeychainItemRef itemRef
,
38 const SecKeychainAttributeList
* attrList
,
40 const void* data
) const;
42 virtual OSStatus
ItemFreeAttributesAndData(SecKeychainAttributeList
* attrList
,
45 virtual OSStatus
ItemDelete(SecKeychainItemRef itemRef
) const;
47 virtual OSStatus
SearchCreateFromAttributes(
48 CFTypeRef keychainOrArray
,
49 SecItemClass itemClass
,
50 const SecKeychainAttributeList
* attrList
,
51 SecKeychainSearchRef
* searchRef
) const;
53 virtual OSStatus
SearchCopyNext(SecKeychainSearchRef searchRef
,
54 SecKeychainItemRef
* itemRef
) const;
56 virtual OSStatus
AddInternetPassword(SecKeychainRef keychain
,
57 UInt32 serverNameLength
,
58 const char* serverName
,
59 UInt32 securityDomainLength
,
60 const char* securityDomain
,
61 UInt32 accountNameLength
,
62 const char* accountName
,
63 UInt32 pathLength
, const char* path
,
64 UInt16 port
, SecProtocolType protocol
,
65 SecAuthenticationType authenticationType
,
66 UInt32 passwordLength
,
67 const void* passwordData
,
68 SecKeychainItemRef
* itemRef
) const;
70 virtual OSStatus
FindGenericPassword(CFTypeRef keychainOrArray
,
71 UInt32 serviceNameLength
,
72 const char* serviceName
,
73 UInt32 accountNameLength
,
74 const char* accountName
,
75 UInt32
* passwordLength
,
77 SecKeychainItemRef
* itemRef
) const;
79 virtual OSStatus
ItemFreeContent(SecKeychainAttributeList
* attrList
,
82 virtual OSStatus
AddGenericPassword(SecKeychainRef keychain
,
83 UInt32 serviceNameLength
,
84 const char* serviceName
,
85 UInt32 accountNameLength
,
86 const char* accountName
,
87 UInt32 passwordLength
,
88 const void* passwordData
,
89 SecKeychainItemRef
* itemRef
) const;
91 // Calls CFRelease on the given ref, after checking that |ref| is non-NULL.
92 virtual void Free(CFTypeRef ref
) const;
95 DISALLOW_COPY_AND_ASSIGN(MacKeychain
);
100 #endif // CRYPTO_KEYCHAIN_MAC_H_