]>
Commit | Line | Data |
---|---|---|
b1ab9ed8 | 1 | /* |
d8f41ccd | 2 | * Copyright (c) 2004,2011,2014 Apple Inc. All Rights Reserved. |
949d2ff0 | 3 | * |
b1ab9ed8 | 4 | * @APPLE_LICENSE_HEADER_START@ |
949d2ff0 | 5 | * |
b1ab9ed8 A |
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. | |
949d2ff0 | 12 | * |
b1ab9ed8 A |
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. | |
949d2ff0 | 20 | * |
b1ab9ed8 A |
21 | * @APPLE_LICENSE_HEADER_END@ |
22 | */ | |
23 | ||
24 | /* | |
25 | * ocspResponse.h - OCSP Response class | |
26 | */ | |
949d2ff0 | 27 | |
b1ab9ed8 A |
28 | #ifndef _OCSP_RESPONSE_H_ |
29 | #define _OCSP_RESPONSE_H_ | |
30 | ||
31 | #include <security_ocspd/ocspExtensions.h> | |
32 | #include <Security/ocspTemplates.h> | |
33 | #include <Security/certextensions.h> | |
34 | #include <Security/SecAsn1Coder.h> | |
35 | #include <CoreFoundation/CoreFoundation.h> | |
36 | ||
37 | /* used to indicate "I don't know the CRLReason" */ | |
38 | #define CrlReason_NONE ((CE_CrlReason)-1) | |
39 | ||
40 | /* | |
949d2ff0 A |
41 | * CertIDs can be represented differently by two peers even though they refer to |
42 | * the same cert. Client can use SHA1 hash and server can use MD5, for example. | |
b1ab9ed8 | 43 | * So all of our code which creates a CertID based on known, existing subject and |
949d2ff0 | 44 | * issuer certs uses one of these "smart" certIDs which can encode itself and also |
b1ab9ed8 A |
45 | * compare against any form of existing SecAsn1OCSPCertID. |
46 | */ | |
47 | class OCSPClientCertID | |
48 | { | |
49 | NOCOPY(OCSPClientCertID); | |
50 | public: | |
51 | /* | |
52 | * Basic constructor given issuer's public key and name, and subject's | |
53 | * serial number. | |
54 | */ | |
55 | OCSPClientCertID( | |
56 | const CSSM_DATA &issuerName, | |
57 | const CSSM_DATA &issuerPubKey, | |
58 | const CSSM_DATA &subjectSerial); | |
949d2ff0 | 59 | |
b1ab9ed8 | 60 | ~OCSPClientCertID(); |
949d2ff0 | 61 | |
b1ab9ed8 A |
62 | /* |
63 | * DER encode. | |
64 | */ | |
65 | const CSSM_DATA *encode(); | |
949d2ff0 | 66 | |
b1ab9ed8 A |
67 | /* |
68 | * Does this object refer to the same cert as specified SecAsn1OCSPCertID? | |
949d2ff0 | 69 | * This is the main purpose of this class's existence; this function works |
b1ab9ed8 | 70 | * even if specified SecAsn1OCSPCertID uses a different hash algorithm |
949d2ff0 | 71 | * than we do, since we keep copies of our basic components. |
b1ab9ed8 A |
72 | * |
73 | * Returns true if compare successful. | |
74 | */ | |
75 | bool compareToExist( | |
76 | const SecAsn1OCSPCertID &exist); | |
949d2ff0 A |
77 | |
78 | /* | |
b1ab9ed8 A |
79 | * Convenience function, like compareToExist, with a raw encoded CertID. |
80 | */ | |
949d2ff0 | 81 | bool compareToExist( |
b1ab9ed8 | 82 | const CSSM_DATA &exist); |
949d2ff0 | 83 | |
b1ab9ed8 A |
84 | private: |
85 | CSSM_DATA mIssuerName; | |
86 | CSSM_DATA mIssuerPubKey; | |
87 | CSSM_DATA mSubjectSerial; | |
88 | CSSM_DATA mEncoded; | |
89 | }; | |
90 | ||
91 | /* | |
949d2ff0 | 92 | * Object representing one SecAsn1OCSPSingleResponse, i.e., the portion of |
b1ab9ed8 A |
93 | * an OCSP response associated with a single CertID. These are created and |
94 | * vended solely by an OCSPResponse object. The client which gets them from | |
95 | * an OCSPResponse (via singleResponse()) must delete the object when finished | |
949d2ff0 | 96 | * with it. |
b1ab9ed8 A |
97 | */ |
98 | class OCSPSingleResponse | |
99 | { | |
100 | NOCOPY(OCSPSingleResponse); | |
101 | public: | |
102 | /* only OCSPResponse creates these */ | |
103 | ~OCSPSingleResponse(); | |
104 | friend class OCSPResponse; | |
105 | protected: | |
949d2ff0 | 106 | |
b1ab9ed8 A |
107 | OCSPSingleResponse( |
108 | SecAsn1OCSPSingleResponse *resp); | |
109 | public: | |
110 | SecAsn1OCSPCertStatusTag certStatus() { return mCertStatus; } | |
111 | CFAbsoluteTime thisUpdate() { return mThisUpdate; } | |
112 | CFAbsoluteTime nextUpdate() { return mNextUpdate; } | |
113 | CFAbsoluteTime revokedTime() { return mRevokedTime; } | |
114 | CE_CrlReason crlReason() { return mCrlReason; } | |
949d2ff0 | 115 | |
b1ab9ed8 | 116 | /* Extension accessors - all are optional */ |
949d2ff0 | 117 | |
b1ab9ed8 A |
118 | /* CRL Reference */ |
119 | const CSSM_DATA *crlUrl(); | |
120 | const CSSM_DATA *crlNum(); | |
121 | CFAbsoluteTime crlTime(); /* may be NULL_TIME */ | |
949d2ff0 | 122 | |
b1ab9ed8 A |
123 | /* archive cutoff */ |
124 | CFAbsoluteTime archiveCutoff(); | |
949d2ff0 | 125 | |
b1ab9ed8 A |
126 | /* service locator not implemented yet */ |
127 | private: | |
128 | SecAsn1CoderRef mCoder; | |
129 | SecAsn1OCSPCertStatusTag mCertStatus; | |
130 | CFAbsoluteTime mThisUpdate; | |
131 | CFAbsoluteTime mNextUpdate; /* may be NULL_TIME */ | |
132 | CFAbsoluteTime mRevokedTime; /* != NULL_TIME for CS_Revoked */ | |
949d2ff0 | 133 | CE_CrlReason mCrlReason; |
b1ab9ed8 A |
134 | OCSPExtensions *mExtensions; |
135 | }; | |
136 | ||
137 | /* | |
949d2ff0 | 138 | * OCSPResponse maintains its own temporal validity status based on the values of |
b1ab9ed8 A |
139 | * all of the enclosed SingleResponses' thisUpdate and (optional) nextUpdate |
140 | * fields, in addition to a default time-to-live (TTL) value passed to | |
141 | * OCSPResponse's constructor. | |
142 | * | |
949d2ff0 | 143 | * First, all of the thisUpdate fields are checked during OCSPResponse's constructor. |
b1ab9ed8 | 144 | * if any of these are later than the current time, the entire response is considered |
949d2ff0 A |
145 | * invalid and the constructor throws a CssmError(CSSMERR_APPLETP_OCSP_BAD_RESPONSE). |
146 | * Subsequent to construction, all thisUpdate fields are ignored. | |
b1ab9ed8 | 147 | * |
949d2ff0 | 148 | * The NextUpdate times are handled as follows. |
b1ab9ed8 | 149 | * |
949d2ff0 A |
150 | * 1. An OCSPResponse's latestNextUpdate is defined as the latest of all of the |
151 | * nextUpdate fields in its SingleResponses. This is evaluated during construction. | |
b1ab9ed8 | 152 | * |
949d2ff0 A |
153 | * 2. An OCSPResponse's latestNextUpdate is NULL_TIME if none of its SingleResponses |
154 | * contain any nextUpdate (this field is in fact optional). | |
b1ab9ed8 | 155 | * |
949d2ff0 A |
156 | * 3. The caller of OCSPResponse's constructor passes in a default time-to-live |
157 | * (TTL) in seconds; call this defaultTTL. Call the time at which the | |
b1ab9ed8 | 158 | * constructor is called, PLUS defaultTTL, "defaultExpire". |
949d2ff0 | 159 | * |
b1ab9ed8 A |
160 | * -- If the OCSPResponse's latestNextUpdate is NULL_TIME then expireTime() returns |
161 | * defaultExpire. | |
162 | * | |
949d2ff0 | 163 | * -- Otherwise, expireTime() returns the lesser of (latestNextUpdate, |
b1ab9ed8 A |
164 | * defaultExpire). |
165 | * | |
166 | * Note that this mechanism is used by both the TP's in-core cache and ocspd's | |
167 | * on-disk cache; the two have different default TTLs values but the mechanism | |
949d2ff0 | 168 | * for calcuating expireTime() is identical. |
b1ab9ed8 A |
169 | */ |
170 | class OCSPResponse | |
171 | { | |
172 | NOCOPY(OCSPResponse) | |
173 | public: | |
174 | /* only constructor, from DER encoded data */ | |
175 | OCSPResponse( | |
176 | const CSSM_DATA &resp, | |
177 | CFTimeInterval defaultTTL); // default time-to-live in seconds | |
949d2ff0 | 178 | |
b1ab9ed8 | 179 | ~OCSPResponse(); |
949d2ff0 A |
180 | |
181 | /* | |
182 | * Info obtained during decode (which is don\ 1e immediately during constructor) | |
b1ab9ed8 A |
183 | */ |
184 | SecAsn1OCSPResponseStatus responseStatus(); | |
185 | const CSSM_DATA *nonce(); /* NULL means not present */ | |
186 | CFAbsoluteTime producedAt(); /* should always work */ | |
187 | CSSM_RETURN sigStatus(); | |
188 | uint32 numSignerCerts(); | |
189 | const CSSM_DATA *signerCert(uint32 dex); | |
949d2ff0 A |
190 | |
191 | /* | |
192 | * Obtain a OCSPSingleResponse for a given CertID. | |
b1ab9ed8 A |
193 | */ |
194 | OCSPSingleResponse *singleResponseFor(OCSPClientCertID &certID); | |
195 | OCSPSingleResponse *singleResponseFor(const CSSM_DATA &matchCertID); | |
949d2ff0 | 196 | |
b1ab9ed8 A |
197 | CFAbsoluteTime expireTime() { return mExpireTime; } |
198 | ||
199 | /* | |
200 | * Access to decoded data. | |
201 | */ | |
202 | const SecAsn1OCSPResponseData &responseData() { return mResponseData; } | |
203 | const SecAsn1OCSPBasicResponse &basicResponse() { return mBasicResponse; } | |
204 | const SecAsn1OCSPResponderID &responderID() { return mResponderId; } | |
205 | SecAsn1OCSPResponderIDTag responderIDTag() { return mResponderIdTag; } | |
206 | ||
207 | const CSSM_DATA *encResponderName(); | |
949d2ff0 | 208 | |
b1ab9ed8 A |
209 | private: |
210 | bool calculateValidity(CFTimeInterval defaultTTL); | |
949d2ff0 | 211 | |
b1ab9ed8 A |
212 | SecAsn1CoderRef mCoder; |
213 | CFAbsoluteTime mLatestNextUpdate; | |
214 | CFAbsoluteTime mExpireTime; | |
949d2ff0 | 215 | CSSM_DATA mEncResponderName; // encoded ResponderId.byName, |
b1ab9ed8 A |
216 | // if responder is in that format, |
217 | // lazily evaluated | |
949d2ff0 A |
218 | /* |
219 | * Fields we decode - all in mCoder's memory space | |
b1ab9ed8 A |
220 | */ |
221 | SecAsn1OCSPResponse mTopResp; | |
222 | SecAsn1OCSPBasicResponse mBasicResponse; | |
223 | SecAsn1OCSPResponseData mResponseData; | |
224 | SecAsn1OCSPResponderID mResponderId; // we have to decode | |
225 | SecAsn1OCSPResponderIDTag mResponderIdTag; // IDs previous field | |
226 | OCSPExtensions *mExtensions; | |
949d2ff0 | 227 | }; |
b1ab9ed8 A |
228 | #endif /* _OCSP_RESPONSE_H_ */ |
229 |