Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(876)

Side by Side Diff: mozilla/security/nss/lib/smime/cmst.h

Issue 14249009: Change the NSS and NSPR source tree to the new directory structure to be (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/deps/third_party/nss/
Patch Set: Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « mozilla/security/nss/lib/smime/cmsreclist.h ('k') | mozilla/security/nss/lib/smime/smime.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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/. */
4
5 /*
6 * Header for CMS types.
7 *
8 * $Id: cmst.h,v 1.15 2012/04/25 14:50:09 gerv%gerv.net Exp $
9 */
10
11 #ifndef _CMST_H_
12 #define _CMST_H_
13
14 #include "seccomon.h"
15 #include "secoidt.h"
16 #include "certt.h"
17 #include "secmodt.h"
18 #include "secmodt.h"
19
20 #include "plarena.h"
21
22 /* Non-opaque objects. NOTE, though: I want them to be treated as
23 * opaque as much as possible. If I could hide them completely,
24 * I would. (I tried, but ran into trouble that was taking me too
25 * much time to get out of.) I still intend to try to do so.
26 * In fact, the only type that "outsiders" should even *name* is
27 * NSSCMSMessage, and they should not reference its fields.
28 */
29 /* rjr: PKCS #11 cert handling (pk11cert.c) does use NSSCMSRecipientInfo's.
30 * This is because when we search the recipient list for the cert and key we
31 * want, we need to invert the order of the loops we used to have. The old
32 * loops were:
33 *
34 * For each recipient {
35 * find_cert = PK11_Find_AllCert(recipient->issuerSN);
36 * [which unrolls to... ]
37 * For each slot {
38 * Log into slot;
39 * search slot for cert;
40 * }
41 * }
42 *
43 * the new loop searchs all the recipients at once on a slot. this allows
44 * PKCS #11 to order slots in such a way that logout slots don't get checked
45 * if we can find the cert on a logged in slot. This eliminates lots of
46 * spurious password prompts when smart cards are installed... so why this
47 * comment? If you make NSSCMSRecipientInfo completely opaque, you need
48 * to provide a non-opaque list of issuerSN's (the only field PKCS#11 needs
49 * and fix up pk11cert.c first. NOTE: Only S/MIME calls this special PKCS #11
50 * function.
51 */
52
53 typedef struct NSSCMSMessageStr NSSCMSMessage;
54
55 typedef union NSSCMSContentUnion NSSCMSContent;
56 typedef struct NSSCMSContentInfoStr NSSCMSContentInfo;
57
58 typedef struct NSSCMSSignedDataStr NSSCMSSignedData;
59 typedef struct NSSCMSSignerInfoStr NSSCMSSignerInfo;
60 typedef struct NSSCMSSignerIdentifierStr NSSCMSSignerIdentifier;
61
62 typedef struct NSSCMSEnvelopedDataStr NSSCMSEnvelopedData;
63 typedef struct NSSCMSOriginatorInfoStr NSSCMSOriginatorInfo;
64 typedef struct NSSCMSRecipientInfoStr NSSCMSRecipientInfo;
65
66 typedef struct NSSCMSDigestedDataStr NSSCMSDigestedData;
67 typedef struct NSSCMSEncryptedDataStr NSSCMSEncryptedData;
68
69 typedef struct NSSCMSGenericWrapperDataStr NSSCMSGenericWrapperData;
70
71 typedef struct NSSCMSAttributeStr NSSCMSAttribute;
72
73 typedef struct NSSCMSDecoderContextStr NSSCMSDecoderContext;
74 typedef struct NSSCMSEncoderContextStr NSSCMSEncoderContext;
75
76 typedef struct NSSCMSCipherContextStr NSSCMSCipherContext;
77 typedef struct NSSCMSDigestContextStr NSSCMSDigestContext;
78
79 typedef struct NSSCMSContentInfoPrivateStr NSSCMSContentInfoPrivate;
80
81 typedef SECStatus (*NSSCMSGenericWrapperDataCallback)
82 (NSSCMSGenericWrapperData *);
83 typedef void (*NSSCMSGenericWrapperDataDestroy)
84 (NSSCMSGenericWrapperData *);
85
86 extern const SEC_ASN1Template NSSCMSGenericWrapperDataTemplate[];
87 extern const SEC_ASN1Template NSS_PointerToCMSGenericWrapperDataTemplate[];
88
89 SEC_ASN1_CHOOSER_DECLARE(NSS_PointerToCMSGenericWrapperDataTemplate)
90 SEC_ASN1_CHOOSER_DECLARE(NSSCMSGenericWrapperDataTemplate)
91
92
93
94 /*
95 * Type of function passed to NSSCMSDecode or NSSCMSDecoderStart.
96 * If specified, this is where the content bytes (only) will be "sent"
97 * as they are recovered during the decoding.
98 * And:
99 * Type of function passed to NSSCMSEncode or NSSCMSEncoderStart.
100 * This is where the DER-encoded bytes will be "sent".
101 *
102 * XXX Should just combine this with NSSCMSEncoderContentCallback type
103 * and use a simpler, common name.
104 */
105 typedef void (*NSSCMSContentCallback)(void *arg, const char *buf, unsigned long len);
106
107 /*
108 * Type of function passed to NSSCMSDecode or NSSCMSDecoderStart
109 * to retrieve the decryption key. This function is intended to be
110 * used for EncryptedData content info's which do not have a key available
111 * in a certificate, etc.
112 */
113 typedef PK11SymKey *(*NSSCMSGetDecryptKeyCallback)(void *arg, SECAlgorithmID *al gid);
114
115
116 /* =============================================================================
117 * ENCAPSULATED CONTENTINFO & CONTENTINFO
118 */
119
120 union NSSCMSContentUnion {
121 /* either unstructured */
122 SECItem * data;
123 /* or structured data */
124 NSSCMSDigestedData * digestedData;
125 NSSCMSEncryptedData * encryptedData;
126 NSSCMSEnvelopedData * envelopedData;
127 NSSCMSSignedData * signedData;
128 NSSCMSGenericWrapperData * genericData;
129 /* or anonymous pointer to something */
130 void * pointer;
131 };
132
133 struct NSSCMSContentInfoStr {
134 SECItem contentType;
135 NSSCMSContent content;
136 /* --------- local; not part of encoding --------- */
137 SECOidData * contentTypeTag;
138
139 /* additional info for encryptedData and envelopedData */
140 /* we waste this space for signedData and digestedData. sue me. */
141
142 SECAlgorithmID contentEncAlg;
143 SECItem * rawContent; /* encrypted DER, option al */
144 /* XXXX bytes not encryp ted, but encoded? */
145 /* --------- local; not part of encoding --------- */
146 PK11SymKey * bulkkey; /* bulk encryption key * /
147 int keysize; /* size of bulk encrypti on key
148 * (only used by creatio n code) */
149 SECOidTag contentEncAlgTag; /* oid tag of encryption algorithm
150 * (only used by creatio n code) */
151 NSSCMSContentInfoPrivate *privateInfo; /* place for NSS private info */
152 void *reserved; /* keep binary compatibi lity */
153 };
154
155 /* =============================================================================
156 * MESSAGE
157 */
158
159 struct NSSCMSMessageStr {
160 NSSCMSContentInfo contentInfo; /* "outer" cinfo */
161 /* --------- local; not part of encoding --------- */
162 PLArenaPool * poolp;
163 PRBool poolp_is_ours;
164 int refCount;
165 /* properties of the "inner" data */
166 SECAlgorithmID ** detached_digestalgs;
167 SECItem ** detached_digests;
168 void * pwfn_arg;
169 NSSCMSGetDecryptKeyCallback decrypt_key_cb;
170 void * decrypt_key_cb_arg;
171 };
172
173 /* ============================================================================
174 * GENERIC WRAPPER
175 *
176 * used for user defined types.
177 */
178 struct NSSCMSGenericWrapperDataStr {
179 NSSCMSContentInfo contentInfo;
180 /* ---- local; not part of encoding ------ */
181 NSSCMSMessage * cmsg;
182 /* wrapperspecific data starts here */
183 };
184
185 /* =============================================================================
186 * SIGNEDDATA
187 */
188
189 struct NSSCMSSignedDataStr {
190 SECItem version;
191 SECAlgorithmID ** digestAlgorithms;
192 NSSCMSContentInfo contentInfo;
193 SECItem ** rawCerts;
194 CERTSignedCrl ** crls;
195 NSSCMSSignerInfo ** signerInfos;
196 /* --------- local; not part of encoding --------- */
197 NSSCMSMessage * cmsg; /* back pointer to messa ge */
198 SECItem ** digests;
199 CERTCertificate ** certs;
200 CERTCertificateList ** certLists;
201 CERTCertificate ** tempCerts; /* temporary certs, need ed
202 * for example for signa ture
203 * verification */
204 };
205 #define NSS_CMS_SIGNED_DATA_VERSION_BASIC 1 /* what we *create* */
206 #define NSS_CMS_SIGNED_DATA_VERSION_EXT 3 /* what we *create* */
207
208 typedef enum {
209 NSSCMSVS_Unverified = 0,
210 NSSCMSVS_GoodSignature = 1,
211 NSSCMSVS_BadSignature = 2,
212 NSSCMSVS_DigestMismatch = 3,
213 NSSCMSVS_SigningCertNotFound = 4,
214 NSSCMSVS_SigningCertNotTrusted = 5,
215 NSSCMSVS_SignatureAlgorithmUnknown = 6,
216 NSSCMSVS_SignatureAlgorithmUnsupported = 7,
217 NSSCMSVS_MalformedSignature = 8,
218 NSSCMSVS_ProcessingError = 9
219 } NSSCMSVerificationStatus;
220
221 typedef enum {
222 NSSCMSSignerID_IssuerSN = 0,
223 NSSCMSSignerID_SubjectKeyID = 1
224 } NSSCMSSignerIDSelector;
225
226 struct NSSCMSSignerIdentifierStr {
227 NSSCMSSignerIDSelector identifierType;
228 union {
229 CERTIssuerAndSN *issuerAndSN;
230 SECItem *subjectKeyID;
231 } id;
232 };
233
234 struct NSSCMSSignerInfoStr {
235 SECItem version;
236 NSSCMSSignerIdentifier signerIdentifier;
237 SECAlgorithmID digestAlg;
238 NSSCMSAttribute ** authAttr;
239 SECAlgorithmID digestEncAlg;
240 SECItem encDigest;
241 NSSCMSAttribute ** unAuthAttr;
242 /* --------- local; not part of encoding --------- */
243 NSSCMSMessage * cmsg; /* back pointer to messa ge */
244 CERTCertificate * cert;
245 CERTCertificateList * certList;
246 PRTime signingTime;
247 NSSCMSVerificationStatus verificationStatus;
248 SECKEYPrivateKey * signingKey; /* Used if we're using subjKeyID*/
249 SECKEYPublicKey * pubKey;
250 };
251 #define NSS_CMS_SIGNER_INFO_VERSION_ISSUERSN 1 /* what we *create* */
252 #define NSS_CMS_SIGNER_INFO_VERSION_SUBJKEY 3 /* what we *create* */
253
254 typedef enum {
255 NSSCMSCM_None = 0,
256 NSSCMSCM_CertOnly = 1,
257 NSSCMSCM_CertChain = 2,
258 NSSCMSCM_CertChainWithRoot = 3
259 } NSSCMSCertChainMode;
260
261 /* =============================================================================
262 * ENVELOPED DATA
263 */
264 struct NSSCMSEnvelopedDataStr {
265 SECItem version;
266 NSSCMSOriginatorInfo * originatorInfo; /* optional */
267 NSSCMSRecipientInfo ** recipientInfos;
268 NSSCMSContentInfo contentInfo;
269 NSSCMSAttribute ** unprotectedAttr;
270 /* --------- local; not part of encoding --------- */
271 NSSCMSMessage * cmsg; /* back pointer to messa ge */
272 };
273 #define NSS_CMS_ENVELOPED_DATA_VERSION_REG 0 /* what we *create* */
274 #define NSS_CMS_ENVELOPED_DATA_VERSION_ADV 2 /* what we *create* */
275
276 struct NSSCMSOriginatorInfoStr {
277 SECItem ** rawCerts;
278 CERTSignedCrl ** crls;
279 /* --------- local; not part of encoding --------- */
280 CERTCertificate ** certs;
281 };
282
283 /* -----------------------------------------------------------------------------
284 * key transport recipient info
285 */
286 typedef enum {
287 NSSCMSRecipientID_IssuerSN = 0,
288 NSSCMSRecipientID_SubjectKeyID = 1,
289 NSSCMSRecipientID_BrandNew = 2
290 } NSSCMSRecipientIDSelector;
291
292 struct NSSCMSRecipientIdentifierStr {
293 NSSCMSRecipientIDSelector identifierType;
294 union {
295 CERTIssuerAndSN *issuerAndSN;
296 SECItem *subjectKeyID;
297 } id;
298 };
299 typedef struct NSSCMSRecipientIdentifierStr NSSCMSRecipientIdentifier;
300
301 struct NSSCMSKeyTransRecipientInfoStr {
302 SECItem version;
303 NSSCMSRecipientIdentifier recipientIdentifier;
304 SECAlgorithmID keyEncAlg;
305 SECItem encKey;
306 };
307 typedef struct NSSCMSKeyTransRecipientInfoStr NSSCMSKeyTransRecipientInfo;
308
309 /*
310 * View comments before NSSCMSRecipientInfoStr for purpose of this
311 * structure.
312 */
313 struct NSSCMSKeyTransRecipientInfoExStr {
314 NSSCMSKeyTransRecipientInfo recipientInfo;
315 int version; /* version of this structure (0) */
316 SECKEYPublicKey *pubKey;
317 };
318
319 typedef struct NSSCMSKeyTransRecipientInfoExStr NSSCMSKeyTransRecipientInfoEx;
320
321 #define NSS_CMS_KEYTRANS_RECIPIENT_INFO_VERSION_ISSUERSN 0 /* what we *create* */
322 #define NSS_CMS_KEYTRANS_RECIPIENT_INFO_VERSION_SUBJKEY 2 /* what we *create* */
323
324 /* -----------------------------------------------------------------------------
325 * key agreement recipient info
326 */
327 struct NSSCMSOriginatorPublicKeyStr {
328 SECAlgorithmID algorithmIdentifier;
329 SECItem publicKey; /* bit s tring! */
330 };
331 typedef struct NSSCMSOriginatorPublicKeyStr NSSCMSOriginatorPublicKey;
332
333 typedef enum {
334 NSSCMSOriginatorIDOrKey_IssuerSN = 0,
335 NSSCMSOriginatorIDOrKey_SubjectKeyID = 1,
336 NSSCMSOriginatorIDOrKey_OriginatorPublicKey = 2
337 } NSSCMSOriginatorIDOrKeySelector;
338
339 struct NSSCMSOriginatorIdentifierOrKeyStr {
340 NSSCMSOriginatorIDOrKeySelector identifierType;
341 union {
342 CERTIssuerAndSN *issuerAndSN; /* static-static */
343 SECItem *subjectKeyID; /* static-static */
344 NSSCMSOriginatorPublicKey originatorPublicKey; /* ephemeral-sta tic */
345 } id;
346 };
347 typedef struct NSSCMSOriginatorIdentifierOrKeyStr NSSCMSOriginatorIdentifierOrKe y;
348
349 struct NSSCMSRecipientKeyIdentifierStr {
350 SECItem * subjectKeyIdentifier;
351 SECItem * date; /* optional */
352 SECItem * other; /* optional */
353 };
354 typedef struct NSSCMSRecipientKeyIdentifierStr NSSCMSRecipientKeyIdentifier;
355
356 typedef enum {
357 NSSCMSKeyAgreeRecipientID_IssuerSN = 0,
358 NSSCMSKeyAgreeRecipientID_RKeyID = 1
359 } NSSCMSKeyAgreeRecipientIDSelector;
360
361 struct NSSCMSKeyAgreeRecipientIdentifierStr {
362 NSSCMSKeyAgreeRecipientIDSelector identifierType;
363 union {
364 CERTIssuerAndSN *issuerAndSN;
365 NSSCMSRecipientKeyIdentifier recipientKeyIdentifier;
366 } id;
367 };
368 typedef struct NSSCMSKeyAgreeRecipientIdentifierStr NSSCMSKeyAgreeRecipientIdent ifier;
369
370 struct NSSCMSRecipientEncryptedKeyStr {
371 NSSCMSKeyAgreeRecipientIdentifier recipientIdentifier;
372 SECItem encKey;
373 };
374 typedef struct NSSCMSRecipientEncryptedKeyStr NSSCMSRecipientEncryptedKey;
375
376 struct NSSCMSKeyAgreeRecipientInfoStr {
377 SECItem version;
378 NSSCMSOriginatorIdentifierOrKey originatorIdentifierOrKey;
379 SECItem * ukm; /* optio nal */
380 SECAlgorithmID keyEncAlg;
381 NSSCMSRecipientEncryptedKey ** recipientEncryptedKeys;
382 };
383 typedef struct NSSCMSKeyAgreeRecipientInfoStr NSSCMSKeyAgreeRecipientInfo;
384
385 #define NSS_CMS_KEYAGREE_RECIPIENT_INFO_VERSION 3 /* what we *create* */
386
387 /* -----------------------------------------------------------------------------
388 * KEK recipient info
389 */
390 struct NSSCMSKEKIdentifierStr {
391 SECItem keyIdentifier;
392 SECItem * date; /* optional */
393 SECItem * other; /* optional */
394 };
395 typedef struct NSSCMSKEKIdentifierStr NSSCMSKEKIdentifier;
396
397 struct NSSCMSKEKRecipientInfoStr {
398 SECItem version;
399 NSSCMSKEKIdentifier kekIdentifier;
400 SECAlgorithmID keyEncAlg;
401 SECItem encKey;
402 };
403 typedef struct NSSCMSKEKRecipientInfoStr NSSCMSKEKRecipientInfo;
404
405 #define NSS_CMS_KEK_RECIPIENT_INFO_VERSION 4 /* what we *create* */
406
407 /* -----------------------------------------------------------------------------
408 * recipient info
409 */
410
411 typedef enum {
412 NSSCMSRecipientInfoID_KeyTrans = 0,
413 NSSCMSRecipientInfoID_KeyAgree = 1,
414 NSSCMSRecipientInfoID_KEK = 2
415 } NSSCMSRecipientInfoIDSelector;
416
417 /*
418 * In order to preserve backwards binary compatibility when implementing
419 * creation of Recipient Info's that uses subjectKeyID in the
420 * keyTransRecipientInfo we need to stash a public key pointer in this
421 * structure somewhere. We figured out that NSSCMSKeyTransRecipientInfo
422 * is the smallest member of the ri union. We're in luck since that's
423 * the very structure that would need to use the public key. So we created
424 * a new structure NSSCMSKeyTransRecipientInfoEx which has a member
425 * NSSCMSKeyTransRecipientInfo as the first member followed by a version
426 * and a public key pointer. This way we can keep backwards compatibility
427 * without changing the size of this structure.
428 *
429 * BTW, size of structure:
430 * NSSCMSKeyTransRecipientInfo: 9 ints, 4 pointers
431 * NSSCMSKeyAgreeRecipientInfo: 12 ints, 8 pointers
432 * NSSCMSKEKRecipientInfo: 10 ints, 7 pointers
433 *
434 * The new structure:
435 * NSSCMSKeyTransRecipientInfoEx: sizeof(NSSCMSKeyTransRecipientInfo) +
436 * 1 int, 1 pointer
437 */
438
439 struct NSSCMSRecipientInfoStr {
440 NSSCMSRecipientInfoIDSelector recipientInfoType;
441 union {
442 NSSCMSKeyTransRecipientInfo keyTransRecipientInfo;
443 NSSCMSKeyAgreeRecipientInfo keyAgreeRecipientInfo;
444 NSSCMSKEKRecipientInfo kekRecipientInfo;
445 NSSCMSKeyTransRecipientInfoEx keyTransRecipientInfoEx;
446 } ri;
447 /* --------- local; not part of encoding --------- */
448 NSSCMSMessage * cmsg; /* back pointer to messa ge */
449 CERTCertificate * cert; /* recipient's certifica te */
450 };
451
452 /* =============================================================================
453 * DIGESTED DATA
454 */
455 struct NSSCMSDigestedDataStr {
456 SECItem version;
457 SECAlgorithmID digestAlg;
458 NSSCMSContentInfo contentInfo;
459 SECItem digest;
460 /* --------- local; not part of encoding --------- */
461 NSSCMSMessage * cmsg; /* back pointer */
462 SECItem cdigest; /* calculated digest */
463 };
464 #define NSS_CMS_DIGESTED_DATA_VERSION_DATA 0 /* what we *create* */
465 #define NSS_CMS_DIGESTED_DATA_VERSION_ENCAP 2 /* what we *create* */
466
467 /* =============================================================================
468 * ENCRYPTED DATA
469 */
470 struct NSSCMSEncryptedDataStr {
471 SECItem version;
472 NSSCMSContentInfo contentInfo;
473 NSSCMSAttribute ** unprotectedAttr; /* optional */
474 /* --------- local; not part of encoding --------- */
475 NSSCMSMessage * cmsg; /* back pointer */
476 };
477 #define NSS_CMS_ENCRYPTED_DATA_VERSION 0 /* what we *create* */
478 #define NSS_CMS_ENCRYPTED_DATA_VERSION_UPATTR 2 /* what we *create* */
479
480 /*
481 * *****************************************************************************
482 * *****************************************************************************
483 * *****************************************************************************
484 */
485
486 /*
487 * See comment above about this type not really belonging to CMS.
488 */
489 struct NSSCMSAttributeStr {
490 /* The following fields make up an encoded Attribute: */
491 SECItem type;
492 SECItem ** values; /* data may or may not be encoded */
493 /* The following fields are not part of an encoded Attribute: */
494 SECOidData * typeTag;
495 PRBool encoded; /* when true, values are encoded */
496 };
497
498 #endif /* _CMST_H_ */
OLDNEW
« no previous file with comments | « mozilla/security/nss/lib/smime/cmsreclist.h ('k') | mozilla/security/nss/lib/smime/smime.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698