1/*
2 * Copyright (c) 2006 Apple Computer, 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/*
25 * SecTrustSettingsPriv.h - TrustSettings SPI functions.
26 */
27
28#ifndef	_SEC_TRUST_SETTINGS_PRIV_H_
29#define _SEC_TRUST_SETTINGS_PRIV_H_
30
31#include <CoreFoundation/CoreFoundation.h>
32#include <Security/cssmtype.h>
33#include <Security/SecPolicy.h>
34#include <Security/SecCertificate.h>
35#include <Security/SecTrustSettings.h>
36
37#ifdef __cplusplus
38extern "C" {
39#endif
40
41/*
42 * Fundamental routine used by TP to ascertain status of one cert.
43 *
44 * Returns true in *foundMatchingEntry if a trust setting matching
45 * specific constraints was found for the cert. Returns true in
46 * *foundAnyEntry if any entry was found for the cert, even if it
47 * did not match the specified constraints. The TP uses this to
48 * optimize for the case where a cert is being evaluated for
49 * one type of usage, and then later for another type. If
50 * foundAnyEntry is false, the second evaluation need not occur.
51 *
52 * Returns the domain in which a setting was found in *foundDomain.
53 *
54 * Allowed errors applying to the specified cert evaluation
55 * are returned in a mallocd array in *allowedErrors and must
56 * be freed by caller.
57 */
58OSStatus SecTrustSettingsEvaluateCert(
59	CFStringRef					certHashStr,
60	/* parameters describing the current cert evalaution */
61	const CSSM_OID				*policyOID,
62	const char					*policyString,		/* optional */
63	uint32						policyStringLen,
64	SecTrustSettingsKeyUsage	keyUsage,			/* optional */
65	bool						isRootCert,			/* for checking default setting */
66	/* RETURNED values */
67	SecTrustSettingsDomain		*foundDomain,
68	CSSM_RETURN					**allowedErrors,	/* mallocd and RETURNED */
69	uint32						*numAllowedErrors,	/* RETURNED */
70	SecTrustSettingsResult		*resultType,		/* RETURNED */
71	bool						*foundMatchingEntry,/* RETURNED */
72	bool						*foundAnyEntry);	/* RETURNED */
73
74/*
75 * Obtain trusted certs which match specified usage.
76 * Only certs with a SecTrustSettingsResult of
77 * kSecTrustSettingsResultTrustRoot or
78 * or kSecTrustSettingsResultTrustAsRoot will be returned.
79 *
80 * To be used by SecureTransport for its (hopefully soon-to-be-
81 * deprecated) SSLSetTrustedRoots() call; I hope nothing else has
82 * to use this...
83 *
84 * Caller must CFRelease the returned CFArrayRef.
85 */
86OSStatus SecTrustSettingsCopyQualifiedCerts(
87	const CSSM_OID				*policyOID,
88	const char					*policyString,		/* optional */
89	uint32						policyStringLen,
90	SecTrustSettingsKeyUsage	keyUsage,			/* optional */
91	CFArrayRef					*certArray);		/* RETURNED */
92
93/*
94 * Obtain unrestricted root certificates from the specified domain(s).
95 * Only returns root certificates with no usage constraints.
96 * Caller must CFRelease the returned CFArrayRef.
97 */
98OSStatus SecTrustSettingsCopyUnrestrictedRoots(
99	Boolean					userDomain,
100	Boolean					adminDomain,
101	Boolean					systemDomain,
102	CFArrayRef				*certArray);		/* RETURNED */
103
104/*
105 * Obtain a string representing a cert's SHA1 digest. This string is
106 * the key used to look up per-cert trust settings in a TrustSettings record.
107 */
108CFStringRef SecTrustSettingsCertHashStrFromCert(
109	SecCertificateRef certRef);
110
111CFStringRef SecTrustSettingsCertHashStrFromData(
112	const void *cert,
113	size_t certLen);
114
115/*
116 * Add a cert's TrustSettings to a non-persistent TrustSettings record.
117 * Primarily intended for use in creating a system TrustSettings record
118 * (which is itself immutable via this module).
119 *
120 * The settingsIn argument is an external representation of a TrustSettings
121 * record, obtained from this function or from
122 * SecTrustSettingsCreateExternalRepresentation().
123 * If settingsIn is NULL, a new (empty) TrustSettings will be created.
124 *
125 * The certRef and trustSettingsDictOrArray arguments are as in
126 * SecTrustSettingsSetTrustSettings(). May be NULL, when e.g. creating
127 * a new and empty TrustSettings record.
128 *
129 * The external representation is written to the settingOut argument,
130 * which must eventually be CFReleased by the caller.
131 */
132OSStatus SecTrustSettingsSetTrustSettingsExternal(
133	CFDataRef			settingsIn,					/* optional */
134	SecCertificateRef	certRef,					/* optional */
135	CFTypeRef			trustSettingsDictOrArray,	/* optional */
136	CFDataRef			*settingsOut);				/* RETURNED */
137
138#ifdef __cplusplus
139}
140#endif
141
142#endif	/* _SEC_TRUST_SETTINGS_PRIV_H_ */
143
144