2 * Copyright (c) 2003-2006,2008-2012 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@
23 * ocspTemplates.h - ASN1 templates OCSP requests and responses.
26 #ifndef _OCSP_TEMPLATES_H_
27 #define _OCSP_TEMPLATES_H_
29 #include <Security/X509Templates.h> /* NSS_CertExtension */
30 #include <Security/nameTemplates.h> /* NSS_GeneralName and support */
36 #pragma clang diagnostic push
37 #pragma clang diagnostic ignored "-Wdeprecated-declarations"
39 // MARK: ----- OCSP Request -----
42 * CertID ::= SEQUENCE {
43 * hashAlgorithm AlgorithmIdentifier,
44 * issuerNameHash OCTET STRING, -- Hash of Issuer's DN
45 * issuerKeyHash OCTET STRING, -- Hash of Issuers public key
46 * serialNumber CertificateSerialNumber } -- i.e., INTEGER
50 SecAsn1Item issuerNameHash
;
51 SecAsn1Item issuerPubKeyHash
;
52 SecAsn1Item serialNumber
;
55 extern const SecAsn1Template kSecAsn1OCSPCertIDTemplate
[];
58 * Request ::= SEQUENCE {
60 * singleRequestExtensions [0] EXPLICIT Extensions OPTIONAL }
63 SecAsn1OCSPCertID reqCert
;
64 NSS_CertExtension
**extensions
; // optional
67 extern const SecAsn1Template kSecAsn1OCSPRequestTemplate
[];
70 * Signature ::= SEQUENCE {
71 * signatureAlgorithm AlgorithmIdentifier,
72 * signature BIT STRING,
73 * certs [0] EXPLICIT SEQUENCE OF Certificate OPTIONAL}
75 * Since we wish to avoid knowing anything about the details of the certs,
76 * we declare them here as ASN_ANY, get/set as raw data, and leave it to
77 * the CL to parse them.
81 SecAsn1Item sig
; // length in BITS
82 SecAsn1Item
**certs
; // OPTIONAL
83 } SecAsn1OCSPSignature
;
85 extern const SecAsn1Template kSecAsn1OCSPSignatureTemplate
[];
88 * TBSRequest ::= SEQUENCE {
89 * version [0] EXPLICIT Version DEFAULT v1,
90 * requestorName [1] EXPLICIT GeneralName OPTIONAL,
91 * requestList SEQUENCE OF Request,
92 * requestExtensions [2] EXPLICIT Extensions OPTIONAL }
95 SecAsn1Item
*version
; // OPTIONAL
96 NSS_GeneralName
*requestorName
; // OPTIONAL
97 SecAsn1OCSPRequest
**requestList
;
98 NSS_CertExtension
**requestExtensions
; // OPTIONAL
99 } SecAsn1OCSPTbsRequest
;
101 extern const SecAsn1Template kSecAsn1OCSPTbsRequestTemplate
[];
104 * OCSPRequest ::= SEQUENCE {
105 * tbsRequest TBSRequest,
106 * optionalSignature [0] EXPLICIT Signature OPTIONAL }
109 SecAsn1OCSPTbsRequest tbsRequest
;
110 SecAsn1OCSPSignature
*signature
; // OPTIONAL
111 } SecAsn1OCSPSignedRequest
;
113 extern const SecAsn1Template kSecAsn1OCSPSignedRequestTemplate
[];
115 // MARK: ----- OCSP Response -----
118 * CertStatus ::= CHOICE {
119 * good [0] IMPLICIT NULL,
120 * revoked [1] IMPLICIT RevokedInfo,
121 * unknown [2] IMPLICIT UnknownInfo }
123 * RevokedInfo ::= SEQUENCE {
124 * revocationTime GeneralizedTime,
125 * revocationReason [0] EXPLICIT CRLReason OPTIONAL }
127 * UnknownInfo ::= NULL -- this can be replaced with an enumeration
129 * See <Security/certextensions.h> for enum values of CE_CrlReason.
132 SecAsn1Item revocationTime
;
133 SecAsn1Item
*revocationReason
; // OPTIONAL, CE_CrlReason
134 } SecAsn1OCSPRevokedInfo
;
137 SecAsn1OCSPRevokedInfo
*revokedInfo
;
138 SecAsn1Item
*nullData
;
139 } SecAsn1OCSPCertStatus
;
145 CS_NotParsed
= 0xff /* Not in protocol: means value not parsed or seen */
146 } SecAsn1OCSPCertStatusTag
;
148 extern const SecAsn1Template kSecAsn1OCSPRevokedInfoTemplate
[];
151 * Encode/decode CertStatus separately using one of these hree templates.
152 * The result goes into SecAsn1OCSPSingleResponse.certStatus on encode.
154 extern const SecAsn1Template kSecAsn1OCSPCertStatusGoodTemplate
[];
155 extern const SecAsn1Template kSecAsn1OCSPCertStatusRevokedTemplate
[];
156 extern const SecAsn1Template kSecAsn1OCSPCertStatusUnknownTemplate
[];
159 * SingleResponse ::= SEQUENCE {
161 * certStatus CertStatus,
162 * thisUpdate GeneralizedTime,
163 * nextUpdate [0] EXPLICIT GeneralizedTime OPTIONAL,
164 * singleExtensions [1] EXPLICIT Extensions OPTIONAL }
167 SecAsn1OCSPCertID certID
;
168 SecAsn1Item certStatus
; // ASN_ANY here
169 SecAsn1Item thisUpdate
; // GeneralizedTime
170 SecAsn1Item
*nextUpdate
; // GeneralizedTime, OPTIONAL
171 NSS_CertExtension
**singleExtensions
; // OPTIONAL
172 } SecAsn1OCSPSingleResponse
;
174 extern const SecAsn1Template kSecAsn1OCSPSingleResponseTemplate
[];
177 * ResponderID ::= CHOICE {
178 * byName EXPLICIT [1] Name,
179 * byKey EXPLICIT [2] KeyHash }
181 * Since our ASN.1 encoder/decoder can't handle CHOICEs very well, we encode
182 * this separately using one of the following two templates. On encode the
183 * result if this step of the encode goes into SecAsn1OCSPResponseData.responderID,
184 * where it's treated as an ANY_ANY when encoding that struct. The reverse happens
189 SecAsn1Item byKey
; // key hash in OCTET STRING
190 } SecAsn1OCSPResponderID
;
195 } SecAsn1OCSPResponderIDTag
;
197 extern const SecAsn1Template kSecAsn1OCSPResponderIDAsNameTemplate
[];
198 extern const SecAsn1Template kSecAsn1OCSPResponderIDAsKeyTemplate
[];
201 * ResponseData ::= SEQUENCE {
202 * version [0] EXPLICIT Version DEFAULT v1,
203 * responderID ResponderID,
204 * producedAt GeneralizedTime,
205 * responses SEQUENCE OF SingleResponse,
206 * responseExtensions [1] EXPLICIT Extensions OPTIONAL }
209 SecAsn1Item
*version
; // OPTIONAL
210 SecAsn1Item responderID
; // ASN_ANY here, decode/encode separately
211 SecAsn1Item producedAt
; // GeneralizedTime
212 SecAsn1OCSPSingleResponse
**responses
;
213 NSS_CertExtension
**responseExtensions
; // OPTIONAL
214 } SecAsn1OCSPResponseData
;
216 extern const SecAsn1Template kSecAsn1OCSPResponseDataTemplate
[];
219 * BasicOCSPResponse ::= SEQUENCE {
220 * tbsResponseData ResponseData,
221 * signatureAlgorithm AlgorithmIdentifier,
222 * signature BIT STRING,
223 * certs [0] EXPLICIT SEQUENCE OF Certificate OPTIONAL }
225 * Since we ALWAYS encode the tbsResponseData in preparation for signing,
226 * we declare it as a raw ASN_ANY in the BasicOCSPResponse.
228 * Certs are likewise ASN_ANY since we use the CL to parse and create them.
231 SecAsn1Item tbsResponseData
;
233 SecAsn1Item sig
; // length in BITS
234 SecAsn1Item
**certs
; // optional
235 } SecAsn1OCSPBasicResponse
;
237 extern const SecAsn1Template kSecAsn1OCSPBasicResponseTemplate
[];
240 * ResponseBytes ::= SEQUENCE {
241 * responseType OBJECT IDENTIFIER,
242 * response OCTET STRING }
244 * The contents of response are actually an encoded SecAsn1OCSPBasicResponse (at
245 * least until another response type is defined).
248 SecAsn1Oid responseType
;
249 SecAsn1Item response
;
250 } SecAsn1OCSPResponseBytes
;
252 extern const SecAsn1Template kSecAsn1OCSPResponseBytesTemplate
[];
255 * OCSPResponse ::= SEQUENCE {
256 * responseStatus OCSPResponseStatus, -- an ENUM
257 * responseBytes [0] EXPLICIT ResponseBytes OPTIONAL }
260 SecAsn1Item responseStatus
; // see enum below
261 SecAsn1OCSPResponseBytes
*responseBytes
; // optional
262 } SecAsn1OCSPResponse
;
264 extern const SecAsn1Template kSecAsn1OCSPResponseTemplate
[];
268 RS_MalformedRequest
= 1,
269 RS_InternalError
= 2,
274 } SecAsn1OCSPResponseStatus
;
277 * This is not part of the OCSP protocol; it's used in the communication between
278 * the Apple X.509 TP module and the ocspd server.
280 * OCSPDRequest ::= SEQUENCE {
281 * cacheWriteDisable :: = EXPLICIT [0] BOOL OPTIONAL; -- cache write disable
283 * cacheWriteDisable :: = EXPLICIT [1] BOOL OPTIONAL; -- cache read disable
285 * certID ::= OCTET STRING; -- for cache lookup
286 * ocspReq ::= EXPLICIT [2] OCTET STRING OPTIONAL; -- for net fetch
287 * localResp ::= EXPLICIT [3] IA5String OPTIONAL; -- for local responder
288 * urls ::= EXPLICIT [4] SEQUENCE of IA5String OPTIONAL;
289 * -- for normal net fetch
293 #define OCSPD_REQUEST_VERS 0
296 SecAsn1Item
*cacheWriteDisable
;
297 SecAsn1Item
*cacheReadDisable
;
298 SecAsn1Item certID
; // DER encoded SecAsn1OCSPCertID
299 SecAsn1Item
*ocspReq
; // DER encoded SecAsn1OCSPSignedRequest
300 SecAsn1Item
*localRespURI
; // local responder URI
301 SecAsn1Item
**urls
; // normal URIs
303 } SecAsn1OCSPDRequest
;
306 * And this is a sequence of them, packaged up and sent to ocspd in one RPC.
309 SecAsn1Item version
; // OCSPD_REQUEST_VERS
310 SecAsn1OCSPDRequest
**requests
;
311 } SecAsn1OCSPDRequests
;
313 extern const SecAsn1Template kSecAsn1OCSPDRequestTemplate
[];
314 extern const SecAsn1Template kSecAsn1OCSPDRequestsTemplate
[];
317 * Unordered set of replies from ocsdp; they map back to individual
318 * SecAsn1OCSPDRequests by the encoded certID (which is obtained from the
319 * SecAsn1OCSPDRequest, NOT from the OCSP response).
322 SecAsn1Item certID
; // DER encoded SecAsn1OCSPCertID
323 SecAsn1Item ocspResp
; // DER encoded SecAsn1OCSPResponse
326 #define OCSPD_REPLY_VERS 0
329 SecAsn1Item version
; // OCSPD_REPLY_VERS
330 SecAsn1OCSPDReply
**replies
;
331 } SecAsn1OCSPReplies
;
333 extern const SecAsn1Template kSecAsn1OCSPDReplyTemplate
[];
334 extern const SecAsn1Template kSecAsn1OCSPDRepliesTemplate
[];
336 #pragma clang diagnostic pop
342 #endif /* _OCSP_TEMPLATES_H_ */