1 /* -*- Mode: C; tab-width: 8 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
15 * The Original Code is the Netscape security libraries.
17 * The Initial Developer of the Original Code is
18 * Netscape Communications Corporation.
19 * Portions created by the Initial Developer are Copyright (C) 1994-2000
20 * the Initial Developer. All Rights Reserved.
24 * Alternatively, the contents of this file may be used under the terms of
25 * either the GNU General Public License Version 2 or later (the "GPL"), or
26 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 * in which case the provisions of the GPL or the LGPL are applicable instead
28 * of those above. If you wish to allow use of your version of this file only
29 * under the terms of either the GPL or the LGPL, and not to allow others to
30 * use your version of this file under the terms of the MPL, indicate your
31 * decision by deleting the provisions above and replace them with the notice
32 * and other provisions required by the GPL or the LGPL. If you do not delete
33 * the provisions above, a recipient may use your version of this file under
34 * the terms of any one of the MPL, the GPL or the LGPL.
36 * ***** END LICENSE BLOCK ***** */
43 SEC_ASN1_MKSUB(SECOID_AlgorithmIDTemplate)
44 SEC_ASN1_MKSUB(SEC_AnyTemplate)
45 SEC_ASN1_MKSUB(SEC_NullTemplate)
46 SEC_ASN1_MKSUB(SEC_BitStringTemplate)
47 SEC_ASN1_MKSUB(SEC_IntegerTemplate)
48 SEC_ASN1_MKSUB(SEC_OctetStringTemplate)
49 SEC_ASN1_MKSUB(CERT_TimeChoiceTemplate)
50 SEC_ASN1_MKSUB(CERT_SubjectPublicKeyInfoTemplate)
51 SEC_ASN1_MKSUB(CERT_NameTemplate)
54 * It's all implicit tagging.
57 const SEC_ASN1Template CRMFControlTemplate[] = {
58 { SEC_ASN1_SEQUENCE, 0, NULL, sizeof(CRMFControl)},
59 { SEC_ASN1_OBJECT_ID, offsetof(CRMFControl, derTag)},
60 { SEC_ASN1_ANY, offsetof(CRMFControl, derValue) },
64 static const SEC_ASN1Template CRMFCertExtensionTemplate[] = {
66 0, NULL, sizeof(CRMFCertExtension) },
68 offsetof(CRMFCertExtension,id) },
69 { SEC_ASN1_OPTIONAL | SEC_ASN1_BOOLEAN,
70 offsetof(CRMFCertExtension,critical) },
71 { SEC_ASN1_OCTET_STRING,
72 offsetof(CRMFCertExtension,value) },
76 static const SEC_ASN1Template CRMFSequenceOfCertExtensionTemplate[] = {
77 { SEC_ASN1_SEQUENCE_OF, 0, CRMFCertExtensionTemplate }
80 static const SEC_ASN1Template CRMFOptionalValidityTemplate[] = {
81 { SEC_ASN1_SEQUENCE, 0, NULL, sizeof (CRMFOptionalValidity) },
82 { SEC_ASN1_EXPLICIT | SEC_ASN1_CONSTRUCTED | SEC_ASN1_NO_STREAM |
83 SEC_ASN1_CONTEXT_SPECIFIC | SEC_ASN1_OPTIONAL | SEC_ASN1_XTRN | 0,
84 offsetof (CRMFOptionalValidity, notBefore),
85 SEC_ASN1_SUB(CERT_TimeChoiceTemplate) },
86 { SEC_ASN1_EXPLICIT | SEC_ASN1_CONSTRUCTED | SEC_ASN1_NO_STREAM |
87 SEC_ASN1_CONTEXT_SPECIFIC | SEC_ASN1_OPTIONAL | SEC_ASN1_XTRN | 1,
88 offsetof (CRMFOptionalValidity, notAfter),
89 SEC_ASN1_SUB(CERT_TimeChoiceTemplate) },
93 static const SEC_ASN1Template crmfPointerToNameTemplate[] = {
94 { SEC_ASN1_POINTER | SEC_ASN1_XTRN, 0, SEC_ASN1_SUB(CERT_NameTemplate)},
98 static const SEC_ASN1Template CRMFCertTemplateTemplate[] = {
99 { SEC_ASN1_SEQUENCE, 0, NULL, sizeof(CRMFCertTemplate) },
100 { SEC_ASN1_OPTIONAL | SEC_ASN1_CONTEXT_SPECIFIC | SEC_ASN1_XTRN | 0,
101 offsetof(CRMFCertTemplate, version),
102 SEC_ASN1_SUB(SEC_IntegerTemplate) },
103 { SEC_ASN1_CONTEXT_SPECIFIC | SEC_ASN1_OPTIONAL | SEC_ASN1_XTRN | 1 ,
104 offsetof (CRMFCertTemplate, serialNumber),
105 SEC_ASN1_SUB(SEC_IntegerTemplate) },
106 { SEC_ASN1_OPTIONAL | SEC_ASN1_CONTEXT_SPECIFIC | SEC_ASN1_POINTER |
108 offsetof (CRMFCertTemplate, signingAlg),
109 SEC_ASN1_SUB(SECOID_AlgorithmIDTemplate) },
110 { SEC_ASN1_OPTIONAL | SEC_ASN1_CONTEXT_SPECIFIC |
111 SEC_ASN1_EXPLICIT | SEC_ASN1_CONSTRUCTED | 3,
112 offsetof (CRMFCertTemplate, issuer), crmfPointerToNameTemplate },
113 { SEC_ASN1_OPTIONAL | SEC_ASN1_CONTEXT_SPECIFIC | SEC_ASN1_POINTER | 4,
114 offsetof (CRMFCertTemplate, validity),
115 CRMFOptionalValidityTemplate },
116 { SEC_ASN1_OPTIONAL | SEC_ASN1_CONTEXT_SPECIFIC |
117 SEC_ASN1_EXPLICIT | SEC_ASN1_CONSTRUCTED | 5,
118 offsetof (CRMFCertTemplate, subject), crmfPointerToNameTemplate },
119 { SEC_ASN1_OPTIONAL | SEC_ASN1_CONTEXT_SPECIFIC | SEC_ASN1_POINTER |
121 offsetof (CRMFCertTemplate, publicKey),
122 SEC_ASN1_SUB(CERT_SubjectPublicKeyInfoTemplate) },
123 { SEC_ASN1_NO_STREAM | SEC_ASN1_CONTEXT_SPECIFIC | SEC_ASN1_OPTIONAL |
125 offsetof (CRMFCertTemplate, issuerUID),
126 SEC_ASN1_SUB(SEC_BitStringTemplate) },
127 { SEC_ASN1_NO_STREAM | SEC_ASN1_CONTEXT_SPECIFIC | SEC_ASN1_OPTIONAL |
129 offsetof (CRMFCertTemplate, subjectUID),
130 SEC_ASN1_SUB(SEC_BitStringTemplate) },
131 { SEC_ASN1_CONSTRUCTED | SEC_ASN1_OPTIONAL |
132 SEC_ASN1_CONTEXT_SPECIFIC | 9,
133 offsetof (CRMFCertTemplate, extensions),
134 CRMFSequenceOfCertExtensionTemplate },
138 static const SEC_ASN1Template CRMFAttributeTemplate[] = {
139 { SEC_ASN1_SEQUENCE, 0, NULL, sizeof(CRMFAttribute)},
140 { SEC_ASN1_OBJECT_ID, offsetof(CRMFAttribute, derTag)},
141 { SEC_ASN1_ANY, offsetof(CRMFAttribute, derValue) },
145 const SEC_ASN1Template CRMFCertRequestTemplate[] = {
146 { SEC_ASN1_SEQUENCE, 0, NULL, sizeof (CRMFCertRequest) },
147 { SEC_ASN1_INTEGER, offsetof(CRMFCertRequest, certReqId)},
148 { SEC_ASN1_INLINE, offsetof(CRMFCertRequest, certTemplate),
149 CRMFCertTemplateTemplate},
150 { SEC_ASN1_OPTIONAL | SEC_ASN1_SEQUENCE_OF,
151 offsetof(CRMFCertRequest,controls),
152 CRMFControlTemplate}, /* SEQUENCE SIZE (1...MAX)*/
156 const SEC_ASN1Template CRMFCertReqMsgTemplate[] = {
157 { SEC_ASN1_SEQUENCE, 0, NULL, sizeof(CRMFCertReqMsg) },
158 { SEC_ASN1_POINTER, offsetof(CRMFCertReqMsg, certReq),
159 CRMFCertRequestTemplate },
160 { SEC_ASN1_ANY | SEC_ASN1_OPTIONAL,
161 offsetof(CRMFCertReqMsg, derPOP) },
162 { SEC_ASN1_OPTIONAL | SEC_ASN1_SEQUENCE_OF,
163 offsetof(CRMFCertReqMsg, regInfo),
164 CRMFAttributeTemplate}, /* SEQUENCE SIZE (1...MAX)*/
168 const SEC_ASN1Template CRMFCertReqMessagesTemplate[] = {
169 { SEC_ASN1_SEQUENCE_OF, offsetof(CRMFCertReqMessages, messages),
170 CRMFCertReqMsgTemplate, sizeof (CRMFCertReqMessages)}
173 static const SEC_ASN1Template CRMFPOPOSigningKeyInputTemplate[] = {
174 { SEC_ASN1_SEQUENCE, 0, NULL,sizeof(CRMFPOPOSigningKeyInput) },
175 { SEC_ASN1_OPTIONAL | SEC_ASN1_CONSTRUCTED |
176 SEC_ASN1_CONTEXT_SPECIFIC | 0,
177 offsetof(CRMFPOPOSigningKeyInput, authInfo.sender) },
178 { SEC_ASN1_BIT_STRING | SEC_ASN1_OPTIONAL | 1,
179 offsetof (CRMFPOPOSigningKeyInput, authInfo.publicKeyMAC) },
180 { SEC_ASN1_INLINE | SEC_ASN1_XTRN,
181 offsetof(CRMFPOPOSigningKeyInput, publicKey),
182 SEC_ASN1_SUB(CERT_SubjectPublicKeyInfoTemplate) },
186 const SEC_ASN1Template CRMFRAVerifiedTemplate[] = {
187 { SEC_ASN1_CONTEXT_SPECIFIC | 0 | SEC_ASN1_XTRN,
189 SEC_ASN1_SUB(SEC_NullTemplate) },
194 /* This template will need to add POPOSigningKeyInput eventually, maybe*/
195 static const SEC_ASN1Template crmfPOPOSigningKeyTemplate[] = {
196 { SEC_ASN1_SEQUENCE, 0, NULL, sizeof(CRMFPOPOSigningKey) },
197 { SEC_ASN1_NO_STREAM | SEC_ASN1_OPTIONAL | SEC_ASN1_CONTEXT_SPECIFIC |
199 offsetof(CRMFPOPOSigningKey, derInput),
200 SEC_ASN1_SUB(SEC_AnyTemplate) },
201 { SEC_ASN1_POINTER | SEC_ASN1_XTRN,
202 offsetof(CRMFPOPOSigningKey, algorithmIdentifier),
203 SEC_ASN1_SUB(SECOID_AlgorithmIDTemplate) },
204 { SEC_ASN1_BIT_STRING | SEC_ASN1_XTRN,
205 offsetof(CRMFPOPOSigningKey, signature),
206 SEC_ASN1_SUB(SEC_BitStringTemplate) },
210 const SEC_ASN1Template CRMFPOPOSigningKeyTemplate[] = {
211 { SEC_ASN1_CONTEXT_SPECIFIC | 1,
213 crmfPOPOSigningKeyTemplate},
217 const SEC_ASN1Template CRMFThisMessageTemplate[] = {
218 { SEC_ASN1_CONTEXT_SPECIFIC | SEC_ASN1_XTRN | 0,
220 SEC_ASN1_SUB(SEC_BitStringTemplate) },
224 const SEC_ASN1Template CRMFSubsequentMessageTemplate[] = {
225 { SEC_ASN1_CONTEXT_SPECIFIC | SEC_ASN1_XTRN | 1,
227 SEC_ASN1_SUB(SEC_IntegerTemplate) },
231 const SEC_ASN1Template CRMFDHMACTemplate[] = {
232 { SEC_ASN1_CONTEXT_SPECIFIC | SEC_ASN1_XTRN | 2,
234 SEC_ASN1_SUB(SEC_BitStringTemplate) },
238 const SEC_ASN1Template CRMFPOPOKeyEnciphermentTemplate[] = {
239 { SEC_ASN1_EXPLICIT | SEC_ASN1_CONSTRUCTED |
240 SEC_ASN1_CONTEXT_SPECIFIC | SEC_ASN1_XTRN | 2,
242 SEC_ASN1_SUB(SEC_AnyTemplate) },
246 const SEC_ASN1Template CRMFPOPOKeyAgreementTemplate[] = {
247 { SEC_ASN1_EXPLICIT | SEC_ASN1_CONSTRUCTED |
248 SEC_ASN1_CONTEXT_SPECIFIC | SEC_ASN1_XTRN | 3,
250 SEC_ASN1_SUB(SEC_AnyTemplate)},
254 const SEC_ASN1Template CRMFEncryptedValueTemplate[] = {
255 { SEC_ASN1_SEQUENCE, 0, NULL, sizeof(CRMFEncryptedValue)},
256 { SEC_ASN1_OPTIONAL | SEC_ASN1_CONTEXT_SPECIFIC | SEC_ASN1_POINTER |
258 offsetof(CRMFEncryptedValue, intendedAlg),
259 SEC_ASN1_SUB(SECOID_AlgorithmIDTemplate) },
260 { SEC_ASN1_OPTIONAL | SEC_ASN1_CONTEXT_SPECIFIC | SEC_ASN1_POINTER |
262 offsetof (CRMFEncryptedValue, symmAlg),
263 SEC_ASN1_SUB(SECOID_AlgorithmIDTemplate) },
264 { SEC_ASN1_NO_STREAM | SEC_ASN1_CONTEXT_SPECIFIC | SEC_ASN1_OPTIONAL |
266 offsetof(CRMFEncryptedValue, encSymmKey),
267 SEC_ASN1_SUB(SEC_BitStringTemplate) },
268 { SEC_ASN1_OPTIONAL | SEC_ASN1_CONTEXT_SPECIFIC | SEC_ASN1_POINTER |
270 offsetof(CRMFEncryptedValue, keyAlg),
271 SEC_ASN1_SUB(SECOID_AlgorithmIDTemplate) },
272 { SEC_ASN1_NO_STREAM | SEC_ASN1_OPTIONAL | SEC_ASN1_CONTEXT_SPECIFIC |
274 offsetof(CRMFEncryptedValue, valueHint),
275 SEC_ASN1_SUB(SEC_OctetStringTemplate) },
276 { SEC_ASN1_BIT_STRING, offsetof(CRMFEncryptedValue, encValue) },
280 const SEC_ASN1Template CRMFEncryptedKeyWithEncryptedValueTemplate [] = {
281 { SEC_ASN1_EXPLICIT | SEC_ASN1_CONSTRUCTED |
282 SEC_ASN1_CONTEXT_SPECIFIC | 0,
284 CRMFEncryptedValueTemplate},
288 static const SEC_ASN1Template CRMFSinglePubInfoTemplate[] = {
289 { SEC_ASN1_SEQUENCE, 0, NULL, sizeof (CRMFSinglePubInfo)},
290 { SEC_ASN1_INTEGER, offsetof(CRMFSinglePubInfo, pubMethod) },
291 { SEC_ASN1_OPTIONAL | SEC_ASN1_CONSTRUCTED | SEC_ASN1_CONTEXT_SPECIFIC,
292 offsetof(CRMFSinglePubInfo, pubLocation) },
296 static const SEC_ASN1Template CRMFPublicationInfoTemplate[] ={
297 { SEC_ASN1_SEQUENCE, 0, NULL, sizeof(CRMFPKIPublicationInfo) },
298 { SEC_ASN1_INTEGER, offsetof(CRMFPKIPublicationInfo, action) },
299 { SEC_ASN1_POINTER, offsetof(CRMFPKIPublicationInfo, pubInfos),
300 CRMFSinglePubInfoTemplate},