2 * Copyright (c) 2012-2014 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 * tsaTemplates.c - ASN1 templates Time Stamping Authority requests and responses
26 #include <Security/keyTemplates.h> /* for kSecAsn1AlgorithmIDTemplate */
27 #include <Security/SecAsn1Templates.h>
31 #include "tsaTemplates.h"
34 #pragma clang diagnostic push
35 #pragma clang diagnostic ignored "-Wunused-const-variable"
37 // *** from CMSEncoder.cpp
44 // SecCmsContentInfoTemplate
45 static const SecAsn1Template cmsSimpleContentInfoTemplate
[] = {
46 { SEC_ASN1_SEQUENCE
, 0, NULL
, sizeof(SimpleContentInfo
) },
47 { SEC_ASN1_OBJECT_ID
, offsetof(SimpleContentInfo
, contentType
) },
48 { SEC_ASN1_EXPLICIT
| SEC_ASN1_CONSTRUCTED
| SEC_ASN1_CONTEXT_SPECIFIC
| 0,
49 offsetof(SimpleContentInfo
, content
),
50 kSecAsn1AnyTemplate
},
54 #pragma mark ----- tsa -----
57 Accuracy ::= SEQUENCE {
58 seconds INTEGER OPTIONAL,
59 millis [0] INTEGER (1..999) OPTIONAL,
60 micros [1] INTEGER (1..999) OPTIONAL }
62 const SecAsn1Template kSecAsn1TSAAccuracyTemplate
[] = {
64 0, NULL
, sizeof(SecAsn1TSAAccuracy
) },
66 offsetof(SecAsn1TSAAccuracy
, seconds
) },
67 { SEC_ASN1_CONTEXT_SPECIFIC
| 0 | SEC_ASN1_OPTIONAL
,
68 offsetof(SecAsn1TSAAccuracy
, millis
), kSecAsn1UnsignedIntegerTemplate
},
69 { SEC_ASN1_CONTEXT_SPECIFIC
| 1 | SEC_ASN1_OPTIONAL
,
70 offsetof(SecAsn1TSAAccuracy
, micros
), kSecAsn1UnsignedIntegerTemplate
},
75 MessageImprint ::= SEQUENCE {
76 hashAlgorithm AlgorithmIdentifier,
77 hashedMessage OCTET STRING }
80 const SecAsn1Template kSecAsn1TSAMessageImprintTemplate
[] = {
82 0, NULL
, sizeof(SecAsn1TSAMessageImprint
) },
83 { SEC_ASN1_INLINE
, offsetof(SecAsn1TSAMessageImprint
,hashAlgorithm
),
84 kSecAsn1AlgorithmIDTemplate
},
85 { SEC_ASN1_OCTET_STRING
,
86 offsetof(SecAsn1TSAMessageImprint
,hashedMessage
) },
91 TimeStampReq ::= SEQUENCE {
92 version INTEGER { v1(1) },
93 messageImprint MessageImprint,
94 --a hash algorithm OID and the hash value of the data to be
96 reqPolicy TSAPolicyId OPTIONAL,
97 nonce INTEGER OPTIONAL,
98 certReq BOOLEAN DEFAULT FALSE,
99 extensions [0] IMPLICIT Extensions OPTIONAL }
101 MessageImprint ::= SEQUENCE {
102 hashAlgorithm AlgorithmIdentifier,
103 hashedMessage OCTET STRING }
105 TSAPolicyId ::= OBJECT IDENTIFIER
108 const SecAsn1Template kSecAsn1TSATimeStampReqTemplate
[] = {
110 0, NULL
, sizeof(SecAsn1TSATimeStampReq
) },
112 offsetof(SecAsn1TSATimeStampReq
, version
) },
113 { SEC_ASN1_INLINE
, offsetof(SecAsn1TSATimeStampReq
,messageImprint
),
114 kSecAsn1TSAMessageImprintTemplate
},
115 { SEC_ASN1_OBJECT_ID
| SEC_ASN1_OPTIONAL
,
116 offsetof(SecAsn1TSATimeStampReq
,reqPolicy
) },
117 { SEC_ASN1_INTEGER
| SEC_ASN1_OPTIONAL
,
118 offsetof(SecAsn1TSATimeStampReq
, nonce
) },
119 { SEC_ASN1_BOOLEAN
| SEC_ASN1_OPTIONAL
,
120 offsetof(SecAsn1TSATimeStampReq
, certReq
) },
121 { SEC_ASN1_OPTIONAL
| SEC_ASN1_CONSTRUCTED
| SEC_ASN1_CONTEXT_SPECIFIC
| 0,
122 offsetof(SecAsn1TSATimeStampReq
, extensions
),
123 kSecAsn1SequenceOfCertExtensionTemplate
},
128 PKIFreeText ::= SEQUENCE {
129 SIZE (1..MAX) OF UTF8String
130 -- text encoded as UTF-8 String (note: each UTF8String SHOULD
131 -- include an RFC 1766 language tag to indicate the language -- of the contained text)
134 See e.g. kSecAsn1SequenceOfUTF8StringTemplate
137 const SecAsn1Template kSecAsn1TSAPKIStatusInfoTemplate
[] = {
139 0, NULL
, sizeof(SecAsn1TSAPKIStatusInfo
) },
141 offsetof(SecAsn1TSAPKIStatusInfo
, status
) },
142 { SEC_ASN1_CONSTRUCTED
| SEC_ASN1_SEQUENCE
| SEC_ASN1_OPTIONAL
,
143 offsetof(SecAsn1TSAPKIStatusInfo
, statusString
) },
144 { SEC_ASN1_BIT_STRING
| SEC_ASN1_OPTIONAL
,
145 offsetof(SecAsn1TSAPKIStatusInfo
,failInfo
) },
149 const SecAsn1Template kSecAsn1TSAPKIStatusInfoTemplateRFC3161
[] = {
151 0, NULL
, sizeof(SecAsn1TSAPKIStatusInfo
) },
153 offsetof(SecAsn1TSAPKIStatusInfo
, status
) },
154 { SEC_ASN1_UTF8_STRING
| SEC_ASN1_OPTIONAL
,
155 offsetof(SecAsn1TSAPKIStatusInfo
, statusString
) },
156 { SEC_ASN1_BIT_STRING
| SEC_ASN1_OPTIONAL
,
157 offsetof(SecAsn1TSAPKIStatusInfo
,failInfo
) },
162 const SecAsn1Template kSecAsn1TSATimeStampRespTemplate
[] = {
164 0, NULL
, sizeof(SecAsn1TimeStampResp
) },
165 { SEC_ASN1_INLINE
, offsetof(SecAsn1TimeStampResp
,status
),
166 kSecAsn1TSAPKIStatusInfoTemplate
},
167 { SEC_ASN1_INLINE
| SEC_ASN1_OPTIONAL
, offsetof(SecAsn1TimeStampResp
,timeStampToken
),
168 SecCmsContentInfoTemplate
},
173 // Decode the status but not the TimeStampToken
174 const SecAsn1Template kSecAsn1TSATimeStampRespTemplateDER
[] = {
176 0, NULL
, sizeof(SecAsn1TimeStampRespDER
) },
177 { SEC_ASN1_INLINE
, offsetof(SecAsn1TimeStampRespDER
,status
),
178 kSecAsn1TSAPKIStatusInfoTemplate
},
179 { SEC_ASN1_ANY
| SEC_ASN1_OPTIONAL
,//| SEC_ASN1_SAVE,
180 offsetof(SecAsn1TimeStampRespDER
, timeStampTokenDER
), kSecAsn1AnyTemplate
},
185 RFC 3161 Time-Stamp Protocol (TSP) August 2001
187 TimeStampToken ::= ContentInfo
189 -- contentType is id-signedData as defined in [CMS]
190 -- content is SignedData as defined in([CMS])
191 -- eContentType within SignedData is id-ct-TSTInfo
192 -- eContent within SignedData is TSTInfo
194 TSTInfo ::= SEQUENCE {
195 version INTEGER { v1(1) },
197 messageImprint MessageImprint,
198 -- MUST have the same value as the similar field in
200 serialNumber INTEGER,
201 -- Time-Stamping users MUST be ready to accommodate integers
203 genTime GeneralizedTime,
204 accuracy Accuracy OPTIONAL,
205 ordering BOOLEAN DEFAULT FALSE,
206 nonce INTEGER OPTIONAL,
207 -- MUST be present if the similar field was present
208 -- in TimeStampReq. In that case it MUST have the same value.
209 tsa [0] GeneralName OPTIONAL,
210 extensions [1] IMPLICIT Extensions OPTIONAL }
212 Accuracy ::= SEQUENCE {
213 seconds INTEGER OPTIONAL,
214 millis [0] INTEGER (1..999) OPTIONAL,
215 micros [1] INTEGER (1..999) OPTIONAL }
218 const SecAsn1Template kSecAsn1TSATSTInfoTemplate
[] = {
220 0, NULL
, sizeof(SecAsn1TSATSTInfo
) },
222 offsetof(SecAsn1TSATSTInfo
, version
) },
223 { SEC_ASN1_OBJECT_ID
,
224 offsetof(SecAsn1TSATSTInfo
,reqPolicy
) },
225 { SEC_ASN1_INLINE
, offsetof(SecAsn1TSATSTInfo
,messageImprint
),
226 kSecAsn1TSAMessageImprintTemplate
},
228 offsetof(SecAsn1TSATSTInfo
, serialNumber
) },
229 { SEC_ASN1_GENERALIZED_TIME
| SEC_ASN1_MAY_STREAM
,
230 offsetof(SecAsn1TSATSTInfo
,genTime
) },
231 { SEC_ASN1_INLINE
| SEC_ASN1_OPTIONAL
,
232 offsetof(SecAsn1TSATSTInfo
,accuracy
),
233 kSecAsn1TSAAccuracyTemplate
},
234 { SEC_ASN1_BOOLEAN
| SEC_ASN1_OPTIONAL
,
235 offsetof(SecAsn1TSATSTInfo
, ordering
) },
236 { SEC_ASN1_INTEGER
| SEC_ASN1_OPTIONAL
,
237 offsetof(SecAsn1TSATSTInfo
, nonce
) },
238 { SEC_ASN1_CONSTRUCTED
| SEC_ASN1_CONTEXT_SPECIFIC
| 0 | SEC_ASN1_OPTIONAL
,
239 offsetof(SecAsn1TSATSTInfo
, tsa
),
240 kSecAsn1GenNameOtherNameTemplate
},
242 { SEC_ASN1_CONSTRUCTED
| SEC_ASN1_CONTEXT_SPECIFIC
| 1 | SEC_ASN1_OPTIONAL
,
243 offsetof(SecAsn1TSATSTInfo
, extensions
),
244 kSecAsn1CertExtensionTemplate
},
248 #pragma clang diagnostic pop