]> git.saurik.com Git - apple/security.git/blob - OSX/libsecurity_keychain/lib/SecIdentitySearch.cpp
Security-58286.1.32.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
33
34 CFTypeID
35 SecIdentitySearchGetTypeID(void)
36 {
37 BEGIN_SECAPI
38 os_activity_t activity = os_activity_create("SecIdentitySearchGetTypeID", OS_ACTIVITY_CURRENT, OS_ACTIVITY_FLAG_IF_NONE_PRESENT);
39 os_activity_scope(activity);
40 os_release(activity);
41
42 return gTypes().IdentityCursor.typeID;
43
44 END_SECAPI1(_kCFRuntimeNotATypeID)
45 }
46
47
48 OSStatus
49 SecIdentitySearchCreate(
50 CFTypeRef keychainOrArray,
51 CSSM_KEYUSE keyUsage,
52 SecIdentitySearchRef *searchRef)
53 {
54 BEGIN_SECAPI
55 os_activity_t activity = os_activity_create("SecIdentitySearchCreate", OS_ACTIVITY_CURRENT, OS_ACTIVITY_FLAG_IF_NONE_PRESENT);
56 os_activity_scope(activity);
57 os_release(activity);
58
59 Required(searchRef);
60
61 StorageManager::KeychainList keychains;
62 globals().storageManager.optionalSearchList(keychainOrArray, keychains);
63 SecPointer<IdentityCursor> identityCursor(new IdentityCursor (keychains, keyUsage));
64 *searchRef = identityCursor->handle();
65
66 END_SECAPI
67 }
68
69 OSStatus SecIdentitySearchCreateWithAttributes(
70 CFDictionaryRef attributes,
71 SecIdentitySearchRef* searchRef)
72 {
73 BEGIN_SECAPI
74 os_activity_t activity = os_activity_create("SecIdentitySearchCreateWithAttributes", OS_ACTIVITY_CURRENT, OS_ACTIVITY_FLAG_IF_NONE_PRESENT);
75 os_activity_scope(activity);
76 os_release(activity);
77
78 //
79 // %%%TBI This function needs a new form of IdentityCursor that takes
80 // the supplied attributes as input.
81 //
82 Required(searchRef);
83 StorageManager::KeychainList keychains;
84 globals().storageManager.getSearchList(keychains);
85 SecPointer<IdentityCursor> identityCursor(new IdentityCursor (keychains, 0));
86 *searchRef = identityCursor->handle();
87
88 END_SECAPI
89 }
90
91 OSStatus SecIdentitySearchCreateWithPolicy(
92 SecPolicyRef policy,
93 CFStringRef idString,
94 CSSM_KEYUSE keyUsage,
95 CFTypeRef keychainOrArray,
96 Boolean returnOnlyValidIdentities,
97 SecIdentitySearchRef* searchRef)
98 {
99 BEGIN_SECAPI
100 os_activity_t activity = os_activity_create("SecIdentitySearchCreateWithPolicy", OS_ACTIVITY_CURRENT, OS_ACTIVITY_FLAG_IF_NONE_PRESENT);
101 os_activity_scope(activity);
102 os_release(activity);
103
104 Required(searchRef);
105
106 StorageManager::KeychainList keychains;
107 globals().storageManager.optionalSearchList(keychainOrArray, keychains);
108 CFRef<SecPolicyRef> policyRef = SecPolicyCreateItemImplInstance(policy);
109 SecPointer<IdentityCursorPolicyAndID> identityCursor(new IdentityCursorPolicyAndID (keychains, keyUsage, idString, policyRef, returnOnlyValidIdentities));
110
111 *searchRef = identityCursor->handle();
112
113 END_SECAPI
114 }
115
116 OSStatus
117 SecIdentitySearchCopyNext(
118 SecIdentitySearchRef searchRef,
119 SecIdentityRef *identityRef)
120 {
121 BEGIN_SECAPI
122 os_activity_t activity = os_activity_create("SecIdentitySearchCopyNext", OS_ACTIVITY_CURRENT, OS_ACTIVITY_FLAG_IF_NONE_PRESENT);
123 os_activity_scope(activity);
124 os_release(activity);
125
126 RequiredParam(identityRef);
127 SecPointer<Identity> identityPtr;
128 if (!IdentityCursor::required(searchRef)->next(identityPtr))
129 return errSecItemNotFound;
130
131 *identityRef = identityPtr->handle();
132
133 END_SECAPI
134 }