PageRenderTime 49ms CodeModel.GetById 16ms app.highlight 28ms RepoModel.GetById 1ms app.codeStats 0ms

/security/nss/lib/pkcs7/pkcs7t.h

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