security/nss/lib/pkcs7/pkcs7t.h

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

michael@0 1 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 2 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 4
michael@0 5 /*
michael@0 6 * Header for pkcs7 types.
michael@0 7 */
michael@0 8
michael@0 9 #ifndef _PKCS7T_H_
michael@0 10 #define _PKCS7T_H_
michael@0 11
michael@0 12 #include "plarena.h"
michael@0 13
michael@0 14 #include "seccomon.h"
michael@0 15 #include "secoidt.h"
michael@0 16 #include "certt.h"
michael@0 17 #include "secmodt.h"
michael@0 18
michael@0 19 /* Opaque objects */
michael@0 20 typedef struct SEC_PKCS7DecoderContextStr SEC_PKCS7DecoderContext;
michael@0 21 typedef struct SEC_PKCS7EncoderContextStr SEC_PKCS7EncoderContext;
michael@0 22
michael@0 23 /* legacy defines that haven't been active for years */
michael@0 24 typedef void *(*SECKEYGetPasswordKey)(void *arg, void *handle);
michael@0 25
michael@0 26
michael@0 27 /* Non-opaque objects. NOTE, though: I want them to be treated as
michael@0 28 * opaque as much as possible. If I could hide them completely,
michael@0 29 * I would. (I tried, but ran into trouble that was taking me too
michael@0 30 * much time to get out of.) I still intend to try to do so.
michael@0 31 * In fact, the only type that "outsiders" should even *name* is
michael@0 32 * SEC_PKCS7ContentInfo, and they should not reference its fields.
michael@0 33 */
michael@0 34 /* rjr: PKCS #11 cert handling (pk11cert.c) does use SEC_PKCS7RecipientInfo's.
michael@0 35 * This is because when we search the recipient list for the cert and key we
michael@0 36 * want, we need to invert the order of the loops we used to have. The old
michael@0 37 * loops were:
michael@0 38 *
michael@0 39 * For each recipient {
michael@0 40 * find_cert = PK11_Find_AllCert(recipient->issuerSN);
michael@0 41 * [which unrolls to... ]
michael@0 42 * For each slot {
michael@0 43 * Log into slot;
michael@0 44 * search slot for cert;
michael@0 45 * }
michael@0 46 * }
michael@0 47 *
michael@0 48 * the new loop searchs all the recipients at once on a slot. this allows
michael@0 49 * PKCS #11 to order slots in such a way that logout slots don't get checked
michael@0 50 * if we can find the cert on a logged in slot. This eliminates lots of
michael@0 51 * spurious password prompts when smart cards are installed... so why this
michael@0 52 * comment? If you make SEC_PKCS7RecipientInfo completely opaque, you need
michael@0 53 * to provide a non-opaque list of issuerSN's (the only field PKCS#11 needs
michael@0 54 * and fix up pk11cert.c first. NOTE: Only S/MIME calls this special PKCS #11
michael@0 55 * function.
michael@0 56 */
michael@0 57 typedef struct SEC_PKCS7ContentInfoStr SEC_PKCS7ContentInfo;
michael@0 58 typedef struct SEC_PKCS7SignedDataStr SEC_PKCS7SignedData;
michael@0 59 typedef struct SEC_PKCS7EncryptedContentInfoStr SEC_PKCS7EncryptedContentInfo;
michael@0 60 typedef struct SEC_PKCS7EnvelopedDataStr SEC_PKCS7EnvelopedData;
michael@0 61 typedef struct SEC_PKCS7SignedAndEnvelopedDataStr
michael@0 62 SEC_PKCS7SignedAndEnvelopedData;
michael@0 63 typedef struct SEC_PKCS7SignerInfoStr SEC_PKCS7SignerInfo;
michael@0 64 typedef struct SEC_PKCS7RecipientInfoStr SEC_PKCS7RecipientInfo;
michael@0 65 typedef struct SEC_PKCS7DigestedDataStr SEC_PKCS7DigestedData;
michael@0 66 typedef struct SEC_PKCS7EncryptedDataStr SEC_PKCS7EncryptedData;
michael@0 67 /*
michael@0 68 * The following is not actually a PKCS7 type, but for now it is only
michael@0 69 * used by PKCS7, so we have adopted it. If someone else *ever* needs
michael@0 70 * it, its name should be changed and it should be moved out of here.
michael@0 71 * Do not dare to use it without doing so!
michael@0 72 */
michael@0 73 typedef struct SEC_PKCS7AttributeStr SEC_PKCS7Attribute;
michael@0 74
michael@0 75 struct SEC_PKCS7ContentInfoStr {
michael@0 76 PLArenaPool *poolp; /* local; not part of encoding */
michael@0 77 PRBool created; /* local; not part of encoding */
michael@0 78 int refCount; /* local; not part of encoding */
michael@0 79 SECOidData *contentTypeTag; /* local; not part of encoding */
michael@0 80 SECKEYGetPasswordKey pwfn; /* local; not part of encoding */
michael@0 81 void *pwfn_arg; /* local; not part of encoding */
michael@0 82 SECItem contentType;
michael@0 83 union {
michael@0 84 SECItem *data;
michael@0 85 SEC_PKCS7DigestedData *digestedData;
michael@0 86 SEC_PKCS7EncryptedData *encryptedData;
michael@0 87 SEC_PKCS7EnvelopedData *envelopedData;
michael@0 88 SEC_PKCS7SignedData *signedData;
michael@0 89 SEC_PKCS7SignedAndEnvelopedData *signedAndEnvelopedData;
michael@0 90 } content;
michael@0 91 };
michael@0 92
michael@0 93 struct SEC_PKCS7SignedDataStr {
michael@0 94 SECItem version;
michael@0 95 SECAlgorithmID **digestAlgorithms;
michael@0 96 SEC_PKCS7ContentInfo contentInfo;
michael@0 97 SECItem **rawCerts;
michael@0 98 CERTSignedCrl **crls;
michael@0 99 SEC_PKCS7SignerInfo **signerInfos;
michael@0 100 SECItem **digests; /* local; not part of encoding */
michael@0 101 CERTCertificate **certs; /* local; not part of encoding */
michael@0 102 CERTCertificateList **certLists; /* local; not part of encoding */
michael@0 103 };
michael@0 104 #define SEC_PKCS7_SIGNED_DATA_VERSION 1 /* what we *create* */
michael@0 105
michael@0 106 struct SEC_PKCS7EncryptedContentInfoStr {
michael@0 107 SECOidData *contentTypeTag; /* local; not part of encoding */
michael@0 108 SECItem contentType;
michael@0 109 SECAlgorithmID contentEncAlg;
michael@0 110 SECItem encContent;
michael@0 111 SECItem plainContent; /* local; not part of encoding */
michael@0 112 /* bytes not encrypted, but encoded */
michael@0 113 int keysize; /* local; not part of encoding */
michael@0 114 /* size of bulk encryption key
michael@0 115 * (only used by creation code) */
michael@0 116 SECOidTag encalg; /* local; not part of encoding */
michael@0 117 /* oid tag of encryption algorithm
michael@0 118 * (only used by creation code) */
michael@0 119 };
michael@0 120
michael@0 121 struct SEC_PKCS7EnvelopedDataStr {
michael@0 122 SECItem version;
michael@0 123 SEC_PKCS7RecipientInfo **recipientInfos;
michael@0 124 SEC_PKCS7EncryptedContentInfo encContentInfo;
michael@0 125 };
michael@0 126 #define SEC_PKCS7_ENVELOPED_DATA_VERSION 0 /* what we *create* */
michael@0 127
michael@0 128 struct SEC_PKCS7SignedAndEnvelopedDataStr {
michael@0 129 SECItem version;
michael@0 130 SEC_PKCS7RecipientInfo **recipientInfos;
michael@0 131 SECAlgorithmID **digestAlgorithms;
michael@0 132 SEC_PKCS7EncryptedContentInfo encContentInfo;
michael@0 133 SECItem **rawCerts;
michael@0 134 CERTSignedCrl **crls;
michael@0 135 SEC_PKCS7SignerInfo **signerInfos;
michael@0 136 SECItem **digests; /* local; not part of encoding */
michael@0 137 CERTCertificate **certs; /* local; not part of encoding */
michael@0 138 CERTCertificateList **certLists; /* local; not part of encoding */
michael@0 139 PK11SymKey *sigKey; /* local; not part of encoding */
michael@0 140 };
michael@0 141 #define SEC_PKCS7_SIGNED_AND_ENVELOPED_DATA_VERSION 1 /* what we *create* */
michael@0 142
michael@0 143 struct SEC_PKCS7SignerInfoStr {
michael@0 144 SECItem version;
michael@0 145 CERTIssuerAndSN *issuerAndSN;
michael@0 146 SECAlgorithmID digestAlg;
michael@0 147 SEC_PKCS7Attribute **authAttr;
michael@0 148 SECAlgorithmID digestEncAlg;
michael@0 149 SECItem encDigest;
michael@0 150 SEC_PKCS7Attribute **unAuthAttr;
michael@0 151 CERTCertificate *cert; /* local; not part of encoding */
michael@0 152 CERTCertificateList *certList; /* local; not part of encoding */
michael@0 153 };
michael@0 154 #define SEC_PKCS7_SIGNER_INFO_VERSION 1 /* what we *create* */
michael@0 155
michael@0 156 struct SEC_PKCS7RecipientInfoStr {
michael@0 157 SECItem version;
michael@0 158 CERTIssuerAndSN *issuerAndSN;
michael@0 159 SECAlgorithmID keyEncAlg;
michael@0 160 SECItem encKey;
michael@0 161 CERTCertificate *cert; /* local; not part of encoding */
michael@0 162 };
michael@0 163 #define SEC_PKCS7_RECIPIENT_INFO_VERSION 0 /* what we *create* */
michael@0 164
michael@0 165 struct SEC_PKCS7DigestedDataStr {
michael@0 166 SECItem version;
michael@0 167 SECAlgorithmID digestAlg;
michael@0 168 SEC_PKCS7ContentInfo contentInfo;
michael@0 169 SECItem digest;
michael@0 170 };
michael@0 171 #define SEC_PKCS7_DIGESTED_DATA_VERSION 0 /* what we *create* */
michael@0 172
michael@0 173 struct SEC_PKCS7EncryptedDataStr {
michael@0 174 SECItem version;
michael@0 175 SEC_PKCS7EncryptedContentInfo encContentInfo;
michael@0 176 };
michael@0 177 #define SEC_PKCS7_ENCRYPTED_DATA_VERSION 0 /* what we *create* */
michael@0 178
michael@0 179 /*
michael@0 180 * See comment above about this type not really belonging to PKCS7.
michael@0 181 */
michael@0 182 struct SEC_PKCS7AttributeStr {
michael@0 183 /* The following fields make up an encoded Attribute: */
michael@0 184 SECItem type;
michael@0 185 SECItem **values; /* data may or may not be encoded */
michael@0 186 /* The following fields are not part of an encoded Attribute: */
michael@0 187 SECOidData *typeTag;
michael@0 188 PRBool encoded; /* when true, values are encoded */
michael@0 189 };
michael@0 190
michael@0 191 /*
michael@0 192 * Type of function passed to SEC_PKCS7Decode or SEC_PKCS7DecoderStart.
michael@0 193 * If specified, this is where the content bytes (only) will be "sent"
michael@0 194 * as they are recovered during the decoding.
michael@0 195 *
michael@0 196 * XXX Should just combine this with SEC_PKCS7EncoderContentCallback type
michael@0 197 * and use a simpler, common name.
michael@0 198 */
michael@0 199 typedef void (* SEC_PKCS7DecoderContentCallback)(void *arg,
michael@0 200 const char *buf,
michael@0 201 unsigned long len);
michael@0 202
michael@0 203 /*
michael@0 204 * Type of function passed to SEC_PKCS7Encode or SEC_PKCS7EncoderStart.
michael@0 205 * This is where the encoded bytes will be "sent".
michael@0 206 *
michael@0 207 * XXX Should just combine this with SEC_PKCS7DecoderContentCallback type
michael@0 208 * and use a simpler, common name.
michael@0 209 */
michael@0 210 typedef void (* SEC_PKCS7EncoderOutputCallback)(void *arg,
michael@0 211 const char *buf,
michael@0 212 unsigned long len);
michael@0 213
michael@0 214
michael@0 215 /*
michael@0 216 * Type of function passed to SEC_PKCS7Decode or SEC_PKCS7DecoderStart
michael@0 217 * to retrieve the decryption key. This function is inteded to be
michael@0 218 * used for EncryptedData content info's which do not have a key available
michael@0 219 * in a certificate, etc.
michael@0 220 */
michael@0 221 typedef PK11SymKey * (* SEC_PKCS7GetDecryptKeyCallback)(void *arg,
michael@0 222 SECAlgorithmID *algid);
michael@0 223
michael@0 224 /*
michael@0 225 * Type of function passed to SEC_PKCS7Decode or SEC_PKCS7DecoderStart.
michael@0 226 * This function in intended to be used to verify that decrypting a
michael@0 227 * particular crypto algorithm is allowed. Content types which do not
michael@0 228 * require decryption will not need the callback. If the callback
michael@0 229 * is not specified for content types which require decryption, the
michael@0 230 * decryption will be disallowed.
michael@0 231 */
michael@0 232 typedef PRBool (* SEC_PKCS7DecryptionAllowedCallback)(SECAlgorithmID *algid,
michael@0 233 PK11SymKey *bulkkey);
michael@0 234
michael@0 235 #endif /* _PKCS7T_H_ */

mercurial