]> git.saurik.com Git - apple/security.git/blob - libsecurity_keychain/lib/Trust.h
Security-55163.44.tar.gz
[apple/security.git] / libsecurity_keychain / lib / Trust.h
1 /*
2 * Copyright (c) 2002-2004 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 // Trust.h - Trust control wrappers
26 //
27 #ifndef _SECURITY_TRUST_H_
28 #define _SECURITY_TRUST_H_
29
30 #include <CoreFoundation/CoreFoundation.h>
31 #include <security_keychain/StorageManager.h>
32 #include <security_cdsa_client/tpclient.h>
33 #include <security_utilities/cfutilities.h>
34 #include <Security/SecTrust.h>
35 #include <security_keychain/Certificate.h>
36 #include <security_keychain/Policies.h>
37 #include <security_keychain/TrustStore.h>
38 #include <vector>
39
40 using namespace CssmClient;
41
42 namespace Security {
43 namespace KeychainCore {
44
45
46 //
47 // The Trust object manages trust-verification workflow.
48 // As such, it represents a somewhat more complex concept than
49 // a single "object".
50 //
51 class Trust : public SecCFObject
52 {
53 NOCOPY(Trust)
54 public:
55 SECCFFUNCTIONS(Trust, SecTrustRef, errSecInvalidItemRef, gTypes().Trust)
56
57 Trust(CFTypeRef certificates, CFTypeRef policies);
58 virtual ~Trust();
59
60 enum AnchorPolicy {
61 useAnchorsDefault, // default policy: trust built-in unless passed-in
62 useAnchorsAndBuiltIns, // SetTrustAnchorCertificatesOnly value = false
63 useAnchorsOnly // SetTrustAnchorCertificatesOnly value = true
64 };
65
66 // set (or reset) more input parameters
67 void policies(CFTypeRef policies) { mPolicies.take(cfArrayize(policies)); }
68 void action(CSSM_TP_ACTION action) { mAction = action; }
69 void actionData(CFDataRef data) { mActionData = data; }
70 void time(CFDateRef verifyTime) { mVerifyTime = verifyTime; }
71 void anchors(CFArrayRef anchorList) { mAnchors.take(cfArrayize(anchorList)); }
72 void anchorPolicy(AnchorPolicy policy) { mAnchorPolicy = policy; }
73
74 StorageManager::KeychainList &searchLibs(bool init=true);
75 void searchLibs(StorageManager::KeychainList &libs);
76
77 // perform evaluation
78 void evaluate(bool disableEV=false);
79
80 // get at evaluation results
81 void buildEvidence(CFArrayRef &certChain, TPEvidenceInfo * &statusChain);
82 CSSM_TP_VERIFY_CONTEXT_RESULT_PTR cssmResult();
83 void extendedResult(CFDictionaryRef &extendedResult);
84 CFArrayRef properties();
85
86 SecTrustResultType result() const { return mResult; }
87 OSStatus cssmResultCode() const { return mTpReturn; }
88 TP getTPHandle() const { return mTP; }
89 CFArrayRef evidence() const { return mEvidenceReturned; }
90 CFArrayRef policies() const { return mPolicies; }
91 CFArrayRef anchors() const { return mAnchors; }
92 CFDateRef time() const { return mVerifyTime; }
93
94 // an independent release function for TP evidence results
95 // (yes, we could hand this out to the C layer if desired)
96 static void releaseTPEvidence(TPVerifyResult &result, Allocator &allocator);
97
98 private:
99 SecTrustResultType diagnoseOutcome();
100 void evaluateUserTrust(const CertGroup &certs,
101 const CSSM_TP_APPLE_EVIDENCE_INFO *info,
102 CFCopyRef<CFArrayRef> anchors);
103 void clearResults();
104
105 Keychain keychainByDLDb(const CSSM_DL_DB_HANDLE &handle);
106
107 /* revocation policy support */
108 CFMutableArrayRef addSpecifiedRevocationPolicies(uint32 &numAdded,
109 Allocator &alloc);
110 void freeSpecifiedRevocationPolicies(CFArrayRef policies,
111 uint32 numAdded,
112 Allocator &alloc);
113 CFMutableArrayRef addPreferenceRevocationPolicies(uint32 &numAdded,
114 Allocator &alloc);
115 void freePreferenceRevocationPolicies(CFArrayRef policies,
116 uint32 numAdded,
117 Allocator &alloc);
118 CFDictionaryRef defaultRevocationSettings();
119
120 bool policySpecified(CFArrayRef policies, const CSSM_OID &inOid);
121 bool revocationPolicySpecified(CFArrayRef policies);
122 void orderRevocationPolicies(CFMutableArrayRef policies);
123 CFMutableArrayRef forceRevocationPolicies(uint32 &numAdded,
124 Allocator &alloc,
125 bool requirePerCert=false);
126
127 private:
128 TP mTP; // our TP
129
130 // input arguments: set up before evaluate()
131 CSSM_TP_ACTION mAction; // TP action to verify
132 CFRef<CFDataRef> mActionData; // action data
133 CFRef<CFDateRef> mVerifyTime; // verification "now"
134 CFRef<CFArrayRef> mCerts; // certificates to verify (item 1 is subject)
135 CFRef<CFArrayRef> mPolicies; // array of policy objects to control verification
136 CFRef<CFArrayRef> mAnchors; // array of anchor certs
137 StorageManager::KeychainList *mSearchLibs; // array of databases to search
138 bool mSearchLibsSet; // true if mSearchLibs has been initialized
139
140 // evaluation results: set as a result of evaluate()
141 SecTrustResultType mResult; // result classification
142 uint32 mResultIndex; // which result cert made the decision?
143 OSStatus mTpReturn; // return code from TP Verify
144 TPVerifyResult mTpResult; // result of latest TP verify
145
146 vector< SecPointer<Certificate> > mCertChain; // distilled certificate chain
147
148 // information returned to caller but owned by us
149 CFRef<CFArrayRef> mEvidenceReturned; // evidence chain returned
150 CFRef<CFArrayRef> mAllowedAnchors; // array of permitted anchor certificates
151 CFRef<CFArrayRef> mFilteredCerts; // array of certificates to verify, post-filtering
152 CFRef<CFDictionaryRef> mExtendedResult; // dictionary of extended results
153
154 bool mUsingTrustSettings; // true if built-in anchors will be trusted
155 AnchorPolicy mAnchorPolicy; // policy for trusting passed-in and/or built-in anchors
156
157 public:
158 static ModuleNexus<TrustStore> gStore;
159
160 private:
161 Mutex mMutex;
162 };
163
164 } // end namespace KeychainCore
165
166 } // end namespace Security
167
168 #endif // !_SECURITY_TRUST_H_