1 /* ***** BEGIN LICENSE BLOCK *****
2 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 * The contents of this file are subject to the Mozilla Public License Version
5 * 1.1 (the "License"); you may not use this file except in compliance with
6 * the License. You may obtain a copy of the License at
7 * http://www.mozilla.org/MPL/
9 * Software distributed under the License is distributed on an "AS IS" basis,
10 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11 * for the specific language governing rights and limitations under the
14 * The Original Code is the Netscape security libraries.
16 * The Initial Developer of the Original Code is
17 * Netscape Communications Corporation.
18 * Portions created by the Initial Developer are Copyright (C) 1994-2000
19 * the Initial Developer. All Rights Reserved.
23 * Alternatively, the contents of this file may be used under the terms of
24 * either the GNU General Public License Version 2 or later (the "GPL"), or
25 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
26 * in which case the provisions of the GPL or the LGPL are applicable instead
27 * of those above. If you wish to allow use of your version of this file only
28 * under the terms of either the GPL or the LGPL, and not to allow others to
29 * use your version of this file under the terms of the MPL, indicate your
30 * decision by deleting the provisions above and replace them with the notice
31 * and other provisions required by the GPL or the LGPL. If you do not delete
32 * the provisions above, a recipient may use your version of this file under
33 * the terms of any one of the MPL, the GPL or the LGPL.
35 * ***** END LICENSE BLOCK ***** */
47 SEC_ASN1_MKSUB(SEC_AnyTemplate
)
48 SEC_ASN1_MKSUB(sgn_DigestInfoTemplate
)
50 static const SEC_ASN1Template
*
51 sec_pkcs12_choose_safe_bag_type(void *src_or_dest
, PRBool encoding
)
53 const SEC_ASN1Template
*theTemplate
;
54 sec_PKCS12SafeBag
*safeBag
;
57 if (src_or_dest
== NULL
) {
61 safeBag
= (sec_PKCS12SafeBag
*)src_or_dest
;
63 oiddata
= SECOID_FindOID(&safeBag
->safeBagType
);
65 return SEC_ASN1_GET(SEC_AnyTemplate
);
68 switch (oiddata
->offset
) {
70 theTemplate
= SEC_ASN1_GET(SEC_AnyTemplate
);
72 case SEC_OID_PKCS12_V1_KEY_BAG_ID
:
73 theTemplate
= SEC_ASN1_GET(SECKEY_PointerToPrivateKeyInfoTemplate
);
75 case SEC_OID_PKCS12_V1_CERT_BAG_ID
:
76 theTemplate
= sec_PKCS12PointerToCertBagTemplate
;
78 case SEC_OID_PKCS12_V1_CRL_BAG_ID
:
79 theTemplate
= sec_PKCS12PointerToCRLBagTemplate
;
81 case SEC_OID_PKCS12_V1_SECRET_BAG_ID
:
82 theTemplate
= sec_PKCS12PointerToSecretBagTemplate
;
84 case SEC_OID_PKCS12_V1_PKCS8_SHROUDED_KEY_BAG_ID
:
86 SEC_ASN1_GET(SECKEY_PointerToEncryptedPrivateKeyInfoTemplate
);
88 case SEC_OID_PKCS12_V1_SAFE_CONTENTS_BAG_ID
:
90 theTemplate
= sec_PKCS12PointerToSafeContentsTemplate
;
92 theTemplate
= SEC_ASN1_GET(SEC_PointerToAnyTemplate
);
99 static const SEC_ASN1Template
*
100 sec_pkcs12_choose_crl_bag_type(void *src_or_dest
, PRBool encoding
)
102 const SEC_ASN1Template
*theTemplate
;
103 sec_PKCS12CRLBag
*crlbag
;
106 if (src_or_dest
== NULL
) {
110 crlbag
= (sec_PKCS12CRLBag
*)src_or_dest
;
112 oiddata
= SECOID_FindOID(&crlbag
->bagID
);
113 if(oiddata
== NULL
) {
114 return SEC_ASN1_GET(SEC_AnyTemplate
);
117 switch (oiddata
->offset
) {
119 theTemplate
= SEC_ASN1_GET(SEC_AnyTemplate
);
121 case SEC_OID_PKCS9_X509_CRL
:
122 theTemplate
= SEC_ASN1_GET(SEC_OctetStringTemplate
);
128 static const SEC_ASN1Template
*
129 sec_pkcs12_choose_cert_bag_type(void *src_or_dest
, PRBool encoding
)
131 const SEC_ASN1Template
*theTemplate
;
132 sec_PKCS12CertBag
*certbag
;
135 if (src_or_dest
== NULL
) {
139 certbag
= (sec_PKCS12CertBag
*)src_or_dest
;
141 oiddata
= SECOID_FindOID(&certbag
->bagID
);
142 if(oiddata
== NULL
) {
143 return SEC_ASN1_GET(SEC_AnyTemplate
);
146 switch (oiddata
->offset
) {
148 theTemplate
= SEC_ASN1_GET(SEC_AnyTemplate
);
150 case SEC_OID_PKCS9_X509_CERT
:
151 theTemplate
= SEC_ASN1_GET(SEC_OctetStringTemplate
);
153 case SEC_OID_PKCS9_SDSI_CERT
:
154 theTemplate
= SEC_ASN1_GET(SEC_IA5StringTemplate
);
160 static const SEC_ASN1Template
*
161 sec_pkcs12_choose_attr_type(void *src_or_dest
, PRBool encoding
)
163 const SEC_ASN1Template
*theTemplate
;
164 sec_PKCS12Attribute
*attr
;
167 if (src_or_dest
== NULL
) {
171 attr
= (sec_PKCS12Attribute
*)src_or_dest
;
173 oiddata
= SECOID_FindOID(&attr
->attrType
);
174 if(oiddata
== NULL
) {
175 return SEC_ASN1_GET(SEC_AnyTemplate
);
178 switch (oiddata
->offset
) {
180 theTemplate
= SEC_ASN1_GET(SEC_AnyTemplate
);
182 case SEC_OID_PKCS9_FRIENDLY_NAME
:
183 theTemplate
= SEC_ASN1_GET(SEC_BMPStringTemplate
);
185 case SEC_OID_PKCS9_LOCAL_KEY_ID
:
186 theTemplate
= SEC_ASN1_GET(SEC_OctetStringTemplate
);
188 case SEC_OID_PKCS12_KEY_USAGE
:
189 theTemplate
= SEC_ASN1_GET(SEC_BitStringTemplate
);
197 const SEC_ASN1Template sec_PKCS12PointerToContentInfoTemplate
[] = {
198 { SEC_ASN1_POINTER
| SEC_ASN1_MAY_STREAM
, 0, sec_PKCS7ContentInfoTemplate
}
201 static const SEC_ASN1TemplateChooserPtr sec_pkcs12_crl_bag_chooser
=
202 sec_pkcs12_choose_crl_bag_type
;
204 static const SEC_ASN1TemplateChooserPtr sec_pkcs12_cert_bag_chooser
=
205 sec_pkcs12_choose_cert_bag_type
;
207 static const SEC_ASN1TemplateChooserPtr sec_pkcs12_safe_bag_chooser
=
208 sec_pkcs12_choose_safe_bag_type
;
210 static const SEC_ASN1TemplateChooserPtr sec_pkcs12_attr_chooser
=
211 sec_pkcs12_choose_attr_type
;
213 const SEC_ASN1Template sec_PKCS12PointerToCertBagTemplate
[] = {
214 { SEC_ASN1_POINTER
, 0, sec_PKCS12CertBagTemplate
}
217 const SEC_ASN1Template sec_PKCS12PointerToCRLBagTemplate
[] = {
218 { SEC_ASN1_POINTER
, 0, sec_PKCS12CRLBagTemplate
}
221 const SEC_ASN1Template sec_PKCS12PointerToSecretBagTemplate
[] = {
222 { SEC_ASN1_POINTER
, 0, sec_PKCS12SecretBagTemplate
}
225 const SEC_ASN1Template sec_PKCS12PointerToSafeContentsTemplate
[] = {
226 { SEC_ASN1_POINTER
, 0, sec_PKCS12SafeContentsTemplate
}
229 const SEC_ASN1Template sec_PKCS12PFXItemTemplate
[] = {
230 { SEC_ASN1_SEQUENCE
| SEC_ASN1_MAY_STREAM
, 0, NULL
,
231 sizeof(sec_PKCS12PFXItem
) },
232 { SEC_ASN1_OPTIONAL
| SEC_ASN1_INTEGER
,
233 offsetof(sec_PKCS12PFXItem
, version
) },
234 { SEC_ASN1_ANY
| SEC_ASN1_MAY_STREAM
,
235 offsetof(sec_PKCS12PFXItem
, encodedAuthSafe
) },
236 { SEC_ASN1_ANY
| SEC_ASN1_MAY_STREAM
,
237 offsetof(sec_PKCS12PFXItem
, encodedMacData
) },
241 const SEC_ASN1Template sec_PKCS12MacDataTemplate
[] = {
242 { SEC_ASN1_SEQUENCE
, 0, NULL
, sizeof(sec_PKCS12MacData
) },
243 { SEC_ASN1_INLINE
| SEC_ASN1_XTRN
, offsetof(sec_PKCS12MacData
, safeMac
),
244 SEC_ASN1_SUB(sgn_DigestInfoTemplate
) },
245 { SEC_ASN1_OCTET_STRING
, offsetof(sec_PKCS12MacData
, macSalt
) },
246 { SEC_ASN1_OPTIONAL
| SEC_ASN1_INTEGER
, offsetof(sec_PKCS12MacData
, iter
) },
250 const SEC_ASN1Template sec_PKCS12AuthenticatedSafeTemplate
[] = {
251 { SEC_ASN1_SEQUENCE_OF
| SEC_ASN1_MAY_STREAM
| SEC_ASN1_XTRN
,
252 offsetof(sec_PKCS12AuthenticatedSafe
, encodedSafes
),
253 SEC_ASN1_SUB(SEC_AnyTemplate
) }
256 const SEC_ASN1Template sec_PKCS12SafeBagTemplate
[] = {
257 { SEC_ASN1_SEQUENCE
| SEC_ASN1_MAY_STREAM
, 0, NULL
,
258 sizeof(sec_PKCS12SafeBag
) },
259 { SEC_ASN1_OBJECT_ID
, offsetof(sec_PKCS12SafeBag
, safeBagType
) },
260 { SEC_ASN1_EXPLICIT
| SEC_ASN1_DYNAMIC
| SEC_ASN1_CONSTRUCTED
|
261 SEC_ASN1_MAY_STREAM
| SEC_ASN1_CONTEXT_SPECIFIC
| 0,
262 offsetof(sec_PKCS12SafeBag
, safeBagContent
),
263 &sec_pkcs12_safe_bag_chooser
},
264 { SEC_ASN1_SET_OF
| SEC_ASN1_OPTIONAL
, offsetof(sec_PKCS12SafeBag
, attribs
),
265 sec_PKCS12AttributeTemplate
},
269 const SEC_ASN1Template sec_PKCS12SafeContentsTemplate
[] = {
270 { SEC_ASN1_SEQUENCE_OF
| SEC_ASN1_MAY_STREAM
,
271 offsetof(sec_PKCS12SafeContents
, safeBags
),
272 sec_PKCS12SafeBagTemplate
}
275 const SEC_ASN1Template sec_PKCS12SequenceOfAnyTemplate
[] = {
276 { SEC_ASN1_SEQUENCE_OF
| SEC_ASN1_MAY_STREAM
| SEC_ASN1_XTRN
, 0,
277 SEC_ASN1_SUB(SEC_AnyTemplate
) }
280 const SEC_ASN1Template sec_PKCS12NestedSafeContentsDecodeTemplate
[] = {
281 { SEC_ASN1_EXPLICIT
| SEC_ASN1_CONTEXT_SPECIFIC
| SEC_ASN1_CONSTRUCTED
| 0,
282 offsetof(sec_PKCS12SafeContents
, encodedSafeBags
),
283 sec_PKCS12SequenceOfAnyTemplate
}
286 const SEC_ASN1Template sec_PKCS12SafeContentsDecodeTemplate
[] = {
287 { SEC_ASN1_SEQUENCE_OF
| SEC_ASN1_MAY_STREAM
| SEC_ASN1_XTRN
,
288 offsetof(sec_PKCS12SafeContents
, encodedSafeBags
),
289 SEC_ASN1_SUB(SEC_AnyTemplate
) }
292 const SEC_ASN1Template sec_PKCS12CRLBagTemplate
[] = {
293 { SEC_ASN1_SEQUENCE
, 0, NULL
, sizeof(sec_PKCS12CRLBag
) },
294 { SEC_ASN1_OBJECT_ID
, offsetof(sec_PKCS12CRLBag
, bagID
) },
295 { SEC_ASN1_DYNAMIC
| SEC_ASN1_POINTER
,
296 offsetof(sec_PKCS12CRLBag
, value
), &sec_pkcs12_crl_bag_chooser
},
300 const SEC_ASN1Template sec_PKCS12CertBagTemplate
[] = {
301 { SEC_ASN1_SEQUENCE
, 0, NULL
, sizeof(sec_PKCS12CertBag
) },
302 { SEC_ASN1_OBJECT_ID
, offsetof(sec_PKCS12CertBag
, bagID
) },
303 { SEC_ASN1_DYNAMIC
| SEC_ASN1_EXPLICIT
| SEC_ASN1_CONSTRUCTED
|
304 SEC_ASN1_CONTEXT_SPECIFIC
| 0,
305 offsetof(sec_PKCS12CertBag
, value
), &sec_pkcs12_cert_bag_chooser
},
309 const SEC_ASN1Template sec_PKCS12SecretBagTemplate
[] = {
310 { SEC_ASN1_SEQUENCE
, 0, NULL
, sizeof(sec_PKCS12SecretBag
) },
311 { SEC_ASN1_OBJECT_ID
, offsetof(sec_PKCS12SecretBag
, secretType
) },
312 { SEC_ASN1_ANY
, offsetof(sec_PKCS12SecretBag
, secretContent
) },
316 const SEC_ASN1Template sec_PKCS12AttributeTemplate
[] = {
317 { SEC_ASN1_SEQUENCE
, 0, NULL
, sizeof(sec_PKCS12Attribute
) },
318 { SEC_ASN1_OBJECT_ID
, offsetof(sec_PKCS12Attribute
, attrType
) },
319 { SEC_ASN1_SET_OF
| SEC_ASN1_DYNAMIC
,
320 offsetof(sec_PKCS12Attribute
, attrValue
),
321 &sec_pkcs12_attr_chooser
},