security/nss/lib/smime/cmsasn1.c

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 /* This Source Code Form is subject to the terms of the Mozilla Public
     2  * License, v. 2.0. If a copy of the MPL was not distributed with this
     3  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     5 /*
     6  * CMS ASN.1 templates
     7  */
     9 #include "cmslocal.h"
    11 #include "cert.h"
    12 #include "key.h"
    13 #include "secasn1.h"
    14 #include "secitem.h"
    15 #include "secoid.h"
    16 #include "prtime.h"
    17 #include "secerr.h"
    20 extern const SEC_ASN1Template nss_cms_set_of_attribute_template[];
    22 SEC_ASN1_MKSUB(CERT_IssuerAndSNTemplate)
    23 SEC_ASN1_MKSUB(CERT_SetOfSignedCrlTemplate)
    24 SEC_ASN1_MKSUB(SECOID_AlgorithmIDTemplate)
    25 SEC_ASN1_MKSUB(SEC_BitStringTemplate)
    26 SEC_ASN1_MKSUB(SEC_OctetStringTemplate)
    27 SEC_ASN1_MKSUB(SEC_PointerToOctetStringTemplate)
    28 SEC_ASN1_MKSUB(SEC_SetOfAnyTemplate)
    30 /* -----------------------------------------------------------------------------
    31  * MESSAGE
    32  * (uses NSSCMSContentInfo)
    33  */
    35 /* forward declaration */
    36 static const SEC_ASN1Template *
    37 nss_cms_choose_content_template(void *src_or_dest, PRBool encoding);
    39 static const SEC_ASN1TemplateChooserPtr nss_cms_chooser
    40 	= nss_cms_choose_content_template;
    42 const SEC_ASN1Template NSSCMSMessageTemplate[] = {
    43     { SEC_ASN1_SEQUENCE | SEC_ASN1_MAY_STREAM,
    44 	  0, NULL, sizeof(NSSCMSMessage) },
    45     { SEC_ASN1_OBJECT_ID,
    46 	  offsetof(NSSCMSMessage,contentInfo.contentType) },
    47     { SEC_ASN1_OPTIONAL | SEC_ASN1_DYNAMIC | SEC_ASN1_MAY_STREAM
    48      | SEC_ASN1_EXPLICIT | SEC_ASN1_CONSTRUCTED | SEC_ASN1_CONTEXT_SPECIFIC | 0,
    49 	  offsetof(NSSCMSMessage,contentInfo.content),
    50 	  &nss_cms_chooser },
    51     { 0 }
    52 };
    54 static const SEC_ASN1Template NSS_PointerToCMSMessageTemplate[] = {
    55     { SEC_ASN1_POINTER, 0, NSSCMSMessageTemplate }
    56 };
    58 /* -----------------------------------------------------------------------------
    59  * ENCAPSULATED & ENCRYPTED CONTENTINFO
    60  * (both use a NSSCMSContentInfo)
    61  */
    62 static const SEC_ASN1Template NSSCMSEncapsulatedContentInfoTemplate[] = {
    63     { SEC_ASN1_SEQUENCE | SEC_ASN1_MAY_STREAM,
    64 	  0, NULL, sizeof(NSSCMSContentInfo) },
    65     { SEC_ASN1_OBJECT_ID,
    66 	  offsetof(NSSCMSContentInfo,contentType) },
    67     { SEC_ASN1_OPTIONAL | SEC_ASN1_EXPLICIT | SEC_ASN1_MAY_STREAM |
    68 	SEC_ASN1_CONSTRUCTED | SEC_ASN1_CONTEXT_SPECIFIC | SEC_ASN1_XTRN | 0,
    69 	  offsetof(NSSCMSContentInfo,rawContent),
    70 	  SEC_ASN1_SUB(SEC_PointerToOctetStringTemplate) },
    71     { 0 }
    72 };
    74 static const SEC_ASN1Template NSSCMSEncryptedContentInfoTemplate[] = {
    75     { SEC_ASN1_SEQUENCE | SEC_ASN1_MAY_STREAM,
    76 	  0, NULL, sizeof(NSSCMSContentInfo) },
    77     { SEC_ASN1_OBJECT_ID,
    78 	  offsetof(NSSCMSContentInfo,contentType) },
    79     { SEC_ASN1_INLINE | SEC_ASN1_XTRN,
    80 	  offsetof(NSSCMSContentInfo,contentEncAlg),
    81 	  SEC_ASN1_SUB(SECOID_AlgorithmIDTemplate) },
    82     { SEC_ASN1_OPTIONAL | SEC_ASN1_POINTER | SEC_ASN1_MAY_STREAM | 
    83       SEC_ASN1_CONTEXT_SPECIFIC | SEC_ASN1_XTRN | 0,
    84 	  offsetof(NSSCMSContentInfo,rawContent),
    85 	  SEC_ASN1_SUB(SEC_OctetStringTemplate) },
    86     { 0 }
    87 };
    89 /* -----------------------------------------------------------------------------
    90  * SIGNED DATA
    91  */
    93 const SEC_ASN1Template NSSCMSSignerInfoTemplate[];
    95 const SEC_ASN1Template NSSCMSSignedDataTemplate[] = {
    96     { SEC_ASN1_SEQUENCE | SEC_ASN1_MAY_STREAM,
    97 	  0, NULL, sizeof(NSSCMSSignedData) },
    98     { SEC_ASN1_INTEGER,
    99 	  offsetof(NSSCMSSignedData,version) },
   100     { SEC_ASN1_SET_OF | SEC_ASN1_XTRN,
   101 	  offsetof(NSSCMSSignedData,digestAlgorithms),
   102 	  SEC_ASN1_SUB(SECOID_AlgorithmIDTemplate) },
   103     { SEC_ASN1_INLINE,
   104 	  offsetof(NSSCMSSignedData,contentInfo),
   105 	  NSSCMSEncapsulatedContentInfoTemplate },
   106     { SEC_ASN1_OPTIONAL | SEC_ASN1_CONSTRUCTED | SEC_ASN1_CONTEXT_SPECIFIC |
   107       SEC_ASN1_XTRN | 0,
   108 	  offsetof(NSSCMSSignedData,rawCerts),
   109 	  SEC_ASN1_SUB(SEC_SetOfAnyTemplate) },
   110     { SEC_ASN1_OPTIONAL | SEC_ASN1_CONSTRUCTED | SEC_ASN1_CONTEXT_SPECIFIC |
   111       SEC_ASN1_XTRN | 1,
   112 	  offsetof(NSSCMSSignedData,crls),
   113 	  SEC_ASN1_SUB(CERT_SetOfSignedCrlTemplate) },
   114     { SEC_ASN1_SET_OF,
   115 	  offsetof(NSSCMSSignedData,signerInfos),
   116 	  NSSCMSSignerInfoTemplate },
   117     { 0 }
   118 };
   120 const SEC_ASN1Template NSS_PointerToCMSSignedDataTemplate[] = {
   121     { SEC_ASN1_POINTER, 0, NSSCMSSignedDataTemplate }
   122 };
   124 /* -----------------------------------------------------------------------------
   125  * signeridentifier
   126  */
   128 static const SEC_ASN1Template NSSCMSSignerIdentifierTemplate[] = {
   129     { SEC_ASN1_CHOICE,
   130 	  offsetof(NSSCMSSignerIdentifier,identifierType), NULL,
   131 	  sizeof(NSSCMSSignerIdentifier) },
   132     { SEC_ASN1_POINTER | SEC_ASN1_CONTEXT_SPECIFIC | SEC_ASN1_XTRN | 0,
   133 	  offsetof(NSSCMSSignerIdentifier,id.subjectKeyID),
   134 	  SEC_ASN1_SUB(SEC_OctetStringTemplate) ,
   135 	  NSSCMSRecipientID_SubjectKeyID },
   136     { SEC_ASN1_POINTER | SEC_ASN1_XTRN,
   137 	  offsetof(NSSCMSSignerIdentifier,id.issuerAndSN),
   138 	  SEC_ASN1_SUB(CERT_IssuerAndSNTemplate),
   139 	  NSSCMSRecipientID_IssuerSN },
   140     { 0 }
   141 };
   143 /* -----------------------------------------------------------------------------
   144  * signerinfo
   145  */
   147 const SEC_ASN1Template NSSCMSSignerInfoTemplate[] = {
   148     { SEC_ASN1_SEQUENCE,
   149 	  0, NULL, sizeof(NSSCMSSignerInfo) },
   150     { SEC_ASN1_INTEGER,
   151 	  offsetof(NSSCMSSignerInfo,version) },
   152     { SEC_ASN1_INLINE,
   153 	  offsetof(NSSCMSSignerInfo,signerIdentifier),
   154 	  NSSCMSSignerIdentifierTemplate },
   155     { SEC_ASN1_INLINE | SEC_ASN1_XTRN,
   156 	  offsetof(NSSCMSSignerInfo,digestAlg),
   157 	  SEC_ASN1_SUB(SECOID_AlgorithmIDTemplate) },
   158     { SEC_ASN1_OPTIONAL | SEC_ASN1_CONSTRUCTED | SEC_ASN1_CONTEXT_SPECIFIC | 0,
   159 	  offsetof(NSSCMSSignerInfo,authAttr),
   160 	  nss_cms_set_of_attribute_template },
   161     { SEC_ASN1_INLINE | SEC_ASN1_XTRN,
   162 	  offsetof(NSSCMSSignerInfo,digestEncAlg),
   163 	  SEC_ASN1_SUB(SECOID_AlgorithmIDTemplate) },
   164     { SEC_ASN1_OCTET_STRING,
   165 	  offsetof(NSSCMSSignerInfo,encDigest) },
   166     { SEC_ASN1_OPTIONAL | SEC_ASN1_CONSTRUCTED | SEC_ASN1_CONTEXT_SPECIFIC | 1,
   167 	  offsetof(NSSCMSSignerInfo,unAuthAttr),
   168 	  nss_cms_set_of_attribute_template },
   169     { 0 }
   170 };
   172 /* -----------------------------------------------------------------------------
   173  * ENVELOPED DATA
   174  */
   176 static const SEC_ASN1Template NSSCMSOriginatorInfoTemplate[] = {
   177     { SEC_ASN1_SEQUENCE,
   178 	  0, NULL, sizeof(NSSCMSOriginatorInfo) },
   179     { SEC_ASN1_OPTIONAL | SEC_ASN1_CONSTRUCTED | SEC_ASN1_CONTEXT_SPECIFIC |
   180       SEC_ASN1_XTRN | 0,
   181 	  offsetof(NSSCMSOriginatorInfo,rawCerts),
   182 	  SEC_ASN1_SUB(SEC_SetOfAnyTemplate) },
   183     { SEC_ASN1_OPTIONAL | SEC_ASN1_CONSTRUCTED | SEC_ASN1_CONTEXT_SPECIFIC |
   184       SEC_ASN1_XTRN | 1,
   185 	  offsetof(NSSCMSOriginatorInfo,crls),
   186 	  SEC_ASN1_SUB(CERT_SetOfSignedCrlTemplate) },
   187     { 0 }
   188 };
   190 const SEC_ASN1Template NSSCMSRecipientInfoTemplate[];
   192 const SEC_ASN1Template NSSCMSEnvelopedDataTemplate[] = {
   193     { SEC_ASN1_SEQUENCE | SEC_ASN1_MAY_STREAM,
   194 	  0, NULL, sizeof(NSSCMSEnvelopedData) },
   195     { SEC_ASN1_INTEGER,
   196 	  offsetof(NSSCMSEnvelopedData,version) },
   197     { SEC_ASN1_OPTIONAL | SEC_ASN1_POINTER | SEC_ASN1_CONSTRUCTED | SEC_ASN1_CONTEXT_SPECIFIC | 0,
   198 	  offsetof(NSSCMSEnvelopedData,originatorInfo),
   199 	  NSSCMSOriginatorInfoTemplate },
   200     { SEC_ASN1_SET_OF,
   201 	  offsetof(NSSCMSEnvelopedData,recipientInfos),
   202 	  NSSCMSRecipientInfoTemplate },
   203     { SEC_ASN1_INLINE,
   204 	  offsetof(NSSCMSEnvelopedData,contentInfo),
   205 	  NSSCMSEncryptedContentInfoTemplate },
   206     { SEC_ASN1_OPTIONAL | SEC_ASN1_CONSTRUCTED | SEC_ASN1_CONTEXT_SPECIFIC | 1,
   207 	  offsetof(NSSCMSEnvelopedData,unprotectedAttr),
   208 	  nss_cms_set_of_attribute_template },
   209     { 0 }
   210 };
   212 const SEC_ASN1Template NSS_PointerToCMSEnvelopedDataTemplate[] = {
   213     { SEC_ASN1_POINTER, 0, NSSCMSEnvelopedDataTemplate }
   214 };
   216 /* here come the 15 gazillion templates for all the v3 varieties of RecipientInfo */
   218 /* -----------------------------------------------------------------------------
   219  * key transport recipient info
   220  */
   222 static const SEC_ASN1Template NSSCMSRecipientIdentifierTemplate[] = {
   223     { SEC_ASN1_CHOICE,
   224 	  offsetof(NSSCMSRecipientIdentifier,identifierType), NULL,
   225 	  sizeof(NSSCMSRecipientIdentifier) },
   226     { SEC_ASN1_POINTER | SEC_ASN1_CONTEXT_SPECIFIC | SEC_ASN1_XTRN | 0,
   227 	  offsetof(NSSCMSRecipientIdentifier,id.subjectKeyID),
   228 	  SEC_ASN1_SUB(SEC_OctetStringTemplate) ,
   229 	  NSSCMSRecipientID_SubjectKeyID },
   230     { SEC_ASN1_POINTER | SEC_ASN1_XTRN,
   231 	  offsetof(NSSCMSRecipientIdentifier,id.issuerAndSN),
   232 	  SEC_ASN1_SUB(CERT_IssuerAndSNTemplate),
   233 	  NSSCMSRecipientID_IssuerSN },
   234     { 0 }
   235 };
   238 static const SEC_ASN1Template NSSCMSKeyTransRecipientInfoTemplate[] = {
   239     { SEC_ASN1_SEQUENCE,
   240 	  0, NULL, sizeof(NSSCMSKeyTransRecipientInfo) },
   241     { SEC_ASN1_INTEGER,
   242 	  offsetof(NSSCMSKeyTransRecipientInfo,version) },
   243     { SEC_ASN1_INLINE,
   244 	  offsetof(NSSCMSKeyTransRecipientInfo,recipientIdentifier),
   245 	  NSSCMSRecipientIdentifierTemplate },
   246     { SEC_ASN1_INLINE | SEC_ASN1_XTRN,
   247 	  offsetof(NSSCMSKeyTransRecipientInfo,keyEncAlg),
   248 	  SEC_ASN1_SUB(SECOID_AlgorithmIDTemplate) },
   249     { SEC_ASN1_OCTET_STRING,
   250 	  offsetof(NSSCMSKeyTransRecipientInfo,encKey) },
   251     { 0 }
   252 };
   254 /* -----------------------------------------------------------------------------
   255  * key agreement recipient info
   256  */
   258 static const SEC_ASN1Template NSSCMSOriginatorPublicKeyTemplate[] = {
   259     { SEC_ASN1_SEQUENCE,
   260 	  0, NULL, sizeof(NSSCMSOriginatorPublicKey) },
   261     { SEC_ASN1_INLINE | SEC_ASN1_XTRN,
   262 	  offsetof(NSSCMSOriginatorPublicKey,algorithmIdentifier),
   263 	  SEC_ASN1_SUB(SECOID_AlgorithmIDTemplate) },
   264     { SEC_ASN1_INLINE | SEC_ASN1_XTRN,
   265 	  offsetof(NSSCMSOriginatorPublicKey,publicKey),
   266 	  SEC_ASN1_SUB(SEC_BitStringTemplate) },
   267     { 0 }
   268 };
   271 static const SEC_ASN1Template NSSCMSOriginatorIdentifierOrKeyTemplate[] = {
   272     { SEC_ASN1_CHOICE,
   273 	  offsetof(NSSCMSOriginatorIdentifierOrKey,identifierType), NULL,
   274 	  sizeof(NSSCMSOriginatorIdentifierOrKey) },
   275     { SEC_ASN1_POINTER | SEC_ASN1_XTRN,
   276 	  offsetof(NSSCMSOriginatorIdentifierOrKey,id.issuerAndSN),
   277 	  SEC_ASN1_SUB(CERT_IssuerAndSNTemplate),
   278 	  NSSCMSOriginatorIDOrKey_IssuerSN },
   279     { SEC_ASN1_EXPLICIT | SEC_ASN1_CONSTRUCTED | SEC_ASN1_CONTEXT_SPECIFIC |
   280       SEC_ASN1_XTRN | 1,
   281 	  offsetof(NSSCMSOriginatorIdentifierOrKey,id.subjectKeyID),
   282 	  SEC_ASN1_SUB(SEC_PointerToOctetStringTemplate) ,
   283 	  NSSCMSOriginatorIDOrKey_SubjectKeyID },
   284     { SEC_ASN1_EXPLICIT | SEC_ASN1_CONSTRUCTED | SEC_ASN1_CONTEXT_SPECIFIC | 2,
   285 	  offsetof(NSSCMSOriginatorIdentifierOrKey,id.originatorPublicKey),
   286 	  NSSCMSOriginatorPublicKeyTemplate,
   287 	  NSSCMSOriginatorIDOrKey_OriginatorPublicKey },
   288     { 0 }
   289 };
   291 const SEC_ASN1Template NSSCMSRecipientKeyIdentifierTemplate[] = {
   292     { SEC_ASN1_SEQUENCE,
   293 	  0, NULL, sizeof(NSSCMSRecipientKeyIdentifier) },
   294     { SEC_ASN1_OCTET_STRING,
   295 	  offsetof(NSSCMSRecipientKeyIdentifier,subjectKeyIdentifier) },
   296     { SEC_ASN1_OPTIONAL | SEC_ASN1_OCTET_STRING,
   297 	  offsetof(NSSCMSRecipientKeyIdentifier,date) },
   298     { SEC_ASN1_OPTIONAL | SEC_ASN1_OCTET_STRING,
   299 	  offsetof(NSSCMSRecipientKeyIdentifier,other) },
   300     { 0 }
   301 };
   304 static const SEC_ASN1Template NSSCMSKeyAgreeRecipientIdentifierTemplate[] = {
   305     { SEC_ASN1_CHOICE,
   306 	  offsetof(NSSCMSKeyAgreeRecipientIdentifier,identifierType), NULL,
   307 	  sizeof(NSSCMSKeyAgreeRecipientIdentifier) },
   308     { SEC_ASN1_POINTER | SEC_ASN1_XTRN,
   309 	  offsetof(NSSCMSKeyAgreeRecipientIdentifier,id.issuerAndSN),
   310 	  SEC_ASN1_SUB(CERT_IssuerAndSNTemplate),
   311 	  NSSCMSKeyAgreeRecipientID_IssuerSN },
   312     { SEC_ASN1_CONSTRUCTED | SEC_ASN1_CONTEXT_SPECIFIC | 0,
   313 	  offsetof(NSSCMSKeyAgreeRecipientIdentifier,id.recipientKeyIdentifier),
   314 	  NSSCMSRecipientKeyIdentifierTemplate,
   315 	  NSSCMSKeyAgreeRecipientID_RKeyID },
   316     { 0 }
   317 };
   319 static const SEC_ASN1Template NSSCMSRecipientEncryptedKeyTemplate[] = {
   320     { SEC_ASN1_SEQUENCE,
   321 	  0, NULL, sizeof(NSSCMSRecipientEncryptedKey) },
   322     { SEC_ASN1_INLINE,
   323 	  offsetof(NSSCMSRecipientEncryptedKey,recipientIdentifier),
   324 	  NSSCMSKeyAgreeRecipientIdentifierTemplate },
   325     { SEC_ASN1_INLINE | SEC_ASN1_XTRN,
   326 	  offsetof(NSSCMSRecipientEncryptedKey,encKey),
   327 	  SEC_ASN1_SUB(SEC_BitStringTemplate) },
   328     { 0 }
   329 };
   331 static const SEC_ASN1Template NSSCMSKeyAgreeRecipientInfoTemplate[] = {
   332     { SEC_ASN1_SEQUENCE,
   333 	  0, NULL, sizeof(NSSCMSKeyAgreeRecipientInfo) },
   334     { SEC_ASN1_INTEGER,
   335 	  offsetof(NSSCMSKeyAgreeRecipientInfo,version) },
   336     { SEC_ASN1_EXPLICIT | SEC_ASN1_CONSTRUCTED | SEC_ASN1_CONTEXT_SPECIFIC | 0,
   337 	  offsetof(NSSCMSKeyAgreeRecipientInfo,originatorIdentifierOrKey),
   338 	  NSSCMSOriginatorIdentifierOrKeyTemplate },
   339     { SEC_ASN1_OPTIONAL | SEC_ASN1_CONSTRUCTED | SEC_ASN1_EXPLICIT |
   340       SEC_ASN1_CONTEXT_SPECIFIC | SEC_ASN1_XTRN | 1,
   341 	  offsetof(NSSCMSKeyAgreeRecipientInfo,ukm),
   342 	  SEC_ASN1_SUB(SEC_OctetStringTemplate) },
   343     { SEC_ASN1_INLINE | SEC_ASN1_XTRN,
   344 	  offsetof(NSSCMSKeyAgreeRecipientInfo,keyEncAlg),
   345 	  SEC_ASN1_SUB(SECOID_AlgorithmIDTemplate) },
   346     { SEC_ASN1_SEQUENCE_OF,
   347 	  offsetof(NSSCMSKeyAgreeRecipientInfo,recipientEncryptedKeys),
   348 	  NSSCMSRecipientEncryptedKeyTemplate },
   349     { 0 }
   350 };
   352 /* -----------------------------------------------------------------------------
   353  * KEK recipient info
   354  */
   356 static const SEC_ASN1Template NSSCMSKEKIdentifierTemplate[] = {
   357     { SEC_ASN1_SEQUENCE,
   358 	  0, NULL, sizeof(NSSCMSKEKIdentifier) },
   359     { SEC_ASN1_OCTET_STRING,
   360 	  offsetof(NSSCMSKEKIdentifier,keyIdentifier) },
   361     { SEC_ASN1_OPTIONAL | SEC_ASN1_OCTET_STRING,
   362 	  offsetof(NSSCMSKEKIdentifier,date) },
   363     { SEC_ASN1_OPTIONAL | SEC_ASN1_OCTET_STRING,
   364 	  offsetof(NSSCMSKEKIdentifier,other) },
   365     { 0 }
   366 };
   368 static const SEC_ASN1Template NSSCMSKEKRecipientInfoTemplate[] = {
   369     { SEC_ASN1_SEQUENCE,
   370 	  0, NULL, sizeof(NSSCMSKEKRecipientInfo) },
   371     { SEC_ASN1_INTEGER,
   372 	  offsetof(NSSCMSKEKRecipientInfo,version) },
   373     { SEC_ASN1_INLINE,
   374 	  offsetof(NSSCMSKEKRecipientInfo,kekIdentifier),
   375 	  NSSCMSKEKIdentifierTemplate },
   376     { SEC_ASN1_INLINE | SEC_ASN1_XTRN,
   377 	  offsetof(NSSCMSKEKRecipientInfo,keyEncAlg),
   378 	  SEC_ASN1_SUB(SECOID_AlgorithmIDTemplate) },
   379     { SEC_ASN1_OCTET_STRING,
   380 	  offsetof(NSSCMSKEKRecipientInfo,encKey) },
   381     { 0 }
   382 };
   384 /* -----------------------------------------------------------------------------
   385  * recipient info
   386  */
   387 const SEC_ASN1Template NSSCMSRecipientInfoTemplate[] = {
   388     { SEC_ASN1_CHOICE,
   389 	  offsetof(NSSCMSRecipientInfo,recipientInfoType), NULL,
   390 	  sizeof(NSSCMSRecipientInfo) },
   391     { SEC_ASN1_EXPLICIT | SEC_ASN1_CONSTRUCTED | SEC_ASN1_CONTEXT_SPECIFIC | 1,
   392 	  offsetof(NSSCMSRecipientInfo,ri.keyAgreeRecipientInfo),
   393 	  NSSCMSKeyAgreeRecipientInfoTemplate,
   394 	  NSSCMSRecipientInfoID_KeyAgree },
   395     { SEC_ASN1_EXPLICIT | SEC_ASN1_CONSTRUCTED | SEC_ASN1_CONTEXT_SPECIFIC | 2,
   396 	  offsetof(NSSCMSRecipientInfo,ri.kekRecipientInfo),
   397 	  NSSCMSKEKRecipientInfoTemplate,
   398 	  NSSCMSRecipientInfoID_KEK },
   399     { SEC_ASN1_INLINE,
   400 	  offsetof(NSSCMSRecipientInfo,ri.keyTransRecipientInfo),
   401 	  NSSCMSKeyTransRecipientInfoTemplate,
   402 	  NSSCMSRecipientInfoID_KeyTrans },
   403     { 0 }
   404 };
   406 /* -----------------------------------------------------------------------------
   407  *
   408  */
   410 const SEC_ASN1Template NSSCMSDigestedDataTemplate[] = {
   411     { SEC_ASN1_SEQUENCE | SEC_ASN1_MAY_STREAM,
   412 	  0, NULL, sizeof(NSSCMSDigestedData) },
   413     { SEC_ASN1_INTEGER,
   414 	  offsetof(NSSCMSDigestedData,version) },
   415     { SEC_ASN1_INLINE | SEC_ASN1_XTRN,
   416 	  offsetof(NSSCMSDigestedData,digestAlg),
   417 	  SEC_ASN1_SUB(SECOID_AlgorithmIDTemplate) },
   418     { SEC_ASN1_INLINE,
   419 	  offsetof(NSSCMSDigestedData,contentInfo),
   420 	  NSSCMSEncapsulatedContentInfoTemplate },
   421     { SEC_ASN1_OCTET_STRING,
   422 	  offsetof(NSSCMSDigestedData,digest) },
   423     { 0 }
   424 };
   426 const SEC_ASN1Template NSS_PointerToCMSDigestedDataTemplate[] = {
   427     { SEC_ASN1_POINTER, 0, NSSCMSDigestedDataTemplate }
   428 };
   430 const SEC_ASN1Template NSSCMSEncryptedDataTemplate[] = {
   431     { SEC_ASN1_SEQUENCE | SEC_ASN1_MAY_STREAM,
   432 	  0, NULL, sizeof(NSSCMSEncryptedData) },
   433     { SEC_ASN1_INTEGER,
   434 	  offsetof(NSSCMSEncryptedData,version) },
   435     { SEC_ASN1_INLINE,
   436 	  offsetof(NSSCMSEncryptedData,contentInfo),
   437 	  NSSCMSEncryptedContentInfoTemplate },
   438     { SEC_ASN1_OPTIONAL | SEC_ASN1_CONSTRUCTED | SEC_ASN1_CONTEXT_SPECIFIC | 1,
   439 	  offsetof(NSSCMSEncryptedData,unprotectedAttr),
   440 	  nss_cms_set_of_attribute_template },
   441     { 0 }
   442 };
   444 const SEC_ASN1Template NSS_PointerToCMSEncryptedDataTemplate[] = {
   445     { SEC_ASN1_POINTER, 0, NSSCMSEncryptedDataTemplate }
   446 };
   448 const SEC_ASN1Template NSSCMSGenericWrapperDataTemplate[] = {
   449     { SEC_ASN1_INLINE,
   450 	  offsetof(NSSCMSGenericWrapperData,contentInfo),
   451 	  NSSCMSEncapsulatedContentInfoTemplate },
   452 };
   454 SEC_ASN1_CHOOSER_IMPLEMENT(NSSCMSGenericWrapperDataTemplate)
   456 const SEC_ASN1Template NSS_PointerToCMSGenericWrapperDataTemplate[] = {
   457     { SEC_ASN1_POINTER, 0, NSSCMSGenericWrapperDataTemplate }
   458 };
   460 SEC_ASN1_CHOOSER_IMPLEMENT(NSS_PointerToCMSGenericWrapperDataTemplate)
   462 /* -----------------------------------------------------------------------------
   463  *
   464  */
   465 static const SEC_ASN1Template *
   466 nss_cms_choose_content_template(void *src_or_dest, PRBool encoding)
   467 {
   468     const SEC_ASN1Template *theTemplate;
   469     NSSCMSContentInfo *cinfo;
   470     SECOidTag type;
   472     PORT_Assert (src_or_dest != NULL);
   473     if (src_or_dest == NULL)
   474 	return NULL;
   476     cinfo = (NSSCMSContentInfo *)src_or_dest;
   477     type = NSS_CMSContentInfo_GetContentTypeTag(cinfo);
   478     switch (type) {
   479     default:
   480 	theTemplate = NSS_CMSType_GetTemplate(type);
   481 	break;
   482     case SEC_OID_PKCS7_DATA:
   483 	theTemplate = SEC_ASN1_GET(SEC_PointerToOctetStringTemplate);
   484 	break;
   485     case SEC_OID_PKCS7_SIGNED_DATA:
   486 	theTemplate = NSS_PointerToCMSSignedDataTemplate;
   487 	break;
   488     case SEC_OID_PKCS7_ENVELOPED_DATA:
   489 	theTemplate = NSS_PointerToCMSEnvelopedDataTemplate;
   490 	break;
   491     case SEC_OID_PKCS7_DIGESTED_DATA:
   492 	theTemplate = NSS_PointerToCMSDigestedDataTemplate;
   493 	break;
   494     case SEC_OID_PKCS7_ENCRYPTED_DATA:
   495 	theTemplate = NSS_PointerToCMSEncryptedDataTemplate;
   496 	break;
   497     }
   498     return theTemplate;
   499 }

mercurial