OpenSSL  1.0.1c
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros
cms.h
Go to the documentation of this file.
1 /* crypto/cms/cms.h */
2 /* Written by Dr Stephen N Henson ([email protected]) for the OpenSSL
3  * project.
4  */
5 /* ====================================================================
6  * Copyright (c) 2008 The OpenSSL Project. All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * 1. Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  *
15  * 2. Redistributions in binary form must reproduce the above copyright
16  * notice, this list of conditions and the following disclaimer in
17  * the documentation and/or other materials provided with the
18  * distribution.
19  *
20  * 3. All advertising materials mentioning features or use of this
21  * software must display the following acknowledgment:
22  * "This product includes software developed by the OpenSSL Project
23  * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24  *
25  * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26  * endorse or promote products derived from this software without
27  * prior written permission. For written permission, please contact
29  *
30  * 5. Products derived from this software may not be called "OpenSSL"
31  * nor may "OpenSSL" appear in their names without prior written
32  * permission of the OpenSSL Project.
33  *
34  * 6. Redistributions of any form whatsoever must retain the following
35  * acknowledgment:
36  * "This product includes software developed by the OpenSSL Project
37  * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38  *
39  * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40  * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50  * OF THE POSSIBILITY OF SUCH DAMAGE.
51  * ====================================================================
52  */
53 
54 
55 #ifndef HEADER_CMS_H
56 #define HEADER_CMS_H
57 
58 #include <openssl/x509.h>
59 
60 #ifdef OPENSSL_NO_CMS
61 #error CMS is disabled.
62 #endif
63 
64 #ifdef __cplusplus
65 extern "C" {
66 #endif
67 
68 
74 typedef struct CMS_ReceiptRequest_st CMS_ReceiptRequest;
75 typedef struct CMS_Receipt_st CMS_Receipt;
76 
78 DECLARE_STACK_OF(GENERAL_NAMES)
82 
83 #define CMS_SIGNERINFO_ISSUER_SERIAL 0
84 #define CMS_SIGNERINFO_KEYIDENTIFIER 1
85 
86 #define CMS_RECIPINFO_TRANS 0
87 #define CMS_RECIPINFO_AGREE 1
88 #define CMS_RECIPINFO_KEK 2
89 #define CMS_RECIPINFO_PASS 3
90 #define CMS_RECIPINFO_OTHER 4
91 
92 /* S/MIME related flags */
93 
94 #define CMS_TEXT 0x1
95 #define CMS_NOCERTS 0x2
96 #define CMS_NO_CONTENT_VERIFY 0x4
97 #define CMS_NO_ATTR_VERIFY 0x8
98 #define CMS_NOSIGS \
99  (CMS_NO_CONTENT_VERIFY|CMS_NO_ATTR_VERIFY)
100 #define CMS_NOINTERN 0x10
101 #define CMS_NO_SIGNER_CERT_VERIFY 0x20
102 #define CMS_NOVERIFY 0x20
103 #define CMS_DETACHED 0x40
104 #define CMS_BINARY 0x80
105 #define CMS_NOATTR 0x100
106 #define CMS_NOSMIMECAP 0x200
107 #define CMS_NOOLDMIMETYPE 0x400
108 #define CMS_CRLFEOL 0x800
109 #define CMS_STREAM 0x1000
110 #define CMS_NOCRL 0x2000
111 #define CMS_PARTIAL 0x4000
112 #define CMS_REUSE_DIGEST 0x8000
113 #define CMS_USE_KEYID 0x10000
114 #define CMS_DEBUG_DECRYPT 0x20000
115 
117 
118 BIO *CMS_dataInit(CMS_ContentInfo *cms, BIO *icont);
119 int CMS_dataFinal(CMS_ContentInfo *cms, BIO *bio);
120 
123 int CMS_set_detached(CMS_ContentInfo *cms, int detached);
124 
125 #ifdef HEADER_PEM_H
127 #endif
128 
129 int CMS_stream(unsigned char ***boundary, CMS_ContentInfo *cms);
131 int i2d_CMS_bio(BIO *bp, CMS_ContentInfo *cms);
132 
133 BIO *BIO_new_CMS(BIO *out, CMS_ContentInfo *cms);
134 int i2d_CMS_bio_stream(BIO *out, CMS_ContentInfo *cms, BIO *in, int flags);
135 int PEM_write_bio_CMS_stream(BIO *out, CMS_ContentInfo *cms, BIO *in, int flags);
136 CMS_ContentInfo *SMIME_read_CMS(BIO *bio, BIO **bcont);
137 int SMIME_write_CMS(BIO *bio, CMS_ContentInfo *cms, BIO *data, int flags);
138 
139 int CMS_final(CMS_ContentInfo *cms, BIO *data, BIO *dcont, unsigned int flags);
140 
141 CMS_ContentInfo *CMS_sign(X509 *signcert, EVP_PKEY *pkey, STACK_OF(X509) *certs,
142  BIO *data, unsigned int flags);
143 
145  X509 *signcert, EVP_PKEY *pkey,
146  STACK_OF(X509) *certs,
147  unsigned int flags);
148 
149 int CMS_data(CMS_ContentInfo *cms, BIO *out, unsigned int flags);
150 CMS_ContentInfo *CMS_data_create(BIO *in, unsigned int flags);
151 
152 int CMS_digest_verify(CMS_ContentInfo *cms, BIO *dcont, BIO *out,
153  unsigned int flags);
155  unsigned int flags);
156 
158  const unsigned char *key, size_t keylen,
159  BIO *dcont, BIO *out, unsigned int flags);
160 
162  const unsigned char *key, size_t keylen,
163  unsigned int flags);
164 
166  const unsigned char *key, size_t keylen);
167 
168 int CMS_verify(CMS_ContentInfo *cms, STACK_OF(X509) *certs,
169  X509_STORE *store, BIO *dcont, BIO *out, unsigned int flags);
170 
172  STACK_OF(X509) *certs,
173  X509_STORE *store, unsigned int flags);
174 
175 STACK_OF(X509) *CMS_get0_signers(CMS_ContentInfo *cms);
176 
178  const EVP_CIPHER *cipher, unsigned int flags);
179 
180 int CMS_decrypt(CMS_ContentInfo *cms, EVP_PKEY *pkey, X509 *cert,
181  BIO *dcont, BIO *out,
182  unsigned int flags);
183 
184 int CMS_decrypt_set1_pkey(CMS_ContentInfo *cms, EVP_PKEY *pk, X509 *cert);
186  unsigned char *key, size_t keylen,
187  unsigned char *id, size_t idlen);
189  unsigned char *pass, ossl_ssize_t passlen);
190 
191 STACK_OF(CMS_RecipientInfo) *CMS_get0_RecipientInfos(CMS_ContentInfo *cms);
195  X509 *recip, unsigned int flags);
199  EVP_PKEY **pk, X509 **recip,
200  X509_ALGOR **palg);
202  ASN1_OCTET_STRING **keyid,
203  X509_NAME **issuer, ASN1_INTEGER **sno);
204 
206  unsigned char *key, size_t keylen,
207  unsigned char *id, size_t idlen,
208  ASN1_GENERALIZEDTIME *date,
209  ASN1_OBJECT *otherTypeId,
210  ASN1_TYPE *otherType);
211 
213  X509_ALGOR **palg,
214  ASN1_OCTET_STRING **pid,
215  ASN1_GENERALIZEDTIME **pdate,
216  ASN1_OBJECT **potherid,
217  ASN1_TYPE **pothertype);
218 
220  unsigned char *key, size_t keylen);
221 
223  const unsigned char *id, size_t idlen);
224 
226  unsigned char *pass,
228 
230  int iter, int wrap_nid, int pbe_nid,
231  unsigned char *pass,
233  const EVP_CIPHER *kekciph);
234 
236 
237 int CMS_uncompress(CMS_ContentInfo *cms, BIO *dcont, BIO *out,
238  unsigned int flags);
239 CMS_ContentInfo *CMS_compress(BIO *in, int comp_nid, unsigned int flags);
240 
243 
245 int CMS_add0_cert(CMS_ContentInfo *cms, X509 *cert);
246 int CMS_add1_cert(CMS_ContentInfo *cms, X509 *cert);
247 STACK_OF(X509) *CMS_get1_certs(CMS_ContentInfo *cms);
248 
250 int CMS_add0_crl(CMS_ContentInfo *cms, X509_CRL *crl);
251 int CMS_add1_crl(CMS_ContentInfo *cms, X509_CRL *crl);
252 STACK_OF(X509_CRL) *CMS_get1_crls(CMS_ContentInfo *cms);
253 
256  X509 *signer, EVP_PKEY *pk, const EVP_MD *md,
257  unsigned int flags);
258 STACK_OF(CMS_SignerInfo) *CMS_get0_SignerInfos(CMS_ContentInfo *cms);
259 
262  ASN1_OCTET_STRING **keyid,
263  X509_NAME **issuer, ASN1_INTEGER **sno);
266  unsigned int flags);
267 void CMS_SignerInfo_get0_algs(CMS_SignerInfo *si, EVP_PKEY **pk, X509 **signer,
268  X509_ALGOR **pdig, X509_ALGOR **psig);
272 
275  int algnid, int keysize);
277 
280  int lastpos);
282  int lastpos);
287  const ASN1_OBJECT *obj, int type,
288  const void *bytes, int len);
290  int nid, int type,
291  const void *bytes, int len);
293  const char *attrname, int type,
294  const void *bytes, int len);
296  int lastpos, int type);
297 
300  int lastpos);
302  int lastpos);
307  const ASN1_OBJECT *obj, int type,
308  const void *bytes, int len);
310  int nid, int type,
311  const void *bytes, int len);
313  const char *attrname, int type,
314  const void *bytes, int len);
316  int lastpos, int type);
317 
318 #ifdef HEADER_X509V3_H
319 
321 CMS_ReceiptRequest *CMS_ReceiptRequest_create0(unsigned char *id, int idlen,
322  int allorfirst,
323  STACK_OF(GENERAL_NAMES) *receiptList,
324  STACK_OF(GENERAL_NAMES) *receiptsTo);
327  ASN1_STRING **pcid,
328  int *pallorfirst,
329  STACK_OF(GENERAL_NAMES) **plist,
330  STACK_OF(GENERAL_NAMES) **prto);
331 
332 #endif
333 
334 /* BEGIN ERROR CODES */
335 /* The following lines are auto generated by the script mkerr.pl. Any changes
336  * made after this point may be overwritten when the script is next run.
337  */
338 void ERR_load_CMS_strings(void);
339 
340 /* Error codes for the CMS functions. */
341 
342 /* Function codes. */
343 #define CMS_F_CHECK_CONTENT 99
344 #define CMS_F_CMS_ADD0_CERT 164
345 #define CMS_F_CMS_ADD0_RECIPIENT_KEY 100
346 #define CMS_F_CMS_ADD0_RECIPIENT_PASSWORD 165
347 #define CMS_F_CMS_ADD1_RECEIPTREQUEST 158
348 #define CMS_F_CMS_ADD1_RECIPIENT_CERT 101
349 #define CMS_F_CMS_ADD1_SIGNER 102
350 #define CMS_F_CMS_ADD1_SIGNINGTIME 103
351 #define CMS_F_CMS_COMPRESS 104
352 #define CMS_F_CMS_COMPRESSEDDATA_CREATE 105
353 #define CMS_F_CMS_COMPRESSEDDATA_INIT_BIO 106
354 #define CMS_F_CMS_COPY_CONTENT 107
355 #define CMS_F_CMS_COPY_MESSAGEDIGEST 108
356 #define CMS_F_CMS_DATA 109
357 #define CMS_F_CMS_DATAFINAL 110
358 #define CMS_F_CMS_DATAINIT 111
359 #define CMS_F_CMS_DECRYPT 112
360 #define CMS_F_CMS_DECRYPT_SET1_KEY 113
361 #define CMS_F_CMS_DECRYPT_SET1_PASSWORD 166
362 #define CMS_F_CMS_DECRYPT_SET1_PKEY 114
363 #define CMS_F_CMS_DIGESTALGORITHM_FIND_CTX 115
364 #define CMS_F_CMS_DIGESTALGORITHM_INIT_BIO 116
365 #define CMS_F_CMS_DIGESTEDDATA_DO_FINAL 117
366 #define CMS_F_CMS_DIGEST_VERIFY 118
367 #define CMS_F_CMS_ENCODE_RECEIPT 161
368 #define CMS_F_CMS_ENCRYPT 119
369 #define CMS_F_CMS_ENCRYPTEDCONTENT_INIT_BIO 120
370 #define CMS_F_CMS_ENCRYPTEDDATA_DECRYPT 121
371 #define CMS_F_CMS_ENCRYPTEDDATA_ENCRYPT 122
372 #define CMS_F_CMS_ENCRYPTEDDATA_SET1_KEY 123
373 #define CMS_F_CMS_ENVELOPEDDATA_CREATE 124
374 #define CMS_F_CMS_ENVELOPEDDATA_INIT_BIO 125
375 #define CMS_F_CMS_ENVELOPED_DATA_INIT 126
376 #define CMS_F_CMS_FINAL 127
377 #define CMS_F_CMS_GET0_CERTIFICATE_CHOICES 128
378 #define CMS_F_CMS_GET0_CONTENT 129
379 #define CMS_F_CMS_GET0_ECONTENT_TYPE 130
380 #define CMS_F_CMS_GET0_ENVELOPED 131
381 #define CMS_F_CMS_GET0_REVOCATION_CHOICES 132
382 #define CMS_F_CMS_GET0_SIGNED 133
383 #define CMS_F_CMS_MSGSIGDIGEST_ADD1 162
384 #define CMS_F_CMS_RECEIPTREQUEST_CREATE0 159
385 #define CMS_F_CMS_RECEIPT_VERIFY 160
386 #define CMS_F_CMS_RECIPIENTINFO_DECRYPT 134
387 #define CMS_F_CMS_RECIPIENTINFO_KEKRI_DECRYPT 135
388 #define CMS_F_CMS_RECIPIENTINFO_KEKRI_ENCRYPT 136
389 #define CMS_F_CMS_RECIPIENTINFO_KEKRI_GET0_ID 137
390 #define CMS_F_CMS_RECIPIENTINFO_KEKRI_ID_CMP 138
391 #define CMS_F_CMS_RECIPIENTINFO_KTRI_CERT_CMP 139
392 #define CMS_F_CMS_RECIPIENTINFO_KTRI_DECRYPT 140
393 #define CMS_F_CMS_RECIPIENTINFO_KTRI_ENCRYPT 141
394 #define CMS_F_CMS_RECIPIENTINFO_KTRI_GET0_ALGS 142
395 #define CMS_F_CMS_RECIPIENTINFO_KTRI_GET0_SIGNER_ID 143
396 #define CMS_F_CMS_RECIPIENTINFO_PWRI_CRYPT 167
397 #define CMS_F_CMS_RECIPIENTINFO_SET0_KEY 144
398 #define CMS_F_CMS_RECIPIENTINFO_SET0_PASSWORD 168
399 #define CMS_F_CMS_RECIPIENTINFO_SET0_PKEY 145
400 #define CMS_F_CMS_SET1_SIGNERIDENTIFIER 146
401 #define CMS_F_CMS_SET_DETACHED 147
402 #define CMS_F_CMS_SIGN 148
403 #define CMS_F_CMS_SIGNED_DATA_INIT 149
404 #define CMS_F_CMS_SIGNERINFO_CONTENT_SIGN 150
405 #define CMS_F_CMS_SIGNERINFO_SIGN 151
406 #define CMS_F_CMS_SIGNERINFO_VERIFY 152
407 #define CMS_F_CMS_SIGNERINFO_VERIFY_CERT 153
408 #define CMS_F_CMS_SIGNERINFO_VERIFY_CONTENT 154
409 #define CMS_F_CMS_SIGN_RECEIPT 163
410 #define CMS_F_CMS_STREAM 155
411 #define CMS_F_CMS_UNCOMPRESS 156
412 #define CMS_F_CMS_VERIFY 157
413 
414 /* Reason codes. */
415 #define CMS_R_ADD_SIGNER_ERROR 99
416 #define CMS_R_CERTIFICATE_ALREADY_PRESENT 175
417 #define CMS_R_CERTIFICATE_HAS_NO_KEYID 160
418 #define CMS_R_CERTIFICATE_VERIFY_ERROR 100
419 #define CMS_R_CIPHER_INITIALISATION_ERROR 101
420 #define CMS_R_CIPHER_PARAMETER_INITIALISATION_ERROR 102
421 #define CMS_R_CMS_DATAFINAL_ERROR 103
422 #define CMS_R_CMS_LIB 104
423 #define CMS_R_CONTENTIDENTIFIER_MISMATCH 170
424 #define CMS_R_CONTENT_NOT_FOUND 105
425 #define CMS_R_CONTENT_TYPE_MISMATCH 171
426 #define CMS_R_CONTENT_TYPE_NOT_COMPRESSED_DATA 106
427 #define CMS_R_CONTENT_TYPE_NOT_ENVELOPED_DATA 107
428 #define CMS_R_CONTENT_TYPE_NOT_SIGNED_DATA 108
429 #define CMS_R_CONTENT_VERIFY_ERROR 109
430 #define CMS_R_CTRL_ERROR 110
431 #define CMS_R_CTRL_FAILURE 111
432 #define CMS_R_DECRYPT_ERROR 112
433 #define CMS_R_DIGEST_ERROR 161
434 #define CMS_R_ERROR_GETTING_PUBLIC_KEY 113
435 #define CMS_R_ERROR_READING_MESSAGEDIGEST_ATTRIBUTE 114
436 #define CMS_R_ERROR_SETTING_KEY 115
437 #define CMS_R_ERROR_SETTING_RECIPIENTINFO 116
438 #define CMS_R_INVALID_ENCRYPTED_KEY_LENGTH 117
439 #define CMS_R_INVALID_KEY_ENCRYPTION_PARAMETER 176
440 #define CMS_R_INVALID_KEY_LENGTH 118
441 #define CMS_R_MD_BIO_INIT_ERROR 119
442 #define CMS_R_MESSAGEDIGEST_ATTRIBUTE_WRONG_LENGTH 120
443 #define CMS_R_MESSAGEDIGEST_WRONG_LENGTH 121
444 #define CMS_R_MSGSIGDIGEST_ERROR 172
445 #define CMS_R_MSGSIGDIGEST_VERIFICATION_FAILURE 162
446 #define CMS_R_MSGSIGDIGEST_WRONG_LENGTH 163
447 #define CMS_R_NEED_ONE_SIGNER 164
448 #define CMS_R_NOT_A_SIGNED_RECEIPT 165
449 #define CMS_R_NOT_ENCRYPTED_DATA 122
450 #define CMS_R_NOT_KEK 123
451 #define CMS_R_NOT_KEY_TRANSPORT 124
452 #define CMS_R_NOT_PWRI 177
453 #define CMS_R_NOT_SUPPORTED_FOR_THIS_KEY_TYPE 125
454 #define CMS_R_NO_CIPHER 126
455 #define CMS_R_NO_CONTENT 127
456 #define CMS_R_NO_CONTENT_TYPE 173
457 #define CMS_R_NO_DEFAULT_DIGEST 128
458 #define CMS_R_NO_DIGEST_SET 129
459 #define CMS_R_NO_KEY 130
460 #define CMS_R_NO_KEY_OR_CERT 174
461 #define CMS_R_NO_MATCHING_DIGEST 131
462 #define CMS_R_NO_MATCHING_RECIPIENT 132
463 #define CMS_R_NO_MATCHING_SIGNATURE 166
464 #define CMS_R_NO_MSGSIGDIGEST 167
465 #define CMS_R_NO_PASSWORD 178
466 #define CMS_R_NO_PRIVATE_KEY 133
467 #define CMS_R_NO_PUBLIC_KEY 134
468 #define CMS_R_NO_RECEIPT_REQUEST 168
469 #define CMS_R_NO_SIGNERS 135
470 #define CMS_R_PRIVATE_KEY_DOES_NOT_MATCH_CERTIFICATE 136
471 #define CMS_R_RECEIPT_DECODE_ERROR 169
472 #define CMS_R_RECIPIENT_ERROR 137
473 #define CMS_R_SIGNER_CERTIFICATE_NOT_FOUND 138
474 #define CMS_R_SIGNFINAL_ERROR 139
475 #define CMS_R_SMIME_TEXT_ERROR 140
476 #define CMS_R_STORE_INIT_ERROR 141
477 #define CMS_R_TYPE_NOT_COMPRESSED_DATA 142
478 #define CMS_R_TYPE_NOT_DATA 143
479 #define CMS_R_TYPE_NOT_DIGESTED_DATA 144
480 #define CMS_R_TYPE_NOT_ENCRYPTED_DATA 145
481 #define CMS_R_TYPE_NOT_ENVELOPED_DATA 146
482 #define CMS_R_UNABLE_TO_FINALIZE_CONTEXT 147
483 #define CMS_R_UNKNOWN_CIPHER 148
484 #define CMS_R_UNKNOWN_DIGEST_ALGORIHM 149
485 #define CMS_R_UNKNOWN_ID 150
486 #define CMS_R_UNSUPPORTED_COMPRESSION_ALGORITHM 151
487 #define CMS_R_UNSUPPORTED_CONTENT_TYPE 152
488 #define CMS_R_UNSUPPORTED_KEK_ALGORITHM 153
489 #define CMS_R_UNSUPPORTED_KEY_ENCRYPTION_ALGORITHM 179
490 #define CMS_R_UNSUPPORTED_RECIPIENT_TYPE 154
491 #define CMS_R_UNSUPPORTED_RECPIENTINFO_TYPE 155
492 #define CMS_R_UNSUPPORTED_TYPE 156
493 #define CMS_R_UNWRAP_ERROR 157
494 #define CMS_R_UNWRAP_FAILURE 180
495 #define CMS_R_VERIFICATION_FAILURE 158
496 #define CMS_R_WRAP_ERROR 159
497 
498 #ifdef __cplusplus
499 }
500 #endif
501 #endif