2 * Copyright (c) 2003-2004,2008,2010,2012 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@
28 #include "pkcs12Templates.h"
30 #include "SecAsn1Templates.h"
33 const SecAsn1Template NSS_P12_MacDataTemplate
[] = {
35 0, NULL
, sizeof(NSS_P12_MacData
) },
37 offsetof(NSS_P12_MacData
,mac
),
38 NSS_P7_DigestInfoTemplate
},
39 { SEC_ASN1_OCTET_STRING
,
40 offsetof(NSS_P12_MacData
,macSalt
) },
41 /* iterations is unsigned - right? */
42 { SEC_ASN1_INTEGER
| SEC_ASN1_OPTIONAL
,
43 offsetof(NSS_P12_MacData
,iterations
) },
47 const SecAsn1Template pointerToMacDataTemplate
[] = {
48 { SEC_ASN1_POINTER
, 0, NSS_P12_MacDataTemplate
}
51 /* raw PFX with unprocessed authSafe */
52 const SecAsn1Template NSS_P12_RawPFXTemplate
[] = {
54 0, NULL
, sizeof(NSS_P12_RawPFX
) },
56 offsetof(NSS_P12_RawPFX
,version
) },
58 offsetof(NSS_P12_RawPFX
, authSafe
),
59 NSS_P7_RawContentInfoTemplate
},
60 { SEC_ASN1_POINTER
| SEC_ASN1_OPTIONAL
,
61 offsetof(NSS_P12_RawPFX
, macData
),
62 NSS_P12_MacDataTemplate
},
66 /* PFX with decoded authSafe */
67 const SecAsn1Template NSS_P12_DecodedPFXTemplate
[] = {
69 0, NULL
, sizeof(NSS_P12_DecodedPFX
) },
71 offsetof(NSS_P12_DecodedPFX
,version
) },
73 offsetof(NSS_P12_DecodedPFX
, authSafe
),
74 NSS_P7_DecodedContentInfoTemplate
},
75 { SEC_ASN1_POINTER
| SEC_ASN1_OPTIONAL
,
76 offsetof(NSS_P12_DecodedPFX
, macData
),
77 NSS_P12_MacDataTemplate
},
81 /* AuthenticatedSafe */
82 const SecAsn1Template NSS_P12_AuthenticatedSafeTemplate
[] = {
83 { SEC_ASN1_SEQUENCE_OF
,
84 offsetof(NSS_P12_AuthenticatedSafe
, info
),
85 NSS_P7_DecodedContentInfoTemplate
,
86 sizeof(NSS_P12_AuthenticatedSafe
) }
90 * Individual SafeBag type-specific templates here when we write 'em
92 const SecAsn1Template NSS_P12_PtrToShroudedKeyBagTemplate
[] = {
93 { SEC_ASN1_POINTER
, 0, kSecAsn1EncryptedPrivateKeyInfoTemplate
}
97 * CertBag via SEC_ASN1_DYNAMIC
99 static const SecAsn1Template
* NSS_P12_CertBagChooser(
100 void *arg
, // --> NSS_P12_CertBag
102 const char *buf
, // on decode, tag byte and length
104 void *dest
) // --> NSS_P12_CertBag.bagValue
106 NSS_P12_CertBag
*bag
= (NSS_P12_CertBag
*)arg
;
107 const SecAsn1Template
*templ
= NULL
;
108 NSS_P12_CertBagType type
= CT_Unknown
;
109 SecAsn1Oid
*oid
= &bag
->bagType
;
111 if(nssCompareSecAsn1Items(oid
, &CSSMOID_PKCS9_X509Certificate
)) {
112 templ
= kSecAsn1OctetStringTemplate
;
115 else if(nssCompareSecAsn1Items(oid
, &CSSMOID_PKCS9_SdsiCertificate
)) {
116 templ
= kSecAsn1IA5StringTemplate
;
121 templ
= kSecAsn1AnyTemplate
;
129 static const SecAsn1TemplateChooserPtr NSS_P12_CertBagChooserPtr
=
130 NSS_P12_CertBagChooser
;
132 const SecAsn1Template NSS_P12_CertBagTemplate
[] = {
134 0, NULL
, sizeof(NSS_P12_CertBag
) },
135 { SEC_ASN1_OBJECT_ID
,
136 offsetof(NSS_P12_CertBag
,bagType
) },
137 /* these come in with a tag of 0xA0, context/constructed,
138 * though I don't know why they are flagged as constructed */
139 { SEC_ASN1_DYNAMIC
| SEC_ASN1_CONTEXT_SPECIFIC
|
140 SEC_ASN1_EXPLICIT
| SEC_ASN1_CONSTRUCTED
| 0,
141 offsetof(NSS_P12_CertBag
, certValue
),
142 &NSS_P12_CertBagChooserPtr
},
146 const SecAsn1Template NSS_P12_PtrToCertBagTemplate
[] = {
147 { SEC_ASN1_POINTER
, 0, NSS_P12_CertBagTemplate
}
151 * CrlBag via SEC_ASN1_DYNAMIC
153 static const SecAsn1Template
* NSS_P12_CrlBagChooser(
154 void *arg
, // --> NSS_P12_CrlBag
156 const char *buf
, // on decode, tag byte and length
158 void *dest
) // --> NSS_P12_CertBag.bagValue
160 NSS_P12_CrlBag
*bag
= (NSS_P12_CrlBag
*)arg
;
161 const SecAsn1Template
*templ
= NULL
;
162 NSS_P12_CrlBagType type
= CRT_Unknown
;
163 SecAsn1Oid
*oid
= &bag
->bagType
;
165 if(nssCompareSecAsn1Items(oid
, &CSSMOID_PKCS9_X509Crl
)) {
166 templ
= kSecAsn1OctetStringTemplate
;
171 templ
= kSecAsn1AnyTemplate
;
179 static const SecAsn1TemplateChooserPtr NSS_P12_CrlBagChooserPtr
=
180 NSS_P12_CrlBagChooser
;
182 const SecAsn1Template NSS_P12_CrlBagTemplate
[] = {
184 0, NULL
, sizeof(NSS_P12_CrlBag
) },
185 { SEC_ASN1_OBJECT_ID
,
186 offsetof(NSS_P12_CrlBag
,bagType
) },
187 /* these come in with a tag of 0xA0, context/constructed,
188 * though I don't know why they are flagged as constructed */
189 { SEC_ASN1_DYNAMIC
| SEC_ASN1_CONTEXT_SPECIFIC
|
190 SEC_ASN1_EXPLICIT
| SEC_ASN1_CONSTRUCTED
| 0,
191 offsetof(NSS_P12_CrlBag
, crlValue
),
192 &NSS_P12_CrlBagChooserPtr
},
196 const SecAsn1Template NSS_P12_PtrToCrlBagTemplate
[] = {
197 { SEC_ASN1_POINTER
, 0, NSS_P12_CrlBagTemplate
}
201 /* the stub templates for unimplemented BagTypes */
202 #define NSS_P12_PtrToKeyBagTemplate kSecAsn1PointerToAnyTemplate
203 #define NSS_P12_PtrToSecretBagTemplate kSecAsn1PointerToAnyTemplate
204 #define NSS_P12_PtrToSafeContentsBagTemplate kSecAsn1PointerToAnyTemplate
208 * SafeBag via SEC_ASN1_DYNAMIC
210 static const SecAsn1Template
* NSS_P12_SafeBagChooser(
211 void *arg
, // --> NSS_P12_SafeBag
213 const char *buf
, // on decode, tag byte and len
215 void *dest
) // --> NSS_P12_SafeBag.bagValue
217 NSS_P12_SafeBag
*bag
= (NSS_P12_SafeBag
*)arg
;
218 const SecAsn1Template
*templ
= NULL
;
219 NSS_P12_SB_Type type
= BT_None
;
220 SecAsn1Oid
*oid
= &bag
->bagId
;
222 if(nssCompareSecAsn1Items(oid
, &CSSMOID_PKCS12_keyBag
)) {
223 templ
= NSS_P12_PtrToKeyBagTemplate
;
226 else if(nssCompareSecAsn1Items(oid
, &CSSMOID_PKCS12_shroudedKeyBag
)) {
227 templ
= NSS_P12_PtrToShroudedKeyBagTemplate
;
228 type
= BT_ShroudedKeyBag
;
230 else if(nssCompareSecAsn1Items(oid
, &CSSMOID_PKCS12_certBag
)) {
231 templ
= NSS_P12_PtrToCertBagTemplate
;
234 else if(nssCompareSecAsn1Items(oid
, &CSSMOID_PKCS12_crlBag
)) {
235 templ
= NSS_P12_PtrToCrlBagTemplate
;
238 else if(nssCompareSecAsn1Items(oid
, &CSSMOID_PKCS12_secretBag
)) {
239 templ
= NSS_P12_PtrToSecretBagTemplate
;
242 else if(nssCompareSecAsn1Items(oid
, &CSSMOID_PKCS12_safeContentsBag
)) {
243 templ
= NSS_P12_PtrToSafeContentsBagTemplate
;
244 type
= BT_SafeContentsBag
;
246 /* add more here when we implement them */
248 templ
= kSecAsn1PointerToAnyTemplate
;
256 static const SecAsn1TemplateChooserPtr NSS_P12_SafeBagChooserPtr
=
257 NSS_P12_SafeBagChooser
;
259 const SecAsn1Template NSS_P12_SafeBagTemplate
[] = {
261 0, NULL
, sizeof(NSS_P12_SafeBag
) },
262 { SEC_ASN1_OBJECT_ID
,
263 offsetof(NSS_P12_SafeBag
,bagId
) },
264 { SEC_ASN1_DYNAMIC
| SEC_ASN1_CONSTRUCTED
|
265 SEC_ASN1_EXPLICIT
| SEC_ASN1_CONTEXT_SPECIFIC
| 0,
266 offsetof(NSS_P12_SafeBag
,bagValue
),
267 &NSS_P12_SafeBagChooserPtr
},
268 { SEC_ASN1_OPTIONAL
| SEC_ASN1_SET_OF
,
269 offsetof(NSS_P12_SafeBag
,bagAttrs
),
270 kSecAsn1AttributeTemplate
},
274 const SecAsn1Template NSS_P12_SafeContentsTemplate
[] = {
275 { SEC_ASN1_SEQUENCE_OF
,
276 offsetof(NSS_P12_SafeContents
, bags
),
277 NSS_P12_SafeBagTemplate
,
278 sizeof(NSS_P12_SafeContents
) }
281 const SecAsn1Template NSS_P12_PBE_ParamsTemplate
[] = {
283 0, NULL
, sizeof(NSS_P12_PBE_Params
) },
284 { SEC_ASN1_OCTET_STRING
,
285 offsetof(NSS_P12_PBE_Params
,salt
) },
286 /* iterations is unsigned - right? */
288 offsetof(NSS_P12_PBE_Params
,iterations
) },