2 * The contents of this file are subject to the Mozilla Public
3 * License Version 1.1 (the "License"); you may not use this file
4 * except in compliance with the License. You may obtain a copy of
5 * the License at http://www.mozilla.org/MPL/
7 * Software distributed under the License is distributed on an "AS
8 * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
9 * implied. See the License for the specific language governing
10 * rights and limitations under the License.
12 * The Original Code is the Netscape security libraries.
14 * The Initial Developer of the Original Code is Netscape
15 * Communications Corporation. Portions created by Netscape are
16 * Copyright (C) 1994-2000 Netscape Communications Corporation. All
21 * Alternatively, the contents of this file may be used under the
22 * terms of the GNU General Public License Version 2 or later (the
23 * "GPL"), in which case the provisions of the GPL are applicable
24 * instead of those above. If you wish to allow use of your
25 * version of this file only under the terms of the GPL and not to
26 * allow others to use your version of this file under the MPL,
27 * indicate your decision by deleting the provisions above and
28 * replace them with the notice and other provisions required by
29 * the GPL. If you do not delete the provisions above, a recipient
30 * may use your version of this file under either the MPL or the
38 #include <Security/SecCmsContentInfo.h>
43 #include <security_asn1/secasn1.h>
44 #include <security_asn1/secerr.h>
47 extern const SecAsn1Template nss_cms_set_of_attribute_template
[];
49 //SEC_ASN1_MKSUB(CERT_IssuerAndSNTemplate)
50 //SEC_ASN1_MKSUB(CERT_SetOfSignedCrlTemplate)
51 SEC_ASN1_MKSUB(SECOID_AlgorithmIDTemplate
)
52 SEC_ASN1_MKSUB(kSecAsn1BitStringTemplate
)
53 SEC_ASN1_MKSUB(kSecAsn1OctetStringTemplate
)
54 SEC_ASN1_MKSUB(kSecAsn1PointerToOctetStringTemplate
)
55 SEC_ASN1_MKSUB(kSecAsn1SetOfAnyTemplate
)
57 /* -----------------------------------------------------------------------------
59 * (uses SecCmsContentInfo)
62 /* forward declaration */
63 static const SecAsn1Template
*
64 nss_cms_choose_content_template(void *src_or_dest
, Boolean encoding
, const char *buf
, size_t len
, void *dest
);
66 static const SecAsn1TemplateChooserPtr nss_cms_chooser
67 = nss_cms_choose_content_template
;
69 const SecAsn1Template SecCmsMessageTemplate
[] = {
70 { SEC_ASN1_SEQUENCE
| SEC_ASN1_MAY_STREAM
,
71 0, NULL
, sizeof(SecCmsMessage
) },
73 offsetof(SecCmsMessage
,contentInfo
.contentType
) },
74 { SEC_ASN1_OPTIONAL
| SEC_ASN1_DYNAMIC
| SEC_ASN1_MAY_STREAM
75 | SEC_ASN1_EXPLICIT
| SEC_ASN1_CONSTRUCTED
| SEC_ASN1_CONTEXT_SPECIFIC
| 0,
76 offsetof(SecCmsMessage
,contentInfo
.content
),
82 static const SecAsn1Template NSS_PointerToCMSMessageTemplate
[] = {
83 { SEC_ASN1_POINTER
, 0, SecCmsMessageTemplate
}
87 /* -----------------------------------------------------------------------------
88 * ENCAPSULATED & ENCRYPTED CONTENTINFO
89 * (both use a SecCmsContentInfo)
91 static const SecAsn1Template SecCmsEncapsulatedContentInfoTemplate
[] = {
92 { SEC_ASN1_SEQUENCE
| SEC_ASN1_MAY_STREAM
,
93 0, NULL
, sizeof(SecCmsContentInfo
) },
95 offsetof(SecCmsContentInfo
,contentType
) },
96 { SEC_ASN1_OPTIONAL
| SEC_ASN1_EXPLICIT
| SEC_ASN1_MAY_STREAM
|
97 SEC_ASN1_CONSTRUCTED
| SEC_ASN1_CONTEXT_SPECIFIC
| SEC_ASN1_XTRN
| 0,
98 offsetof(SecCmsContentInfo
,rawContent
),
99 SEC_ASN1_SUB(kSecAsn1PointerToOctetStringTemplate
) },
103 static const SecAsn1Template SecCmsEncryptedContentInfoTemplate
[] = {
104 { SEC_ASN1_SEQUENCE
| SEC_ASN1_MAY_STREAM
,
105 0, NULL
, sizeof(SecCmsContentInfo
) },
106 { SEC_ASN1_OBJECT_ID
,
107 offsetof(SecCmsContentInfo
,contentType
) },
108 { SEC_ASN1_INLINE
| SEC_ASN1_XTRN
,
109 offsetof(SecCmsContentInfo
,contentEncAlg
),
110 SEC_ASN1_SUB(SECOID_AlgorithmIDTemplate
) },
111 { SEC_ASN1_OPTIONAL
| SEC_ASN1_POINTER
| SEC_ASN1_MAY_STREAM
|
112 SEC_ASN1_CONTEXT_SPECIFIC
| SEC_ASN1_XTRN
| 0,
113 offsetof(SecCmsContentInfo
,rawContent
),
114 SEC_ASN1_SUB(kSecAsn1OctetStringTemplate
) },
118 /* -----------------------------------------------------------------------------
122 const SecAsn1Template SecCmsSignerInfoTemplate
[];
125 const SecAsn1Template SecCmsSignedDataTemplate
[] = {
126 { SEC_ASN1_SEQUENCE
| SEC_ASN1_MAY_STREAM
,
127 0, NULL
, sizeof(SecCmsSignedData
) },
128 { SEC_ASN1_INTEGER
| SEC_ASN1_SIGNED_INT
,
129 offsetof(SecCmsSignedData
,version
) },
130 { SEC_ASN1_SET_OF
| SEC_ASN1_XTRN
,
131 offsetof(SecCmsSignedData
,digestAlgorithms
),
132 SEC_ASN1_SUB(SECOID_AlgorithmIDTemplate
) },
134 offsetof(SecCmsSignedData
,contentInfo
),
135 SecCmsEncapsulatedContentInfoTemplate
},
136 { SEC_ASN1_OPTIONAL
| SEC_ASN1_CONSTRUCTED
| SEC_ASN1_CONTEXT_SPECIFIC
|
138 offsetof(SecCmsSignedData
,rawCerts
),
139 SEC_ASN1_SUB(kSecAsn1SetOfAnyTemplate
) },
140 { SEC_ASN1_OPTIONAL
| SEC_ASN1_CONSTRUCTED
| SEC_ASN1_CONTEXT_SPECIFIC
|
142 offsetof(SecCmsSignedData
,rawCrls
),
143 SEC_ASN1_SUB(kSecAsn1SetOfAnyTemplate
) },
145 offsetof(SecCmsSignedData
,signerInfos
),
146 SecCmsSignerInfoTemplate
},
150 const SecAsn1Template NSS_PointerToCMSSignedDataTemplate
[] = {
151 { SEC_ASN1_POINTER
, 0, SecCmsSignedDataTemplate
}
154 /* -----------------------------------------------------------------------------
158 static const SecAsn1Template SecCmsSignerIdentifierTemplate
[] = {
160 offsetof(SecCmsSignerIdentifier
,identifierType
), NULL
,
161 sizeof(SecCmsSignerIdentifier
) },
162 { SEC_ASN1_POINTER
| SEC_ASN1_CONTEXT_SPECIFIC
| SEC_ASN1_XTRN
| 0,
163 offsetof(SecCmsSignerIdentifier
,id
.subjectKeyID
),
164 SEC_ASN1_SUB(kSecAsn1OctetStringTemplate
) ,
165 SecCmsRecipientIDSubjectKeyID
},
166 { SEC_ASN1_POINTER
| SEC_ASN1_XTRN
,
167 offsetof(SecCmsSignerIdentifier
,id
.issuerAndSN
),
168 SEC_ASN1_SUB(SecCmsIssuerAndSNTemplate
),
169 SecCmsRecipientIDIssuerSN
},
173 /* -----------------------------------------------------------------------------
177 const SecAsn1Template SecCmsSignerInfoTemplate
[] = {
179 0, NULL
, sizeof(SecCmsSignerInfo
) },
180 { SEC_ASN1_INTEGER
| SEC_ASN1_SIGNED_INT
,
181 offsetof(SecCmsSignerInfo
,version
) },
183 offsetof(SecCmsSignerInfo
,signerIdentifier
),
184 SecCmsSignerIdentifierTemplate
},
185 { SEC_ASN1_INLINE
| SEC_ASN1_XTRN
,
186 offsetof(SecCmsSignerInfo
,digestAlg
),
187 SEC_ASN1_SUB(SECOID_AlgorithmIDTemplate
) },
188 { SEC_ASN1_OPTIONAL
| SEC_ASN1_CONSTRUCTED
| SEC_ASN1_CONTEXT_SPECIFIC
| 0,
189 offsetof(SecCmsSignerInfo
,authAttr
),
190 nss_cms_set_of_attribute_template
},
191 { SEC_ASN1_INLINE
| SEC_ASN1_XTRN
,
192 offsetof(SecCmsSignerInfo
,digestEncAlg
),
193 SEC_ASN1_SUB(SECOID_AlgorithmIDTemplate
) },
194 { SEC_ASN1_OCTET_STRING
,
195 offsetof(SecCmsSignerInfo
,encDigest
) },
196 { SEC_ASN1_OPTIONAL
| SEC_ASN1_CONSTRUCTED
| SEC_ASN1_CONTEXT_SPECIFIC
| 1,
197 offsetof(SecCmsSignerInfo
,unAuthAttr
),
198 nss_cms_set_of_attribute_template
},
202 /* -----------------------------------------------------------------------------
206 static const SecAsn1Template SecCmsOriginatorInfoTemplate
[] = {
208 0, NULL
, sizeof(SecCmsOriginatorInfo
) },
209 { SEC_ASN1_OPTIONAL
| SEC_ASN1_CONSTRUCTED
| SEC_ASN1_CONTEXT_SPECIFIC
|
211 offsetof(SecCmsOriginatorInfo
,rawCerts
),
212 SEC_ASN1_SUB(kSecAsn1SetOfAnyTemplate
) },
213 { SEC_ASN1_OPTIONAL
| SEC_ASN1_CONSTRUCTED
| SEC_ASN1_CONTEXT_SPECIFIC
|
215 offsetof(SecCmsOriginatorInfo
,rawCrls
),
216 SEC_ASN1_SUB(kSecAsn1SetOfAnyTemplate
) },
220 const SecAsn1Template SecCmsRecipientInfoTemplate
[];
222 const SecAsn1Template SecCmsEnvelopedDataTemplate
[] = {
223 { SEC_ASN1_SEQUENCE
| SEC_ASN1_MAY_STREAM
,
224 0, NULL
, sizeof(SecCmsEnvelopedData
) },
225 { SEC_ASN1_INTEGER
| SEC_ASN1_SIGNED_INT
,
226 offsetof(SecCmsEnvelopedData
,version
) },
227 { SEC_ASN1_OPTIONAL
| SEC_ASN1_POINTER
| SEC_ASN1_CONSTRUCTED
| SEC_ASN1_CONTEXT_SPECIFIC
| 0,
228 offsetof(SecCmsEnvelopedData
,originatorInfo
),
229 SecCmsOriginatorInfoTemplate
},
231 offsetof(SecCmsEnvelopedData
,recipientInfos
),
232 SecCmsRecipientInfoTemplate
},
234 offsetof(SecCmsEnvelopedData
,contentInfo
),
235 SecCmsEncryptedContentInfoTemplate
},
236 { SEC_ASN1_OPTIONAL
| SEC_ASN1_CONSTRUCTED
| SEC_ASN1_CONTEXT_SPECIFIC
| 1,
237 offsetof(SecCmsEnvelopedData
,unprotectedAttr
),
238 nss_cms_set_of_attribute_template
},
242 const SecAsn1Template NSS_PointerToCMSEnvelopedDataTemplate
[] = {
243 { SEC_ASN1_POINTER
, 0, SecCmsEnvelopedDataTemplate
}
246 /* here come the 15 gazillion templates for all the v3 varieties of RecipientInfo */
248 /* -----------------------------------------------------------------------------
249 * key transport recipient info
252 static const SecAsn1Template SecCmsRecipientIdentifierTemplate
[] = {
254 offsetof(SecCmsRecipientIdentifier
,identifierType
), NULL
,
255 sizeof(SecCmsRecipientIdentifier
) },
256 { SEC_ASN1_POINTER
| SEC_ASN1_CONTEXT_SPECIFIC
| SEC_ASN1_XTRN
| 0,
257 offsetof(SecCmsRecipientIdentifier
,id
.subjectKeyID
),
258 SEC_ASN1_SUB(kSecAsn1OctetStringTemplate
) ,
259 SecCmsRecipientIDSubjectKeyID
},
260 { SEC_ASN1_POINTER
| SEC_ASN1_XTRN
,
261 offsetof(SecCmsRecipientIdentifier
,id
.issuerAndSN
),
262 SEC_ASN1_SUB(SecCmsIssuerAndSNTemplate
),
263 SecCmsRecipientIDIssuerSN
},
268 static const SecAsn1Template SecCmsKeyTransRecipientInfoTemplate
[] = {
270 0, NULL
, sizeof(SecCmsKeyTransRecipientInfo
) },
271 { SEC_ASN1_INTEGER
| SEC_ASN1_SIGNED_INT
,
272 offsetof(SecCmsKeyTransRecipientInfo
,version
) },
274 offsetof(SecCmsKeyTransRecipientInfo
,recipientIdentifier
),
275 SecCmsRecipientIdentifierTemplate
},
276 { SEC_ASN1_INLINE
| SEC_ASN1_XTRN
,
277 offsetof(SecCmsKeyTransRecipientInfo
,keyEncAlg
),
278 SEC_ASN1_SUB(SECOID_AlgorithmIDTemplate
) },
279 { SEC_ASN1_OCTET_STRING
,
280 offsetof(SecCmsKeyTransRecipientInfo
,encKey
) },
284 /* -----------------------------------------------------------------------------
285 * key agreement recipient info
288 static const SecAsn1Template SecCmsOriginatorPublicKeyTemplate
[] = {
290 0, NULL
, sizeof(SecCmsOriginatorPublicKey
) },
291 { SEC_ASN1_INLINE
| SEC_ASN1_XTRN
,
292 offsetof(SecCmsOriginatorPublicKey
,algorithmIdentifier
),
293 SEC_ASN1_SUB(SECOID_AlgorithmIDTemplate
) },
294 { SEC_ASN1_INLINE
| SEC_ASN1_XTRN
,
295 offsetof(SecCmsOriginatorPublicKey
,publicKey
),
296 SEC_ASN1_SUB(kSecAsn1BitStringTemplate
) },
301 static const SecAsn1Template SecCmsOriginatorIdentifierOrKeyTemplate
[] = {
303 offsetof(SecCmsOriginatorIdentifierOrKey
,identifierType
), NULL
,
304 sizeof(SecCmsOriginatorIdentifierOrKey
) },
305 { SEC_ASN1_POINTER
| SEC_ASN1_XTRN
,
306 offsetof(SecCmsOriginatorIdentifierOrKey
,id
.issuerAndSN
),
307 SEC_ASN1_SUB(SecCmsIssuerAndSNTemplate
),
308 SecCmsOriginatorIDOrKeyIssuerSN
},
309 { SEC_ASN1_EXPLICIT
| SEC_ASN1_CONSTRUCTED
| SEC_ASN1_CONTEXT_SPECIFIC
|
310 /* this was tag 1 here, 2 for the next; RFC 3852 says they are 0 and 1 */
312 offsetof(SecCmsOriginatorIdentifierOrKey
,id
.subjectKeyID
),
313 kSecAsn1OctetStringTemplate
,
314 SecCmsOriginatorIDOrKeySubjectKeyID
},
315 { SEC_ASN1_EXPLICIT
| SEC_ASN1_CONSTRUCTED
| SEC_ASN1_CONTEXT_SPECIFIC
| 1,
316 offsetof(SecCmsOriginatorIdentifierOrKey
,id
.originatorPublicKey
),
317 SecCmsOriginatorPublicKeyTemplate
,
318 SecCmsOriginatorIDOrKeyOriginatorPublicKey
},
322 const SecAsn1Template SecCmsRecipientKeyIdentifierTemplate
[] = {
324 0, NULL
, sizeof(SecCmsRecipientKeyIdentifier
) },
325 { SEC_ASN1_OCTET_STRING
,
326 offsetof(SecCmsRecipientKeyIdentifier
,subjectKeyIdentifier
) },
327 { SEC_ASN1_OPTIONAL
| SEC_ASN1_OCTET_STRING
,
328 offsetof(SecCmsRecipientKeyIdentifier
,date
) },
329 { SEC_ASN1_OPTIONAL
| SEC_ASN1_OCTET_STRING
,
330 offsetof(SecCmsRecipientKeyIdentifier
,other
) },
335 static const SecAsn1Template SecCmsKeyAgreeRecipientIdentifierTemplate
[] = {
337 offsetof(SecCmsKeyAgreeRecipientIdentifier
,identifierType
), NULL
,
338 sizeof(SecCmsKeyAgreeRecipientIdentifier
) },
339 { SEC_ASN1_POINTER
| SEC_ASN1_XTRN
,
340 offsetof(SecCmsKeyAgreeRecipientIdentifier
,id
.issuerAndSN
),
341 SEC_ASN1_SUB(SecCmsIssuerAndSNTemplate
),
342 SecCmsKeyAgreeRecipientIDIssuerSN
},
343 { SEC_ASN1_CONSTRUCTED
| SEC_ASN1_CONTEXT_SPECIFIC
| 0,
344 offsetof(SecCmsKeyAgreeRecipientIdentifier
,id
.recipientKeyIdentifier
),
345 SecCmsRecipientKeyIdentifierTemplate
,
346 SecCmsKeyAgreeRecipientIDRKeyID
},
350 static const SecAsn1Template SecCmsRecipientEncryptedKeyTemplate
[] = {
352 0, NULL
, sizeof(SecCmsRecipientEncryptedKey
) },
354 offsetof(SecCmsRecipientEncryptedKey
,recipientIdentifier
),
355 SecCmsKeyAgreeRecipientIdentifierTemplate
},
356 { SEC_ASN1_INLINE
| SEC_ASN1_XTRN
,
357 offsetof(SecCmsRecipientEncryptedKey
,encKey
),
358 SEC_ASN1_SUB(kSecAsn1OctetStringTemplate
) },
362 static const SecAsn1Template SecCmsKeyAgreeRecipientInfoTemplate
[] = {
364 0, NULL
, sizeof(SecCmsKeyAgreeRecipientInfo
) },
365 { SEC_ASN1_INTEGER
| SEC_ASN1_SIGNED_INT
,
366 offsetof(SecCmsKeyAgreeRecipientInfo
,version
) },
367 { SEC_ASN1_EXPLICIT
| SEC_ASN1_CONSTRUCTED
| SEC_ASN1_CONTEXT_SPECIFIC
| 0,
368 offsetof(SecCmsKeyAgreeRecipientInfo
,originatorIdentifierOrKey
),
369 SecCmsOriginatorIdentifierOrKeyTemplate
},
370 { SEC_ASN1_OPTIONAL
| SEC_ASN1_CONSTRUCTED
| SEC_ASN1_EXPLICIT
|
371 SEC_ASN1_CONTEXT_SPECIFIC
| SEC_ASN1_XTRN
| 1,
372 offsetof(SecCmsKeyAgreeRecipientInfo
,ukm
),
373 SEC_ASN1_SUB(kSecAsn1OctetStringTemplate
) },
374 { SEC_ASN1_INLINE
| SEC_ASN1_XTRN
,
375 offsetof(SecCmsKeyAgreeRecipientInfo
,keyEncAlg
),
376 SEC_ASN1_SUB(SECOID_AlgorithmIDTemplate
) },
377 { SEC_ASN1_SEQUENCE_OF
,
378 offsetof(SecCmsKeyAgreeRecipientInfo
,recipientEncryptedKeys
),
379 SecCmsRecipientEncryptedKeyTemplate
},
383 /* -----------------------------------------------------------------------------
387 static const SecAsn1Template SecCmsKEKIdentifierTemplate
[] = {
389 0, NULL
, sizeof(SecCmsKEKIdentifier
) },
390 { SEC_ASN1_OCTET_STRING
,
391 offsetof(SecCmsKEKIdentifier
,keyIdentifier
) },
392 { SEC_ASN1_OPTIONAL
| SEC_ASN1_OCTET_STRING
,
393 offsetof(SecCmsKEKIdentifier
,date
) },
394 { SEC_ASN1_OPTIONAL
| SEC_ASN1_OCTET_STRING
,
395 offsetof(SecCmsKEKIdentifier
,other
) },
399 static const SecAsn1Template SecCmsKEKRecipientInfoTemplate
[] = {
401 0, NULL
, sizeof(SecCmsKEKRecipientInfo
) },
402 { SEC_ASN1_INTEGER
| SEC_ASN1_SIGNED_INT
,
403 offsetof(SecCmsKEKRecipientInfo
,version
) },
405 offsetof(SecCmsKEKRecipientInfo
,kekIdentifier
),
406 SecCmsKEKIdentifierTemplate
},
407 { SEC_ASN1_INLINE
| SEC_ASN1_XTRN
,
408 offsetof(SecCmsKEKRecipientInfo
,keyEncAlg
),
409 SEC_ASN1_SUB(SECOID_AlgorithmIDTemplate
) },
410 { SEC_ASN1_OCTET_STRING
,
411 offsetof(SecCmsKEKRecipientInfo
,encKey
) },
415 /* -----------------------------------------------------------------------------
418 const SecAsn1Template SecCmsRecipientInfoTemplate
[] = {
420 offsetof(SecCmsRecipientInfo
,recipientInfoType
), NULL
,
421 sizeof(SecCmsRecipientInfo
) },
422 { SEC_ASN1_EXPLICIT
| SEC_ASN1_CONSTRUCTED
| SEC_ASN1_CONTEXT_SPECIFIC
| 1,
423 offsetof(SecCmsRecipientInfo
,ri
.keyAgreeRecipientInfo
),
424 SecCmsKeyAgreeRecipientInfoTemplate
,
425 SecCmsRecipientInfoIDKeyAgree
},
426 { SEC_ASN1_EXPLICIT
| SEC_ASN1_CONSTRUCTED
| SEC_ASN1_CONTEXT_SPECIFIC
| 2,
427 offsetof(SecCmsRecipientInfo
,ri
.kekRecipientInfo
),
428 SecCmsKEKRecipientInfoTemplate
,
429 SecCmsRecipientInfoIDKEK
},
431 offsetof(SecCmsRecipientInfo
,ri
.keyTransRecipientInfo
),
432 SecCmsKeyTransRecipientInfoTemplate
,
433 SecCmsRecipientInfoIDKeyTrans
},
437 /* -----------------------------------------------------------------------------
441 const SecAsn1Template SecCmsDigestedDataTemplate
[] = {
442 { SEC_ASN1_SEQUENCE
| SEC_ASN1_MAY_STREAM
,
443 0, NULL
, sizeof(SecCmsDigestedData
) },
444 { SEC_ASN1_INTEGER
| SEC_ASN1_SIGNED_INT
,
445 offsetof(SecCmsDigestedData
,version
) },
446 { SEC_ASN1_INLINE
| SEC_ASN1_XTRN
,
447 offsetof(SecCmsDigestedData
,digestAlg
),
448 SEC_ASN1_SUB(SECOID_AlgorithmIDTemplate
) },
450 offsetof(SecCmsDigestedData
,contentInfo
),
451 SecCmsEncapsulatedContentInfoTemplate
},
452 { SEC_ASN1_OCTET_STRING
,
453 offsetof(SecCmsDigestedData
,digest
) },
457 const SecAsn1Template NSS_PointerToCMSDigestedDataTemplate
[] = {
458 { SEC_ASN1_POINTER
, 0, SecCmsDigestedDataTemplate
}
461 const SecAsn1Template SecCmsEncryptedDataTemplate
[] = {
462 { SEC_ASN1_SEQUENCE
| SEC_ASN1_MAY_STREAM
,
463 0, NULL
, sizeof(SecCmsEncryptedData
) },
464 { SEC_ASN1_INTEGER
| SEC_ASN1_SIGNED_INT
,
465 offsetof(SecCmsEncryptedData
,version
) },
467 offsetof(SecCmsEncryptedData
,contentInfo
),
468 SecCmsEncryptedContentInfoTemplate
},
469 { SEC_ASN1_OPTIONAL
| SEC_ASN1_CONSTRUCTED
| SEC_ASN1_CONTEXT_SPECIFIC
| 1,
470 offsetof(SecCmsEncryptedData
,unprotectedAttr
),
471 nss_cms_set_of_attribute_template
},
475 const SecAsn1Template NSS_PointerToCMSEncryptedDataTemplate
[] = {
476 { SEC_ASN1_POINTER
, 0, SecCmsEncryptedDataTemplate
}
479 /* -----------------------------------------------------------------------------
480 * SetOfSignedCrlTemplate
482 const SecAsn1Template SecCmsIssuerAndSNTemplate
[] = {
484 0, NULL
, sizeof(SecCmsIssuerAndSN
) },
485 #if 1 // @@@ Switch to using NSS_NameTemplate
487 offsetof(SecCmsIssuerAndSN
,derIssuer
) },
490 offsetof(SecCmsIssuerAndSN
,issuer
),
493 { SEC_ASN1_INTEGER
| SEC_ASN1_SIGNED_INT
,
494 offsetof(SecCmsIssuerAndSN
,serialNumber
) },
499 /* -----------------------------------------------------------------------------
502 const SecAsn1Template NSS_SMIMEKEAParamTemplateSkipjack
[] = {
504 0, NULL
, sizeof(SecCmsSMIMEKEAParameters
) },
505 { SEC_ASN1_OCTET_STRING
/* | SEC_ASN1_OPTIONAL */,
506 offsetof(SecCmsSMIMEKEAParameters
,originatorKEAKey
) },
507 { SEC_ASN1_OCTET_STRING
,
508 offsetof(SecCmsSMIMEKEAParameters
,originatorRA
) },
512 const SecAsn1Template NSS_SMIMEKEAParamTemplateNoSkipjack
[] = {
514 0, NULL
, sizeof(SecCmsSMIMEKEAParameters
) },
515 { SEC_ASN1_OCTET_STRING
/* | SEC_ASN1_OPTIONAL */,
516 offsetof(SecCmsSMIMEKEAParameters
,originatorKEAKey
) },
517 { SEC_ASN1_OCTET_STRING
,
518 offsetof(SecCmsSMIMEKEAParameters
,originatorRA
) },
519 { SEC_ASN1_OCTET_STRING
| SEC_ASN1_OPTIONAL
,
520 offsetof(SecCmsSMIMEKEAParameters
,nonSkipjackIV
) },
524 const SecAsn1Template NSS_SMIMEKEAParamTemplateAllParams
[] = {
526 0, NULL
, sizeof(SecCmsSMIMEKEAParameters
) },
527 { SEC_ASN1_OCTET_STRING
/* | SEC_ASN1_OPTIONAL */,
528 offsetof(SecCmsSMIMEKEAParameters
,originatorKEAKey
) },
529 { SEC_ASN1_OCTET_STRING
,
530 offsetof(SecCmsSMIMEKEAParameters
,originatorRA
) },
531 { SEC_ASN1_OCTET_STRING
| SEC_ASN1_OPTIONAL
,
532 offsetof(SecCmsSMIMEKEAParameters
,nonSkipjackIV
) },
533 { SEC_ASN1_OCTET_STRING
| SEC_ASN1_OPTIONAL
,
534 offsetof(SecCmsSMIMEKEAParameters
,bulkKeySize
) },
538 /*TODO: this should be in some header */
539 const SecAsn1Template
*
540 nss_cms_get_kea_template(SecCmsKEATemplateSelector whichTemplate
);
541 const SecAsn1Template
*
542 nss_cms_get_kea_template(SecCmsKEATemplateSelector whichTemplate
)
544 const SecAsn1Template
*returnVal
= NULL
;
546 switch(whichTemplate
)
548 case SecCmsKEAUsesNonSkipjack
:
549 returnVal
= NSS_SMIMEKEAParamTemplateNoSkipjack
;
551 case SecCmsKEAUsesSkipjack
:
552 returnVal
= NSS_SMIMEKEAParamTemplateSkipjack
;
554 case SecCmsKEAUsesNonSkipjackWithPaddedEncKey
:
556 returnVal
= NSS_SMIMEKEAParamTemplateAllParams
;
562 /* -----------------------------------------------------------------------------
565 static const SecAsn1Template
*
566 nss_cms_choose_content_template(void *src_or_dest
, Boolean encoding
, const char *buf
, size_t len
, void *dest
)
568 const SecAsn1Template
*theTemplate
;
569 SecCmsContentInfoRef cinfo
;
571 PORT_Assert (src_or_dest
!= NULL
);
572 if (src_or_dest
== NULL
)
575 cinfo
= (SecCmsContentInfoRef
)src_or_dest
;
576 switch (SecCmsContentInfoGetContentTypeTag(cinfo
)) {
578 theTemplate
= SEC_ASN1_GET(kSecAsn1PointerToAnyTemplate
);
580 case SEC_OID_PKCS7_DATA
:
582 theTemplate
= SEC_ASN1_GET(kSecAsn1PointerToOctetStringTemplate
);
584 case SEC_OID_PKCS7_SIGNED_DATA
:
585 theTemplate
= NSS_PointerToCMSSignedDataTemplate
;
587 case SEC_OID_PKCS7_ENVELOPED_DATA
:
588 theTemplate
= NSS_PointerToCMSEnvelopedDataTemplate
;
590 case SEC_OID_PKCS7_DIGESTED_DATA
:
591 theTemplate
= NSS_PointerToCMSDigestedDataTemplate
;
593 case SEC_OID_PKCS7_ENCRYPTED_DATA
:
594 theTemplate
= NSS_PointerToCMSEncryptedDataTemplate
;