]> git.saurik.com Git - apple/security.git/blob - OSX/libsecurity_keychain/lib/SecIdentitySearch.cpp
Security-59754.41.1.tar.gz
[apple/security.git] / OSX / libsecurity_keychain / lib / SecIdentitySearch.cpp
1 /*
2 * Copyright (c) 2002-2004,2011,2014-2015 Apple Inc. All Rights Reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
11 * file.
12 *
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 */
23
24 #include <Security/SecIdentitySearch.h>
25 #include <Security/SecIdentitySearchPriv.h>
26 #include <Security/SecPolicyPriv.h>
27 #include <security_keychain/IdentityCursor.h>
28 #include <security_keychain/Identity.h>
29 #include <os/activity.h>
30
31 #include "SecBridge.h"
32 #include "LegacyAPICounts.h"
33
34 CFTypeID
35 SecIdentitySearchGetTypeID(void)
36 {
37 BEGIN_SECAPI
38
39 return gTypes().IdentityCursor.typeID;
40
41 END_SECAPI1(_kCFRuntimeNotATypeID)
42 }
43
44
45 OSStatus
46 SecIdentitySearchCreate(
47 CFTypeRef keychainOrArray,
48 CSSM_KEYUSE keyUsage,
49 SecIdentitySearchRef *searchRef)
50 {
51 BEGIN_SECAPI
52 os_activity_t activity = os_activity_create("SecIdentitySearchCreate", OS_ACTIVITY_CURRENT, OS_ACTIVITY_FLAG_IF_NONE_PRESENT);
53 os_activity_scope(activity);
54 os_release(activity);
55
56 Required(searchRef);
57
58 StorageManager::KeychainList keychains;
59 globals().storageManager.optionalSearchList(keychainOrArray, keychains);
60 SecPointer<IdentityCursor> identityCursor(new IdentityCursor (keychains, keyUsage));
61 *searchRef = identityCursor->handle();
62
63 END_SECAPI
64 }
65
66 OSStatus SecIdentitySearchCreateWithAttributes(
67 CFDictionaryRef attributes,
68 SecIdentitySearchRef* searchRef)
69 {
70 BEGIN_SECAPI
71 os_activity_t activity = os_activity_create("SecIdentitySearchCreateWithAttributes", OS_ACTIVITY_CURRENT, OS_ACTIVITY_FLAG_IF_NONE_PRESENT);
72 os_activity_scope(activity);
73 os_release(activity);
74
75 //
76 // %%%TBI This function needs a new form of IdentityCursor that takes
77 // the supplied attributes as input.
78 //
79 Required(searchRef);
80 StorageManager::KeychainList keychains;
81 globals().storageManager.getSearchList(keychains);
82 SecPointer<IdentityCursor> identityCursor(new IdentityCursor (keychains, 0));
83 *searchRef = identityCursor->handle();
84
85 END_SECAPI
86 }
87
88 OSStatus SecIdentitySearchCreateWithPolicy(
89 SecPolicyRef policy,
90 CFStringRef idString,
91 CSSM_KEYUSE keyUsage,
92 CFTypeRef keychainOrArray,
93 Boolean returnOnlyValidIdentities,
94 SecIdentitySearchRef* searchRef)
95 {
96 BEGIN_SECAPI
97 os_activity_t activity = os_activity_create("SecIdentitySearchCreateWithPolicy", OS_ACTIVITY_CURRENT, OS_ACTIVITY_FLAG_IF_NONE_PRESENT);
98 os_activity_scope(activity);
99 os_release(activity);
100
101 Required(searchRef);
102
103 StorageManager::KeychainList keychains;
104 globals().storageManager.optionalSearchList(keychainOrArray, keychains);
105 CFRef<SecPolicyRef> policyRef = SecPolicyCreateItemImplInstance(policy);
106 SecPointer<IdentityCursorPolicyAndID> identityCursor(new IdentityCursorPolicyAndID (keychains, keyUsage, idString, policyRef, returnOnlyValidIdentities));
107
108 *searchRef = identityCursor->handle();
109
110 END_SECAPI
111 }
112
113 OSStatus
114 SecIdentitySearchCopyNext(
115 SecIdentitySearchRef searchRef,
116 SecIdentityRef *identityRef)
117 {
118 BEGIN_SECAPI
119 os_activity_t activity = os_activity_create("SecIdentitySearchCopyNext", OS_ACTIVITY_CURRENT, OS_ACTIVITY_FLAG_IF_NONE_PRESENT);
120 os_activity_scope(activity);
121 os_release(activity);
122
123 RequiredParam(identityRef);
124 SecPointer<Identity> identityPtr;
125 if (!IdentityCursor::required(searchRef)->next(identityPtr))
126 return errSecItemNotFound;
127
128 *identityRef = identityPtr->handle();
129
130 END_SECAPI
131 }