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_asn1/keyTemplates.h> /* for kSecAsn1AlgorithmIDTemplate */
27 #include <security_asn1/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 }
63 const SecAsn1Template kSecAsn1SignedIntegerTemplate
[] = {
64 { SEC_ASN1_INTEGER
| SEC_ASN1_SIGNED_INT
, 0, NULL
, sizeof(SecAsn1Item
) }
67 const SecAsn1Template kSecAsn1UnsignedIntegerTemplate
[] = {
68 { SEC_ASN1_INTEGER
, 0, NULL
, sizeof(SecAsn1Item
) }
71 const SecAsn1Template kSecAsn1TSAAccuracyTemplate
[] = {
73 0, NULL
, sizeof(SecAsn1TSAAccuracy
) },
75 offsetof(SecAsn1TSAAccuracy
, seconds
) },
76 { SEC_ASN1_CONTEXT_SPECIFIC
| 0 | SEC_ASN1_OPTIONAL
,
77 offsetof(SecAsn1TSAAccuracy
, millis
), kSecAsn1UnsignedIntegerTemplate
},
78 { SEC_ASN1_CONTEXT_SPECIFIC
| 1 | SEC_ASN1_OPTIONAL
,
79 offsetof(SecAsn1TSAAccuracy
, micros
), kSecAsn1UnsignedIntegerTemplate
},
84 MessageImprint ::= SEQUENCE {
85 hashAlgorithm AlgorithmIdentifier,
86 hashedMessage OCTET STRING }
89 const SecAsn1Template kSecAsn1TSAMessageImprintTemplate
[] = {
91 0, NULL
, sizeof(SecAsn1TSAMessageImprint
) },
92 { SEC_ASN1_INLINE
, offsetof(SecAsn1TSAMessageImprint
,hashAlgorithm
),
93 kSecAsn1AlgorithmIDTemplate
},
94 { SEC_ASN1_OCTET_STRING
,
95 offsetof(SecAsn1TSAMessageImprint
,hashedMessage
) },
100 TimeStampReq ::= SEQUENCE {
101 version INTEGER { v1(1) },
102 messageImprint MessageImprint,
103 --a hash algorithm OID and the hash value of the data to be
105 reqPolicy TSAPolicyId OPTIONAL,
106 nonce INTEGER OPTIONAL,
107 certReq BOOLEAN DEFAULT FALSE,
108 extensions [0] IMPLICIT Extensions OPTIONAL }
110 MessageImprint ::= SEQUENCE {
111 hashAlgorithm AlgorithmIdentifier,
112 hashedMessage OCTET STRING }
114 TSAPolicyId ::= OBJECT IDENTIFIER
117 const SecAsn1Template kSecAsn1TSATimeStampReqTemplate
[] = {
119 0, NULL
, sizeof(SecAsn1TSATimeStampReq
) },
121 offsetof(SecAsn1TSATimeStampReq
, version
) },
122 { SEC_ASN1_INLINE
, offsetof(SecAsn1TSATimeStampReq
,messageImprint
),
123 kSecAsn1TSAMessageImprintTemplate
},
124 { SEC_ASN1_OBJECT_ID
| SEC_ASN1_OPTIONAL
,
125 offsetof(SecAsn1TSATimeStampReq
,reqPolicy
) },
126 { SEC_ASN1_INTEGER
| SEC_ASN1_OPTIONAL
,
127 offsetof(SecAsn1TSATimeStampReq
, nonce
) },
128 { SEC_ASN1_BOOLEAN
| SEC_ASN1_OPTIONAL
,
129 offsetof(SecAsn1TSATimeStampReq
, certReq
) },
130 { SEC_ASN1_OPTIONAL
| SEC_ASN1_CONSTRUCTED
| SEC_ASN1_CONTEXT_SPECIFIC
| 0,
131 offsetof(SecAsn1TSATimeStampReq
, extensions
),
132 kSecAsn1SequenceOfCertExtensionTemplate
},
137 PKIFreeText ::= SEQUENCE {
138 SIZE (1..MAX) OF UTF8String
139 -- text encoded as UTF-8 String (note: each UTF8String SHOULD
140 -- include an RFC 1766 language tag to indicate the language -- of the contained text)
143 See e.g. kSecAsn1SequenceOfUTF8StringTemplate
146 const SecAsn1Template kSecAsn1TSAPKIStatusInfoTemplate
[] = {
148 0, NULL
, sizeof(SecAsn1TSAPKIStatusInfo
) },
150 offsetof(SecAsn1TSAPKIStatusInfo
, status
) },
151 { SEC_ASN1_CONSTRUCTED
| SEC_ASN1_SEQUENCE
| SEC_ASN1_OPTIONAL
,
152 offsetof(SecAsn1TSAPKIStatusInfo
, statusString
) },
153 { SEC_ASN1_BIT_STRING
| SEC_ASN1_OPTIONAL
,
154 offsetof(SecAsn1TSAPKIStatusInfo
,failInfo
) },
158 const SecAsn1Template kSecAsn1TSAPKIStatusInfoTemplateRFC3161
[] = {
160 0, NULL
, sizeof(SecAsn1TSAPKIStatusInfo
) },
162 offsetof(SecAsn1TSAPKIStatusInfo
, status
) },
163 { SEC_ASN1_UTF8_STRING
| SEC_ASN1_OPTIONAL
,
164 offsetof(SecAsn1TSAPKIStatusInfo
, statusString
) },
165 { SEC_ASN1_BIT_STRING
| SEC_ASN1_OPTIONAL
,
166 offsetof(SecAsn1TSAPKIStatusInfo
,failInfo
) },
171 const SecAsn1Template kSecAsn1TSATimeStampRespTemplate
[] = {
173 0, NULL
, sizeof(SecAsn1TimeStampResp
) },
174 { SEC_ASN1_INLINE
, offsetof(SecAsn1TimeStampResp
,status
),
175 kSecAsn1TSAPKIStatusInfoTemplate
},
176 { SEC_ASN1_INLINE
| SEC_ASN1_OPTIONAL
, offsetof(SecAsn1TimeStampResp
,timeStampToken
),
177 SecCmsContentInfoTemplate
},
182 // Decode the status but not the TimeStampToken
183 const SecAsn1Template kSecAsn1TSATimeStampRespTemplateDER
[] = {
185 0, NULL
, sizeof(SecAsn1TimeStampRespDER
) },
186 { SEC_ASN1_INLINE
, offsetof(SecAsn1TimeStampRespDER
,status
),
187 kSecAsn1TSAPKIStatusInfoTemplate
},
188 { SEC_ASN1_ANY
| SEC_ASN1_OPTIONAL
,//| SEC_ASN1_SAVE,
189 offsetof(SecAsn1TimeStampRespDER
, timeStampTokenDER
), kSecAsn1AnyTemplate
},
194 RFC 3161 Time-Stamp Protocol (TSP) August 2001
196 TimeStampToken ::= ContentInfo
198 -- contentType is id-signedData as defined in [CMS]
199 -- content is SignedData as defined in([CMS])
200 -- eContentType within SignedData is id-ct-TSTInfo
201 -- eContent within SignedData is TSTInfo
203 TSTInfo ::= SEQUENCE {
204 version INTEGER { v1(1) },
206 messageImprint MessageImprint,
207 -- MUST have the same value as the similar field in
209 serialNumber INTEGER,
210 -- Time-Stamping users MUST be ready to accommodate integers
212 genTime GeneralizedTime,
213 accuracy Accuracy OPTIONAL,
214 ordering BOOLEAN DEFAULT FALSE,
215 nonce INTEGER OPTIONAL,
216 -- MUST be present if the similar field was present
217 -- in TimeStampReq. In that case it MUST have the same value.
218 tsa [0] GeneralName OPTIONAL,
219 extensions [1] IMPLICIT Extensions OPTIONAL }
221 Accuracy ::= SEQUENCE {
222 seconds INTEGER OPTIONAL,
223 millis [0] INTEGER (1..999) OPTIONAL,
224 micros [1] INTEGER (1..999) OPTIONAL }
227 const SecAsn1Template kSecAsn1TSATSTInfoTemplate
[] = {
229 0, NULL
, sizeof(SecAsn1TSATSTInfo
) },
231 offsetof(SecAsn1TSATSTInfo
, version
) },
232 { SEC_ASN1_OBJECT_ID
,
233 offsetof(SecAsn1TSATSTInfo
,reqPolicy
) },
234 { SEC_ASN1_INLINE
, offsetof(SecAsn1TSATSTInfo
,messageImprint
),
235 kSecAsn1TSAMessageImprintTemplate
},
237 offsetof(SecAsn1TSATSTInfo
, serialNumber
) },
238 { SEC_ASN1_GENERALIZED_TIME
| SEC_ASN1_MAY_STREAM
,
239 offsetof(SecAsn1TSATSTInfo
,genTime
) },
240 { SEC_ASN1_INLINE
| SEC_ASN1_OPTIONAL
,
241 offsetof(SecAsn1TSATSTInfo
,accuracy
),
242 kSecAsn1TSAAccuracyTemplate
},
243 { SEC_ASN1_BOOLEAN
| SEC_ASN1_OPTIONAL
,
244 offsetof(SecAsn1TSATSTInfo
, ordering
) },
245 { SEC_ASN1_INTEGER
| SEC_ASN1_OPTIONAL
,
246 offsetof(SecAsn1TSATSTInfo
, nonce
) },
247 { SEC_ASN1_CONSTRUCTED
| SEC_ASN1_CONTEXT_SPECIFIC
| 0 | SEC_ASN1_OPTIONAL
,
248 offsetof(SecAsn1TSATSTInfo
, tsa
),
249 kSecAsn1GenNameOtherNameTemplate
},
251 { SEC_ASN1_CONSTRUCTED
| SEC_ASN1_CONTEXT_SPECIFIC
| 1 | SEC_ASN1_OPTIONAL
,
252 offsetof(SecAsn1TSATSTInfo
, extensions
),
253 kSecAsn1CertExtensionTemplate
},
257 #pragma clang diagnostic pop