michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: /* michael@0: * Header for pkcs7 types. michael@0: */ michael@0: michael@0: #ifndef _PKCS7T_H_ michael@0: #define _PKCS7T_H_ michael@0: michael@0: #include "plarena.h" michael@0: michael@0: #include "seccomon.h" michael@0: #include "secoidt.h" michael@0: #include "certt.h" michael@0: #include "secmodt.h" michael@0: michael@0: /* Opaque objects */ michael@0: typedef struct SEC_PKCS7DecoderContextStr SEC_PKCS7DecoderContext; michael@0: typedef struct SEC_PKCS7EncoderContextStr SEC_PKCS7EncoderContext; michael@0: michael@0: /* legacy defines that haven't been active for years */ michael@0: typedef void *(*SECKEYGetPasswordKey)(void *arg, void *handle); michael@0: michael@0: michael@0: /* Non-opaque objects. NOTE, though: I want them to be treated as michael@0: * opaque as much as possible. If I could hide them completely, michael@0: * I would. (I tried, but ran into trouble that was taking me too michael@0: * much time to get out of.) I still intend to try to do so. michael@0: * In fact, the only type that "outsiders" should even *name* is michael@0: * SEC_PKCS7ContentInfo, and they should not reference its fields. michael@0: */ michael@0: /* rjr: PKCS #11 cert handling (pk11cert.c) does use SEC_PKCS7RecipientInfo's. michael@0: * This is because when we search the recipient list for the cert and key we michael@0: * want, we need to invert the order of the loops we used to have. The old michael@0: * loops were: michael@0: * michael@0: * For each recipient { michael@0: * find_cert = PK11_Find_AllCert(recipient->issuerSN); michael@0: * [which unrolls to... ] michael@0: * For each slot { michael@0: * Log into slot; michael@0: * search slot for cert; michael@0: * } michael@0: * } michael@0: * michael@0: * the new loop searchs all the recipients at once on a slot. this allows michael@0: * PKCS #11 to order slots in such a way that logout slots don't get checked michael@0: * if we can find the cert on a logged in slot. This eliminates lots of michael@0: * spurious password prompts when smart cards are installed... so why this michael@0: * comment? If you make SEC_PKCS7RecipientInfo completely opaque, you need michael@0: * to provide a non-opaque list of issuerSN's (the only field PKCS#11 needs michael@0: * and fix up pk11cert.c first. NOTE: Only S/MIME calls this special PKCS #11 michael@0: * function. michael@0: */ michael@0: typedef struct SEC_PKCS7ContentInfoStr SEC_PKCS7ContentInfo; michael@0: typedef struct SEC_PKCS7SignedDataStr SEC_PKCS7SignedData; michael@0: typedef struct SEC_PKCS7EncryptedContentInfoStr SEC_PKCS7EncryptedContentInfo; michael@0: typedef struct SEC_PKCS7EnvelopedDataStr SEC_PKCS7EnvelopedData; michael@0: typedef struct SEC_PKCS7SignedAndEnvelopedDataStr michael@0: SEC_PKCS7SignedAndEnvelopedData; michael@0: typedef struct SEC_PKCS7SignerInfoStr SEC_PKCS7SignerInfo; michael@0: typedef struct SEC_PKCS7RecipientInfoStr SEC_PKCS7RecipientInfo; michael@0: typedef struct SEC_PKCS7DigestedDataStr SEC_PKCS7DigestedData; michael@0: typedef struct SEC_PKCS7EncryptedDataStr SEC_PKCS7EncryptedData; michael@0: /* michael@0: * The following is not actually a PKCS7 type, but for now it is only michael@0: * used by PKCS7, so we have adopted it. If someone else *ever* needs michael@0: * it, its name should be changed and it should be moved out of here. michael@0: * Do not dare to use it without doing so! michael@0: */ michael@0: typedef struct SEC_PKCS7AttributeStr SEC_PKCS7Attribute; michael@0: michael@0: struct SEC_PKCS7ContentInfoStr { michael@0: PLArenaPool *poolp; /* local; not part of encoding */ michael@0: PRBool created; /* local; not part of encoding */ michael@0: int refCount; /* local; not part of encoding */ michael@0: SECOidData *contentTypeTag; /* local; not part of encoding */ michael@0: SECKEYGetPasswordKey pwfn; /* local; not part of encoding */ michael@0: void *pwfn_arg; /* local; not part of encoding */ michael@0: SECItem contentType; michael@0: union { michael@0: SECItem *data; michael@0: SEC_PKCS7DigestedData *digestedData; michael@0: SEC_PKCS7EncryptedData *encryptedData; michael@0: SEC_PKCS7EnvelopedData *envelopedData; michael@0: SEC_PKCS7SignedData *signedData; michael@0: SEC_PKCS7SignedAndEnvelopedData *signedAndEnvelopedData; michael@0: } content; michael@0: }; michael@0: michael@0: struct SEC_PKCS7SignedDataStr { michael@0: SECItem version; michael@0: SECAlgorithmID **digestAlgorithms; michael@0: SEC_PKCS7ContentInfo contentInfo; michael@0: SECItem **rawCerts; michael@0: CERTSignedCrl **crls; michael@0: SEC_PKCS7SignerInfo **signerInfos; michael@0: SECItem **digests; /* local; not part of encoding */ michael@0: CERTCertificate **certs; /* local; not part of encoding */ michael@0: CERTCertificateList **certLists; /* local; not part of encoding */ michael@0: }; michael@0: #define SEC_PKCS7_SIGNED_DATA_VERSION 1 /* what we *create* */ michael@0: michael@0: struct SEC_PKCS7EncryptedContentInfoStr { michael@0: SECOidData *contentTypeTag; /* local; not part of encoding */ michael@0: SECItem contentType; michael@0: SECAlgorithmID contentEncAlg; michael@0: SECItem encContent; michael@0: SECItem plainContent; /* local; not part of encoding */ michael@0: /* bytes not encrypted, but encoded */ michael@0: int keysize; /* local; not part of encoding */ michael@0: /* size of bulk encryption key michael@0: * (only used by creation code) */ michael@0: SECOidTag encalg; /* local; not part of encoding */ michael@0: /* oid tag of encryption algorithm michael@0: * (only used by creation code) */ michael@0: }; michael@0: michael@0: struct SEC_PKCS7EnvelopedDataStr { michael@0: SECItem version; michael@0: SEC_PKCS7RecipientInfo **recipientInfos; michael@0: SEC_PKCS7EncryptedContentInfo encContentInfo; michael@0: }; michael@0: #define SEC_PKCS7_ENVELOPED_DATA_VERSION 0 /* what we *create* */ michael@0: michael@0: struct SEC_PKCS7SignedAndEnvelopedDataStr { michael@0: SECItem version; michael@0: SEC_PKCS7RecipientInfo **recipientInfos; michael@0: SECAlgorithmID **digestAlgorithms; michael@0: SEC_PKCS7EncryptedContentInfo encContentInfo; michael@0: SECItem **rawCerts; michael@0: CERTSignedCrl **crls; michael@0: SEC_PKCS7SignerInfo **signerInfos; michael@0: SECItem **digests; /* local; not part of encoding */ michael@0: CERTCertificate **certs; /* local; not part of encoding */ michael@0: CERTCertificateList **certLists; /* local; not part of encoding */ michael@0: PK11SymKey *sigKey; /* local; not part of encoding */ michael@0: }; michael@0: #define SEC_PKCS7_SIGNED_AND_ENVELOPED_DATA_VERSION 1 /* what we *create* */ michael@0: michael@0: struct SEC_PKCS7SignerInfoStr { michael@0: SECItem version; michael@0: CERTIssuerAndSN *issuerAndSN; michael@0: SECAlgorithmID digestAlg; michael@0: SEC_PKCS7Attribute **authAttr; michael@0: SECAlgorithmID digestEncAlg; michael@0: SECItem encDigest; michael@0: SEC_PKCS7Attribute **unAuthAttr; michael@0: CERTCertificate *cert; /* local; not part of encoding */ michael@0: CERTCertificateList *certList; /* local; not part of encoding */ michael@0: }; michael@0: #define SEC_PKCS7_SIGNER_INFO_VERSION 1 /* what we *create* */ michael@0: michael@0: struct SEC_PKCS7RecipientInfoStr { michael@0: SECItem version; michael@0: CERTIssuerAndSN *issuerAndSN; michael@0: SECAlgorithmID keyEncAlg; michael@0: SECItem encKey; michael@0: CERTCertificate *cert; /* local; not part of encoding */ michael@0: }; michael@0: #define SEC_PKCS7_RECIPIENT_INFO_VERSION 0 /* what we *create* */ michael@0: michael@0: struct SEC_PKCS7DigestedDataStr { michael@0: SECItem version; michael@0: SECAlgorithmID digestAlg; michael@0: SEC_PKCS7ContentInfo contentInfo; michael@0: SECItem digest; michael@0: }; michael@0: #define SEC_PKCS7_DIGESTED_DATA_VERSION 0 /* what we *create* */ michael@0: michael@0: struct SEC_PKCS7EncryptedDataStr { michael@0: SECItem version; michael@0: SEC_PKCS7EncryptedContentInfo encContentInfo; michael@0: }; michael@0: #define SEC_PKCS7_ENCRYPTED_DATA_VERSION 0 /* what we *create* */ michael@0: michael@0: /* michael@0: * See comment above about this type not really belonging to PKCS7. michael@0: */ michael@0: struct SEC_PKCS7AttributeStr { michael@0: /* The following fields make up an encoded Attribute: */ michael@0: SECItem type; michael@0: SECItem **values; /* data may or may not be encoded */ michael@0: /* The following fields are not part of an encoded Attribute: */ michael@0: SECOidData *typeTag; michael@0: PRBool encoded; /* when true, values are encoded */ michael@0: }; michael@0: michael@0: /* michael@0: * Type of function passed to SEC_PKCS7Decode or SEC_PKCS7DecoderStart. michael@0: * If specified, this is where the content bytes (only) will be "sent" michael@0: * as they are recovered during the decoding. michael@0: * michael@0: * XXX Should just combine this with SEC_PKCS7EncoderContentCallback type michael@0: * and use a simpler, common name. michael@0: */ michael@0: typedef void (* SEC_PKCS7DecoderContentCallback)(void *arg, michael@0: const char *buf, michael@0: unsigned long len); michael@0: michael@0: /* michael@0: * Type of function passed to SEC_PKCS7Encode or SEC_PKCS7EncoderStart. michael@0: * This is where the encoded bytes will be "sent". michael@0: * michael@0: * XXX Should just combine this with SEC_PKCS7DecoderContentCallback type michael@0: * and use a simpler, common name. michael@0: */ michael@0: typedef void (* SEC_PKCS7EncoderOutputCallback)(void *arg, michael@0: const char *buf, michael@0: unsigned long len); michael@0: michael@0: michael@0: /* michael@0: * Type of function passed to SEC_PKCS7Decode or SEC_PKCS7DecoderStart michael@0: * to retrieve the decryption key. This function is inteded to be michael@0: * used for EncryptedData content info's which do not have a key available michael@0: * in a certificate, etc. michael@0: */ michael@0: typedef PK11SymKey * (* SEC_PKCS7GetDecryptKeyCallback)(void *arg, michael@0: SECAlgorithmID *algid); michael@0: michael@0: /* michael@0: * Type of function passed to SEC_PKCS7Decode or SEC_PKCS7DecoderStart. michael@0: * This function in intended to be used to verify that decrypting a michael@0: * particular crypto algorithm is allowed. Content types which do not michael@0: * require decryption will not need the callback. If the callback michael@0: * is not specified for content types which require decryption, the michael@0: * decryption will be disallowed. michael@0: */ michael@0: typedef PRBool (* SEC_PKCS7DecryptionAllowedCallback)(SECAlgorithmID *algid, michael@0: PK11SymKey *bulkkey); michael@0: michael@0: #endif /* _PKCS7T_H_ */