Fix error in case CMP msg POPO is not provided in OSSL_CRMF_MSGS_verify_popo()
[openssl.git] / include / openssl / cms.h
1 /*
2  * Copyright 2008-2019 The OpenSSL Project Authors. All Rights Reserved.
3  *
4  * Licensed under the Apache License 2.0 (the "License").  You may not use
5  * this file except in compliance with the License.  You can obtain a copy
6  * in the file LICENSE in the source distribution or at
7  * https://www.openssl.org/source/license.html
8  */
9
10 #ifndef OPENSSL_CMS_H
11 # define OPENSSL_CMS_H
12 # pragma once
13
14 # include <openssl/macros.h>
15 # ifndef OPENSSL_NO_DEPRECATED_3_0
16 #  define HEADER_CMS_H
17 # endif
18
19 # include <openssl/opensslconf.h>
20
21 # ifndef OPENSSL_NO_CMS
22 # include <openssl/x509.h>
23 # include <openssl/x509v3.h>
24 # include <openssl/cmserr.h>
25 # ifdef __cplusplus
26 extern "C" {
27 # endif
28
29 typedef struct CMS_ContentInfo_st CMS_ContentInfo;
30 typedef struct CMS_SignerInfo_st CMS_SignerInfo;
31 typedef struct CMS_CertificateChoices CMS_CertificateChoices;
32 typedef struct CMS_RevocationInfoChoice_st CMS_RevocationInfoChoice;
33 typedef struct CMS_RecipientInfo_st CMS_RecipientInfo;
34 typedef struct CMS_ReceiptRequest_st CMS_ReceiptRequest;
35 typedef struct CMS_Receipt_st CMS_Receipt;
36 typedef struct CMS_RecipientEncryptedKey_st CMS_RecipientEncryptedKey;
37 typedef struct CMS_OtherKeyAttribute_st CMS_OtherKeyAttribute;
38
39 DEFINE_STACK_OF(CMS_SignerInfo)
40 DEFINE_STACK_OF(CMS_RecipientEncryptedKey)
41 DEFINE_STACK_OF(CMS_RecipientInfo)
42 DEFINE_STACK_OF(CMS_RevocationInfoChoice)
43 DECLARE_ASN1_FUNCTIONS(CMS_ContentInfo)
44 DECLARE_ASN1_FUNCTIONS(CMS_ReceiptRequest)
45 DECLARE_ASN1_PRINT_FUNCTION(CMS_ContentInfo)
46
47 # define CMS_SIGNERINFO_ISSUER_SERIAL    0
48 # define CMS_SIGNERINFO_KEYIDENTIFIER    1
49
50 # define CMS_RECIPINFO_NONE              -1
51 # define CMS_RECIPINFO_TRANS             0
52 # define CMS_RECIPINFO_AGREE             1
53 # define CMS_RECIPINFO_KEK               2
54 # define CMS_RECIPINFO_PASS              3
55 # define CMS_RECIPINFO_OTHER             4
56
57 /* S/MIME related flags */
58
59 # define CMS_TEXT                        0x1
60 # define CMS_NOCERTS                     0x2
61 # define CMS_NO_CONTENT_VERIFY           0x4
62 # define CMS_NO_ATTR_VERIFY              0x8
63 # define CMS_NOSIGS                      \
64                         (CMS_NO_CONTENT_VERIFY|CMS_NO_ATTR_VERIFY)
65 # define CMS_NOINTERN                    0x10
66 # define CMS_NO_SIGNER_CERT_VERIFY       0x20
67 # define CMS_NOVERIFY                    0x20
68 # define CMS_DETACHED                    0x40
69 # define CMS_BINARY                      0x80
70 # define CMS_NOATTR                      0x100
71 # define CMS_NOSMIMECAP                  0x200
72 # define CMS_NOOLDMIMETYPE               0x400
73 # define CMS_CRLFEOL                     0x800
74 # define CMS_STREAM                      0x1000
75 # define CMS_NOCRL                       0x2000
76 # define CMS_PARTIAL                     0x4000
77 # define CMS_REUSE_DIGEST                0x8000
78 # define CMS_USE_KEYID                   0x10000
79 # define CMS_DEBUG_DECRYPT               0x20000
80 # define CMS_KEY_PARAM                   0x40000
81 # define CMS_ASCIICRLF                   0x80000
82 # define CMS_CADES                       0x100000
83 # define CMS_USE_ORIGINATOR_KEYID        0x200000
84
85 const ASN1_OBJECT *CMS_get0_type(const CMS_ContentInfo *cms);
86
87 BIO *CMS_dataInit(CMS_ContentInfo *cms, BIO *icont);
88 int CMS_dataFinal(CMS_ContentInfo *cms, BIO *bio);
89
90 ASN1_OCTET_STRING **CMS_get0_content(CMS_ContentInfo *cms);
91 int CMS_is_detached(CMS_ContentInfo *cms);
92 int CMS_set_detached(CMS_ContentInfo *cms, int detached);
93
94 # ifdef OPENSSL_PEM_H
95 DECLARE_PEM_rw(CMS, CMS_ContentInfo)
96 # endif
97 int CMS_stream(unsigned char ***boundary, CMS_ContentInfo *cms);
98 CMS_ContentInfo *d2i_CMS_bio(BIO *bp, CMS_ContentInfo **cms);
99 int i2d_CMS_bio(BIO *bp, CMS_ContentInfo *cms);
100
101 BIO *BIO_new_CMS(BIO *out, CMS_ContentInfo *cms);
102 int i2d_CMS_bio_stream(BIO *out, CMS_ContentInfo *cms, BIO *in, int flags);
103 int PEM_write_bio_CMS_stream(BIO *out, CMS_ContentInfo *cms, BIO *in,
104                              int flags);
105 CMS_ContentInfo *SMIME_read_CMS(BIO *bio, BIO **bcont);
106 int SMIME_write_CMS(BIO *bio, CMS_ContentInfo *cms, BIO *data, int flags);
107
108 int CMS_final(CMS_ContentInfo *cms, BIO *data, BIO *dcont,
109               unsigned int flags);
110
111 CMS_ContentInfo *CMS_sign(X509 *signcert, EVP_PKEY *pkey,
112                           STACK_OF(X509) *certs, BIO *data,
113                           unsigned int flags);
114
115 CMS_ContentInfo *CMS_sign_receipt(CMS_SignerInfo *si,
116                                   X509 *signcert, EVP_PKEY *pkey,
117                                   STACK_OF(X509) *certs, unsigned int flags);
118
119 int CMS_data(CMS_ContentInfo *cms, BIO *out, unsigned int flags);
120 CMS_ContentInfo *CMS_data_create(BIO *in, unsigned int flags);
121
122 int CMS_digest_verify(CMS_ContentInfo *cms, BIO *dcont, BIO *out,
123                       unsigned int flags);
124 CMS_ContentInfo *CMS_digest_create(BIO *in, const EVP_MD *md,
125                                    unsigned int flags);
126
127 int CMS_EncryptedData_decrypt(CMS_ContentInfo *cms,
128                               const unsigned char *key, size_t keylen,
129                               BIO *dcont, BIO *out, unsigned int flags);
130
131 CMS_ContentInfo *CMS_EncryptedData_encrypt(BIO *in, const EVP_CIPHER *cipher,
132                                            const unsigned char *key,
133                                            size_t keylen, unsigned int flags);
134
135 int CMS_EncryptedData_set1_key(CMS_ContentInfo *cms, const EVP_CIPHER *ciph,
136                                const unsigned char *key, size_t keylen);
137
138 int CMS_verify(CMS_ContentInfo *cms, STACK_OF(X509) *certs,
139                X509_STORE *store, BIO *dcont, BIO *out, unsigned int flags);
140
141 int CMS_verify_receipt(CMS_ContentInfo *rcms, CMS_ContentInfo *ocms,
142                        STACK_OF(X509) *certs,
143                        X509_STORE *store, unsigned int flags);
144
145 STACK_OF(X509) *CMS_get0_signers(CMS_ContentInfo *cms);
146
147 CMS_ContentInfo *CMS_encrypt(STACK_OF(X509) *certs, BIO *in,
148                              const EVP_CIPHER *cipher, unsigned int flags);
149
150 int CMS_decrypt(CMS_ContentInfo *cms, EVP_PKEY *pkey, X509 *cert,
151                 BIO *dcont, BIO *out, unsigned int flags);
152
153 int CMS_decrypt_set1_pkey(CMS_ContentInfo *cms, EVP_PKEY *pk, X509 *cert);
154 int CMS_decrypt_set1_pkey_and_peer(CMS_ContentInfo *cms, EVP_PKEY *pk, X509 *cert, X509 *peer);
155 int CMS_decrypt_set1_key(CMS_ContentInfo *cms,
156                          unsigned char *key, size_t keylen,
157                          const unsigned char *id, size_t idlen);
158 int CMS_decrypt_set1_password(CMS_ContentInfo *cms,
159                               unsigned char *pass, ossl_ssize_t passlen);
160
161 STACK_OF(CMS_RecipientInfo) *CMS_get0_RecipientInfos(CMS_ContentInfo *cms);
162 int CMS_RecipientInfo_type(CMS_RecipientInfo *ri);
163 EVP_PKEY_CTX *CMS_RecipientInfo_get0_pkey_ctx(CMS_RecipientInfo *ri);
164 CMS_ContentInfo *CMS_EnvelopedData_create(const EVP_CIPHER *cipher);
165 CMS_RecipientInfo *CMS_add1_recipient_cert(CMS_ContentInfo *cms,
166                                            X509 *recip, unsigned int flags);
167 CMS_RecipientInfo *CMS_add1_recipient(CMS_ContentInfo *cms, X509 *recip,
168      EVP_PKEY *originatorPrivKey, X509 * originator, unsigned int flags);
169 int CMS_RecipientInfo_set0_pkey(CMS_RecipientInfo *ri, EVP_PKEY *pkey);
170 int CMS_RecipientInfo_ktri_cert_cmp(CMS_RecipientInfo *ri, X509 *cert);
171 int CMS_RecipientInfo_ktri_get0_algs(CMS_RecipientInfo *ri,
172                                      EVP_PKEY **pk, X509 **recip,
173                                      X509_ALGOR **palg);
174 int CMS_RecipientInfo_ktri_get0_signer_id(CMS_RecipientInfo *ri,
175                                           ASN1_OCTET_STRING **keyid,
176                                           X509_NAME **issuer,
177                                           ASN1_INTEGER **sno);
178
179 CMS_RecipientInfo *CMS_add0_recipient_key(CMS_ContentInfo *cms, int nid,
180                                           unsigned char *key, size_t keylen,
181                                           unsigned char *id, size_t idlen,
182                                           ASN1_GENERALIZEDTIME *date,
183                                           ASN1_OBJECT *otherTypeId,
184                                           ASN1_TYPE *otherType);
185
186 int CMS_RecipientInfo_kekri_get0_id(CMS_RecipientInfo *ri,
187                                     X509_ALGOR **palg,
188                                     ASN1_OCTET_STRING **pid,
189                                     ASN1_GENERALIZEDTIME **pdate,
190                                     ASN1_OBJECT **potherid,
191                                     ASN1_TYPE **pothertype);
192
193 int CMS_RecipientInfo_set0_key(CMS_RecipientInfo *ri,
194                                unsigned char *key, size_t keylen);
195
196 int CMS_RecipientInfo_kekri_id_cmp(CMS_RecipientInfo *ri,
197                                    const unsigned char *id, size_t idlen);
198
199 int CMS_RecipientInfo_set0_password(CMS_RecipientInfo *ri,
200                                     unsigned char *pass,
201                                     ossl_ssize_t passlen);
202
203 CMS_RecipientInfo *CMS_add0_recipient_password(CMS_ContentInfo *cms,
204                                                int iter, int wrap_nid,
205                                                int pbe_nid,
206                                                unsigned char *pass,
207                                                ossl_ssize_t passlen,
208                                                const EVP_CIPHER *kekciph);
209
210 int CMS_RecipientInfo_decrypt(CMS_ContentInfo *cms, CMS_RecipientInfo *ri);
211 int CMS_RecipientInfo_encrypt(const CMS_ContentInfo *cms, CMS_RecipientInfo *ri);
212
213 int CMS_uncompress(CMS_ContentInfo *cms, BIO *dcont, BIO *out,
214                    unsigned int flags);
215 CMS_ContentInfo *CMS_compress(BIO *in, int comp_nid, unsigned int flags);
216
217 int CMS_set1_eContentType(CMS_ContentInfo *cms, const ASN1_OBJECT *oid);
218 const ASN1_OBJECT *CMS_get0_eContentType(CMS_ContentInfo *cms);
219
220 CMS_CertificateChoices *CMS_add0_CertificateChoices(CMS_ContentInfo *cms);
221 int CMS_add0_cert(CMS_ContentInfo *cms, X509 *cert);
222 int CMS_add1_cert(CMS_ContentInfo *cms, X509 *cert);
223 STACK_OF(X509) *CMS_get1_certs(CMS_ContentInfo *cms);
224
225 CMS_RevocationInfoChoice *CMS_add0_RevocationInfoChoice(CMS_ContentInfo *cms);
226 int CMS_add0_crl(CMS_ContentInfo *cms, X509_CRL *crl);
227 int CMS_add1_crl(CMS_ContentInfo *cms, X509_CRL *crl);
228 STACK_OF(X509_CRL) *CMS_get1_crls(CMS_ContentInfo *cms);
229
230 int CMS_SignedData_init(CMS_ContentInfo *cms);
231 CMS_SignerInfo *CMS_add1_signer(CMS_ContentInfo *cms,
232                                 X509 *signer, EVP_PKEY *pk, const EVP_MD *md,
233                                 unsigned int flags);
234 EVP_PKEY_CTX *CMS_SignerInfo_get0_pkey_ctx(CMS_SignerInfo *si);
235 EVP_MD_CTX *CMS_SignerInfo_get0_md_ctx(CMS_SignerInfo *si);
236 STACK_OF(CMS_SignerInfo) *CMS_get0_SignerInfos(CMS_ContentInfo *cms);
237
238 void CMS_SignerInfo_set1_signer_cert(CMS_SignerInfo *si, X509 *signer);
239 int CMS_SignerInfo_get0_signer_id(CMS_SignerInfo *si,
240                                   ASN1_OCTET_STRING **keyid,
241                                   X509_NAME **issuer, ASN1_INTEGER **sno);
242 int CMS_SignerInfo_cert_cmp(CMS_SignerInfo *si, X509 *cert);
243 int CMS_set1_signers_certs(CMS_ContentInfo *cms, STACK_OF(X509) *certs,
244                            unsigned int flags);
245 void CMS_SignerInfo_get0_algs(CMS_SignerInfo *si, EVP_PKEY **pk,
246                               X509 **signer, X509_ALGOR **pdig,
247                               X509_ALGOR **psig);
248 ASN1_OCTET_STRING *CMS_SignerInfo_get0_signature(CMS_SignerInfo *si);
249 int CMS_SignerInfo_sign(CMS_SignerInfo *si);
250 int CMS_SignerInfo_verify(CMS_SignerInfo *si);
251 int CMS_SignerInfo_verify_content(CMS_SignerInfo *si, BIO *chain);
252
253 int CMS_add_smimecap(CMS_SignerInfo *si, STACK_OF(X509_ALGOR) *algs);
254 int CMS_add_simple_smimecap(STACK_OF(X509_ALGOR) **algs,
255                             int algnid, int keysize);
256 int CMS_add_standard_smimecap(STACK_OF(X509_ALGOR) **smcap);
257
258 int CMS_signed_get_attr_count(const CMS_SignerInfo *si);
259 int CMS_signed_get_attr_by_NID(const CMS_SignerInfo *si, int nid,
260                                int lastpos);
261 int CMS_signed_get_attr_by_OBJ(const CMS_SignerInfo *si, const ASN1_OBJECT *obj,
262                                int lastpos);
263 X509_ATTRIBUTE *CMS_signed_get_attr(const CMS_SignerInfo *si, int loc);
264 X509_ATTRIBUTE *CMS_signed_delete_attr(CMS_SignerInfo *si, int loc);
265 int CMS_signed_add1_attr(CMS_SignerInfo *si, X509_ATTRIBUTE *attr);
266 int CMS_signed_add1_attr_by_OBJ(CMS_SignerInfo *si,
267                                 const ASN1_OBJECT *obj, int type,
268                                 const void *bytes, int len);
269 int CMS_signed_add1_attr_by_NID(CMS_SignerInfo *si,
270                                 int nid, int type,
271                                 const void *bytes, int len);
272 int CMS_signed_add1_attr_by_txt(CMS_SignerInfo *si,
273                                 const char *attrname, int type,
274                                 const void *bytes, int len);
275 void *CMS_signed_get0_data_by_OBJ(CMS_SignerInfo *si, const ASN1_OBJECT *oid,
276                                   int lastpos, int type);
277
278 int CMS_unsigned_get_attr_count(const CMS_SignerInfo *si);
279 int CMS_unsigned_get_attr_by_NID(const CMS_SignerInfo *si, int nid,
280                                  int lastpos);
281 int CMS_unsigned_get_attr_by_OBJ(const CMS_SignerInfo *si,
282                                  const ASN1_OBJECT *obj, int lastpos);
283 X509_ATTRIBUTE *CMS_unsigned_get_attr(const CMS_SignerInfo *si, int loc);
284 X509_ATTRIBUTE *CMS_unsigned_delete_attr(CMS_SignerInfo *si, int loc);
285 int CMS_unsigned_add1_attr(CMS_SignerInfo *si, X509_ATTRIBUTE *attr);
286 int CMS_unsigned_add1_attr_by_OBJ(CMS_SignerInfo *si,
287                                   const ASN1_OBJECT *obj, int type,
288                                   const void *bytes, int len);
289 int CMS_unsigned_add1_attr_by_NID(CMS_SignerInfo *si,
290                                   int nid, int type,
291                                   const void *bytes, int len);
292 int CMS_unsigned_add1_attr_by_txt(CMS_SignerInfo *si,
293                                   const char *attrname, int type,
294                                   const void *bytes, int len);
295 void *CMS_unsigned_get0_data_by_OBJ(CMS_SignerInfo *si, ASN1_OBJECT *oid,
296                                     int lastpos, int type);
297
298 int CMS_get1_ReceiptRequest(CMS_SignerInfo *si, CMS_ReceiptRequest **prr);
299 CMS_ReceiptRequest *CMS_ReceiptRequest_create0(unsigned char *id, int idlen,
300                                                int allorfirst,
301                                                STACK_OF(GENERAL_NAMES)
302                                                *receiptList, STACK_OF(GENERAL_NAMES)
303                                                *receiptsTo);
304 int CMS_add1_ReceiptRequest(CMS_SignerInfo *si, CMS_ReceiptRequest *rr);
305 void CMS_ReceiptRequest_get0_values(CMS_ReceiptRequest *rr,
306                                     ASN1_STRING **pcid,
307                                     int *pallorfirst,
308                                     STACK_OF(GENERAL_NAMES) **plist,
309                                     STACK_OF(GENERAL_NAMES) **prto);
310 int CMS_RecipientInfo_kari_get0_alg(CMS_RecipientInfo *ri,
311                                     X509_ALGOR **palg,
312                                     ASN1_OCTET_STRING **pukm);
313 STACK_OF(CMS_RecipientEncryptedKey)
314 *CMS_RecipientInfo_kari_get0_reks(CMS_RecipientInfo *ri);
315
316 int CMS_RecipientInfo_kari_get0_orig_id(CMS_RecipientInfo *ri,
317                                         X509_ALGOR **pubalg,
318                                         ASN1_BIT_STRING **pubkey,
319                                         ASN1_OCTET_STRING **keyid,
320                                         X509_NAME **issuer,
321                                         ASN1_INTEGER **sno);
322
323 int CMS_RecipientInfo_kari_orig_id_cmp(CMS_RecipientInfo *ri, X509 *cert);
324
325 int CMS_RecipientEncryptedKey_get0_id(CMS_RecipientEncryptedKey *rek,
326                                       ASN1_OCTET_STRING **keyid,
327                                       ASN1_GENERALIZEDTIME **tm,
328                                       CMS_OtherKeyAttribute **other,
329                                       X509_NAME **issuer, ASN1_INTEGER **sno);
330 int CMS_RecipientEncryptedKey_cert_cmp(CMS_RecipientEncryptedKey *rek,
331                                        X509 *cert);
332 int CMS_RecipientInfo_kari_set0_pkey(CMS_RecipientInfo *ri, EVP_PKEY *pk);
333 int CMS_RecipientInfo_kari_set0_pkey_and_peer(CMS_RecipientInfo *ri, EVP_PKEY *pk, X509 *peer);
334 EVP_CIPHER_CTX *CMS_RecipientInfo_kari_get0_ctx(CMS_RecipientInfo *ri);
335 int CMS_RecipientInfo_kari_decrypt(CMS_ContentInfo *cms,
336                                    CMS_RecipientInfo *ri,
337                                    CMS_RecipientEncryptedKey *rek);
338
339 int CMS_SharedInfo_encode(unsigned char **pder, X509_ALGOR *kekalg,
340                           ASN1_OCTET_STRING *ukm, int keylen);
341
342 /* Backward compatibility for spelling errors. */
343 # define CMS_R_UNKNOWN_DIGEST_ALGORITM CMS_R_UNKNOWN_DIGEST_ALGORITHM
344 # define CMS_R_UNSUPPORTED_RECPIENTINFO_TYPE \
345     CMS_R_UNSUPPORTED_RECIPIENTINFO_TYPE
346
347 #  ifdef  __cplusplus
348 }
349 #  endif
350 # endif
351 #endif