1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
|
/* -*- Mode: C; tab-width: 8 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "crmf.h"
#include "crmfi.h"
#include "secoid.h"
#include "secasn1.h"
SEC_ASN1_MKSUB(SECOID_AlgorithmIDTemplate)
SEC_ASN1_MKSUB(SEC_AnyTemplate)
SEC_ASN1_MKSUB(SEC_NullTemplate)
SEC_ASN1_MKSUB(SEC_BitStringTemplate)
SEC_ASN1_MKSUB(SEC_IntegerTemplate)
SEC_ASN1_MKSUB(SEC_OctetStringTemplate)
SEC_ASN1_MKSUB(CERT_TimeChoiceTemplate)
SEC_ASN1_MKSUB(CERT_SubjectPublicKeyInfoTemplate)
SEC_ASN1_MKSUB(CERT_NameTemplate)
/*
* It's all implicit tagging.
*/
const SEC_ASN1Template CRMFControlTemplate[] = {
{ SEC_ASN1_SEQUENCE, 0, NULL, sizeof(CRMFControl) },
{ SEC_ASN1_OBJECT_ID, offsetof(CRMFControl, derTag) },
{ SEC_ASN1_ANY, offsetof(CRMFControl, derValue) },
{ 0 }
};
static const SEC_ASN1Template CRMFCertExtensionTemplate[] = {
{ SEC_ASN1_SEQUENCE,
0, NULL, sizeof(CRMFCertExtension) },
{ SEC_ASN1_OBJECT_ID,
offsetof(CRMFCertExtension, id) },
{ SEC_ASN1_OPTIONAL | SEC_ASN1_BOOLEAN,
offsetof(CRMFCertExtension, critical) },
{ SEC_ASN1_OCTET_STRING,
offsetof(CRMFCertExtension, value) },
{ 0 }
};
static const SEC_ASN1Template CRMFSequenceOfCertExtensionTemplate[] = {
{ SEC_ASN1_SEQUENCE_OF, 0, CRMFCertExtensionTemplate }
};
static const SEC_ASN1Template CRMFOptionalValidityTemplate[] = {
{ SEC_ASN1_SEQUENCE, 0, NULL, sizeof(CRMFOptionalValidity) },
{ SEC_ASN1_EXPLICIT | SEC_ASN1_CONSTRUCTED | SEC_ASN1_NO_STREAM |
SEC_ASN1_CONTEXT_SPECIFIC | SEC_ASN1_OPTIONAL | SEC_ASN1_XTRN | 0,
offsetof(CRMFOptionalValidity, notBefore),
SEC_ASN1_SUB(CERT_TimeChoiceTemplate) },
{ SEC_ASN1_EXPLICIT | SEC_ASN1_CONSTRUCTED | SEC_ASN1_NO_STREAM |
SEC_ASN1_CONTEXT_SPECIFIC | SEC_ASN1_OPTIONAL | SEC_ASN1_XTRN | 1,
offsetof(CRMFOptionalValidity, notAfter),
SEC_ASN1_SUB(CERT_TimeChoiceTemplate) },
{ 0 }
};
static const SEC_ASN1Template crmfPointerToNameTemplate[] = {
{ SEC_ASN1_POINTER | SEC_ASN1_XTRN, 0, SEC_ASN1_SUB(CERT_NameTemplate) },
{ 0 }
};
static const SEC_ASN1Template CRMFCertTemplateTemplate[] = {
{ SEC_ASN1_SEQUENCE, 0, NULL, sizeof(CRMFCertTemplate) },
{ SEC_ASN1_OPTIONAL | SEC_ASN1_CONTEXT_SPECIFIC | SEC_ASN1_XTRN | 0,
offsetof(CRMFCertTemplate, version),
SEC_ASN1_SUB(SEC_IntegerTemplate) },
{ SEC_ASN1_CONTEXT_SPECIFIC | SEC_ASN1_OPTIONAL | SEC_ASN1_XTRN | 1,
offsetof(CRMFCertTemplate, serialNumber),
SEC_ASN1_SUB(SEC_IntegerTemplate) },
{ SEC_ASN1_OPTIONAL | SEC_ASN1_CONTEXT_SPECIFIC | SEC_ASN1_POINTER |
SEC_ASN1_XTRN | 2,
offsetof(CRMFCertTemplate, signingAlg),
SEC_ASN1_SUB(SECOID_AlgorithmIDTemplate) },
{ SEC_ASN1_OPTIONAL | SEC_ASN1_CONTEXT_SPECIFIC |
SEC_ASN1_EXPLICIT | SEC_ASN1_CONSTRUCTED | 3,
offsetof(CRMFCertTemplate, issuer), crmfPointerToNameTemplate },
{ SEC_ASN1_OPTIONAL | SEC_ASN1_CONTEXT_SPECIFIC | SEC_ASN1_POINTER | 4,
offsetof(CRMFCertTemplate, validity),
CRMFOptionalValidityTemplate },
{ SEC_ASN1_OPTIONAL | SEC_ASN1_CONTEXT_SPECIFIC |
SEC_ASN1_EXPLICIT | SEC_ASN1_CONSTRUCTED | 5,
offsetof(CRMFCertTemplate, subject), crmfPointerToNameTemplate },
{ SEC_ASN1_OPTIONAL | SEC_ASN1_CONTEXT_SPECIFIC | SEC_ASN1_POINTER |
SEC_ASN1_XTRN | 6,
offsetof(CRMFCertTemplate, publicKey),
SEC_ASN1_SUB(CERT_SubjectPublicKeyInfoTemplate) },
{ SEC_ASN1_NO_STREAM | SEC_ASN1_CONTEXT_SPECIFIC | SEC_ASN1_OPTIONAL |
SEC_ASN1_XTRN | 7,
offsetof(CRMFCertTemplate, issuerUID),
SEC_ASN1_SUB(SEC_BitStringTemplate) },
{ SEC_ASN1_NO_STREAM | SEC_ASN1_CONTEXT_SPECIFIC | SEC_ASN1_OPTIONAL |
SEC_ASN1_XTRN | 8,
offsetof(CRMFCertTemplate, subjectUID),
SEC_ASN1_SUB(SEC_BitStringTemplate) },
{ SEC_ASN1_CONSTRUCTED | SEC_ASN1_OPTIONAL |
SEC_ASN1_CONTEXT_SPECIFIC | 9,
offsetof(CRMFCertTemplate, extensions),
CRMFSequenceOfCertExtensionTemplate },
{ 0 }
};
static const SEC_ASN1Template CRMFAttributeTemplate[] = {
{ SEC_ASN1_SEQUENCE, 0, NULL, sizeof(CRMFAttribute) },
{ SEC_ASN1_OBJECT_ID, offsetof(CRMFAttribute, derTag) },
{ SEC_ASN1_ANY, offsetof(CRMFAttribute, derValue) },
{ 0 }
};
const SEC_ASN1Template CRMFCertRequestTemplate[] = {
{ SEC_ASN1_SEQUENCE, 0, NULL, sizeof(CRMFCertRequest) },
{ SEC_ASN1_INTEGER, offsetof(CRMFCertRequest, certReqId) },
{ SEC_ASN1_INLINE, offsetof(CRMFCertRequest, certTemplate),
CRMFCertTemplateTemplate },
{ SEC_ASN1_OPTIONAL | SEC_ASN1_SEQUENCE_OF,
offsetof(CRMFCertRequest, controls),
CRMFControlTemplate }, /* SEQUENCE SIZE (1...MAX)*/
{ 0 }
};
const SEC_ASN1Template CRMFCertReqMsgTemplate[] = {
{ SEC_ASN1_SEQUENCE, 0, NULL, sizeof(CRMFCertReqMsg) },
{ SEC_ASN1_POINTER, offsetof(CRMFCertReqMsg, certReq),
CRMFCertRequestTemplate },
{ SEC_ASN1_ANY | SEC_ASN1_OPTIONAL,
offsetof(CRMFCertReqMsg, derPOP) },
{ SEC_ASN1_OPTIONAL | SEC_ASN1_SEQUENCE_OF,
offsetof(CRMFCertReqMsg, regInfo),
CRMFAttributeTemplate }, /* SEQUENCE SIZE (1...MAX)*/
{ 0 }
};
const SEC_ASN1Template CRMFCertReqMessagesTemplate[] = {
{ SEC_ASN1_SEQUENCE_OF, offsetof(CRMFCertReqMessages, messages),
CRMFCertReqMsgTemplate, sizeof(CRMFCertReqMessages) }
};
const SEC_ASN1Template CRMFRAVerifiedTemplate[] = {
{ SEC_ASN1_CONTEXT_SPECIFIC | 0 | SEC_ASN1_XTRN,
0,
SEC_ASN1_SUB(SEC_NullTemplate) },
{ 0 }
};
/* This template will need to add POPOSigningKeyInput eventually, maybe*/
static const SEC_ASN1Template crmfPOPOSigningKeyTemplate[] = {
{ SEC_ASN1_SEQUENCE, 0, NULL, sizeof(CRMFPOPOSigningKey) },
{ SEC_ASN1_NO_STREAM | SEC_ASN1_OPTIONAL | SEC_ASN1_CONTEXT_SPECIFIC |
SEC_ASN1_XTRN | 0,
offsetof(CRMFPOPOSigningKey, derInput),
SEC_ASN1_SUB(SEC_AnyTemplate) },
{ SEC_ASN1_POINTER | SEC_ASN1_XTRN,
offsetof(CRMFPOPOSigningKey, algorithmIdentifier),
SEC_ASN1_SUB(SECOID_AlgorithmIDTemplate) },
{ SEC_ASN1_BIT_STRING | SEC_ASN1_XTRN,
offsetof(CRMFPOPOSigningKey, signature),
SEC_ASN1_SUB(SEC_BitStringTemplate) },
{ 0 }
};
const SEC_ASN1Template CRMFPOPOSigningKeyTemplate[] = {
{ SEC_ASN1_CONTEXT_SPECIFIC | 1,
0,
crmfPOPOSigningKeyTemplate },
{ 0 }
};
const SEC_ASN1Template CRMFThisMessageTemplate[] = {
{ SEC_ASN1_CONTEXT_SPECIFIC | SEC_ASN1_XTRN | 0,
0,
SEC_ASN1_SUB(SEC_BitStringTemplate) },
{ 0 }
};
const SEC_ASN1Template CRMFSubsequentMessageTemplate[] = {
{ SEC_ASN1_CONTEXT_SPECIFIC | SEC_ASN1_XTRN | 1,
0,
SEC_ASN1_SUB(SEC_IntegerTemplate) },
{ 0 }
};
const SEC_ASN1Template CRMFDHMACTemplate[] = {
{ SEC_ASN1_CONTEXT_SPECIFIC | SEC_ASN1_XTRN | 2,
0,
SEC_ASN1_SUB(SEC_BitStringTemplate) },
{ 0 }
};
const SEC_ASN1Template CRMFPOPOKeyEnciphermentTemplate[] = {
{ SEC_ASN1_EXPLICIT | SEC_ASN1_CONSTRUCTED |
SEC_ASN1_CONTEXT_SPECIFIC | SEC_ASN1_XTRN | 2,
0,
SEC_ASN1_SUB(SEC_AnyTemplate) },
{ 0 }
};
const SEC_ASN1Template CRMFPOPOKeyAgreementTemplate[] = {
{ SEC_ASN1_EXPLICIT | SEC_ASN1_CONSTRUCTED |
SEC_ASN1_CONTEXT_SPECIFIC | SEC_ASN1_XTRN | 3,
0,
SEC_ASN1_SUB(SEC_AnyTemplate) },
{ 0 }
};
const SEC_ASN1Template CRMFEncryptedValueTemplate[] = {
{ SEC_ASN1_SEQUENCE, 0, NULL, sizeof(CRMFEncryptedValue) },
{ SEC_ASN1_OPTIONAL | SEC_ASN1_CONTEXT_SPECIFIC | SEC_ASN1_POINTER |
SEC_ASN1_XTRN | 0,
offsetof(CRMFEncryptedValue, intendedAlg),
SEC_ASN1_SUB(SECOID_AlgorithmIDTemplate) },
{ SEC_ASN1_OPTIONAL | SEC_ASN1_CONTEXT_SPECIFIC | SEC_ASN1_POINTER |
SEC_ASN1_XTRN | 1,
offsetof(CRMFEncryptedValue, symmAlg),
SEC_ASN1_SUB(SECOID_AlgorithmIDTemplate) },
{ SEC_ASN1_NO_STREAM | SEC_ASN1_CONTEXT_SPECIFIC | SEC_ASN1_OPTIONAL |
SEC_ASN1_XTRN | 2,
offsetof(CRMFEncryptedValue, encSymmKey),
SEC_ASN1_SUB(SEC_BitStringTemplate) },
{ SEC_ASN1_OPTIONAL | SEC_ASN1_CONTEXT_SPECIFIC | SEC_ASN1_POINTER |
SEC_ASN1_XTRN | 3,
offsetof(CRMFEncryptedValue, keyAlg),
SEC_ASN1_SUB(SECOID_AlgorithmIDTemplate) },
{ SEC_ASN1_NO_STREAM | SEC_ASN1_OPTIONAL | SEC_ASN1_CONTEXT_SPECIFIC |
SEC_ASN1_XTRN | 4,
offsetof(CRMFEncryptedValue, valueHint),
SEC_ASN1_SUB(SEC_OctetStringTemplate) },
{ SEC_ASN1_BIT_STRING, offsetof(CRMFEncryptedValue, encValue) },
{ 0 }
};
const SEC_ASN1Template CRMFEncryptedKeyWithEncryptedValueTemplate[] = {
{ SEC_ASN1_EXPLICIT | SEC_ASN1_CONSTRUCTED |
SEC_ASN1_CONTEXT_SPECIFIC | 0,
0,
CRMFEncryptedValueTemplate },
{ 0 }
};
|