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"
32 #include "LegacyAPICounts.h"
35 SecIdentitySearchGetTypeID(void)
39 return gTypes().IdentityCursor
.typeID
;
41 END_SECAPI1(_kCFRuntimeNotATypeID
)
46 SecIdentitySearchCreate(
47 CFTypeRef keychainOrArray
,
49 SecIdentitySearchRef
*searchRef
)
52 os_activity_t activity
= os_activity_create("SecIdentitySearchCreate", OS_ACTIVITY_CURRENT
, OS_ACTIVITY_FLAG_IF_NONE_PRESENT
);
53 os_activity_scope(activity
);
58 StorageManager::KeychainList keychains
;
59 globals().storageManager
.optionalSearchList(keychainOrArray
, keychains
);
60 SecPointer
<IdentityCursor
> identityCursor(new IdentityCursor (keychains
, keyUsage
));
61 *searchRef
= identityCursor
->handle();
66 OSStatus
SecIdentitySearchCreateWithAttributes(
67 CFDictionaryRef attributes
,
68 SecIdentitySearchRef
* searchRef
)
71 os_activity_t activity
= os_activity_create("SecIdentitySearchCreateWithAttributes", OS_ACTIVITY_CURRENT
, OS_ACTIVITY_FLAG_IF_NONE_PRESENT
);
72 os_activity_scope(activity
);
76 // %%%TBI This function needs a new form of IdentityCursor that takes
77 // the supplied attributes as input.
80 StorageManager::KeychainList keychains
;
81 globals().storageManager
.getSearchList(keychains
);
82 SecPointer
<IdentityCursor
> identityCursor(new IdentityCursor (keychains
, 0));
83 *searchRef
= identityCursor
->handle();
88 OSStatus
SecIdentitySearchCreateWithPolicy(
92 CFTypeRef keychainOrArray
,
93 Boolean returnOnlyValidIdentities
,
94 SecIdentitySearchRef
* searchRef
)
97 os_activity_t activity
= os_activity_create("SecIdentitySearchCreateWithPolicy", OS_ACTIVITY_CURRENT
, OS_ACTIVITY_FLAG_IF_NONE_PRESENT
);
98 os_activity_scope(activity
);
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
));
108 *searchRef
= identityCursor
->handle();
114 SecIdentitySearchCopyNext(
115 SecIdentitySearchRef searchRef
,
116 SecIdentityRef
*identityRef
)
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
);
123 RequiredParam(identityRef
);
124 SecPointer
<Identity
> identityPtr
;
125 if (!IdentityCursor::required(searchRef
)->next(identityPtr
))
126 return errSecItemNotFound
;
128 *identityRef
= identityPtr
->handle();