~ubuntu-branches/ubuntu/precise/kompozer/precise

« back to all changes in this revision

Viewing changes to mozilla/security/nss/lib/pkcs7/pkcs7t.h

  • Committer: Bazaar Package Importer
  • Author(s): Anthony Yarusso
  • Date: 2007-08-27 01:11:03 UTC
  • Revision ID: james.westby@ubuntu.com-20070827011103-2jgf4s6532gqu2ka
Tags: upstream-0.7.10
ImportĀ upstreamĀ versionĀ 0.7.10

Show diffs side-by-side

added added

removed removed

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