]> git.ipfire.org Git - thirdparty/openssl.git/blame - include/openssl/pkcs7.h
Deprecate the low level Diffie-Hellman functions.
[thirdparty/openssl.git] / include / openssl / pkcs7.h
CommitLineData
21dcbebc
RS
1/*
2 * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
d02b48c6 3 *
48f4ad77 4 * Licensed under the Apache License 2.0 (the "License"). You may not use
21dcbebc
RS
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
d02b48c6
RE
8 */
9
ae4186b0
DMSP
10#ifndef OPENSSL_PKCS7_H
11# define OPENSSL_PKCS7_H
d86167ec
DMSP
12# pragma once
13
14# include <openssl/macros.h>
936c2b9e 15# ifndef OPENSSL_NO_DEPRECATED_3_0
d86167ec
DMSP
16# define HEADER_PKCS7_H
17# endif
d02b48c6 18
0f113f3e
MC
19# include <openssl/asn1.h>
20# include <openssl/bio.h>
21# include <openssl/e_os2.h>
d02b48c6 22
0f113f3e 23# include <openssl/symhacks.h>
50cd4768 24# include <openssl/types.h>
52df25cf 25# include <openssl/pkcs7err.h>
8c197cc5 26
82271cee
RL
27#ifdef __cplusplus
28extern "C" {
29#endif
30
1d97c843 31/*-
0f113f3e
MC
32Encryption_ID DES-CBC
33Digest_ID MD5
34Digest_Encryption_ID rsaEncryption
35Key_Encryption_ID rsaEncryption
d02b48c6
RE
36*/
37
0f113f3e
MC
38typedef struct pkcs7_issuer_and_serial_st {
39 X509_NAME *issuer;
40 ASN1_INTEGER *serial;
41} PKCS7_ISSUER_AND_SERIAL;
42
43typedef struct pkcs7_signer_info_st {
44 ASN1_INTEGER *version; /* version 1 */
45 PKCS7_ISSUER_AND_SERIAL *issuer_and_serial;
46 X509_ALGOR *digest_alg;
47 STACK_OF(X509_ATTRIBUTE) *auth_attr; /* [ 0 ] */
48 X509_ALGOR *digest_enc_alg;
49 ASN1_OCTET_STRING *enc_digest;
50 STACK_OF(X509_ATTRIBUTE) *unauth_attr; /* [ 1 ] */
51 /* The private key to sign with */
52 EVP_PKEY *pkey;
53} PKCS7_SIGNER_INFO;
d02b48c6 54
85885715 55DEFINE_STACK_OF(PKCS7_SIGNER_INFO)
b05b50e6 56
0f113f3e
MC
57typedef struct pkcs7_recip_info_st {
58 ASN1_INTEGER *version; /* version 0 */
59 PKCS7_ISSUER_AND_SERIAL *issuer_and_serial;
60 X509_ALGOR *key_enc_algor;
61 ASN1_OCTET_STRING *enc_key;
62 X509 *cert; /* get the pub-key from this */
63} PKCS7_RECIP_INFO;
d02b48c6 64
85885715 65DEFINE_STACK_OF(PKCS7_RECIP_INFO)
8f0edcd1 66
0f113f3e
MC
67typedef struct pkcs7_signed_st {
68 ASN1_INTEGER *version; /* version 1 */
69 STACK_OF(X509_ALGOR) *md_algs; /* md used */
70 STACK_OF(X509) *cert; /* [ 0 ] */
71 STACK_OF(X509_CRL) *crl; /* [ 1 ] */
72 STACK_OF(PKCS7_SIGNER_INFO) *signer_info;
73 struct pkcs7_st *contents;
74} PKCS7_SIGNED;
75/*
76 * The above structure is very very similar to PKCS7_SIGN_ENVELOPE. How about
77 * merging the two
78 */
79
80typedef struct pkcs7_enc_content_st {
81 ASN1_OBJECT *content_type;
82 X509_ALGOR *algorithm;
83 ASN1_OCTET_STRING *enc_data; /* [ 0 ] */
84 const EVP_CIPHER *cipher;
85} PKCS7_ENC_CONTENT;
86
87typedef struct pkcs7_enveloped_st {
88 ASN1_INTEGER *version; /* version 0 */
89 STACK_OF(PKCS7_RECIP_INFO) *recipientinfo;
90 PKCS7_ENC_CONTENT *enc_data;
91} PKCS7_ENVELOPE;
92
93typedef struct pkcs7_signedandenveloped_st {
94 ASN1_INTEGER *version; /* version 1 */
95 STACK_OF(X509_ALGOR) *md_algs; /* md used */
96 STACK_OF(X509) *cert; /* [ 0 ] */
97 STACK_OF(X509_CRL) *crl; /* [ 1 ] */
98 STACK_OF(PKCS7_SIGNER_INFO) *signer_info;
99 PKCS7_ENC_CONTENT *enc_data;
100 STACK_OF(PKCS7_RECIP_INFO) *recipientinfo;
101} PKCS7_SIGN_ENVELOPE;
102
103typedef struct pkcs7_digest_st {
104 ASN1_INTEGER *version; /* version 0 */
105 X509_ALGOR *md; /* md used */
106 struct pkcs7_st *contents;
107 ASN1_OCTET_STRING *digest;
108} PKCS7_DIGEST;
109
110typedef struct pkcs7_encrypted_st {
111 ASN1_INTEGER *version; /* version 0 */
112 PKCS7_ENC_CONTENT *enc_data;
113} PKCS7_ENCRYPT;
114
115typedef struct pkcs7_st {
116 /*
117 * The following is non NULL if it contains ASN1 encoding of this
118 * structure
119 */
120 unsigned char *asn1;
121 long length;
122# define PKCS7_S_HEADER 0
123# define PKCS7_S_BODY 1
124# define PKCS7_S_TAIL 2
125 int state; /* used during processing */
126 int detached;
127 ASN1_OBJECT *type;
128 /* content as defined by the type */
129 /*
130 * all encryption/message digests are applied to the 'contents', leaving
131 * out the 'type' field.
132 */
133 union {
134 char *ptr;
135 /* NID_pkcs7_data */
136 ASN1_OCTET_STRING *data;
137 /* NID_pkcs7_signed */
138 PKCS7_SIGNED *sign;
139 /* NID_pkcs7_enveloped */
140 PKCS7_ENVELOPE *enveloped;
141 /* NID_pkcs7_signedAndEnveloped */
142 PKCS7_SIGN_ENVELOPE *signed_and_enveloped;
143 /* NID_pkcs7_digest */
144 PKCS7_DIGEST *digest;
145 /* NID_pkcs7_encrypted */
146 PKCS7_ENCRYPT *encrypted;
147 /* Anything else */
148 ASN1_TYPE *other;
149 } d;
150} PKCS7;
d02b48c6 151
85885715 152DEFINE_STACK_OF(PKCS7)
5de603ab 153
0f113f3e
MC
154# define PKCS7_OP_SET_DETACHED_SIGNATURE 1
155# define PKCS7_OP_GET_DETACHED_SIGNATURE 2
d02b48c6 156
0f113f3e
MC
157# define PKCS7_get_signed_attributes(si) ((si)->auth_attr)
158# define PKCS7_get_attributes(si) ((si)->unauth_attr)
dfeab068 159
0f113f3e
MC
160# define PKCS7_type_is_signed(a) (OBJ_obj2nid((a)->type) == NID_pkcs7_signed)
161# define PKCS7_type_is_encrypted(a) (OBJ_obj2nid((a)->type) == NID_pkcs7_encrypted)
162# define PKCS7_type_is_enveloped(a) (OBJ_obj2nid((a)->type) == NID_pkcs7_enveloped)
163# define PKCS7_type_is_signedAndEnveloped(a) \
164 (OBJ_obj2nid((a)->type) == NID_pkcs7_signedAndEnveloped)
165# define PKCS7_type_is_data(a) (OBJ_obj2nid((a)->type) == NID_pkcs7_data)
166# define PKCS7_type_is_digest(a) (OBJ_obj2nid((a)->type) == NID_pkcs7_digest)
c5a55463 167
0f113f3e
MC
168# define PKCS7_set_detached(p,v) \
169 PKCS7_ctrl(p,PKCS7_OP_SET_DETACHED_SIGNATURE,v,NULL)
170# define PKCS7_get_detached(p) \
171 PKCS7_ctrl(p,PKCS7_OP_GET_DETACHED_SIGNATURE,0,NULL)
d02b48c6 172
0f113f3e 173# define PKCS7_is_detached(p7) (PKCS7_type_is_signed(p7) && PKCS7_get_detached(p7))
9d6b1ce6 174
5a9a4b29
DSH
175/* S/MIME related flags */
176
0f113f3e
MC
177# define PKCS7_TEXT 0x1
178# define PKCS7_NOCERTS 0x2
179# define PKCS7_NOSIGS 0x4
180# define PKCS7_NOCHAIN 0x8
181# define PKCS7_NOINTERN 0x10
182# define PKCS7_NOVERIFY 0x20
183# define PKCS7_DETACHED 0x40
184# define PKCS7_BINARY 0x80
185# define PKCS7_NOATTR 0x100
186# define PKCS7_NOSMIMECAP 0x200
187# define PKCS7_NOOLDMIMETYPE 0x400
188# define PKCS7_CRLFEOL 0x800
189# define PKCS7_STREAM 0x1000
190# define PKCS7_NOCRL 0x2000
191# define PKCS7_PARTIAL 0x4000
192# define PKCS7_REUSE_DIGEST 0x8000
6b2ebe43 193# define PKCS7_NO_DUAL_CONTENT 0x10000
5a9a4b29 194
657e60fa 195/* Flags: for compatibility with older code */
5a9a4b29 196
0f113f3e
MC
197# define SMIME_TEXT PKCS7_TEXT
198# define SMIME_NOCERTS PKCS7_NOCERTS
199# define SMIME_NOSIGS PKCS7_NOSIGS
200# define SMIME_NOCHAIN PKCS7_NOCHAIN
201# define SMIME_NOINTERN PKCS7_NOINTERN
202# define SMIME_NOVERIFY PKCS7_NOVERIFY
203# define SMIME_DETACHED PKCS7_DETACHED
204# define SMIME_BINARY PKCS7_BINARY
205# define SMIME_NOATTR PKCS7_NOATTR
58964a49 206
847865d0 207/* CRLF ASCII canonicalisation */
0f113f3e 208# define SMIME_ASCIICRLF 0x80000
847865d0 209
9d6b1ce6 210DECLARE_ASN1_FUNCTIONS(PKCS7_ISSUER_AND_SERIAL)
d02b48c6 211
0f113f3e
MC
212int PKCS7_ISSUER_AND_SERIAL_digest(PKCS7_ISSUER_AND_SERIAL *data,
213 const EVP_MD *type, unsigned char *md,
214 unsigned int *len);
215# ifndef OPENSSL_NO_STDIO
216PKCS7 *d2i_PKCS7_fp(FILE *fp, PKCS7 **p7);
9fdcc21f 217int i2d_PKCS7_fp(FILE *fp, const PKCS7 *p7);
0f113f3e 218# endif
9fdcc21f 219DECLARE_ASN1_DUP_FUNCTION(PKCS7)
0f113f3e 220PKCS7 *d2i_PKCS7_bio(BIO *bp, PKCS7 **p7);
9fdcc21f 221int i2d_PKCS7_bio(BIO *bp, const PKCS7 *p7);
9cfc8a9d
DSH
222int i2d_PKCS7_bio_stream(BIO *out, PKCS7 *p7, BIO *in, int flags);
223int PEM_write_bio_PKCS7_stream(BIO *out, PKCS7 *p7, BIO *in, int flags);
d02b48c6 224
9d6b1ce6
DSH
225DECLARE_ASN1_FUNCTIONS(PKCS7_SIGNER_INFO)
226DECLARE_ASN1_FUNCTIONS(PKCS7_RECIP_INFO)
227DECLARE_ASN1_FUNCTIONS(PKCS7_SIGNED)
228DECLARE_ASN1_FUNCTIONS(PKCS7_ENC_CONTENT)
229DECLARE_ASN1_FUNCTIONS(PKCS7_ENVELOPE)
230DECLARE_ASN1_FUNCTIONS(PKCS7_SIGN_ENVELOPE)
231DECLARE_ASN1_FUNCTIONS(PKCS7_DIGEST)
232DECLARE_ASN1_FUNCTIONS(PKCS7_ENCRYPT)
233DECLARE_ASN1_FUNCTIONS(PKCS7)
d02b48c6 234
ec5add87
DSH
235DECLARE_ASN1_ITEM(PKCS7_ATTR_SIGN)
236DECLARE_ASN1_ITEM(PKCS7_ATTR_VERIFY)
237
a2a1a04e 238DECLARE_ASN1_NDEF_FUNCTION(PKCS7)
9194296d 239DECLARE_ASN1_PRINT_FUNCTION(PKCS7)
d02b48c6
RE
240
241long PKCS7_ctrl(PKCS7 *p7, int cmd, long larg, char *parg);
242
243int PKCS7_set_type(PKCS7 *p7, int type);
8d9086df 244int PKCS7_set0_type_other(PKCS7 *p7, int type, ASN1_TYPE *other);
d02b48c6
RE
245int PKCS7_set_content(PKCS7 *p7, PKCS7 *p7_data);
246int PKCS7_SIGNER_INFO_set(PKCS7_SIGNER_INFO *p7i, X509 *x509, EVP_PKEY *pkey,
0f113f3e 247 const EVP_MD *dgst);
76fa8f18 248int PKCS7_SIGNER_INFO_sign(PKCS7_SIGNER_INFO *si);
d02b48c6
RE
249int PKCS7_add_signer(PKCS7 *p7, PKCS7_SIGNER_INFO *p7i);
250int PKCS7_add_certificate(PKCS7 *p7, X509 *x509);
251int PKCS7_add_crl(PKCS7 *p7, X509_CRL *x509);
252int PKCS7_content_new(PKCS7 *p7, int nid);
d02b48c6 253int PKCS7_dataVerify(X509_STORE *cert_store, X509_STORE_CTX *ctx,
0f113f3e 254 BIO *bio, PKCS7 *p7, PKCS7_SIGNER_INFO *si);
170afce5 255int PKCS7_signatureVerify(BIO *bio, PKCS7 *p7, PKCS7_SIGNER_INFO *si,
0f113f3e 256 X509 *x509);
d02b48c6
RE
257
258BIO *PKCS7_dataInit(PKCS7 *p7, BIO *bio);
dfeab068 259int PKCS7_dataFinal(PKCS7 *p7, BIO *bio);
84fa704c 260BIO *PKCS7_dataDecode(PKCS7 *p7, EVP_PKEY *pkey, BIO *in_bio, X509 *pcert);
dfeab068 261
d02b48c6 262PKCS7_SIGNER_INFO *PKCS7_add_signature(PKCS7 *p7, X509 *x509,
0f113f3e 263 EVP_PKEY *pkey, const EVP_MD *dgst);
d02b48c6 264X509 *PKCS7_cert_from_signer_info(PKCS7 *p7, PKCS7_SIGNER_INFO *si);
c5a55463 265int PKCS7_set_digest(PKCS7 *p7, const EVP_MD *md);
b05b50e6 266STACK_OF(PKCS7_SIGNER_INFO) *PKCS7_get_signer_info(PKCS7 *p7);
d02b48c6 267
58964a49 268PKCS7_RECIP_INFO *PKCS7_add_recipient(PKCS7 *p7, X509 *x509);
492a9e24 269void PKCS7_SIGNER_INFO_get0_algs(PKCS7_SIGNER_INFO *si, EVP_PKEY **pk,
0f113f3e 270 X509_ALGOR **pdig, X509_ALGOR **psig);
e4b21c74 271void PKCS7_RECIP_INFO_get0_alg(PKCS7_RECIP_INFO *ri, X509_ALGOR **penc);
58964a49
RE
272int PKCS7_add_recipient_info(PKCS7 *p7, PKCS7_RECIP_INFO *ri);
273int PKCS7_RECIP_INFO_set(PKCS7_RECIP_INFO *p7i, X509 *x509);
84fa704c 274int PKCS7_set_cipher(PKCS7 *p7, const EVP_CIPHER *cipher);
11d8cdc6 275int PKCS7_stream(unsigned char ***boundary, PKCS7 *p7);
58964a49 276
dfeab068 277PKCS7_ISSUER_AND_SERIAL *PKCS7_get_issuer_and_serial(PKCS7 *p7, int idx);
b6436ff2 278ASN1_OCTET_STRING *PKCS7_digest_from_attributes(STACK_OF(X509_ATTRIBUTE) *sk);
0f113f3e
MC
279int PKCS7_add_signed_attribute(PKCS7_SIGNER_INFO *p7si, int nid, int type,
280 void *data);
281int PKCS7_add_attribute(PKCS7_SIGNER_INFO *p7si, int nid, int atrtype,
282 void *value);
dfeab068
RE
283ASN1_TYPE *PKCS7_get_attribute(PKCS7_SIGNER_INFO *si, int nid);
284ASN1_TYPE *PKCS7_get_signed_attribute(PKCS7_SIGNER_INFO *si, int nid);
b6436ff2 285int PKCS7_set_signed_attributes(PKCS7_SIGNER_INFO *p7si,
0f113f3e
MC
286 STACK_OF(X509_ATTRIBUTE) *sk);
287int PKCS7_set_attributes(PKCS7_SIGNER_INFO *p7si,
288 STACK_OF(X509_ATTRIBUTE) *sk);
58964a49 289
5a9a4b29 290PKCS7 *PKCS7_sign(X509 *signcert, EVP_PKEY *pkey, STACK_OF(X509) *certs,
0f113f3e 291 BIO *data, int flags);
60f20632
DSH
292
293PKCS7_SIGNER_INFO *PKCS7_sign_add_signer(PKCS7 *p7,
0f113f3e
MC
294 X509 *signcert, EVP_PKEY *pkey,
295 const EVP_MD *md, int flags);
60f20632
DSH
296
297int PKCS7_final(PKCS7 *p7, BIO *data, int flags);
5a9a4b29 298int PKCS7_verify(PKCS7 *p7, STACK_OF(X509) *certs, X509_STORE *store,
0f113f3e
MC
299 BIO *indata, BIO *out, int flags);
300STACK_OF(X509) *PKCS7_get0_signers(PKCS7 *p7, STACK_OF(X509) *certs,
301 int flags);
13588350 302PKCS7 *PKCS7_encrypt(STACK_OF(X509) *certs, BIO *in, const EVP_CIPHER *cipher,
0f113f3e
MC
303 int flags);
304int PKCS7_decrypt(PKCS7 *p7, EVP_PKEY *pkey, X509 *cert, BIO *data,
305 int flags);
5a9a4b29 306
371acb22 307int PKCS7_add_attrib_smimecap(PKCS7_SIGNER_INFO *si,
0f113f3e 308 STACK_OF(X509_ALGOR) *cap);
4d29312c 309STACK_OF(X509_ALGOR) *PKCS7_get_smimecap(PKCS7_SIGNER_INFO *si);
371acb22 310int PKCS7_simple_smimecap(STACK_OF(X509_ALGOR) *sk, int nid, int arg);
5a9a4b29 311
76fa8f18
DSH
312int PKCS7_add_attrib_content_type(PKCS7_SIGNER_INFO *si, ASN1_OBJECT *coid);
313int PKCS7_add0_attrib_signing_time(PKCS7_SIGNER_INFO *si, ASN1_TIME *t);
314int PKCS7_add1_attrib_digest(PKCS7_SIGNER_INFO *si,
0f113f3e 315 const unsigned char *md, int mdlen);
76fa8f18 316
5a9a4b29
DSH
317int SMIME_write_PKCS7(BIO *bio, PKCS7 *p7, BIO *data, int flags);
318PKCS7 *SMIME_read_PKCS7(BIO *bio, BIO **bcont);
dfeab068 319
c2d1c2d3
BL
320BIO *BIO_new_PKCS7(BIO *out, PKCS7 *p7);
321
0cd0a820 322# ifdef __cplusplus
d02b48c6 323}
0cd0a820 324# endif
d02b48c6 325#endif