2012-10-01 22:02:15 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2008-06-06 16:40:11 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* CMS ASN.1 templates
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "cmslocal.h"
|
|
|
|
|
|
|
|
#include "cert.h"
|
2018-09-19 19:43:03 +03:00
|
|
|
#include "keyhi.h"
|
2008-06-06 16:40:11 +04:00
|
|
|
#include "secasn1.h"
|
|
|
|
#include "secitem.h"
|
|
|
|
#include "secoid.h"
|
|
|
|
#include "prtime.h"
|
|
|
|
#include "secerr.h"
|
|
|
|
|
|
|
|
extern const SEC_ASN1Template nss_cms_set_of_attribute_template[];
|
|
|
|
|
|
|
|
SEC_ASN1_MKSUB(CERT_IssuerAndSNTemplate)
|
|
|
|
SEC_ASN1_MKSUB(CERT_SetOfSignedCrlTemplate)
|
|
|
|
SEC_ASN1_MKSUB(SECOID_AlgorithmIDTemplate)
|
|
|
|
SEC_ASN1_MKSUB(SEC_BitStringTemplate)
|
|
|
|
SEC_ASN1_MKSUB(SEC_OctetStringTemplate)
|
|
|
|
SEC_ASN1_MKSUB(SEC_PointerToOctetStringTemplate)
|
|
|
|
SEC_ASN1_MKSUB(SEC_SetOfAnyTemplate)
|
|
|
|
|
|
|
|
/* -----------------------------------------------------------------------------
|
|
|
|
* MESSAGE
|
|
|
|
* (uses NSSCMSContentInfo)
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* forward declaration */
|
|
|
|
static const SEC_ASN1Template *
|
|
|
|
nss_cms_choose_content_template(void *src_or_dest, PRBool encoding);
|
|
|
|
|
2016-11-02 12:29:58 +03:00
|
|
|
static const SEC_ASN1TemplateChooserPtr nss_cms_chooser = nss_cms_choose_content_template;
|
2008-06-06 16:40:11 +04:00
|
|
|
|
|
|
|
const SEC_ASN1Template NSSCMSMessageTemplate[] = {
|
|
|
|
{ SEC_ASN1_SEQUENCE | SEC_ASN1_MAY_STREAM,
|
2016-11-02 12:29:58 +03:00
|
|
|
0, NULL, sizeof(NSSCMSMessage) },
|
2008-06-06 16:40:11 +04:00
|
|
|
{ SEC_ASN1_OBJECT_ID,
|
2016-11-02 12:29:58 +03:00
|
|
|
offsetof(NSSCMSMessage, contentInfo.contentType) },
|
|
|
|
{ SEC_ASN1_OPTIONAL | SEC_ASN1_DYNAMIC | SEC_ASN1_MAY_STREAM |
|
|
|
|
SEC_ASN1_EXPLICIT | SEC_ASN1_CONSTRUCTED | SEC_ASN1_CONTEXT_SPECIFIC | 0,
|
|
|
|
offsetof(NSSCMSMessage, contentInfo.content),
|
|
|
|
&nss_cms_chooser },
|
2008-06-06 16:40:11 +04:00
|
|
|
{ 0 }
|
|
|
|
};
|
|
|
|
|
|
|
|
/* -----------------------------------------------------------------------------
|
|
|
|
* ENCAPSULATED & ENCRYPTED CONTENTINFO
|
|
|
|
* (both use a NSSCMSContentInfo)
|
|
|
|
*/
|
|
|
|
static const SEC_ASN1Template NSSCMSEncapsulatedContentInfoTemplate[] = {
|
|
|
|
{ SEC_ASN1_SEQUENCE | SEC_ASN1_MAY_STREAM,
|
2016-11-02 12:29:58 +03:00
|
|
|
0, NULL, sizeof(NSSCMSContentInfo) },
|
2008-06-06 16:40:11 +04:00
|
|
|
{ SEC_ASN1_OBJECT_ID,
|
2016-11-02 12:29:58 +03:00
|
|
|
offsetof(NSSCMSContentInfo, contentType) },
|
2008-06-06 16:40:11 +04:00
|
|
|
{ SEC_ASN1_OPTIONAL | SEC_ASN1_EXPLICIT | SEC_ASN1_MAY_STREAM |
|
2016-11-02 12:29:58 +03:00
|
|
|
SEC_ASN1_CONSTRUCTED | SEC_ASN1_CONTEXT_SPECIFIC | SEC_ASN1_XTRN | 0,
|
|
|
|
offsetof(NSSCMSContentInfo, rawContent),
|
|
|
|
SEC_ASN1_SUB(SEC_PointerToOctetStringTemplate) },
|
2008-06-06 16:40:11 +04:00
|
|
|
{ 0 }
|
|
|
|
};
|
|
|
|
|
|
|
|
static const SEC_ASN1Template NSSCMSEncryptedContentInfoTemplate[] = {
|
|
|
|
{ SEC_ASN1_SEQUENCE | SEC_ASN1_MAY_STREAM,
|
2016-11-02 12:29:58 +03:00
|
|
|
0, NULL, sizeof(NSSCMSContentInfo) },
|
2008-06-06 16:40:11 +04:00
|
|
|
{ SEC_ASN1_OBJECT_ID,
|
2016-11-02 12:29:58 +03:00
|
|
|
offsetof(NSSCMSContentInfo, contentType) },
|
2008-06-06 16:40:11 +04:00
|
|
|
{ SEC_ASN1_INLINE | SEC_ASN1_XTRN,
|
2016-11-02 12:29:58 +03:00
|
|
|
offsetof(NSSCMSContentInfo, contentEncAlg),
|
|
|
|
SEC_ASN1_SUB(SECOID_AlgorithmIDTemplate) },
|
|
|
|
{ SEC_ASN1_OPTIONAL | SEC_ASN1_POINTER | SEC_ASN1_MAY_STREAM |
|
|
|
|
SEC_ASN1_CONTEXT_SPECIFIC | SEC_ASN1_XTRN | 0,
|
|
|
|
offsetof(NSSCMSContentInfo, rawContent),
|
|
|
|
SEC_ASN1_SUB(SEC_OctetStringTemplate) },
|
2008-06-06 16:40:11 +04:00
|
|
|
{ 0 }
|
|
|
|
};
|
|
|
|
|
|
|
|
/* -----------------------------------------------------------------------------
|
|
|
|
* SIGNED DATA
|
|
|
|
*/
|
|
|
|
|
|
|
|
const SEC_ASN1Template NSSCMSSignerInfoTemplate[];
|
|
|
|
|
|
|
|
const SEC_ASN1Template NSSCMSSignedDataTemplate[] = {
|
|
|
|
{ SEC_ASN1_SEQUENCE | SEC_ASN1_MAY_STREAM,
|
2016-11-02 12:29:58 +03:00
|
|
|
0, NULL, sizeof(NSSCMSSignedData) },
|
2008-06-06 16:40:11 +04:00
|
|
|
{ SEC_ASN1_INTEGER,
|
2016-11-02 12:29:58 +03:00
|
|
|
offsetof(NSSCMSSignedData, version) },
|
2008-06-06 16:40:11 +04:00
|
|
|
{ SEC_ASN1_SET_OF | SEC_ASN1_XTRN,
|
2016-11-02 12:29:58 +03:00
|
|
|
offsetof(NSSCMSSignedData, digestAlgorithms),
|
|
|
|
SEC_ASN1_SUB(SECOID_AlgorithmIDTemplate) },
|
2008-06-06 16:40:11 +04:00
|
|
|
{ SEC_ASN1_INLINE,
|
2016-11-02 12:29:58 +03:00
|
|
|
offsetof(NSSCMSSignedData, contentInfo),
|
|
|
|
NSSCMSEncapsulatedContentInfoTemplate },
|
2008-06-06 16:40:11 +04:00
|
|
|
{ SEC_ASN1_OPTIONAL | SEC_ASN1_CONSTRUCTED | SEC_ASN1_CONTEXT_SPECIFIC |
|
2016-11-02 12:29:58 +03:00
|
|
|
SEC_ASN1_XTRN | 0,
|
|
|
|
offsetof(NSSCMSSignedData, rawCerts),
|
|
|
|
SEC_ASN1_SUB(SEC_SetOfAnyTemplate) },
|
2008-06-06 16:40:11 +04:00
|
|
|
{ SEC_ASN1_OPTIONAL | SEC_ASN1_CONSTRUCTED | SEC_ASN1_CONTEXT_SPECIFIC |
|
2016-11-02 12:29:58 +03:00
|
|
|
SEC_ASN1_XTRN | 1,
|
|
|
|
offsetof(NSSCMSSignedData, crls),
|
|
|
|
SEC_ASN1_SUB(CERT_SetOfSignedCrlTemplate) },
|
2008-06-06 16:40:11 +04:00
|
|
|
{ SEC_ASN1_SET_OF,
|
2016-11-02 12:29:58 +03:00
|
|
|
offsetof(NSSCMSSignedData, signerInfos),
|
|
|
|
NSSCMSSignerInfoTemplate },
|
2008-06-06 16:40:11 +04:00
|
|
|
{ 0 }
|
|
|
|
};
|
|
|
|
|
|
|
|
const SEC_ASN1Template NSS_PointerToCMSSignedDataTemplate[] = {
|
|
|
|
{ SEC_ASN1_POINTER, 0, NSSCMSSignedDataTemplate }
|
|
|
|
};
|
|
|
|
|
|
|
|
/* -----------------------------------------------------------------------------
|
|
|
|
* signeridentifier
|
|
|
|
*/
|
|
|
|
|
|
|
|
static const SEC_ASN1Template NSSCMSSignerIdentifierTemplate[] = {
|
|
|
|
{ SEC_ASN1_CHOICE,
|
2016-11-02 12:29:58 +03:00
|
|
|
offsetof(NSSCMSSignerIdentifier, identifierType), NULL,
|
|
|
|
sizeof(NSSCMSSignerIdentifier) },
|
2008-06-06 16:40:11 +04:00
|
|
|
{ SEC_ASN1_POINTER | SEC_ASN1_CONTEXT_SPECIFIC | SEC_ASN1_XTRN | 0,
|
2016-11-02 12:29:58 +03:00
|
|
|
offsetof(NSSCMSSignerIdentifier, id.subjectKeyID),
|
|
|
|
SEC_ASN1_SUB(SEC_OctetStringTemplate),
|
|
|
|
NSSCMSRecipientID_SubjectKeyID },
|
2008-06-06 16:40:11 +04:00
|
|
|
{ SEC_ASN1_POINTER | SEC_ASN1_XTRN,
|
2016-11-02 12:29:58 +03:00
|
|
|
offsetof(NSSCMSSignerIdentifier, id.issuerAndSN),
|
|
|
|
SEC_ASN1_SUB(CERT_IssuerAndSNTemplate),
|
|
|
|
NSSCMSRecipientID_IssuerSN },
|
2008-06-06 16:40:11 +04:00
|
|
|
{ 0 }
|
|
|
|
};
|
|
|
|
|
|
|
|
/* -----------------------------------------------------------------------------
|
|
|
|
* signerinfo
|
|
|
|
*/
|
|
|
|
|
|
|
|
const SEC_ASN1Template NSSCMSSignerInfoTemplate[] = {
|
|
|
|
{ SEC_ASN1_SEQUENCE,
|
2016-11-02 12:29:58 +03:00
|
|
|
0, NULL, sizeof(NSSCMSSignerInfo) },
|
2008-06-06 16:40:11 +04:00
|
|
|
{ SEC_ASN1_INTEGER,
|
2016-11-02 12:29:58 +03:00
|
|
|
offsetof(NSSCMSSignerInfo, version) },
|
2008-06-06 16:40:11 +04:00
|
|
|
{ SEC_ASN1_INLINE,
|
2016-11-02 12:29:58 +03:00
|
|
|
offsetof(NSSCMSSignerInfo, signerIdentifier),
|
|
|
|
NSSCMSSignerIdentifierTemplate },
|
2008-06-06 16:40:11 +04:00
|
|
|
{ SEC_ASN1_INLINE | SEC_ASN1_XTRN,
|
2016-11-02 12:29:58 +03:00
|
|
|
offsetof(NSSCMSSignerInfo, digestAlg),
|
|
|
|
SEC_ASN1_SUB(SECOID_AlgorithmIDTemplate) },
|
2008-06-06 16:40:11 +04:00
|
|
|
{ SEC_ASN1_OPTIONAL | SEC_ASN1_CONSTRUCTED | SEC_ASN1_CONTEXT_SPECIFIC | 0,
|
2016-11-02 12:29:58 +03:00
|
|
|
offsetof(NSSCMSSignerInfo, authAttr),
|
|
|
|
nss_cms_set_of_attribute_template },
|
2008-06-06 16:40:11 +04:00
|
|
|
{ SEC_ASN1_INLINE | SEC_ASN1_XTRN,
|
2016-11-02 12:29:58 +03:00
|
|
|
offsetof(NSSCMSSignerInfo, digestEncAlg),
|
|
|
|
SEC_ASN1_SUB(SECOID_AlgorithmIDTemplate) },
|
2008-06-06 16:40:11 +04:00
|
|
|
{ SEC_ASN1_OCTET_STRING,
|
2016-11-02 12:29:58 +03:00
|
|
|
offsetof(NSSCMSSignerInfo, encDigest) },
|
2008-06-06 16:40:11 +04:00
|
|
|
{ SEC_ASN1_OPTIONAL | SEC_ASN1_CONSTRUCTED | SEC_ASN1_CONTEXT_SPECIFIC | 1,
|
2016-11-02 12:29:58 +03:00
|
|
|
offsetof(NSSCMSSignerInfo, unAuthAttr),
|
|
|
|
nss_cms_set_of_attribute_template },
|
2008-06-06 16:40:11 +04:00
|
|
|
{ 0 }
|
|
|
|
};
|
|
|
|
|
|
|
|
/* -----------------------------------------------------------------------------
|
|
|
|
* ENVELOPED DATA
|
|
|
|
*/
|
|
|
|
|
|
|
|
static const SEC_ASN1Template NSSCMSOriginatorInfoTemplate[] = {
|
|
|
|
{ SEC_ASN1_SEQUENCE,
|
2016-11-02 12:29:58 +03:00
|
|
|
0, NULL, sizeof(NSSCMSOriginatorInfo) },
|
2008-06-06 16:40:11 +04:00
|
|
|
{ SEC_ASN1_OPTIONAL | SEC_ASN1_CONSTRUCTED | SEC_ASN1_CONTEXT_SPECIFIC |
|
2016-11-02 12:29:58 +03:00
|
|
|
SEC_ASN1_XTRN | 0,
|
|
|
|
offsetof(NSSCMSOriginatorInfo, rawCerts),
|
|
|
|
SEC_ASN1_SUB(SEC_SetOfAnyTemplate) },
|
2008-06-06 16:40:11 +04:00
|
|
|
{ SEC_ASN1_OPTIONAL | SEC_ASN1_CONSTRUCTED | SEC_ASN1_CONTEXT_SPECIFIC |
|
2016-11-02 12:29:58 +03:00
|
|
|
SEC_ASN1_XTRN | 1,
|
|
|
|
offsetof(NSSCMSOriginatorInfo, crls),
|
|
|
|
SEC_ASN1_SUB(CERT_SetOfSignedCrlTemplate) },
|
2008-06-06 16:40:11 +04:00
|
|
|
{ 0 }
|
|
|
|
};
|
|
|
|
|
|
|
|
const SEC_ASN1Template NSSCMSRecipientInfoTemplate[];
|
|
|
|
|
|
|
|
const SEC_ASN1Template NSSCMSEnvelopedDataTemplate[] = {
|
|
|
|
{ SEC_ASN1_SEQUENCE | SEC_ASN1_MAY_STREAM,
|
2016-11-02 12:29:58 +03:00
|
|
|
0, NULL, sizeof(NSSCMSEnvelopedData) },
|
2008-06-06 16:40:11 +04:00
|
|
|
{ SEC_ASN1_INTEGER,
|
2016-11-02 12:29:58 +03:00
|
|
|
offsetof(NSSCMSEnvelopedData, version) },
|
|
|
|
{ SEC_ASN1_OPTIONAL | SEC_ASN1_POINTER | SEC_ASN1_CONSTRUCTED |
|
|
|
|
SEC_ASN1_CONTEXT_SPECIFIC | 0,
|
|
|
|
offsetof(NSSCMSEnvelopedData, originatorInfo),
|
|
|
|
NSSCMSOriginatorInfoTemplate },
|
2008-06-06 16:40:11 +04:00
|
|
|
{ SEC_ASN1_SET_OF,
|
2016-11-02 12:29:58 +03:00
|
|
|
offsetof(NSSCMSEnvelopedData, recipientInfos),
|
|
|
|
NSSCMSRecipientInfoTemplate },
|
2008-06-06 16:40:11 +04:00
|
|
|
{ SEC_ASN1_INLINE,
|
2016-11-02 12:29:58 +03:00
|
|
|
offsetof(NSSCMSEnvelopedData, contentInfo),
|
|
|
|
NSSCMSEncryptedContentInfoTemplate },
|
2008-06-06 16:40:11 +04:00
|
|
|
{ SEC_ASN1_OPTIONAL | SEC_ASN1_CONSTRUCTED | SEC_ASN1_CONTEXT_SPECIFIC | 1,
|
2016-11-02 12:29:58 +03:00
|
|
|
offsetof(NSSCMSEnvelopedData, unprotectedAttr),
|
|
|
|
nss_cms_set_of_attribute_template },
|
2008-06-06 16:40:11 +04:00
|
|
|
{ 0 }
|
|
|
|
};
|
|
|
|
|
|
|
|
const SEC_ASN1Template NSS_PointerToCMSEnvelopedDataTemplate[] = {
|
|
|
|
{ SEC_ASN1_POINTER, 0, NSSCMSEnvelopedDataTemplate }
|
|
|
|
};
|
|
|
|
|
|
|
|
/* here come the 15 gazillion templates for all the v3 varieties of RecipientInfo */
|
|
|
|
|
|
|
|
/* -----------------------------------------------------------------------------
|
|
|
|
* key transport recipient info
|
|
|
|
*/
|
|
|
|
|
|
|
|
static const SEC_ASN1Template NSSCMSRecipientIdentifierTemplate[] = {
|
|
|
|
{ SEC_ASN1_CHOICE,
|
2016-11-02 12:29:58 +03:00
|
|
|
offsetof(NSSCMSRecipientIdentifier, identifierType), NULL,
|
|
|
|
sizeof(NSSCMSRecipientIdentifier) },
|
2010-07-19 09:45:52 +04:00
|
|
|
{ SEC_ASN1_POINTER | SEC_ASN1_CONTEXT_SPECIFIC | SEC_ASN1_XTRN | 0,
|
2016-11-02 12:29:58 +03:00
|
|
|
offsetof(NSSCMSRecipientIdentifier, id.subjectKeyID),
|
|
|
|
SEC_ASN1_SUB(SEC_OctetStringTemplate),
|
|
|
|
NSSCMSRecipientID_SubjectKeyID },
|
2008-06-06 16:40:11 +04:00
|
|
|
{ SEC_ASN1_POINTER | SEC_ASN1_XTRN,
|
2016-11-02 12:29:58 +03:00
|
|
|
offsetof(NSSCMSRecipientIdentifier, id.issuerAndSN),
|
|
|
|
SEC_ASN1_SUB(CERT_IssuerAndSNTemplate),
|
|
|
|
NSSCMSRecipientID_IssuerSN },
|
2008-06-06 16:40:11 +04:00
|
|
|
{ 0 }
|
|
|
|
};
|
|
|
|
|
|
|
|
static const SEC_ASN1Template NSSCMSKeyTransRecipientInfoTemplate[] = {
|
|
|
|
{ SEC_ASN1_SEQUENCE,
|
2016-11-02 12:29:58 +03:00
|
|
|
0, NULL, sizeof(NSSCMSKeyTransRecipientInfo) },
|
2008-06-06 16:40:11 +04:00
|
|
|
{ SEC_ASN1_INTEGER,
|
2016-11-02 12:29:58 +03:00
|
|
|
offsetof(NSSCMSKeyTransRecipientInfo, version) },
|
2008-06-06 16:40:11 +04:00
|
|
|
{ SEC_ASN1_INLINE,
|
2016-11-02 12:29:58 +03:00
|
|
|
offsetof(NSSCMSKeyTransRecipientInfo, recipientIdentifier),
|
|
|
|
NSSCMSRecipientIdentifierTemplate },
|
2008-06-06 16:40:11 +04:00
|
|
|
{ SEC_ASN1_INLINE | SEC_ASN1_XTRN,
|
2016-11-02 12:29:58 +03:00
|
|
|
offsetof(NSSCMSKeyTransRecipientInfo, keyEncAlg),
|
|
|
|
SEC_ASN1_SUB(SECOID_AlgorithmIDTemplate) },
|
2008-06-06 16:40:11 +04:00
|
|
|
{ SEC_ASN1_OCTET_STRING,
|
2016-11-02 12:29:58 +03:00
|
|
|
offsetof(NSSCMSKeyTransRecipientInfo, encKey) },
|
2008-06-06 16:40:11 +04:00
|
|
|
{ 0 }
|
|
|
|
};
|
|
|
|
|
|
|
|
/* -----------------------------------------------------------------------------
|
|
|
|
* key agreement recipient info
|
|
|
|
*/
|
|
|
|
|
|
|
|
static const SEC_ASN1Template NSSCMSOriginatorPublicKeyTemplate[] = {
|
|
|
|
{ SEC_ASN1_SEQUENCE,
|
2016-11-02 12:29:58 +03:00
|
|
|
0, NULL, sizeof(NSSCMSOriginatorPublicKey) },
|
2008-06-06 16:40:11 +04:00
|
|
|
{ SEC_ASN1_INLINE | SEC_ASN1_XTRN,
|
2016-11-02 12:29:58 +03:00
|
|
|
offsetof(NSSCMSOriginatorPublicKey, algorithmIdentifier),
|
|
|
|
SEC_ASN1_SUB(SECOID_AlgorithmIDTemplate) },
|
2008-06-06 16:40:11 +04:00
|
|
|
{ SEC_ASN1_INLINE | SEC_ASN1_XTRN,
|
2016-11-02 12:29:58 +03:00
|
|
|
offsetof(NSSCMSOriginatorPublicKey, publicKey),
|
|
|
|
SEC_ASN1_SUB(SEC_BitStringTemplate) },
|
2008-06-06 16:40:11 +04:00
|
|
|
{ 0 }
|
|
|
|
};
|
|
|
|
|
|
|
|
static const SEC_ASN1Template NSSCMSOriginatorIdentifierOrKeyTemplate[] = {
|
|
|
|
{ SEC_ASN1_CHOICE,
|
2016-11-02 12:29:58 +03:00
|
|
|
offsetof(NSSCMSOriginatorIdentifierOrKey, identifierType), NULL,
|
|
|
|
sizeof(NSSCMSOriginatorIdentifierOrKey) },
|
2008-06-06 16:40:11 +04:00
|
|
|
{ SEC_ASN1_POINTER | SEC_ASN1_XTRN,
|
2016-11-02 12:29:58 +03:00
|
|
|
offsetof(NSSCMSOriginatorIdentifierOrKey, id.issuerAndSN),
|
|
|
|
SEC_ASN1_SUB(CERT_IssuerAndSNTemplate),
|
|
|
|
NSSCMSOriginatorIDOrKey_IssuerSN },
|
2008-06-06 16:40:11 +04:00
|
|
|
{ SEC_ASN1_EXPLICIT | SEC_ASN1_CONSTRUCTED | SEC_ASN1_CONTEXT_SPECIFIC |
|
2016-11-02 12:29:58 +03:00
|
|
|
SEC_ASN1_XTRN | 1,
|
|
|
|
offsetof(NSSCMSOriginatorIdentifierOrKey, id.subjectKeyID),
|
|
|
|
SEC_ASN1_SUB(SEC_PointerToOctetStringTemplate),
|
|
|
|
NSSCMSOriginatorIDOrKey_SubjectKeyID },
|
2008-06-06 16:40:11 +04:00
|
|
|
{ SEC_ASN1_EXPLICIT | SEC_ASN1_CONSTRUCTED | SEC_ASN1_CONTEXT_SPECIFIC | 2,
|
2016-11-02 12:29:58 +03:00
|
|
|
offsetof(NSSCMSOriginatorIdentifierOrKey, id.originatorPublicKey),
|
|
|
|
NSSCMSOriginatorPublicKeyTemplate,
|
|
|
|
NSSCMSOriginatorIDOrKey_OriginatorPublicKey },
|
2008-06-06 16:40:11 +04:00
|
|
|
{ 0 }
|
|
|
|
};
|
|
|
|
|
|
|
|
const SEC_ASN1Template NSSCMSRecipientKeyIdentifierTemplate[] = {
|
|
|
|
{ SEC_ASN1_SEQUENCE,
|
2016-11-02 12:29:58 +03:00
|
|
|
0, NULL, sizeof(NSSCMSRecipientKeyIdentifier) },
|
2008-06-06 16:40:11 +04:00
|
|
|
{ SEC_ASN1_OCTET_STRING,
|
2016-11-02 12:29:58 +03:00
|
|
|
offsetof(NSSCMSRecipientKeyIdentifier, subjectKeyIdentifier) },
|
2008-06-06 16:40:11 +04:00
|
|
|
{ SEC_ASN1_OPTIONAL | SEC_ASN1_OCTET_STRING,
|
2016-11-02 12:29:58 +03:00
|
|
|
offsetof(NSSCMSRecipientKeyIdentifier, date) },
|
2008-06-06 16:40:11 +04:00
|
|
|
{ SEC_ASN1_OPTIONAL | SEC_ASN1_OCTET_STRING,
|
2016-11-02 12:29:58 +03:00
|
|
|
offsetof(NSSCMSRecipientKeyIdentifier, other) },
|
2008-06-06 16:40:11 +04:00
|
|
|
{ 0 }
|
|
|
|
};
|
|
|
|
|
|
|
|
static const SEC_ASN1Template NSSCMSKeyAgreeRecipientIdentifierTemplate[] = {
|
|
|
|
{ SEC_ASN1_CHOICE,
|
2016-11-02 12:29:58 +03:00
|
|
|
offsetof(NSSCMSKeyAgreeRecipientIdentifier, identifierType), NULL,
|
|
|
|
sizeof(NSSCMSKeyAgreeRecipientIdentifier) },
|
2008-06-06 16:40:11 +04:00
|
|
|
{ SEC_ASN1_POINTER | SEC_ASN1_XTRN,
|
2016-11-02 12:29:58 +03:00
|
|
|
offsetof(NSSCMSKeyAgreeRecipientIdentifier, id.issuerAndSN),
|
|
|
|
SEC_ASN1_SUB(CERT_IssuerAndSNTemplate),
|
|
|
|
NSSCMSKeyAgreeRecipientID_IssuerSN },
|
2008-06-06 16:40:11 +04:00
|
|
|
{ SEC_ASN1_CONSTRUCTED | SEC_ASN1_CONTEXT_SPECIFIC | 0,
|
2016-11-02 12:29:58 +03:00
|
|
|
offsetof(NSSCMSKeyAgreeRecipientIdentifier, id.recipientKeyIdentifier),
|
|
|
|
NSSCMSRecipientKeyIdentifierTemplate,
|
|
|
|
NSSCMSKeyAgreeRecipientID_RKeyID },
|
2008-06-06 16:40:11 +04:00
|
|
|
{ 0 }
|
|
|
|
};
|
|
|
|
|
|
|
|
static const SEC_ASN1Template NSSCMSRecipientEncryptedKeyTemplate[] = {
|
|
|
|
{ SEC_ASN1_SEQUENCE,
|
2016-11-02 12:29:58 +03:00
|
|
|
0, NULL, sizeof(NSSCMSRecipientEncryptedKey) },
|
2008-06-06 16:40:11 +04:00
|
|
|
{ SEC_ASN1_INLINE,
|
2016-11-02 12:29:58 +03:00
|
|
|
offsetof(NSSCMSRecipientEncryptedKey, recipientIdentifier),
|
|
|
|
NSSCMSKeyAgreeRecipientIdentifierTemplate },
|
2008-06-06 16:40:11 +04:00
|
|
|
{ SEC_ASN1_INLINE | SEC_ASN1_XTRN,
|
2016-11-02 12:29:58 +03:00
|
|
|
offsetof(NSSCMSRecipientEncryptedKey, encKey),
|
|
|
|
SEC_ASN1_SUB(SEC_BitStringTemplate) },
|
2008-06-06 16:40:11 +04:00
|
|
|
{ 0 }
|
|
|
|
};
|
|
|
|
|
|
|
|
static const SEC_ASN1Template NSSCMSKeyAgreeRecipientInfoTemplate[] = {
|
|
|
|
{ SEC_ASN1_SEQUENCE,
|
2016-11-02 12:29:58 +03:00
|
|
|
0, NULL, sizeof(NSSCMSKeyAgreeRecipientInfo) },
|
2008-06-06 16:40:11 +04:00
|
|
|
{ SEC_ASN1_INTEGER,
|
2016-11-02 12:29:58 +03:00
|
|
|
offsetof(NSSCMSKeyAgreeRecipientInfo, version) },
|
2008-06-06 16:40:11 +04:00
|
|
|
{ SEC_ASN1_EXPLICIT | SEC_ASN1_CONSTRUCTED | SEC_ASN1_CONTEXT_SPECIFIC | 0,
|
2016-11-02 12:29:58 +03:00
|
|
|
offsetof(NSSCMSKeyAgreeRecipientInfo, originatorIdentifierOrKey),
|
|
|
|
NSSCMSOriginatorIdentifierOrKeyTemplate },
|
2008-06-06 16:40:11 +04:00
|
|
|
{ SEC_ASN1_OPTIONAL | SEC_ASN1_CONSTRUCTED | SEC_ASN1_EXPLICIT |
|
2016-11-02 12:29:58 +03:00
|
|
|
SEC_ASN1_CONTEXT_SPECIFIC | SEC_ASN1_XTRN | 1,
|
|
|
|
offsetof(NSSCMSKeyAgreeRecipientInfo, ukm),
|
|
|
|
SEC_ASN1_SUB(SEC_OctetStringTemplate) },
|
2008-06-06 16:40:11 +04:00
|
|
|
{ SEC_ASN1_INLINE | SEC_ASN1_XTRN,
|
2016-11-02 12:29:58 +03:00
|
|
|
offsetof(NSSCMSKeyAgreeRecipientInfo, keyEncAlg),
|
|
|
|
SEC_ASN1_SUB(SECOID_AlgorithmIDTemplate) },
|
2008-06-06 16:40:11 +04:00
|
|
|
{ SEC_ASN1_SEQUENCE_OF,
|
2016-11-02 12:29:58 +03:00
|
|
|
offsetof(NSSCMSKeyAgreeRecipientInfo, recipientEncryptedKeys),
|
|
|
|
NSSCMSRecipientEncryptedKeyTemplate },
|
2008-06-06 16:40:11 +04:00
|
|
|
{ 0 }
|
|
|
|
};
|
|
|
|
|
|
|
|
/* -----------------------------------------------------------------------------
|
|
|
|
* KEK recipient info
|
|
|
|
*/
|
|
|
|
|
|
|
|
static const SEC_ASN1Template NSSCMSKEKIdentifierTemplate[] = {
|
|
|
|
{ SEC_ASN1_SEQUENCE,
|
2016-11-02 12:29:58 +03:00
|
|
|
0, NULL, sizeof(NSSCMSKEKIdentifier) },
|
2008-06-06 16:40:11 +04:00
|
|
|
{ SEC_ASN1_OCTET_STRING,
|
2016-11-02 12:29:58 +03:00
|
|
|
offsetof(NSSCMSKEKIdentifier, keyIdentifier) },
|
2008-06-06 16:40:11 +04:00
|
|
|
{ SEC_ASN1_OPTIONAL | SEC_ASN1_OCTET_STRING,
|
2016-11-02 12:29:58 +03:00
|
|
|
offsetof(NSSCMSKEKIdentifier, date) },
|
2008-06-06 16:40:11 +04:00
|
|
|
{ SEC_ASN1_OPTIONAL | SEC_ASN1_OCTET_STRING,
|
2016-11-02 12:29:58 +03:00
|
|
|
offsetof(NSSCMSKEKIdentifier, other) },
|
2008-06-06 16:40:11 +04:00
|
|
|
{ 0 }
|
|
|
|
};
|
|
|
|
|
|
|
|
static const SEC_ASN1Template NSSCMSKEKRecipientInfoTemplate[] = {
|
|
|
|
{ SEC_ASN1_SEQUENCE,
|
2016-11-02 12:29:58 +03:00
|
|
|
0, NULL, sizeof(NSSCMSKEKRecipientInfo) },
|
2008-06-06 16:40:11 +04:00
|
|
|
{ SEC_ASN1_INTEGER,
|
2016-11-02 12:29:58 +03:00
|
|
|
offsetof(NSSCMSKEKRecipientInfo, version) },
|
2008-06-06 16:40:11 +04:00
|
|
|
{ SEC_ASN1_INLINE,
|
2016-11-02 12:29:58 +03:00
|
|
|
offsetof(NSSCMSKEKRecipientInfo, kekIdentifier),
|
|
|
|
NSSCMSKEKIdentifierTemplate },
|
2008-06-06 16:40:11 +04:00
|
|
|
{ SEC_ASN1_INLINE | SEC_ASN1_XTRN,
|
2016-11-02 12:29:58 +03:00
|
|
|
offsetof(NSSCMSKEKRecipientInfo, keyEncAlg),
|
|
|
|
SEC_ASN1_SUB(SECOID_AlgorithmIDTemplate) },
|
2008-06-06 16:40:11 +04:00
|
|
|
{ SEC_ASN1_OCTET_STRING,
|
2016-11-02 12:29:58 +03:00
|
|
|
offsetof(NSSCMSKEKRecipientInfo, encKey) },
|
2008-06-06 16:40:11 +04:00
|
|
|
{ 0 }
|
|
|
|
};
|
|
|
|
|
|
|
|
/* -----------------------------------------------------------------------------
|
|
|
|
* recipient info
|
|
|
|
*/
|
|
|
|
const SEC_ASN1Template NSSCMSRecipientInfoTemplate[] = {
|
|
|
|
{ SEC_ASN1_CHOICE,
|
2016-11-02 12:29:58 +03:00
|
|
|
offsetof(NSSCMSRecipientInfo, recipientInfoType), NULL,
|
|
|
|
sizeof(NSSCMSRecipientInfo) },
|
2008-06-06 16:40:11 +04:00
|
|
|
{ SEC_ASN1_EXPLICIT | SEC_ASN1_CONSTRUCTED | SEC_ASN1_CONTEXT_SPECIFIC | 1,
|
2016-11-02 12:29:58 +03:00
|
|
|
offsetof(NSSCMSRecipientInfo, ri.keyAgreeRecipientInfo),
|
|
|
|
NSSCMSKeyAgreeRecipientInfoTemplate,
|
|
|
|
NSSCMSRecipientInfoID_KeyAgree },
|
2008-06-06 16:40:11 +04:00
|
|
|
{ SEC_ASN1_EXPLICIT | SEC_ASN1_CONSTRUCTED | SEC_ASN1_CONTEXT_SPECIFIC | 2,
|
2016-11-02 12:29:58 +03:00
|
|
|
offsetof(NSSCMSRecipientInfo, ri.kekRecipientInfo),
|
|
|
|
NSSCMSKEKRecipientInfoTemplate,
|
|
|
|
NSSCMSRecipientInfoID_KEK },
|
2008-06-06 16:40:11 +04:00
|
|
|
{ SEC_ASN1_INLINE,
|
2016-11-02 12:29:58 +03:00
|
|
|
offsetof(NSSCMSRecipientInfo, ri.keyTransRecipientInfo),
|
|
|
|
NSSCMSKeyTransRecipientInfoTemplate,
|
|
|
|
NSSCMSRecipientInfoID_KeyTrans },
|
2008-06-06 16:40:11 +04:00
|
|
|
{ 0 }
|
|
|
|
};
|
|
|
|
|
|
|
|
/* -----------------------------------------------------------------------------
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
const SEC_ASN1Template NSSCMSDigestedDataTemplate[] = {
|
|
|
|
{ SEC_ASN1_SEQUENCE | SEC_ASN1_MAY_STREAM,
|
2016-11-02 12:29:58 +03:00
|
|
|
0, NULL, sizeof(NSSCMSDigestedData) },
|
2008-06-06 16:40:11 +04:00
|
|
|
{ SEC_ASN1_INTEGER,
|
2016-11-02 12:29:58 +03:00
|
|
|
offsetof(NSSCMSDigestedData, version) },
|
2008-06-06 16:40:11 +04:00
|
|
|
{ SEC_ASN1_INLINE | SEC_ASN1_XTRN,
|
2016-11-02 12:29:58 +03:00
|
|
|
offsetof(NSSCMSDigestedData, digestAlg),
|
|
|
|
SEC_ASN1_SUB(SECOID_AlgorithmIDTemplate) },
|
2008-06-06 16:40:11 +04:00
|
|
|
{ SEC_ASN1_INLINE,
|
2016-11-02 12:29:58 +03:00
|
|
|
offsetof(NSSCMSDigestedData, contentInfo),
|
|
|
|
NSSCMSEncapsulatedContentInfoTemplate },
|
2008-06-06 16:40:11 +04:00
|
|
|
{ SEC_ASN1_OCTET_STRING,
|
2016-11-02 12:29:58 +03:00
|
|
|
offsetof(NSSCMSDigestedData, digest) },
|
2008-06-06 16:40:11 +04:00
|
|
|
{ 0 }
|
|
|
|
};
|
|
|
|
|
|
|
|
const SEC_ASN1Template NSS_PointerToCMSDigestedDataTemplate[] = {
|
|
|
|
{ SEC_ASN1_POINTER, 0, NSSCMSDigestedDataTemplate }
|
|
|
|
};
|
|
|
|
|
|
|
|
const SEC_ASN1Template NSSCMSEncryptedDataTemplate[] = {
|
|
|
|
{ SEC_ASN1_SEQUENCE | SEC_ASN1_MAY_STREAM,
|
2016-11-02 12:29:58 +03:00
|
|
|
0, NULL, sizeof(NSSCMSEncryptedData) },
|
2008-06-06 16:40:11 +04:00
|
|
|
{ SEC_ASN1_INTEGER,
|
2016-11-02 12:29:58 +03:00
|
|
|
offsetof(NSSCMSEncryptedData, version) },
|
2008-06-06 16:40:11 +04:00
|
|
|
{ SEC_ASN1_INLINE,
|
2016-11-02 12:29:58 +03:00
|
|
|
offsetof(NSSCMSEncryptedData, contentInfo),
|
|
|
|
NSSCMSEncryptedContentInfoTemplate },
|
2008-06-06 16:40:11 +04:00
|
|
|
{ SEC_ASN1_OPTIONAL | SEC_ASN1_CONSTRUCTED | SEC_ASN1_CONTEXT_SPECIFIC | 1,
|
2016-11-02 12:29:58 +03:00
|
|
|
offsetof(NSSCMSEncryptedData, unprotectedAttr),
|
|
|
|
nss_cms_set_of_attribute_template },
|
2008-06-06 16:40:11 +04:00
|
|
|
{ 0 }
|
|
|
|
};
|
|
|
|
|
|
|
|
const SEC_ASN1Template NSS_PointerToCMSEncryptedDataTemplate[] = {
|
|
|
|
{ SEC_ASN1_POINTER, 0, NSSCMSEncryptedDataTemplate }
|
|
|
|
};
|
|
|
|
|
2011-05-05 18:35:11 +04:00
|
|
|
const SEC_ASN1Template NSSCMSGenericWrapperDataTemplate[] = {
|
|
|
|
{ SEC_ASN1_INLINE,
|
2016-11-02 12:29:58 +03:00
|
|
|
offsetof(NSSCMSGenericWrapperData, contentInfo),
|
|
|
|
NSSCMSEncapsulatedContentInfoTemplate },
|
2011-05-05 18:35:11 +04:00
|
|
|
};
|
|
|
|
|
2012-12-21 02:04:14 +04:00
|
|
|
SEC_ASN1_CHOOSER_IMPLEMENT(NSSCMSGenericWrapperDataTemplate)
|
2011-05-05 18:35:11 +04:00
|
|
|
|
|
|
|
const SEC_ASN1Template NSS_PointerToCMSGenericWrapperDataTemplate[] = {
|
|
|
|
{ SEC_ASN1_POINTER, 0, NSSCMSGenericWrapperDataTemplate }
|
|
|
|
};
|
|
|
|
|
2012-12-21 02:04:14 +04:00
|
|
|
SEC_ASN1_CHOOSER_IMPLEMENT(NSS_PointerToCMSGenericWrapperDataTemplate)
|
2011-05-05 18:35:11 +04:00
|
|
|
|
2008-06-06 16:40:11 +04:00
|
|
|
/* -----------------------------------------------------------------------------
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
static const SEC_ASN1Template *
|
|
|
|
nss_cms_choose_content_template(void *src_or_dest, PRBool encoding)
|
|
|
|
{
|
|
|
|
const SEC_ASN1Template *theTemplate;
|
|
|
|
NSSCMSContentInfo *cinfo;
|
2011-05-05 18:35:11 +04:00
|
|
|
SECOidTag type;
|
2008-06-06 16:40:11 +04:00
|
|
|
|
2016-11-02 12:29:58 +03:00
|
|
|
PORT_Assert(src_or_dest != NULL);
|
2008-06-06 16:40:11 +04:00
|
|
|
if (src_or_dest == NULL)
|
2016-11-02 12:29:58 +03:00
|
|
|
return NULL;
|
2008-06-06 16:40:11 +04:00
|
|
|
|
|
|
|
cinfo = (NSSCMSContentInfo *)src_or_dest;
|
2011-05-05 18:35:11 +04:00
|
|
|
type = NSS_CMSContentInfo_GetContentTypeTag(cinfo);
|
|
|
|
switch (type) {
|
2016-11-02 12:29:58 +03:00
|
|
|
default:
|
|
|
|
theTemplate = NSS_CMSType_GetTemplate(type);
|
|
|
|
break;
|
|
|
|
case SEC_OID_PKCS7_DATA:
|
|
|
|
theTemplate = SEC_ASN1_GET(SEC_PointerToOctetStringTemplate);
|
|
|
|
break;
|
|
|
|
case SEC_OID_PKCS7_SIGNED_DATA:
|
|
|
|
theTemplate = NSS_PointerToCMSSignedDataTemplate;
|
|
|
|
break;
|
|
|
|
case SEC_OID_PKCS7_ENVELOPED_DATA:
|
|
|
|
theTemplate = NSS_PointerToCMSEnvelopedDataTemplate;
|
|
|
|
break;
|
|
|
|
case SEC_OID_PKCS7_DIGESTED_DATA:
|
|
|
|
theTemplate = NSS_PointerToCMSDigestedDataTemplate;
|
|
|
|
break;
|
|
|
|
case SEC_OID_PKCS7_ENCRYPTED_DATA:
|
|
|
|
theTemplate = NSS_PointerToCMSEncryptedDataTemplate;
|
|
|
|
break;
|
2008-06-06 16:40:11 +04:00
|
|
|
}
|
|
|
|
return theTemplate;
|
|
|
|
}
|