2 * Copyright (c) 2002-2004,2011,2014-2015 Apple Inc. All Rights Reserved.
4 * @APPLE_LICENSE_HEADER_START@
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
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.
21 * @APPLE_LICENSE_HEADER_END@
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>
31 #include "SecBridge.h"
35 SecIdentitySearchGetTypeID(void)
38 os_activity_t activity
= os_activity_create("SecIdentitySearchGetTypeID", OS_ACTIVITY_CURRENT
, OS_ACTIVITY_FLAG_IF_NONE_PRESENT
);
39 os_activity_scope(activity
);
42 return gTypes().IdentityCursor
.typeID
;
44 END_SECAPI1(_kCFRuntimeNotATypeID
)
49 SecIdentitySearchCreate(
50 CFTypeRef keychainOrArray
,
52 SecIdentitySearchRef
*searchRef
)
55 os_activity_t activity
= os_activity_create("SecIdentitySearchCreate", OS_ACTIVITY_CURRENT
, OS_ACTIVITY_FLAG_IF_NONE_PRESENT
);
56 os_activity_scope(activity
);
61 StorageManager::KeychainList keychains
;
62 globals().storageManager
.optionalSearchList(keychainOrArray
, keychains
);
63 SecPointer
<IdentityCursor
> identityCursor(new IdentityCursor (keychains
, keyUsage
));
64 *searchRef
= identityCursor
->handle();
69 OSStatus
SecIdentitySearchCreateWithAttributes(
70 CFDictionaryRef attributes
,
71 SecIdentitySearchRef
* searchRef
)
74 os_activity_t activity
= os_activity_create("SecIdentitySearchCreateWithAttributes", OS_ACTIVITY_CURRENT
, OS_ACTIVITY_FLAG_IF_NONE_PRESENT
);
75 os_activity_scope(activity
);
79 // %%%TBI This function needs a new form of IdentityCursor that takes
80 // the supplied attributes as input.
83 StorageManager::KeychainList keychains
;
84 globals().storageManager
.getSearchList(keychains
);
85 SecPointer
<IdentityCursor
> identityCursor(new IdentityCursor (keychains
, 0));
86 *searchRef
= identityCursor
->handle();
91 OSStatus
SecIdentitySearchCreateWithPolicy(
95 CFTypeRef keychainOrArray
,
96 Boolean returnOnlyValidIdentities
,
97 SecIdentitySearchRef
* searchRef
)
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
);
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
));
111 *searchRef
= identityCursor
->handle();
117 SecIdentitySearchCopyNext(
118 SecIdentitySearchRef searchRef
,
119 SecIdentityRef
*identityRef
)
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
);
126 RequiredParam(identityRef
);
127 SecPointer
<Identity
> identityPtr
;
128 if (!IdentityCursor::required(searchRef
)->next(identityPtr
))
129 return errSecItemNotFound
;
131 *identityRef
= identityPtr
->handle();