2 * Copyright (c) 2003-2004,2011,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@
26 *******************************************************************
28 * In a probably vain attempt to clarify the structure of a PKCS12
29 * PFX, here is a high-level summary.
31 * The top level item in P12 is a PFX.
35 * ContentInfo authSafe; -- from PKCS7
36 * MacData mac; -- optional, password integrity version
39 * The authSafe in a PFX has two legal contentTypes in the P12
40 * world, CT_Data (password integrity mode) or CT_SignedData
41 * (public key integrity mode). The current version of this library
42 * only supports password integrity mode. Thus the integrity of
43 * the whole authSafe item is protected by a MAC in the PFX.
45 * The authSafe.content field is a BER-encoded AuthenticatedSafe.
47 * AuthenticatedSafe = {
48 * SEQUENCE OF ContentInfo;
51 * OK. Each ContentInfo in an AuthenticatedSafe can either be type
52 * CT_Data, CT_EnvData, or CT_EncryptedData. In the latter cases the
53 * content is decrypted to produce an encoded SafeContents; in the
54 * former case the content *is* an encoded SafeContents.
56 * A SafeContents is a sequence of SafeBags.
58 * Each SafeBag can be of several types:
69 #ifndef _PKCS12_TEMPLATES_H_
70 #define _PKCS12_TEMPLATES_H_
72 #include <Security/secasn1t.h>
73 #include <Security/keyTemplates.h> /* for NSS_Attribute */
74 #include <Security/cssmtype.h>
75 #include "pkcs7Templates.h" /* will be lib-specific place */
82 * MacData ::= SEQUENCE {
84 * macSalt OCTET STRING,
85 * iterations INTEGER DEFAULT 1
89 NSS_P7_DigestInfo mac
;
91 CSSM_DATA iterations
; // optional
94 extern const SecAsn1Template NSS_P12_MacDataTemplate
[];
98 * version INTEGER {v3(3)}(v3,...),
99 * authSafe ContentInfo,
100 * macData MacData OPTIONAL
105 * First the top level PFX with unparsed ContentInfo.content.
109 NSS_P7_RawContentInfo authSafe
;
110 NSS_P12_MacData
*macData
;
113 extern const SecAsn1Template NSS_P12_RawPFXTemplate
[];
116 * And a PFX with a decoded ContentInfo.content.
120 NSS_P7_DecodedContentInfo authSafe
;
121 NSS_P12_MacData
*macData
;
122 } NSS_P12_DecodedPFX
;
124 extern const SecAsn1Template NSS_P12_DecodedPFXTemplate
[];
127 * The CSSMOID_PKCS7_Data-style ContentInfo.content of a PFX
128 * contains an encoded AuthenticatedSafe.
130 * AuthenticatedSafe ::= SEQUENCE OF ContentInfo
131 * -- Data if unencrypted
132 * -- EncryptedData if password-encrypted
133 * -- EnvelopedData if public key-encrypted
136 NSS_P7_DecodedContentInfo
**info
;
137 } NSS_P12_AuthenticatedSafe
;
139 extern const SecAsn1Template NSS_P12_AuthenticatedSafeTemplate
[];
142 * Individual BagTypes.
145 typedef CSSM_DATA NSS_P12_KeyBag
;
146 typedef NSS_EncryptedPrivateKeyInfo NSS_P12_ShroudedKeyBag
;
147 typedef CSSM_DATA NSS_P12_SecretBag
;
148 typedef CSSM_DATA NSS_P12_SafeContentsBag
;
153 * CertBag ::= SEQUENCE {
154 * certId BAG-TYPE.&id ({CertTypes}),
155 * certValue [0] EXPLICIT BAG-TYPE.&Type ({CertTypes}{@certId})
158 * x509Certificate BAG-TYPE ::=
159 * {OCTET STRING IDENTIFIED BY {certTypes 1}}
160 * -- DER-encoded X.509 certificate stored in OCTET STRING
161 * sdsiCertificate BAG-TYPE ::=
162 * {IA5String IDENTIFIED BY {certTypes 2}}
163 * -- Base64-encoded SDSI certificate stored in IA5String
166 CT_Unknown
, // --> ASN_ANY
169 } NSS_P12_CertBagType
;
173 NSS_P12_CertBagType type
;
177 extern const SecAsn1Template NSS_P12_CertBagTemplate
[];
182 * CRLBag ::= SEQUENCE {
183 * certId BAG-TYPE.&id ({CertTypes}),
184 * certValue [0] EXPLICIT BAG-TYPE.&Type ({CertTypes}{@certId})
187 * x509Certificate BAG-TYPE ::=
188 * {OCTET STRING IDENTIFIED BY {certTypes 1}}
189 * -- DER-encoded X.509 certificate stored in OCTET STRING
190 * sdsiCertificate BAG-TYPE ::=
191 * {IA5String IDENTIFIED BY {certTypes 2}}
192 * -- Base64-encoded SDSI certificate stored in IA5String
195 CRT_Unknown
, // --> ASN_ANY
197 } NSS_P12_CrlBagType
;
201 NSS_P12_CrlBagType type
;
205 extern const SecAsn1Template NSS_P12_CrlBagTemplate
[];
208 * BagId OIDs map to one of these for convenience. Our dynamic
209 * template chooser drops one of these into NSS_P12_SafeBag.type
223 * The ContentInfo.content values of each element in
224 * an AuthenticatedSafe map to a sequence of these - either directly
225 * (contentType CSSMOID_PKCS7_Data, octet string contents are
226 * the DER encoding of this) or indirectly (encrypted or
227 * shrouded, the decrypted content is the DER encoding of this).
231 NSS_P12_SB_Type type
;
233 NSS_P12_KeyBag
*keyBag
;
234 NSS_P12_ShroudedKeyBag
*shroudedKeyBag
;
235 NSS_P12_CertBag
*certBag
;
236 NSS_P12_CrlBag
*crlBag
;
237 NSS_P12_SecretBag
*secretBag
;
238 NSS_P12_SafeContentsBag
*safeContentsBag
;
240 NSS_Attribute
**bagAttrs
; // optional
243 extern const SecAsn1Template NSS_P12_SafeBagTemplate
[];
246 * SafeContents, the contents of an element in an AuthenticatedSafe.
249 NSS_P12_SafeBag
**bags
;
251 NSS_P12_SafeContents
;
253 extern const SecAsn1Template NSS_P12_SafeContentsTemplate
[];
256 * PKCS12-specific algorithm parameters.
257 * A DER encoded version of this is the parameters value of
258 * a CSSM_X509_ALGORITHM_IDENTIFIER used in a
259 * NSS_P7_EncrContentInfo.encrAlg in P12 password privacy mode.
261 * pkcs-12PbeParams ::= SEQUENCE {
266 * NOTE the P12 spec does place a limit on the value of iterations.
267 * I guess we have to assume in actual usage that it's
268 * restricted to (0..MAX), i.e., uint32-sized.
270 * We're also assuming that it is explicitly an unsigned value,
271 * so that the value bytes in the encoding of 0xff would be
276 CSSM_DATA iterations
;
277 } NSS_P12_PBE_Params
;
279 extern const SecAsn1Template NSS_P12_PBE_ParamsTemplate
[];
285 #endif /* _PKCS12_TEMPLATES_H_ */