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@
27 #include "pkcs7Templates.h"
28 #include <Security/keyTemplates.h> /* NSS_AlgorithmIDTemplate */
29 #include <Security/SecAsn1Templates.h>
30 #include <security_asn1/nssUtils.h>
31 #include "pkcs12Utils.h"
32 #include <Security/oidsattr.h>
34 const SecAsn1Template NSS_P7_DigestInfoTemplate
[] = {
36 0, NULL
, sizeof(NSS_P7_DigestInfo
) },
38 offsetof(NSS_P7_DigestInfo
,digestAlgorithm
),
39 kSecAsn1AlgorithmIDTemplate
},
40 { SEC_ASN1_OCTET_STRING
,
41 offsetof(NSS_P7_DigestInfo
,digest
) },
46 * Uninterpreted ContentInfo, with content stripped from its
47 * EXPLICIT CONTEXT_SPECIFIC wrapper
49 const SecAsn1Template NSS_P7_RawContentInfoTemplate
[] = {
51 0, NULL
, sizeof(NSS_P7_RawContentInfo
) },
53 offsetof(NSS_P7_RawContentInfo
,contentType
) },
54 { SEC_ASN1_CONTEXT_SPECIFIC
| SEC_ASN1_EXPLICIT
|
55 SEC_ASN1_CONSTRUCTED
| SEC_ASN1_OPTIONAL
| 0,
56 offsetof(NSS_P7_RawContentInfo
,content
),
57 kSecAsn1AnyTemplate
},
62 * Individual ContentInfo.content templates
64 const SecAsn1Template NSS_P7_EncrContentInfoTemplate
[] = {
66 0, NULL
, sizeof(NSS_P7_EncrContentInfo
) },
68 offsetof(NSS_P7_EncrContentInfo
,contentType
) },
70 offsetof(NSS_P7_EncrContentInfo
,encrAlg
),
71 kSecAsn1AlgorithmIDTemplate
},
72 { SEC_ASN1_CONTEXT_SPECIFIC
| SEC_ASN1_OPTIONAL
| 0,
73 offsetof(NSS_P7_EncrContentInfo
,encrContent
),
74 kSecAsn1OctetStringTemplate
},
78 const SecAsn1Template NSS_P7_EncryptedDataTemplate
[] = {
80 0, NULL
, sizeof(NSS_P7_EncryptedData
) },
82 offsetof(NSS_P7_EncryptedData
,version
) },
84 offsetof(NSS_P7_EncryptedData
,contentInfo
),
85 NSS_P7_EncrContentInfoTemplate
},
89 const SecAsn1Template NSS_P7_PtrToEncryptedDataTemplate
[] = {
90 { SEC_ASN1_POINTER
, 0, NSS_P7_EncryptedDataTemplate
}
94 * Decoded ContentInfo via SEC_ASN1_DYNAMIC
97 static const SecAsn1Template
* NSS_P7_ContentInfoChooser(
98 void *arg
, // --> NSS_P7_DecodedContentInfo
100 const char *buf
, // on decode, tag byte and length
102 void *dest
) // --> NSS_P7_DecodedContentInfo.content
104 NSS_P7_DecodedContentInfo
*dci
=
105 (NSS_P7_DecodedContentInfo
*)arg
;
106 const SecAsn1Template
*templ
= NULL
;
107 NSS_P7_CI_Type type
= CT_None
;
109 if(nssCompareCssmData(&dci
->contentType
,
110 &CSSMOID_PKCS7_Data
)) {
111 templ
= kSecAsn1PointerToOctetStringTemplate
;
114 else if(nssCompareCssmData(&dci
->contentType
,
115 &CSSMOID_PKCS7_EncryptedData
)) {
116 templ
= NSS_P7_PtrToEncryptedDataTemplate
;
117 type
= CT_EncryptedData
;
119 else if(nssCompareCssmData(&dci
->contentType
,
120 &CSSMOID_PKCS7_SignedData
)) {
121 templ
= NSS_P7_PtrToSignedDataTemplate
;
122 type
= CT_SignedData
;
124 else if(nssCompareCssmData(&dci
->contentType
,
125 &CSSMOID_PKCS7_EnvelopedData
)) {
126 templ
= NSS_P7_PtrToEnvelDataTemplate
;
129 else if(nssCompareCssmData(&dci
->contentType
,
130 &CSSMOID_PKCS7_SignedAndEnvelopedData
)) {
131 templ
= NSS_P7_PtrToSignEnvelDataTemplate
;
132 type
= CT_SignedEnvData
;
134 else if(nssCompareCssmData(&dci
->contentType
,
135 &CSSMOID_PKCS7_DigestedData
)) {
136 templ
= NSS_P7_PtrToDigestedDataTemplate
;
137 type
= CT_DigestData
;
139 /* add more here when we implement them */
141 return kSecAsn1PointerToAnyTemplate
;
149 static const SecAsn1TemplateChooserPtr NSS_P7_ContentInfoChooserPtr
=
150 NSS_P7_ContentInfoChooser
;
152 const SecAsn1Template NSS_P7_DecodedContentInfoTemplate
[] = {
154 0, NULL
, sizeof(NSS_P7_DecodedContentInfo
) },
155 { SEC_ASN1_OBJECT_ID
,
156 offsetof(NSS_P7_DecodedContentInfo
,contentType
) },
157 { SEC_ASN1_OPTIONAL
| SEC_ASN1_DYNAMIC
|
158 SEC_ASN1_EXPLICIT
| SEC_ASN1_CONSTRUCTED
|
159 SEC_ASN1_CONTEXT_SPECIFIC
| 0,
160 offsetof(NSS_P7_DecodedContentInfo
,content
),
161 &NSS_P7_ContentInfoChooserPtr
},