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