diff options
Diffstat (limited to 'src/lib/libcrypto/pkcs7')
-rw-r--r-- | src/lib/libcrypto/pkcs7/pk7_attr.c | 89 | ||||
-rw-r--r-- | src/lib/libcrypto/pkcs7/pk7_doit.c | 946 | ||||
-rw-r--r-- | src/lib/libcrypto/pkcs7/pk7_lib.c | 469 | ||||
-rw-r--r-- | src/lib/libcrypto/pkcs7/pk7_mime.c | 685 | ||||
-rw-r--r-- | src/lib/libcrypto/pkcs7/pk7_smime.c | 432 | ||||
-rw-r--r-- | src/lib/libcrypto/pkcs7/pkcs7.h | 505 | ||||
-rw-r--r-- | src/lib/libcrypto/pkcs7/pkcs7err.c | 161 |
7 files changed, 0 insertions, 3287 deletions
diff --git a/src/lib/libcrypto/pkcs7/pk7_attr.c b/src/lib/libcrypto/pkcs7/pk7_attr.c deleted file mode 100644 index 6ae264cbf9..0000000000 --- a/src/lib/libcrypto/pkcs7/pk7_attr.c +++ /dev/null | |||
@@ -1,89 +0,0 @@ | |||
1 | /* pk7_attr.c */ | ||
2 | /* S/MIME code. | ||
3 | * Copyright (C) 1997-8 Dr S N Henson (shenson@bigfoot.com) | ||
4 | * All Rights Reserved. | ||
5 | * Redistribution of this code without the authors permission is expressly | ||
6 | * prohibited. | ||
7 | */ | ||
8 | |||
9 | #include <stdio.h> | ||
10 | #include <stdlib.h> | ||
11 | #include <openssl/bio.h> | ||
12 | #include <openssl/asn1.h> | ||
13 | #include <openssl/pem.h> | ||
14 | #include <openssl/pkcs7.h> | ||
15 | #include <openssl/x509.h> | ||
16 | #include <openssl/err.h> | ||
17 | |||
18 | int PKCS7_add_attrib_smimecap(PKCS7_SIGNER_INFO *si, STACK_OF(X509_ALGOR) *cap) | ||
19 | { | ||
20 | ASN1_STRING *seq; | ||
21 | unsigned char *p, *pp; | ||
22 | int len; | ||
23 | len=i2d_ASN1_SET_OF_X509_ALGOR(cap,NULL,i2d_X509_ALGOR, | ||
24 | V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL, | ||
25 | IS_SEQUENCE); | ||
26 | if(!(pp=(unsigned char *)OPENSSL_malloc(len))) { | ||
27 | PKCS7err(PKCS7_F_PKCS7_ADD_ATTRIB_SMIMECAP,ERR_R_MALLOC_FAILURE); | ||
28 | return 0; | ||
29 | } | ||
30 | p=pp; | ||
31 | i2d_ASN1_SET_OF_X509_ALGOR(cap,&p,i2d_X509_ALGOR, V_ASN1_SEQUENCE, | ||
32 | V_ASN1_UNIVERSAL, IS_SEQUENCE); | ||
33 | if(!(seq = ASN1_STRING_new())) { | ||
34 | PKCS7err(PKCS7_F_PKCS7_ADD_ATTRIB_SMIMECAP,ERR_R_MALLOC_FAILURE); | ||
35 | return 0; | ||
36 | } | ||
37 | if(!ASN1_STRING_set (seq, pp, len)) { | ||
38 | PKCS7err(PKCS7_F_PKCS7_ADD_ATTRIB_SMIMECAP,ERR_R_MALLOC_FAILURE); | ||
39 | return 0; | ||
40 | } | ||
41 | OPENSSL_free (pp); | ||
42 | return PKCS7_add_signed_attribute(si, NID_SMIMECapabilities, | ||
43 | V_ASN1_SEQUENCE, seq); | ||
44 | } | ||
45 | |||
46 | STACK_OF(X509_ALGOR) *PKCS7_get_smimecap(PKCS7_SIGNER_INFO *si) | ||
47 | { | ||
48 | ASN1_TYPE *cap; | ||
49 | unsigned char *p; | ||
50 | cap = PKCS7_get_signed_attribute(si, NID_SMIMECapabilities); | ||
51 | if (!cap) return NULL; | ||
52 | p = cap->value.sequence->data; | ||
53 | return d2i_ASN1_SET_OF_X509_ALGOR(NULL, &p, | ||
54 | cap->value.sequence->length, | ||
55 | d2i_X509_ALGOR, X509_ALGOR_free, | ||
56 | V_ASN1_SEQUENCE, V_ASN1_UNIVERSAL); | ||
57 | } | ||
58 | |||
59 | /* Basic smime-capabilities OID and optional integer arg */ | ||
60 | int PKCS7_simple_smimecap(STACK_OF(X509_ALGOR) *sk, int nid, int arg) | ||
61 | { | ||
62 | X509_ALGOR *alg; | ||
63 | |||
64 | if(!(alg = X509_ALGOR_new())) { | ||
65 | PKCS7err(PKCS7_F_PKCS7_SIMPLE_SMIMECAP,ERR_R_MALLOC_FAILURE); | ||
66 | return 0; | ||
67 | } | ||
68 | ASN1_OBJECT_free(alg->algorithm); | ||
69 | alg->algorithm = OBJ_nid2obj (nid); | ||
70 | if (arg > 0) { | ||
71 | ASN1_INTEGER *nbit; | ||
72 | if(!(alg->parameter = ASN1_TYPE_new())) { | ||
73 | PKCS7err(PKCS7_F_PKCS7_SIMPLE_SMIMECAP,ERR_R_MALLOC_FAILURE); | ||
74 | return 0; | ||
75 | } | ||
76 | if(!(nbit = ASN1_INTEGER_new())) { | ||
77 | PKCS7err(PKCS7_F_PKCS7_SIMPLE_SMIMECAP,ERR_R_MALLOC_FAILURE); | ||
78 | return 0; | ||
79 | } | ||
80 | if(!ASN1_INTEGER_set (nbit, arg)) { | ||
81 | PKCS7err(PKCS7_F_PKCS7_SIMPLE_SMIMECAP,ERR_R_MALLOC_FAILURE); | ||
82 | return 0; | ||
83 | } | ||
84 | alg->parameter->value.integer = nbit; | ||
85 | alg->parameter->type = V_ASN1_INTEGER; | ||
86 | } | ||
87 | sk_X509_ALGOR_push (sk, alg); | ||
88 | return 1; | ||
89 | } | ||
diff --git a/src/lib/libcrypto/pkcs7/pk7_doit.c b/src/lib/libcrypto/pkcs7/pk7_doit.c deleted file mode 100644 index bf43d030ad..0000000000 --- a/src/lib/libcrypto/pkcs7/pk7_doit.c +++ /dev/null | |||
@@ -1,946 +0,0 @@ | |||
1 | /* crypto/pkcs7/pk7_doit.c */ | ||
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
3 | * All rights reserved. | ||
4 | * | ||
5 | * This package is an SSL implementation written | ||
6 | * by Eric Young (eay@cryptsoft.com). | ||
7 | * The implementation was written so as to conform with Netscapes SSL. | ||
8 | * | ||
9 | * This library is free for commercial and non-commercial use as long as | ||
10 | * the following conditions are aheared to. The following conditions | ||
11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
13 | * included with this distribution is covered by the same copyright terms | ||
14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
15 | * | ||
16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
17 | * the code are not to be removed. | ||
18 | * If this package is used in a product, Eric Young should be given attribution | ||
19 | * as the author of the parts of the library used. | ||
20 | * This can be in the form of a textual message at program startup or | ||
21 | * in documentation (online or textual) provided with the package. | ||
22 | * | ||
23 | * Redistribution and use in source and binary forms, with or without | ||
24 | * modification, are permitted provided that the following conditions | ||
25 | * are met: | ||
26 | * 1. Redistributions of source code must retain the copyright | ||
27 | * notice, this list of conditions and the following disclaimer. | ||
28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
29 | * notice, this list of conditions and the following disclaimer in the | ||
30 | * documentation and/or other materials provided with the distribution. | ||
31 | * 3. All advertising materials mentioning features or use of this software | ||
32 | * must display the following acknowledgement: | ||
33 | * "This product includes cryptographic software written by | ||
34 | * Eric Young (eay@cryptsoft.com)" | ||
35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
36 | * being used are not cryptographic related :-). | ||
37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
38 | * the apps directory (application code) you must include an acknowledgement: | ||
39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
40 | * | ||
41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
51 | * SUCH DAMAGE. | ||
52 | * | ||
53 | * The licence and distribution terms for any publically available version or | ||
54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
55 | * copied and put under another distribution licence | ||
56 | * [including the GNU Public Licence.] | ||
57 | */ | ||
58 | |||
59 | #include <stdio.h> | ||
60 | #include "cryptlib.h" | ||
61 | #include <openssl/rand.h> | ||
62 | #include <openssl/objects.h> | ||
63 | #include <openssl/x509.h> | ||
64 | #include <openssl/x509v3.h> | ||
65 | |||
66 | static int add_attribute(STACK_OF(X509_ATTRIBUTE) **sk, int nid, int atrtype, | ||
67 | void *value); | ||
68 | static ASN1_TYPE *get_attribute(STACK_OF(X509_ATTRIBUTE) *sk, int nid); | ||
69 | |||
70 | BIO *PKCS7_dataInit(PKCS7 *p7, BIO *bio) | ||
71 | { | ||
72 | int i,j; | ||
73 | BIO *out=NULL,*btmp=NULL; | ||
74 | X509_ALGOR *xa; | ||
75 | const EVP_MD *evp_md; | ||
76 | const EVP_CIPHER *evp_cipher=NULL; | ||
77 | STACK_OF(X509_ALGOR) *md_sk=NULL; | ||
78 | STACK_OF(PKCS7_RECIP_INFO) *rsk=NULL; | ||
79 | X509_ALGOR *xalg=NULL; | ||
80 | PKCS7_RECIP_INFO *ri=NULL; | ||
81 | EVP_PKEY *pkey; | ||
82 | |||
83 | i=OBJ_obj2nid(p7->type); | ||
84 | p7->state=PKCS7_S_HEADER; | ||
85 | |||
86 | switch (i) | ||
87 | { | ||
88 | case NID_pkcs7_signed: | ||
89 | md_sk=p7->d.sign->md_algs; | ||
90 | break; | ||
91 | case NID_pkcs7_signedAndEnveloped: | ||
92 | rsk=p7->d.signed_and_enveloped->recipientinfo; | ||
93 | md_sk=p7->d.signed_and_enveloped->md_algs; | ||
94 | xalg=p7->d.signed_and_enveloped->enc_data->algorithm; | ||
95 | evp_cipher=p7->d.signed_and_enveloped->enc_data->cipher; | ||
96 | if (evp_cipher == NULL) | ||
97 | { | ||
98 | PKCS7err(PKCS7_F_PKCS7_DATAINIT, | ||
99 | PKCS7_R_CIPHER_NOT_INITIALIZED); | ||
100 | goto err; | ||
101 | } | ||
102 | break; | ||
103 | case NID_pkcs7_enveloped: | ||
104 | rsk=p7->d.enveloped->recipientinfo; | ||
105 | xalg=p7->d.enveloped->enc_data->algorithm; | ||
106 | evp_cipher=p7->d.enveloped->enc_data->cipher; | ||
107 | if (evp_cipher == NULL) | ||
108 | { | ||
109 | PKCS7err(PKCS7_F_PKCS7_DATAINIT, | ||
110 | PKCS7_R_CIPHER_NOT_INITIALIZED); | ||
111 | goto err; | ||
112 | } | ||
113 | break; | ||
114 | default: | ||
115 | PKCS7err(PKCS7_F_PKCS7_DATAINIT,PKCS7_R_UNSUPPORTED_CONTENT_TYPE); | ||
116 | goto err; | ||
117 | } | ||
118 | |||
119 | if (md_sk != NULL) | ||
120 | { | ||
121 | for (i=0; i<sk_X509_ALGOR_num(md_sk); i++) | ||
122 | { | ||
123 | xa=sk_X509_ALGOR_value(md_sk,i); | ||
124 | if ((btmp=BIO_new(BIO_f_md())) == NULL) | ||
125 | { | ||
126 | PKCS7err(PKCS7_F_PKCS7_DATAINIT,ERR_R_BIO_LIB); | ||
127 | goto err; | ||
128 | } | ||
129 | |||
130 | j=OBJ_obj2nid(xa->algorithm); | ||
131 | evp_md=EVP_get_digestbyname(OBJ_nid2sn(j)); | ||
132 | if (evp_md == NULL) | ||
133 | { | ||
134 | PKCS7err(PKCS7_F_PKCS7_DATAINIT,PKCS7_R_UNKNOWN_DIGEST_TYPE); | ||
135 | goto err; | ||
136 | } | ||
137 | |||
138 | BIO_set_md(btmp,evp_md); | ||
139 | if (out == NULL) | ||
140 | out=btmp; | ||
141 | else | ||
142 | BIO_push(out,btmp); | ||
143 | btmp=NULL; | ||
144 | } | ||
145 | } | ||
146 | |||
147 | if (evp_cipher != NULL) | ||
148 | { | ||
149 | unsigned char key[EVP_MAX_KEY_LENGTH]; | ||
150 | unsigned char iv[EVP_MAX_IV_LENGTH]; | ||
151 | int keylen,ivlen; | ||
152 | int jj,max; | ||
153 | unsigned char *tmp; | ||
154 | EVP_CIPHER_CTX *ctx; | ||
155 | |||
156 | if ((btmp=BIO_new(BIO_f_cipher())) == NULL) | ||
157 | { | ||
158 | PKCS7err(PKCS7_F_PKCS7_DATAINIT,ERR_R_BIO_LIB); | ||
159 | goto err; | ||
160 | } | ||
161 | BIO_get_cipher_ctx(btmp, &ctx); | ||
162 | keylen=EVP_CIPHER_key_length(evp_cipher); | ||
163 | ivlen=EVP_CIPHER_iv_length(evp_cipher); | ||
164 | if (RAND_bytes(key,keylen) <= 0) | ||
165 | goto err; | ||
166 | xalg->algorithm = OBJ_nid2obj(EVP_CIPHER_type(evp_cipher)); | ||
167 | if (ivlen > 0) RAND_pseudo_bytes(iv,ivlen); | ||
168 | EVP_CipherInit(ctx, evp_cipher, key, iv, 1); | ||
169 | |||
170 | if (ivlen > 0) { | ||
171 | if (xalg->parameter == NULL) | ||
172 | xalg->parameter=ASN1_TYPE_new(); | ||
173 | if(EVP_CIPHER_param_to_asn1(ctx, xalg->parameter) < 0) | ||
174 | goto err; | ||
175 | } | ||
176 | |||
177 | /* Lets do the pub key stuff :-) */ | ||
178 | max=0; | ||
179 | for (i=0; i<sk_PKCS7_RECIP_INFO_num(rsk); i++) | ||
180 | { | ||
181 | ri=sk_PKCS7_RECIP_INFO_value(rsk,i); | ||
182 | if (ri->cert == NULL) | ||
183 | { | ||
184 | PKCS7err(PKCS7_F_PKCS7_DATAINIT,PKCS7_R_MISSING_CERIPEND_INFO); | ||
185 | goto err; | ||
186 | } | ||
187 | pkey=X509_get_pubkey(ri->cert); | ||
188 | jj=EVP_PKEY_size(pkey); | ||
189 | EVP_PKEY_free(pkey); | ||
190 | if (max < jj) max=jj; | ||
191 | } | ||
192 | if ((tmp=(unsigned char *)OPENSSL_malloc(max)) == NULL) | ||
193 | { | ||
194 | PKCS7err(PKCS7_F_PKCS7_DATAINIT,ERR_R_MALLOC_FAILURE); | ||
195 | goto err; | ||
196 | } | ||
197 | for (i=0; i<sk_PKCS7_RECIP_INFO_num(rsk); i++) | ||
198 | { | ||
199 | ri=sk_PKCS7_RECIP_INFO_value(rsk,i); | ||
200 | pkey=X509_get_pubkey(ri->cert); | ||
201 | jj=EVP_PKEY_encrypt(tmp,key,keylen,pkey); | ||
202 | EVP_PKEY_free(pkey); | ||
203 | if (jj <= 0) | ||
204 | { | ||
205 | PKCS7err(PKCS7_F_PKCS7_DATAINIT,ERR_R_EVP_LIB); | ||
206 | OPENSSL_free(tmp); | ||
207 | goto err; | ||
208 | } | ||
209 | M_ASN1_OCTET_STRING_set(ri->enc_key,tmp,jj); | ||
210 | } | ||
211 | OPENSSL_free(tmp); | ||
212 | memset(key, 0, keylen); | ||
213 | |||
214 | if (out == NULL) | ||
215 | out=btmp; | ||
216 | else | ||
217 | BIO_push(out,btmp); | ||
218 | btmp=NULL; | ||
219 | } | ||
220 | |||
221 | if (bio == NULL) { | ||
222 | if (p7->detached) | ||
223 | bio=BIO_new(BIO_s_null()); | ||
224 | else { | ||
225 | if (PKCS7_type_is_signed(p7) && | ||
226 | PKCS7_type_is_data(p7->d.sign->contents)) { | ||
227 | ASN1_OCTET_STRING *os; | ||
228 | os=p7->d.sign->contents->d.data; | ||
229 | if (os->length > 0) bio = | ||
230 | BIO_new_mem_buf(os->data, os->length); | ||
231 | } | ||
232 | if(bio == NULL) { | ||
233 | bio=BIO_new(BIO_s_mem()); | ||
234 | BIO_set_mem_eof_return(bio,0); | ||
235 | } | ||
236 | } | ||
237 | } | ||
238 | BIO_push(out,bio); | ||
239 | bio=NULL; | ||
240 | if (0) | ||
241 | { | ||
242 | err: | ||
243 | if (out != NULL) | ||
244 | BIO_free_all(out); | ||
245 | if (btmp != NULL) | ||
246 | BIO_free_all(btmp); | ||
247 | out=NULL; | ||
248 | } | ||
249 | return(out); | ||
250 | } | ||
251 | |||
252 | /* int */ | ||
253 | BIO *PKCS7_dataDecode(PKCS7 *p7, EVP_PKEY *pkey, BIO *in_bio, X509 *pcert) | ||
254 | { | ||
255 | int i,j; | ||
256 | BIO *out=NULL,*btmp=NULL,*etmp=NULL,*bio=NULL; | ||
257 | unsigned char *tmp=NULL; | ||
258 | X509_ALGOR *xa; | ||
259 | ASN1_OCTET_STRING *data_body=NULL; | ||
260 | const EVP_MD *evp_md; | ||
261 | const EVP_CIPHER *evp_cipher=NULL; | ||
262 | EVP_CIPHER_CTX *evp_ctx=NULL; | ||
263 | X509_ALGOR *enc_alg=NULL; | ||
264 | STACK_OF(X509_ALGOR) *md_sk=NULL; | ||
265 | STACK_OF(PKCS7_RECIP_INFO) *rsk=NULL; | ||
266 | X509_ALGOR *xalg=NULL; | ||
267 | PKCS7_RECIP_INFO *ri=NULL; | ||
268 | |||
269 | i=OBJ_obj2nid(p7->type); | ||
270 | p7->state=PKCS7_S_HEADER; | ||
271 | |||
272 | switch (i) | ||
273 | { | ||
274 | case NID_pkcs7_signed: | ||
275 | data_body=p7->d.sign->contents->d.data; | ||
276 | md_sk=p7->d.sign->md_algs; | ||
277 | break; | ||
278 | case NID_pkcs7_signedAndEnveloped: | ||
279 | rsk=p7->d.signed_and_enveloped->recipientinfo; | ||
280 | md_sk=p7->d.signed_and_enveloped->md_algs; | ||
281 | data_body=p7->d.signed_and_enveloped->enc_data->enc_data; | ||
282 | enc_alg=p7->d.signed_and_enveloped->enc_data->algorithm; | ||
283 | evp_cipher=EVP_get_cipherbyname(OBJ_nid2sn(OBJ_obj2nid(enc_alg->algorithm))); | ||
284 | if (evp_cipher == NULL) | ||
285 | { | ||
286 | PKCS7err(PKCS7_F_PKCS7_DATADECODE,PKCS7_R_UNSUPPORTED_CIPHER_TYPE); | ||
287 | goto err; | ||
288 | } | ||
289 | xalg=p7->d.signed_and_enveloped->enc_data->algorithm; | ||
290 | break; | ||
291 | case NID_pkcs7_enveloped: | ||
292 | rsk=p7->d.enveloped->recipientinfo; | ||
293 | enc_alg=p7->d.enveloped->enc_data->algorithm; | ||
294 | data_body=p7->d.enveloped->enc_data->enc_data; | ||
295 | evp_cipher=EVP_get_cipherbyname(OBJ_nid2sn(OBJ_obj2nid(enc_alg->algorithm))); | ||
296 | if (evp_cipher == NULL) | ||
297 | { | ||
298 | PKCS7err(PKCS7_F_PKCS7_DATADECODE,PKCS7_R_UNSUPPORTED_CIPHER_TYPE); | ||
299 | goto err; | ||
300 | } | ||
301 | xalg=p7->d.enveloped->enc_data->algorithm; | ||
302 | break; | ||
303 | default: | ||
304 | PKCS7err(PKCS7_F_PKCS7_DATADECODE,PKCS7_R_UNSUPPORTED_CONTENT_TYPE); | ||
305 | goto err; | ||
306 | } | ||
307 | |||
308 | /* We will be checking the signature */ | ||
309 | if (md_sk != NULL) | ||
310 | { | ||
311 | for (i=0; i<sk_X509_ALGOR_num(md_sk); i++) | ||
312 | { | ||
313 | xa=sk_X509_ALGOR_value(md_sk,i); | ||
314 | if ((btmp=BIO_new(BIO_f_md())) == NULL) | ||
315 | { | ||
316 | PKCS7err(PKCS7_F_PKCS7_DATADECODE,ERR_R_BIO_LIB); | ||
317 | goto err; | ||
318 | } | ||
319 | |||
320 | j=OBJ_obj2nid(xa->algorithm); | ||
321 | evp_md=EVP_get_digestbyname(OBJ_nid2sn(j)); | ||
322 | if (evp_md == NULL) | ||
323 | { | ||
324 | PKCS7err(PKCS7_F_PKCS7_DATADECODE,PKCS7_R_UNKNOWN_DIGEST_TYPE); | ||
325 | goto err; | ||
326 | } | ||
327 | |||
328 | BIO_set_md(btmp,evp_md); | ||
329 | if (out == NULL) | ||
330 | out=btmp; | ||
331 | else | ||
332 | BIO_push(out,btmp); | ||
333 | btmp=NULL; | ||
334 | } | ||
335 | } | ||
336 | |||
337 | if (evp_cipher != NULL) | ||
338 | { | ||
339 | #if 0 | ||
340 | unsigned char key[EVP_MAX_KEY_LENGTH]; | ||
341 | unsigned char iv[EVP_MAX_IV_LENGTH]; | ||
342 | unsigned char *p; | ||
343 | int keylen,ivlen; | ||
344 | int max; | ||
345 | X509_OBJECT ret; | ||
346 | #endif | ||
347 | int jj; | ||
348 | |||
349 | if ((etmp=BIO_new(BIO_f_cipher())) == NULL) | ||
350 | { | ||
351 | PKCS7err(PKCS7_F_PKCS7_DATADECODE,ERR_R_BIO_LIB); | ||
352 | goto err; | ||
353 | } | ||
354 | |||
355 | /* It was encrypted, we need to decrypt the secret key | ||
356 | * with the private key */ | ||
357 | |||
358 | /* Find the recipientInfo which matches the passed certificate | ||
359 | * (if any) | ||
360 | */ | ||
361 | |||
362 | for (i=0; i<sk_PKCS7_RECIP_INFO_num(rsk); i++) { | ||
363 | ri=sk_PKCS7_RECIP_INFO_value(rsk,i); | ||
364 | if(!X509_NAME_cmp(ri->issuer_and_serial->issuer, | ||
365 | pcert->cert_info->issuer) && | ||
366 | !M_ASN1_INTEGER_cmp(pcert->cert_info->serialNumber, | ||
367 | ri->issuer_and_serial->serial)) break; | ||
368 | ri=NULL; | ||
369 | } | ||
370 | if (ri == NULL) { | ||
371 | PKCS7err(PKCS7_F_PKCS7_DATADECODE, | ||
372 | PKCS7_R_NO_RECIPIENT_MATCHES_CERTIFICATE); | ||
373 | goto err; | ||
374 | } | ||
375 | |||
376 | jj=EVP_PKEY_size(pkey); | ||
377 | tmp=(unsigned char *)OPENSSL_malloc(jj+10); | ||
378 | if (tmp == NULL) | ||
379 | { | ||
380 | PKCS7err(PKCS7_F_PKCS7_DATADECODE,ERR_R_MALLOC_FAILURE); | ||
381 | goto err; | ||
382 | } | ||
383 | |||
384 | jj=EVP_PKEY_decrypt(tmp, M_ASN1_STRING_data(ri->enc_key), | ||
385 | M_ASN1_STRING_length(ri->enc_key), pkey); | ||
386 | if (jj <= 0) | ||
387 | { | ||
388 | PKCS7err(PKCS7_F_PKCS7_DATADECODE,ERR_R_EVP_LIB); | ||
389 | goto err; | ||
390 | } | ||
391 | |||
392 | evp_ctx=NULL; | ||
393 | BIO_get_cipher_ctx(etmp,&evp_ctx); | ||
394 | EVP_CipherInit(evp_ctx,evp_cipher,NULL,NULL,0); | ||
395 | if (EVP_CIPHER_asn1_to_param(evp_ctx,enc_alg->parameter) < 0) | ||
396 | goto err; | ||
397 | |||
398 | if (jj != EVP_CIPHER_CTX_key_length(evp_ctx)) { | ||
399 | /* Some S/MIME clients don't use the same key | ||
400 | * and effective key length. The key length is | ||
401 | * determined by the size of the decrypted RSA key. | ||
402 | */ | ||
403 | if(!EVP_CIPHER_CTX_set_key_length(evp_ctx, jj)) | ||
404 | { | ||
405 | PKCS7err(PKCS7_F_PKCS7_DATADECODE, | ||
406 | PKCS7_R_DECRYPTED_KEY_IS_WRONG_LENGTH); | ||
407 | goto err; | ||
408 | } | ||
409 | } | ||
410 | EVP_CipherInit(evp_ctx,NULL,tmp,NULL,0); | ||
411 | |||
412 | memset(tmp,0,jj); | ||
413 | |||
414 | if (out == NULL) | ||
415 | out=etmp; | ||
416 | else | ||
417 | BIO_push(out,etmp); | ||
418 | etmp=NULL; | ||
419 | } | ||
420 | |||
421 | #if 1 | ||
422 | if (p7->detached || (in_bio != NULL)) | ||
423 | { | ||
424 | bio=in_bio; | ||
425 | } | ||
426 | else | ||
427 | { | ||
428 | #if 0 | ||
429 | bio=BIO_new(BIO_s_mem()); | ||
430 | /* We need to set this so that when we have read all | ||
431 | * the data, the encrypt BIO, if present, will read | ||
432 | * EOF and encode the last few bytes */ | ||
433 | BIO_set_mem_eof_return(bio,0); | ||
434 | |||
435 | if (data_body->length > 0) | ||
436 | BIO_write(bio,(char *)data_body->data,data_body->length); | ||
437 | #else | ||
438 | if (data_body->length > 0) | ||
439 | bio = BIO_new_mem_buf(data_body->data,data_body->length); | ||
440 | else { | ||
441 | bio=BIO_new(BIO_s_mem()); | ||
442 | BIO_set_mem_eof_return(bio,0); | ||
443 | } | ||
444 | #endif | ||
445 | } | ||
446 | BIO_push(out,bio); | ||
447 | bio=NULL; | ||
448 | #endif | ||
449 | if (0) | ||
450 | { | ||
451 | err: | ||
452 | if (out != NULL) BIO_free_all(out); | ||
453 | if (btmp != NULL) BIO_free_all(btmp); | ||
454 | if (etmp != NULL) BIO_free_all(etmp); | ||
455 | if (bio != NULL) BIO_free_all(bio); | ||
456 | out=NULL; | ||
457 | } | ||
458 | if (tmp != NULL) | ||
459 | OPENSSL_free(tmp); | ||
460 | return(out); | ||
461 | } | ||
462 | |||
463 | int PKCS7_dataFinal(PKCS7 *p7, BIO *bio) | ||
464 | { | ||
465 | int ret=0; | ||
466 | int i,j; | ||
467 | BIO *btmp; | ||
468 | BUF_MEM *buf_mem=NULL; | ||
469 | BUF_MEM *buf=NULL; | ||
470 | PKCS7_SIGNER_INFO *si; | ||
471 | EVP_MD_CTX *mdc,ctx_tmp; | ||
472 | STACK_OF(X509_ATTRIBUTE) *sk; | ||
473 | STACK_OF(PKCS7_SIGNER_INFO) *si_sk=NULL; | ||
474 | unsigned char *p,*pp=NULL; | ||
475 | int x; | ||
476 | ASN1_OCTET_STRING *os=NULL; | ||
477 | |||
478 | i=OBJ_obj2nid(p7->type); | ||
479 | p7->state=PKCS7_S_HEADER; | ||
480 | |||
481 | switch (i) | ||
482 | { | ||
483 | case NID_pkcs7_signedAndEnveloped: | ||
484 | /* XXXXXXXXXXXXXXXX */ | ||
485 | si_sk=p7->d.signed_and_enveloped->signer_info; | ||
486 | os=M_ASN1_OCTET_STRING_new(); | ||
487 | p7->d.signed_and_enveloped->enc_data->enc_data=os; | ||
488 | break; | ||
489 | case NID_pkcs7_enveloped: | ||
490 | /* XXXXXXXXXXXXXXXX */ | ||
491 | os=M_ASN1_OCTET_STRING_new(); | ||
492 | p7->d.enveloped->enc_data->enc_data=os; | ||
493 | break; | ||
494 | case NID_pkcs7_signed: | ||
495 | si_sk=p7->d.sign->signer_info; | ||
496 | os=p7->d.sign->contents->d.data; | ||
497 | /* If detached data then the content is excluded */ | ||
498 | if(p7->detached) { | ||
499 | M_ASN1_OCTET_STRING_free(os); | ||
500 | p7->d.sign->contents->d.data = NULL; | ||
501 | } | ||
502 | break; | ||
503 | } | ||
504 | |||
505 | if (si_sk != NULL) | ||
506 | { | ||
507 | if ((buf=BUF_MEM_new()) == NULL) | ||
508 | { | ||
509 | PKCS7err(PKCS7_F_PKCS7_DATASIGN,ERR_R_BIO_LIB); | ||
510 | goto err; | ||
511 | } | ||
512 | for (i=0; i<sk_PKCS7_SIGNER_INFO_num(si_sk); i++) | ||
513 | { | ||
514 | si=sk_PKCS7_SIGNER_INFO_value(si_sk,i); | ||
515 | if (si->pkey == NULL) continue; | ||
516 | |||
517 | j=OBJ_obj2nid(si->digest_alg->algorithm); | ||
518 | |||
519 | btmp=bio; | ||
520 | for (;;) | ||
521 | { | ||
522 | if ((btmp=BIO_find_type(btmp,BIO_TYPE_MD)) | ||
523 | == NULL) | ||
524 | { | ||
525 | PKCS7err(PKCS7_F_PKCS7_DATASIGN,PKCS7_R_UNABLE_TO_FIND_MESSAGE_DIGEST); | ||
526 | goto err; | ||
527 | } | ||
528 | BIO_get_md_ctx(btmp,&mdc); | ||
529 | if (mdc == NULL) | ||
530 | { | ||
531 | PKCS7err(PKCS7_F_PKCS7_DATASIGN,PKCS7_R_INTERNAL_ERROR); | ||
532 | goto err; | ||
533 | } | ||
534 | if (EVP_MD_CTX_type(mdc) == j) | ||
535 | break; | ||
536 | else | ||
537 | btmp=BIO_next(btmp); | ||
538 | } | ||
539 | |||
540 | /* We now have the EVP_MD_CTX, lets do the | ||
541 | * signing. */ | ||
542 | memcpy(&ctx_tmp,mdc,sizeof(ctx_tmp)); | ||
543 | if (!BUF_MEM_grow(buf,EVP_PKEY_size(si->pkey))) | ||
544 | { | ||
545 | PKCS7err(PKCS7_F_PKCS7_DATASIGN,ERR_R_BIO_LIB); | ||
546 | goto err; | ||
547 | } | ||
548 | |||
549 | sk=si->auth_attr; | ||
550 | |||
551 | /* If there are attributes, we add the digest | ||
552 | * attribute and only sign the attributes */ | ||
553 | if ((sk != NULL) && (sk_X509_ATTRIBUTE_num(sk) != 0)) | ||
554 | { | ||
555 | unsigned char md_data[EVP_MAX_MD_SIZE]; | ||
556 | unsigned int md_len; | ||
557 | ASN1_OCTET_STRING *digest; | ||
558 | ASN1_UTCTIME *sign_time; | ||
559 | const EVP_MD *md_tmp; | ||
560 | |||
561 | /* Add signing time */ | ||
562 | sign_time=X509_gmtime_adj(NULL,0); | ||
563 | PKCS7_add_signed_attribute(si, | ||
564 | NID_pkcs9_signingTime, | ||
565 | V_ASN1_UTCTIME,sign_time); | ||
566 | |||
567 | /* Add digest */ | ||
568 | md_tmp=EVP_MD_CTX_md(&ctx_tmp); | ||
569 | EVP_DigestFinal(&ctx_tmp,md_data,&md_len); | ||
570 | digest=M_ASN1_OCTET_STRING_new(); | ||
571 | M_ASN1_OCTET_STRING_set(digest,md_data,md_len); | ||
572 | PKCS7_add_signed_attribute(si, | ||
573 | NID_pkcs9_messageDigest, | ||
574 | V_ASN1_OCTET_STRING,digest); | ||
575 | |||
576 | /* Now sign the mess */ | ||
577 | EVP_SignInit(&ctx_tmp,md_tmp); | ||
578 | x=i2d_ASN1_SET_OF_X509_ATTRIBUTE(sk,NULL, | ||
579 | i2d_X509_ATTRIBUTE, | ||
580 | V_ASN1_SET,V_ASN1_UNIVERSAL,IS_SET); | ||
581 | pp=(unsigned char *)OPENSSL_malloc(x); | ||
582 | p=pp; | ||
583 | i2d_ASN1_SET_OF_X509_ATTRIBUTE(sk,&p, | ||
584 | i2d_X509_ATTRIBUTE, | ||
585 | V_ASN1_SET,V_ASN1_UNIVERSAL,IS_SET); | ||
586 | EVP_SignUpdate(&ctx_tmp,pp,x); | ||
587 | OPENSSL_free(pp); | ||
588 | pp=NULL; | ||
589 | } | ||
590 | |||
591 | #ifndef NO_DSA | ||
592 | if (si->pkey->type == EVP_PKEY_DSA) | ||
593 | ctx_tmp.digest=EVP_dss1(); | ||
594 | #endif | ||
595 | |||
596 | if (!EVP_SignFinal(&ctx_tmp,(unsigned char *)buf->data, | ||
597 | (unsigned int *)&buf->length,si->pkey)) | ||
598 | { | ||
599 | PKCS7err(PKCS7_F_PKCS7_DATASIGN,ERR_R_EVP_LIB); | ||
600 | goto err; | ||
601 | } | ||
602 | if (!ASN1_STRING_set(si->enc_digest, | ||
603 | (unsigned char *)buf->data,buf->length)) | ||
604 | { | ||
605 | PKCS7err(PKCS7_F_PKCS7_DATASIGN,ERR_R_ASN1_LIB); | ||
606 | goto err; | ||
607 | } | ||
608 | } | ||
609 | } | ||
610 | |||
611 | if (!p7->detached) | ||
612 | { | ||
613 | btmp=BIO_find_type(bio,BIO_TYPE_MEM); | ||
614 | if (btmp == NULL) | ||
615 | { | ||
616 | PKCS7err(PKCS7_F_PKCS7_DATASIGN,PKCS7_R_UNABLE_TO_FIND_MEM_BIO); | ||
617 | goto err; | ||
618 | } | ||
619 | BIO_get_mem_ptr(btmp,&buf_mem); | ||
620 | /* Mark the BIO read only then we can use its copy of the data | ||
621 | * instead of making an extra copy. | ||
622 | */ | ||
623 | BIO_set_flags(btmp, BIO_FLAGS_MEM_RDONLY); | ||
624 | BIO_set_mem_eof_return(btmp, 0); | ||
625 | os->data = (unsigned char *)buf_mem->data; | ||
626 | os->length = buf_mem->length; | ||
627 | #if 0 | ||
628 | M_ASN1_OCTET_STRING_set(os, | ||
629 | (unsigned char *)buf_mem->data,buf_mem->length); | ||
630 | #endif | ||
631 | } | ||
632 | if (pp != NULL) OPENSSL_free(pp); | ||
633 | pp=NULL; | ||
634 | |||
635 | ret=1; | ||
636 | err: | ||
637 | if (buf != NULL) BUF_MEM_free(buf); | ||
638 | return(ret); | ||
639 | } | ||
640 | |||
641 | int PKCS7_dataVerify(X509_STORE *cert_store, X509_STORE_CTX *ctx, BIO *bio, | ||
642 | PKCS7 *p7, PKCS7_SIGNER_INFO *si) | ||
643 | { | ||
644 | PKCS7_ISSUER_AND_SERIAL *ias; | ||
645 | int ret=0,i; | ||
646 | STACK_OF(X509) *cert; | ||
647 | X509 *x509; | ||
648 | |||
649 | if (PKCS7_type_is_signed(p7)) | ||
650 | { | ||
651 | cert=p7->d.sign->cert; | ||
652 | } | ||
653 | else if (PKCS7_type_is_signedAndEnveloped(p7)) | ||
654 | { | ||
655 | cert=p7->d.signed_and_enveloped->cert; | ||
656 | } | ||
657 | else | ||
658 | { | ||
659 | PKCS7err(PKCS7_F_PKCS7_DATAVERIFY,PKCS7_R_WRONG_PKCS7_TYPE); | ||
660 | goto err; | ||
661 | } | ||
662 | /* XXXXXXXXXXXXXXXXXXXXXXX */ | ||
663 | ias=si->issuer_and_serial; | ||
664 | |||
665 | x509=X509_find_by_issuer_and_serial(cert,ias->issuer,ias->serial); | ||
666 | |||
667 | /* were we able to find the cert in passed to us */ | ||
668 | if (x509 == NULL) | ||
669 | { | ||
670 | PKCS7err(PKCS7_F_PKCS7_DATAVERIFY,PKCS7_R_UNABLE_TO_FIND_CERTIFICATE); | ||
671 | goto err; | ||
672 | } | ||
673 | |||
674 | /* Lets verify */ | ||
675 | X509_STORE_CTX_init(ctx,cert_store,x509,cert); | ||
676 | X509_STORE_CTX_set_purpose(ctx, X509_PURPOSE_SMIME_SIGN); | ||
677 | i=X509_verify_cert(ctx); | ||
678 | if (i <= 0) | ||
679 | { | ||
680 | PKCS7err(PKCS7_F_PKCS7_DATAVERIFY,ERR_R_X509_LIB); | ||
681 | X509_STORE_CTX_cleanup(ctx); | ||
682 | goto err; | ||
683 | } | ||
684 | X509_STORE_CTX_cleanup(ctx); | ||
685 | |||
686 | return PKCS7_signatureVerify(bio, p7, si, x509); | ||
687 | err: | ||
688 | return ret; | ||
689 | } | ||
690 | |||
691 | int PKCS7_signatureVerify(BIO *bio, PKCS7 *p7, PKCS7_SIGNER_INFO *si, | ||
692 | X509 *x509) | ||
693 | { | ||
694 | ASN1_OCTET_STRING *os; | ||
695 | EVP_MD_CTX mdc_tmp,*mdc; | ||
696 | unsigned char *pp,*p; | ||
697 | int ret=0,i; | ||
698 | int md_type; | ||
699 | STACK_OF(X509_ATTRIBUTE) *sk; | ||
700 | BIO *btmp; | ||
701 | EVP_PKEY *pkey; | ||
702 | |||
703 | if (!PKCS7_type_is_signed(p7) && | ||
704 | !PKCS7_type_is_signedAndEnveloped(p7)) { | ||
705 | PKCS7err(PKCS7_F_PKCS7_SIGNATUREVERIFY, | ||
706 | PKCS7_R_WRONG_PKCS7_TYPE); | ||
707 | goto err; | ||
708 | } | ||
709 | |||
710 | md_type=OBJ_obj2nid(si->digest_alg->algorithm); | ||
711 | |||
712 | btmp=bio; | ||
713 | for (;;) | ||
714 | { | ||
715 | if ((btmp == NULL) || | ||
716 | ((btmp=BIO_find_type(btmp,BIO_TYPE_MD)) == NULL)) | ||
717 | { | ||
718 | PKCS7err(PKCS7_F_PKCS7_SIGNATUREVERIFY, | ||
719 | PKCS7_R_UNABLE_TO_FIND_MESSAGE_DIGEST); | ||
720 | goto err; | ||
721 | } | ||
722 | BIO_get_md_ctx(btmp,&mdc); | ||
723 | if (mdc == NULL) | ||
724 | { | ||
725 | PKCS7err(PKCS7_F_PKCS7_SIGNATUREVERIFY, | ||
726 | PKCS7_R_INTERNAL_ERROR); | ||
727 | goto err; | ||
728 | } | ||
729 | if (EVP_MD_CTX_type(mdc) == md_type) | ||
730 | break; | ||
731 | btmp=BIO_next(btmp); | ||
732 | } | ||
733 | |||
734 | /* mdc is the digest ctx that we want, unless there are attributes, | ||
735 | * in which case the digest is the signed attributes */ | ||
736 | memcpy(&mdc_tmp,mdc,sizeof(mdc_tmp)); | ||
737 | |||
738 | sk=si->auth_attr; | ||
739 | if ((sk != NULL) && (sk_X509_ATTRIBUTE_num(sk) != 0)) | ||
740 | { | ||
741 | unsigned char md_dat[EVP_MAX_MD_SIZE]; | ||
742 | unsigned int md_len; | ||
743 | ASN1_OCTET_STRING *message_digest; | ||
744 | |||
745 | EVP_DigestFinal(&mdc_tmp,md_dat,&md_len); | ||
746 | message_digest=PKCS7_digest_from_attributes(sk); | ||
747 | if (!message_digest) | ||
748 | { | ||
749 | PKCS7err(PKCS7_F_PKCS7_SIGNATUREVERIFY, | ||
750 | PKCS7_R_UNABLE_TO_FIND_MESSAGE_DIGEST); | ||
751 | goto err; | ||
752 | } | ||
753 | if ((message_digest->length != (int)md_len) || | ||
754 | (memcmp(message_digest->data,md_dat,md_len))) | ||
755 | { | ||
756 | #if 0 | ||
757 | { | ||
758 | int ii; | ||
759 | for (ii=0; ii<message_digest->length; ii++) | ||
760 | printf("%02X",message_digest->data[ii]); printf(" sent\n"); | ||
761 | for (ii=0; ii<md_len; ii++) printf("%02X",md_dat[ii]); printf(" calc\n"); | ||
762 | } | ||
763 | #endif | ||
764 | PKCS7err(PKCS7_F_PKCS7_SIGNATUREVERIFY, | ||
765 | PKCS7_R_DIGEST_FAILURE); | ||
766 | ret= -1; | ||
767 | goto err; | ||
768 | } | ||
769 | |||
770 | EVP_VerifyInit(&mdc_tmp,EVP_get_digestbynid(md_type)); | ||
771 | /* Note: when forming the encoding of the attributes we | ||
772 | * shouldn't reorder them or this will break the signature. | ||
773 | * This is done by using the IS_SEQUENCE flag. | ||
774 | */ | ||
775 | i=i2d_ASN1_SET_OF_X509_ATTRIBUTE(sk,NULL,i2d_X509_ATTRIBUTE, | ||
776 | V_ASN1_SET,V_ASN1_UNIVERSAL, IS_SEQUENCE); | ||
777 | pp=OPENSSL_malloc(i); | ||
778 | p=pp; | ||
779 | i2d_ASN1_SET_OF_X509_ATTRIBUTE(sk,&p,i2d_X509_ATTRIBUTE, | ||
780 | V_ASN1_SET,V_ASN1_UNIVERSAL, IS_SEQUENCE); | ||
781 | EVP_VerifyUpdate(&mdc_tmp,pp,i); | ||
782 | |||
783 | OPENSSL_free(pp); | ||
784 | } | ||
785 | |||
786 | os=si->enc_digest; | ||
787 | pkey = X509_get_pubkey(x509); | ||
788 | if (!pkey) | ||
789 | { | ||
790 | ret = -1; | ||
791 | goto err; | ||
792 | } | ||
793 | #ifndef NO_DSA | ||
794 | if(pkey->type == EVP_PKEY_DSA) mdc_tmp.digest=EVP_dss1(); | ||
795 | #endif | ||
796 | |||
797 | i=EVP_VerifyFinal(&mdc_tmp,os->data,os->length, pkey); | ||
798 | EVP_PKEY_free(pkey); | ||
799 | if (i <= 0) | ||
800 | { | ||
801 | PKCS7err(PKCS7_F_PKCS7_SIGNATUREVERIFY, | ||
802 | PKCS7_R_SIGNATURE_FAILURE); | ||
803 | ret= -1; | ||
804 | goto err; | ||
805 | } | ||
806 | else | ||
807 | ret=1; | ||
808 | err: | ||
809 | return(ret); | ||
810 | } | ||
811 | |||
812 | PKCS7_ISSUER_AND_SERIAL *PKCS7_get_issuer_and_serial(PKCS7 *p7, int idx) | ||
813 | { | ||
814 | STACK_OF(PKCS7_RECIP_INFO) *rsk; | ||
815 | PKCS7_RECIP_INFO *ri; | ||
816 | int i; | ||
817 | |||
818 | i=OBJ_obj2nid(p7->type); | ||
819 | if (i != NID_pkcs7_signedAndEnveloped) return(NULL); | ||
820 | rsk=p7->d.signed_and_enveloped->recipientinfo; | ||
821 | ri=sk_PKCS7_RECIP_INFO_value(rsk,0); | ||
822 | if (sk_PKCS7_RECIP_INFO_num(rsk) <= idx) return(NULL); | ||
823 | ri=sk_PKCS7_RECIP_INFO_value(rsk,idx); | ||
824 | return(ri->issuer_and_serial); | ||
825 | } | ||
826 | |||
827 | ASN1_TYPE *PKCS7_get_signed_attribute(PKCS7_SIGNER_INFO *si, int nid) | ||
828 | { | ||
829 | return(get_attribute(si->auth_attr,nid)); | ||
830 | } | ||
831 | |||
832 | ASN1_TYPE *PKCS7_get_attribute(PKCS7_SIGNER_INFO *si, int nid) | ||
833 | { | ||
834 | return(get_attribute(si->unauth_attr,nid)); | ||
835 | } | ||
836 | |||
837 | static ASN1_TYPE *get_attribute(STACK_OF(X509_ATTRIBUTE) *sk, int nid) | ||
838 | { | ||
839 | int i; | ||
840 | X509_ATTRIBUTE *xa; | ||
841 | ASN1_OBJECT *o; | ||
842 | |||
843 | o=OBJ_nid2obj(nid); | ||
844 | if (!o || !sk) return(NULL); | ||
845 | for (i=0; i<sk_X509_ATTRIBUTE_num(sk); i++) | ||
846 | { | ||
847 | xa=sk_X509_ATTRIBUTE_value(sk,i); | ||
848 | if (OBJ_cmp(xa->object,o) == 0) | ||
849 | { | ||
850 | if (xa->set && sk_ASN1_TYPE_num(xa->value.set)) | ||
851 | return(sk_ASN1_TYPE_value(xa->value.set,0)); | ||
852 | else | ||
853 | return(NULL); | ||
854 | } | ||
855 | } | ||
856 | return(NULL); | ||
857 | } | ||
858 | |||
859 | ASN1_OCTET_STRING *PKCS7_digest_from_attributes(STACK_OF(X509_ATTRIBUTE) *sk) | ||
860 | { | ||
861 | ASN1_TYPE *astype; | ||
862 | if(!(astype = get_attribute(sk, NID_pkcs9_messageDigest))) return NULL; | ||
863 | return astype->value.octet_string; | ||
864 | } | ||
865 | |||
866 | int PKCS7_set_signed_attributes(PKCS7_SIGNER_INFO *p7si, | ||
867 | STACK_OF(X509_ATTRIBUTE) *sk) | ||
868 | { | ||
869 | int i; | ||
870 | |||
871 | if (p7si->auth_attr != NULL) | ||
872 | sk_X509_ATTRIBUTE_pop_free(p7si->auth_attr,X509_ATTRIBUTE_free); | ||
873 | p7si->auth_attr=sk_X509_ATTRIBUTE_dup(sk); | ||
874 | for (i=0; i<sk_X509_ATTRIBUTE_num(sk); i++) | ||
875 | { | ||
876 | if ((sk_X509_ATTRIBUTE_set(p7si->auth_attr,i, | ||
877 | X509_ATTRIBUTE_dup(sk_X509_ATTRIBUTE_value(sk,i)))) | ||
878 | == NULL) | ||
879 | return(0); | ||
880 | } | ||
881 | return(1); | ||
882 | } | ||
883 | |||
884 | int PKCS7_set_attributes(PKCS7_SIGNER_INFO *p7si, STACK_OF(X509_ATTRIBUTE) *sk) | ||
885 | { | ||
886 | int i; | ||
887 | |||
888 | if (p7si->unauth_attr != NULL) | ||
889 | sk_X509_ATTRIBUTE_pop_free(p7si->unauth_attr, | ||
890 | X509_ATTRIBUTE_free); | ||
891 | p7si->unauth_attr=sk_X509_ATTRIBUTE_dup(sk); | ||
892 | for (i=0; i<sk_X509_ATTRIBUTE_num(sk); i++) | ||
893 | { | ||
894 | if ((sk_X509_ATTRIBUTE_set(p7si->unauth_attr,i, | ||
895 | X509_ATTRIBUTE_dup(sk_X509_ATTRIBUTE_value(sk,i)))) | ||
896 | == NULL) | ||
897 | return(0); | ||
898 | } | ||
899 | return(1); | ||
900 | } | ||
901 | |||
902 | int PKCS7_add_signed_attribute(PKCS7_SIGNER_INFO *p7si, int nid, int atrtype, | ||
903 | void *value) | ||
904 | { | ||
905 | return(add_attribute(&(p7si->auth_attr),nid,atrtype,value)); | ||
906 | } | ||
907 | |||
908 | int PKCS7_add_attribute(PKCS7_SIGNER_INFO *p7si, int nid, int atrtype, | ||
909 | void *value) | ||
910 | { | ||
911 | return(add_attribute(&(p7si->unauth_attr),nid,atrtype,value)); | ||
912 | } | ||
913 | |||
914 | static int add_attribute(STACK_OF(X509_ATTRIBUTE) **sk, int nid, int atrtype, | ||
915 | void *value) | ||
916 | { | ||
917 | X509_ATTRIBUTE *attr=NULL; | ||
918 | |||
919 | if (*sk == NULL) | ||
920 | { | ||
921 | *sk = sk_X509_ATTRIBUTE_new_null(); | ||
922 | new_attrib: | ||
923 | attr=X509_ATTRIBUTE_create(nid,atrtype,value); | ||
924 | sk_X509_ATTRIBUTE_push(*sk,attr); | ||
925 | } | ||
926 | else | ||
927 | { | ||
928 | int i; | ||
929 | |||
930 | for (i=0; i<sk_X509_ATTRIBUTE_num(*sk); i++) | ||
931 | { | ||
932 | attr=sk_X509_ATTRIBUTE_value(*sk,i); | ||
933 | if (OBJ_obj2nid(attr->object) == nid) | ||
934 | { | ||
935 | X509_ATTRIBUTE_free(attr); | ||
936 | attr=X509_ATTRIBUTE_create(nid,atrtype,value); | ||
937 | sk_X509_ATTRIBUTE_set(*sk,i,attr); | ||
938 | goto end; | ||
939 | } | ||
940 | } | ||
941 | goto new_attrib; | ||
942 | } | ||
943 | end: | ||
944 | return(1); | ||
945 | } | ||
946 | |||
diff --git a/src/lib/libcrypto/pkcs7/pk7_lib.c b/src/lib/libcrypto/pkcs7/pk7_lib.c deleted file mode 100644 index 45973fe850..0000000000 --- a/src/lib/libcrypto/pkcs7/pk7_lib.c +++ /dev/null | |||
@@ -1,469 +0,0 @@ | |||
1 | /* crypto/pkcs7/pk7_lib.c */ | ||
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
3 | * All rights reserved. | ||
4 | * | ||
5 | * This package is an SSL implementation written | ||
6 | * by Eric Young (eay@cryptsoft.com). | ||
7 | * The implementation was written so as to conform with Netscapes SSL. | ||
8 | * | ||
9 | * This library is free for commercial and non-commercial use as long as | ||
10 | * the following conditions are aheared to. The following conditions | ||
11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
13 | * included with this distribution is covered by the same copyright terms | ||
14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
15 | * | ||
16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
17 | * the code are not to be removed. | ||
18 | * If this package is used in a product, Eric Young should be given attribution | ||
19 | * as the author of the parts of the library used. | ||
20 | * This can be in the form of a textual message at program startup or | ||
21 | * in documentation (online or textual) provided with the package. | ||
22 | * | ||
23 | * Redistribution and use in source and binary forms, with or without | ||
24 | * modification, are permitted provided that the following conditions | ||
25 | * are met: | ||
26 | * 1. Redistributions of source code must retain the copyright | ||
27 | * notice, this list of conditions and the following disclaimer. | ||
28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
29 | * notice, this list of conditions and the following disclaimer in the | ||
30 | * documentation and/or other materials provided with the distribution. | ||
31 | * 3. All advertising materials mentioning features or use of this software | ||
32 | * must display the following acknowledgement: | ||
33 | * "This product includes cryptographic software written by | ||
34 | * Eric Young (eay@cryptsoft.com)" | ||
35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
36 | * being used are not cryptographic related :-). | ||
37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
38 | * the apps directory (application code) you must include an acknowledgement: | ||
39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
40 | * | ||
41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
51 | * SUCH DAMAGE. | ||
52 | * | ||
53 | * The licence and distribution terms for any publically available version or | ||
54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
55 | * copied and put under another distribution licence | ||
56 | * [including the GNU Public Licence.] | ||
57 | */ | ||
58 | |||
59 | #include <stdio.h> | ||
60 | #include "cryptlib.h" | ||
61 | #include <openssl/objects.h> | ||
62 | #include <openssl/x509.h> | ||
63 | |||
64 | long PKCS7_ctrl(PKCS7 *p7, int cmd, long larg, char *parg) | ||
65 | { | ||
66 | int nid; | ||
67 | long ret; | ||
68 | |||
69 | nid=OBJ_obj2nid(p7->type); | ||
70 | |||
71 | switch (cmd) | ||
72 | { | ||
73 | case PKCS7_OP_SET_DETACHED_SIGNATURE: | ||
74 | if (nid == NID_pkcs7_signed) | ||
75 | { | ||
76 | ret=p7->detached=(int)larg; | ||
77 | } | ||
78 | else | ||
79 | { | ||
80 | PKCS7err(PKCS7_F_PKCS7_CTRL,PKCS7_R_OPERATION_NOT_SUPPORTED_ON_THIS_TYPE); | ||
81 | ret=0; | ||
82 | } | ||
83 | break; | ||
84 | case PKCS7_OP_GET_DETACHED_SIGNATURE: | ||
85 | if (nid == NID_pkcs7_signed) | ||
86 | { | ||
87 | ret=p7->detached; | ||
88 | } | ||
89 | else | ||
90 | { | ||
91 | PKCS7err(PKCS7_F_PKCS7_CTRL,PKCS7_R_OPERATION_NOT_SUPPORTED_ON_THIS_TYPE); | ||
92 | ret=0; | ||
93 | } | ||
94 | |||
95 | break; | ||
96 | default: | ||
97 | PKCS7err(PKCS7_F_PKCS7_CTRL,PKCS7_R_UNKNOWN_OPERATION); | ||
98 | ret=0; | ||
99 | } | ||
100 | return(ret); | ||
101 | } | ||
102 | |||
103 | int PKCS7_content_new(PKCS7 *p7, int type) | ||
104 | { | ||
105 | PKCS7 *ret=NULL; | ||
106 | |||
107 | if ((ret=PKCS7_new()) == NULL) goto err; | ||
108 | if (!PKCS7_set_type(ret,type)) goto err; | ||
109 | if (!PKCS7_set_content(p7,ret)) goto err; | ||
110 | |||
111 | return(1); | ||
112 | err: | ||
113 | if (ret != NULL) PKCS7_free(ret); | ||
114 | return(0); | ||
115 | } | ||
116 | |||
117 | int PKCS7_set_content(PKCS7 *p7, PKCS7 *p7_data) | ||
118 | { | ||
119 | int i; | ||
120 | |||
121 | i=OBJ_obj2nid(p7->type); | ||
122 | switch (i) | ||
123 | { | ||
124 | case NID_pkcs7_signed: | ||
125 | if (p7->d.sign->contents != NULL) | ||
126 | PKCS7_free(p7->d.sign->contents); | ||
127 | p7->d.sign->contents=p7_data; | ||
128 | break; | ||
129 | case NID_pkcs7_digest: | ||
130 | case NID_pkcs7_data: | ||
131 | case NID_pkcs7_enveloped: | ||
132 | case NID_pkcs7_signedAndEnveloped: | ||
133 | case NID_pkcs7_encrypted: | ||
134 | default: | ||
135 | PKCS7err(PKCS7_F_PKCS7_SET_CONTENT,PKCS7_R_UNSUPPORTED_CONTENT_TYPE); | ||
136 | goto err; | ||
137 | } | ||
138 | return(1); | ||
139 | err: | ||
140 | return(0); | ||
141 | } | ||
142 | |||
143 | int PKCS7_set_type(PKCS7 *p7, int type) | ||
144 | { | ||
145 | ASN1_OBJECT *obj; | ||
146 | |||
147 | PKCS7_content_free(p7); | ||
148 | obj=OBJ_nid2obj(type); /* will not fail */ | ||
149 | |||
150 | switch (type) | ||
151 | { | ||
152 | case NID_pkcs7_signed: | ||
153 | p7->type=obj; | ||
154 | if ((p7->d.sign=PKCS7_SIGNED_new()) == NULL) | ||
155 | goto err; | ||
156 | ASN1_INTEGER_set(p7->d.sign->version,1); | ||
157 | break; | ||
158 | case NID_pkcs7_data: | ||
159 | p7->type=obj; | ||
160 | if ((p7->d.data=M_ASN1_OCTET_STRING_new()) == NULL) | ||
161 | goto err; | ||
162 | break; | ||
163 | case NID_pkcs7_signedAndEnveloped: | ||
164 | p7->type=obj; | ||
165 | if ((p7->d.signed_and_enveloped=PKCS7_SIGN_ENVELOPE_new()) | ||
166 | == NULL) goto err; | ||
167 | ASN1_INTEGER_set(p7->d.signed_and_enveloped->version,1); | ||
168 | break; | ||
169 | case NID_pkcs7_enveloped: | ||
170 | p7->type=obj; | ||
171 | if ((p7->d.enveloped=PKCS7_ENVELOPE_new()) | ||
172 | == NULL) goto err; | ||
173 | ASN1_INTEGER_set(p7->d.enveloped->version,0); | ||
174 | break; | ||
175 | case NID_pkcs7_encrypted: | ||
176 | p7->type=obj; | ||
177 | if ((p7->d.encrypted=PKCS7_ENCRYPT_new()) | ||
178 | == NULL) goto err; | ||
179 | ASN1_INTEGER_set(p7->d.encrypted->version,0); | ||
180 | break; | ||
181 | |||
182 | case NID_pkcs7_digest: | ||
183 | default: | ||
184 | PKCS7err(PKCS7_F_PKCS7_SET_TYPE,PKCS7_R_UNSUPPORTED_CONTENT_TYPE); | ||
185 | goto err; | ||
186 | } | ||
187 | return(1); | ||
188 | err: | ||
189 | return(0); | ||
190 | } | ||
191 | |||
192 | int PKCS7_add_signer(PKCS7 *p7, PKCS7_SIGNER_INFO *psi) | ||
193 | { | ||
194 | int i,j,nid; | ||
195 | X509_ALGOR *alg; | ||
196 | STACK_OF(PKCS7_SIGNER_INFO) *signer_sk; | ||
197 | STACK_OF(X509_ALGOR) *md_sk; | ||
198 | |||
199 | i=OBJ_obj2nid(p7->type); | ||
200 | switch (i) | ||
201 | { | ||
202 | case NID_pkcs7_signed: | ||
203 | signer_sk= p7->d.sign->signer_info; | ||
204 | md_sk= p7->d.sign->md_algs; | ||
205 | break; | ||
206 | case NID_pkcs7_signedAndEnveloped: | ||
207 | signer_sk= p7->d.signed_and_enveloped->signer_info; | ||
208 | md_sk= p7->d.signed_and_enveloped->md_algs; | ||
209 | break; | ||
210 | default: | ||
211 | PKCS7err(PKCS7_F_PKCS7_ADD_SIGNER,PKCS7_R_WRONG_CONTENT_TYPE); | ||
212 | return(0); | ||
213 | } | ||
214 | |||
215 | nid=OBJ_obj2nid(psi->digest_alg->algorithm); | ||
216 | |||
217 | /* If the digest is not currently listed, add it */ | ||
218 | j=0; | ||
219 | for (i=0; i<sk_X509_ALGOR_num(md_sk); i++) | ||
220 | { | ||
221 | alg=sk_X509_ALGOR_value(md_sk,i); | ||
222 | if (OBJ_obj2nid(alg->algorithm) == nid) | ||
223 | { | ||
224 | j=1; | ||
225 | break; | ||
226 | } | ||
227 | } | ||
228 | if (!j) /* we need to add another algorithm */ | ||
229 | { | ||
230 | if(!(alg=X509_ALGOR_new()) | ||
231 | || !(alg->parameter = ASN1_TYPE_new())) { | ||
232 | PKCS7err(PKCS7_F_PKCS7_ADD_SIGNER,ERR_R_MALLOC_FAILURE); | ||
233 | return(0); | ||
234 | } | ||
235 | alg->algorithm=OBJ_nid2obj(nid); | ||
236 | alg->parameter->type = V_ASN1_NULL; | ||
237 | sk_X509_ALGOR_push(md_sk,alg); | ||
238 | } | ||
239 | |||
240 | sk_PKCS7_SIGNER_INFO_push(signer_sk,psi); | ||
241 | return(1); | ||
242 | } | ||
243 | |||
244 | int PKCS7_add_certificate(PKCS7 *p7, X509 *x509) | ||
245 | { | ||
246 | int i; | ||
247 | STACK_OF(X509) **sk; | ||
248 | |||
249 | i=OBJ_obj2nid(p7->type); | ||
250 | switch (i) | ||
251 | { | ||
252 | case NID_pkcs7_signed: | ||
253 | sk= &(p7->d.sign->cert); | ||
254 | break; | ||
255 | case NID_pkcs7_signedAndEnveloped: | ||
256 | sk= &(p7->d.signed_and_enveloped->cert); | ||
257 | break; | ||
258 | default: | ||
259 | PKCS7err(PKCS7_F_PKCS7_ADD_CERTIFICATE,PKCS7_R_WRONG_CONTENT_TYPE); | ||
260 | return(0); | ||
261 | } | ||
262 | |||
263 | if (*sk == NULL) | ||
264 | *sk=sk_X509_new_null(); | ||
265 | CRYPTO_add(&x509->references,1,CRYPTO_LOCK_X509); | ||
266 | sk_X509_push(*sk,x509); | ||
267 | return(1); | ||
268 | } | ||
269 | |||
270 | int PKCS7_add_crl(PKCS7 *p7, X509_CRL *crl) | ||
271 | { | ||
272 | int i; | ||
273 | STACK_OF(X509_CRL) **sk; | ||
274 | |||
275 | i=OBJ_obj2nid(p7->type); | ||
276 | switch (i) | ||
277 | { | ||
278 | case NID_pkcs7_signed: | ||
279 | sk= &(p7->d.sign->crl); | ||
280 | break; | ||
281 | case NID_pkcs7_signedAndEnveloped: | ||
282 | sk= &(p7->d.signed_and_enveloped->crl); | ||
283 | break; | ||
284 | default: | ||
285 | PKCS7err(PKCS7_F_PKCS7_ADD_CRL,PKCS7_R_WRONG_CONTENT_TYPE); | ||
286 | return(0); | ||
287 | } | ||
288 | |||
289 | if (*sk == NULL) | ||
290 | *sk=sk_X509_CRL_new_null(); | ||
291 | |||
292 | CRYPTO_add(&crl->references,1,CRYPTO_LOCK_X509_CRL); | ||
293 | sk_X509_CRL_push(*sk,crl); | ||
294 | return(1); | ||
295 | } | ||
296 | |||
297 | int PKCS7_SIGNER_INFO_set(PKCS7_SIGNER_INFO *p7i, X509 *x509, EVP_PKEY *pkey, | ||
298 | EVP_MD *dgst) | ||
299 | { | ||
300 | char is_dsa; | ||
301 | if (pkey->type == EVP_PKEY_DSA) is_dsa = 1; | ||
302 | else is_dsa = 0; | ||
303 | /* We now need to add another PKCS7_SIGNER_INFO entry */ | ||
304 | ASN1_INTEGER_set(p7i->version,1); | ||
305 | X509_NAME_set(&p7i->issuer_and_serial->issuer, | ||
306 | X509_get_issuer_name(x509)); | ||
307 | |||
308 | /* because ASN1_INTEGER_set is used to set a 'long' we will do | ||
309 | * things the ugly way. */ | ||
310 | M_ASN1_INTEGER_free(p7i->issuer_and_serial->serial); | ||
311 | p7i->issuer_and_serial->serial= | ||
312 | M_ASN1_INTEGER_dup(X509_get_serialNumber(x509)); | ||
313 | |||
314 | /* lets keep the pkey around for a while */ | ||
315 | CRYPTO_add(&pkey->references,1,CRYPTO_LOCK_EVP_PKEY); | ||
316 | p7i->pkey=pkey; | ||
317 | |||
318 | /* Set the algorithms */ | ||
319 | if (is_dsa) p7i->digest_alg->algorithm=OBJ_nid2obj(NID_sha1); | ||
320 | else | ||
321 | p7i->digest_alg->algorithm=OBJ_nid2obj(EVP_MD_type(dgst)); | ||
322 | |||
323 | if (p7i->digest_alg->parameter != NULL) | ||
324 | ASN1_TYPE_free(p7i->digest_alg->parameter); | ||
325 | if ((p7i->digest_alg->parameter=ASN1_TYPE_new()) == NULL) | ||
326 | goto err; | ||
327 | p7i->digest_alg->parameter->type=V_ASN1_NULL; | ||
328 | |||
329 | p7i->digest_enc_alg->algorithm=OBJ_nid2obj(EVP_PKEY_type(pkey->type)); | ||
330 | |||
331 | if (p7i->digest_enc_alg->parameter != NULL) | ||
332 | ASN1_TYPE_free(p7i->digest_enc_alg->parameter); | ||
333 | if(is_dsa) p7i->digest_enc_alg->parameter = NULL; | ||
334 | else { | ||
335 | if (!(p7i->digest_enc_alg->parameter=ASN1_TYPE_new())) | ||
336 | goto err; | ||
337 | p7i->digest_enc_alg->parameter->type=V_ASN1_NULL; | ||
338 | } | ||
339 | |||
340 | return(1); | ||
341 | err: | ||
342 | return(0); | ||
343 | } | ||
344 | |||
345 | PKCS7_SIGNER_INFO *PKCS7_add_signature(PKCS7 *p7, X509 *x509, EVP_PKEY *pkey, | ||
346 | EVP_MD *dgst) | ||
347 | { | ||
348 | PKCS7_SIGNER_INFO *si; | ||
349 | |||
350 | if ((si=PKCS7_SIGNER_INFO_new()) == NULL) goto err; | ||
351 | if (!PKCS7_SIGNER_INFO_set(si,x509,pkey,dgst)) goto err; | ||
352 | if (!PKCS7_add_signer(p7,si)) goto err; | ||
353 | return(si); | ||
354 | err: | ||
355 | return(NULL); | ||
356 | } | ||
357 | |||
358 | STACK_OF(PKCS7_SIGNER_INFO) *PKCS7_get_signer_info(PKCS7 *p7) | ||
359 | { | ||
360 | if (PKCS7_type_is_signed(p7)) | ||
361 | { | ||
362 | return(p7->d.sign->signer_info); | ||
363 | } | ||
364 | else if (PKCS7_type_is_signedAndEnveloped(p7)) | ||
365 | { | ||
366 | return(p7->d.signed_and_enveloped->signer_info); | ||
367 | } | ||
368 | else | ||
369 | return(NULL); | ||
370 | } | ||
371 | |||
372 | PKCS7_RECIP_INFO *PKCS7_add_recipient(PKCS7 *p7, X509 *x509) | ||
373 | { | ||
374 | PKCS7_RECIP_INFO *ri; | ||
375 | |||
376 | if ((ri=PKCS7_RECIP_INFO_new()) == NULL) goto err; | ||
377 | if (!PKCS7_RECIP_INFO_set(ri,x509)) goto err; | ||
378 | if (!PKCS7_add_recipient_info(p7,ri)) goto err; | ||
379 | return(ri); | ||
380 | err: | ||
381 | return(NULL); | ||
382 | } | ||
383 | |||
384 | int PKCS7_add_recipient_info(PKCS7 *p7, PKCS7_RECIP_INFO *ri) | ||
385 | { | ||
386 | int i; | ||
387 | STACK_OF(PKCS7_RECIP_INFO) *sk; | ||
388 | |||
389 | i=OBJ_obj2nid(p7->type); | ||
390 | switch (i) | ||
391 | { | ||
392 | case NID_pkcs7_signedAndEnveloped: | ||
393 | sk= p7->d.signed_and_enveloped->recipientinfo; | ||
394 | break; | ||
395 | case NID_pkcs7_enveloped: | ||
396 | sk= p7->d.enveloped->recipientinfo; | ||
397 | break; | ||
398 | default: | ||
399 | PKCS7err(PKCS7_F_PKCS7_ADD_RECIPIENT_INFO,PKCS7_R_WRONG_CONTENT_TYPE); | ||
400 | return(0); | ||
401 | } | ||
402 | |||
403 | sk_PKCS7_RECIP_INFO_push(sk,ri); | ||
404 | return(1); | ||
405 | } | ||
406 | |||
407 | int PKCS7_RECIP_INFO_set(PKCS7_RECIP_INFO *p7i, X509 *x509) | ||
408 | { | ||
409 | ASN1_INTEGER_set(p7i->version,0); | ||
410 | X509_NAME_set(&p7i->issuer_and_serial->issuer, | ||
411 | X509_get_issuer_name(x509)); | ||
412 | |||
413 | M_ASN1_INTEGER_free(p7i->issuer_and_serial->serial); | ||
414 | p7i->issuer_and_serial->serial= | ||
415 | M_ASN1_INTEGER_dup(X509_get_serialNumber(x509)); | ||
416 | |||
417 | X509_ALGOR_free(p7i->key_enc_algor); | ||
418 | p7i->key_enc_algor=(X509_ALGOR *)ASN1_dup(i2d_X509_ALGOR, | ||
419 | (char *(*)())d2i_X509_ALGOR, | ||
420 | (char *)x509->cert_info->key->algor); | ||
421 | |||
422 | CRYPTO_add(&x509->references,1,CRYPTO_LOCK_X509); | ||
423 | p7i->cert=x509; | ||
424 | |||
425 | return(1); | ||
426 | } | ||
427 | |||
428 | X509 *PKCS7_cert_from_signer_info(PKCS7 *p7, PKCS7_SIGNER_INFO *si) | ||
429 | { | ||
430 | if (PKCS7_type_is_signed(p7)) | ||
431 | return(X509_find_by_issuer_and_serial(p7->d.sign->cert, | ||
432 | si->issuer_and_serial->issuer, | ||
433 | si->issuer_and_serial->serial)); | ||
434 | else | ||
435 | return(NULL); | ||
436 | } | ||
437 | |||
438 | int PKCS7_set_cipher(PKCS7 *p7, const EVP_CIPHER *cipher) | ||
439 | { | ||
440 | int i; | ||
441 | ASN1_OBJECT *objtmp; | ||
442 | PKCS7_ENC_CONTENT *ec; | ||
443 | |||
444 | i=OBJ_obj2nid(p7->type); | ||
445 | switch (i) | ||
446 | { | ||
447 | case NID_pkcs7_signedAndEnveloped: | ||
448 | ec=p7->d.signed_and_enveloped->enc_data; | ||
449 | break; | ||
450 | case NID_pkcs7_enveloped: | ||
451 | ec=p7->d.enveloped->enc_data; | ||
452 | break; | ||
453 | default: | ||
454 | PKCS7err(PKCS7_F_PKCS7_SET_CIPHER,PKCS7_R_WRONG_CONTENT_TYPE); | ||
455 | return(0); | ||
456 | } | ||
457 | |||
458 | /* Check cipher OID exists and has data in it*/ | ||
459 | i = EVP_CIPHER_type(cipher); | ||
460 | if(i == NID_undef) { | ||
461 | PKCS7err(PKCS7_F_PKCS7_SET_CIPHER,PKCS7_R_CIPHER_HAS_NO_OBJECT_IDENTIFIER); | ||
462 | return(0); | ||
463 | } | ||
464 | objtmp = OBJ_nid2obj(i); | ||
465 | |||
466 | ec->cipher = cipher; | ||
467 | return 1; | ||
468 | } | ||
469 | |||
diff --git a/src/lib/libcrypto/pkcs7/pk7_mime.c b/src/lib/libcrypto/pkcs7/pk7_mime.c deleted file mode 100644 index 086d394270..0000000000 --- a/src/lib/libcrypto/pkcs7/pk7_mime.c +++ /dev/null | |||
@@ -1,685 +0,0 @@ | |||
1 | /* pk7_mime.c */ | ||
2 | /* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL | ||
3 | * project 1999. | ||
4 | */ | ||
5 | /* ==================================================================== | ||
6 | * Copyright (c) 1999 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 | ||
28 | * licensing@OpenSSL.org. | ||
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 | * This product includes cryptographic software written by Eric Young | ||
54 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
55 | * Hudson (tjh@cryptsoft.com). | ||
56 | * | ||
57 | */ | ||
58 | |||
59 | #include <stdio.h> | ||
60 | #include <ctype.h> | ||
61 | #include "cryptlib.h" | ||
62 | #include <openssl/rand.h> | ||
63 | #include <openssl/x509.h> | ||
64 | |||
65 | /* MIME and related routines */ | ||
66 | |||
67 | /* MIME format structures | ||
68 | * Note that all are translated to lower case apart from | ||
69 | * parameter values. Quotes are stripped off | ||
70 | */ | ||
71 | |||
72 | typedef struct { | ||
73 | char *param_name; /* Param name e.g. "micalg" */ | ||
74 | char *param_value; /* Param value e.g. "sha1" */ | ||
75 | } MIME_PARAM; | ||
76 | |||
77 | DECLARE_STACK_OF(MIME_PARAM) | ||
78 | IMPLEMENT_STACK_OF(MIME_PARAM) | ||
79 | |||
80 | typedef struct { | ||
81 | char *name; /* Name of line e.g. "content-type" */ | ||
82 | char *value; /* Value of line e.g. "text/plain" */ | ||
83 | STACK_OF(MIME_PARAM) *params; /* Zero or more parameters */ | ||
84 | } MIME_HEADER; | ||
85 | |||
86 | DECLARE_STACK_OF(MIME_HEADER) | ||
87 | IMPLEMENT_STACK_OF(MIME_HEADER) | ||
88 | |||
89 | static int B64_write_PKCS7(BIO *bio, PKCS7 *p7); | ||
90 | static PKCS7 *B64_read_PKCS7(BIO *bio); | ||
91 | static char * strip_ends(char *name); | ||
92 | static char * strip_start(char *name); | ||
93 | static char * strip_end(char *name); | ||
94 | static MIME_HEADER *mime_hdr_new(char *name, char *value); | ||
95 | static int mime_hdr_addparam(MIME_HEADER *mhdr, char *name, char *value); | ||
96 | static STACK_OF(MIME_HEADER) *mime_parse_hdr(BIO *bio); | ||
97 | static int mime_hdr_cmp(const MIME_HEADER * const *a, | ||
98 | const MIME_HEADER * const *b); | ||
99 | static int mime_param_cmp(const MIME_PARAM * const *a, | ||
100 | const MIME_PARAM * const *b); | ||
101 | static void mime_param_free(MIME_PARAM *param); | ||
102 | static int mime_bound_check(char *line, int linelen, char *bound, int blen); | ||
103 | static int multi_split(BIO *bio, char *bound, STACK_OF(BIO) **ret); | ||
104 | static int iscrlf(char c); | ||
105 | static MIME_HEADER *mime_hdr_find(STACK_OF(MIME_HEADER) *hdrs, char *name); | ||
106 | static MIME_PARAM *mime_param_find(MIME_HEADER *hdr, char *name); | ||
107 | static void mime_hdr_free(MIME_HEADER *hdr); | ||
108 | |||
109 | #define MAX_SMLEN 1024 | ||
110 | #define mime_debug(x) /* x */ | ||
111 | |||
112 | |||
113 | typedef void (*stkfree)(); | ||
114 | |||
115 | /* Base 64 read and write of PKCS#7 structure */ | ||
116 | |||
117 | static int B64_write_PKCS7(BIO *bio, PKCS7 *p7) | ||
118 | { | ||
119 | BIO *b64; | ||
120 | if(!(b64 = BIO_new(BIO_f_base64()))) { | ||
121 | PKCS7err(PKCS7_F_B64_WRITE_PKCS7,ERR_R_MALLOC_FAILURE); | ||
122 | return 0; | ||
123 | } | ||
124 | bio = BIO_push(b64, bio); | ||
125 | i2d_PKCS7_bio(bio, p7); | ||
126 | BIO_flush(bio); | ||
127 | bio = BIO_pop(bio); | ||
128 | BIO_free(b64); | ||
129 | return 1; | ||
130 | } | ||
131 | |||
132 | static PKCS7 *B64_read_PKCS7(BIO *bio) | ||
133 | { | ||
134 | BIO *b64; | ||
135 | PKCS7 *p7; | ||
136 | if(!(b64 = BIO_new(BIO_f_base64()))) { | ||
137 | PKCS7err(PKCS7_F_B64_READ_PKCS7,ERR_R_MALLOC_FAILURE); | ||
138 | return 0; | ||
139 | } | ||
140 | bio = BIO_push(b64, bio); | ||
141 | if(!(p7 = d2i_PKCS7_bio(bio, NULL))) | ||
142 | PKCS7err(PKCS7_F_B64_READ_PKCS7,PKCS7_R_DECODE_ERROR); | ||
143 | BIO_flush(bio); | ||
144 | bio = BIO_pop(bio); | ||
145 | BIO_free(b64); | ||
146 | return p7; | ||
147 | } | ||
148 | |||
149 | /* SMIME sender */ | ||
150 | |||
151 | int SMIME_write_PKCS7(BIO *bio, PKCS7 *p7, BIO *data, int flags) | ||
152 | { | ||
153 | char linebuf[MAX_SMLEN]; | ||
154 | char bound[33], c; | ||
155 | int i; | ||
156 | if((flags & PKCS7_DETACHED) && data) { | ||
157 | /* We want multipart/signed */ | ||
158 | /* Generate a random boundary */ | ||
159 | RAND_pseudo_bytes((unsigned char *)bound, 32); | ||
160 | for(i = 0; i < 32; i++) { | ||
161 | c = bound[i] & 0xf; | ||
162 | if(c < 10) c += '0'; | ||
163 | else c += 'A' - 10; | ||
164 | bound[i] = c; | ||
165 | } | ||
166 | bound[32] = 0; | ||
167 | BIO_printf(bio, "MIME-Version: 1.0\n"); | ||
168 | BIO_printf(bio, "Content-Type: multipart/signed;"); | ||
169 | BIO_printf(bio, " protocol=\"application/x-pkcs7-signature\";"); | ||
170 | BIO_printf(bio, " micalg=sha1; boundary=\"----%s\"\n\n", bound); | ||
171 | BIO_printf(bio, "This is an S/MIME signed message\n\n"); | ||
172 | /* Now write out the first part */ | ||
173 | BIO_printf(bio, "------%s\n", bound); | ||
174 | if(flags & PKCS7_TEXT) BIO_printf(bio, "Content-Type: text/plain\n\n"); | ||
175 | while((i = BIO_read(data, linebuf, MAX_SMLEN)) > 0) | ||
176 | BIO_write(bio, linebuf, i); | ||
177 | BIO_printf(bio, "\n------%s\n", bound); | ||
178 | |||
179 | /* Headers for signature */ | ||
180 | |||
181 | BIO_printf(bio, "Content-Type: application/x-pkcs7-signature; name=\"smime.p7s\"\n"); | ||
182 | BIO_printf(bio, "Content-Transfer-Encoding: base64\n"); | ||
183 | BIO_printf(bio, "Content-Disposition: attachment; filename=\"smime.p7s\"\n\n"); | ||
184 | B64_write_PKCS7(bio, p7); | ||
185 | BIO_printf(bio,"\n------%s--\n\n", bound); | ||
186 | return 1; | ||
187 | } | ||
188 | /* MIME headers */ | ||
189 | BIO_printf(bio, "MIME-Version: 1.0\n"); | ||
190 | BIO_printf(bio, "Content-Disposition: attachment; filename=\"smime.p7m\"\n"); | ||
191 | BIO_printf(bio, "Content-Type: application/x-pkcs7-mime; name=\"smime.p7m\"\n"); | ||
192 | BIO_printf(bio, "Content-Transfer-Encoding: base64\n\n"); | ||
193 | B64_write_PKCS7(bio, p7); | ||
194 | BIO_printf(bio, "\n"); | ||
195 | return 1; | ||
196 | } | ||
197 | |||
198 | /* SMIME reader: handle multipart/signed and opaque signing. | ||
199 | * in multipart case the content is placed in a memory BIO | ||
200 | * pointed to by "bcont". In opaque this is set to NULL | ||
201 | */ | ||
202 | |||
203 | PKCS7 *SMIME_read_PKCS7(BIO *bio, BIO **bcont) | ||
204 | { | ||
205 | BIO *p7in; | ||
206 | STACK_OF(MIME_HEADER) *headers = NULL; | ||
207 | STACK_OF(BIO) *parts = NULL; | ||
208 | MIME_HEADER *hdr; | ||
209 | MIME_PARAM *prm; | ||
210 | PKCS7 *p7; | ||
211 | int ret; | ||
212 | |||
213 | if(bcont) *bcont = NULL; | ||
214 | |||
215 | if (!(headers = mime_parse_hdr(bio))) { | ||
216 | PKCS7err(PKCS7_F_SMIME_READ_PKCS7,PKCS7_R_MIME_PARSE_ERROR); | ||
217 | return NULL; | ||
218 | } | ||
219 | |||
220 | if(!(hdr = mime_hdr_find(headers, "content-type")) || !hdr->value) { | ||
221 | sk_MIME_HEADER_pop_free(headers, mime_hdr_free); | ||
222 | PKCS7err(PKCS7_F_SMIME_READ_PKCS7, PKCS7_R_NO_CONTENT_TYPE); | ||
223 | return NULL; | ||
224 | } | ||
225 | |||
226 | /* Handle multipart/signed */ | ||
227 | |||
228 | if(!strcmp(hdr->value, "multipart/signed")) { | ||
229 | /* Split into two parts */ | ||
230 | prm = mime_param_find(hdr, "boundary"); | ||
231 | if(!prm || !prm->param_value) { | ||
232 | sk_MIME_HEADER_pop_free(headers, mime_hdr_free); | ||
233 | PKCS7err(PKCS7_F_SMIME_READ_PKCS7, PKCS7_R_NO_MULTIPART_BOUNDARY); | ||
234 | return NULL; | ||
235 | } | ||
236 | ret = multi_split(bio, prm->param_value, &parts); | ||
237 | sk_MIME_HEADER_pop_free(headers, mime_hdr_free); | ||
238 | if(!ret || (sk_BIO_num(parts) != 2) ) { | ||
239 | PKCS7err(PKCS7_F_SMIME_READ_PKCS7, PKCS7_R_NO_MULTIPART_BODY_FAILURE); | ||
240 | sk_BIO_pop_free(parts, BIO_vfree); | ||
241 | return NULL; | ||
242 | } | ||
243 | |||
244 | /* Parse the signature piece */ | ||
245 | p7in = sk_BIO_value(parts, 1); | ||
246 | |||
247 | if (!(headers = mime_parse_hdr(p7in))) { | ||
248 | PKCS7err(PKCS7_F_SMIME_READ_PKCS7,PKCS7_R_MIME_SIG_PARSE_ERROR); | ||
249 | sk_BIO_pop_free(parts, BIO_vfree); | ||
250 | return NULL; | ||
251 | } | ||
252 | |||
253 | /* Get content type */ | ||
254 | |||
255 | if(!(hdr = mime_hdr_find(headers, "content-type")) || | ||
256 | !hdr->value) { | ||
257 | sk_MIME_HEADER_pop_free(headers, mime_hdr_free); | ||
258 | PKCS7err(PKCS7_F_SMIME_READ_PKCS7, PKCS7_R_NO_SIG_CONTENT_TYPE); | ||
259 | return NULL; | ||
260 | } | ||
261 | |||
262 | if(strcmp(hdr->value, "application/x-pkcs7-signature") && | ||
263 | strcmp(hdr->value, "application/pkcs7-signature")) { | ||
264 | sk_MIME_HEADER_pop_free(headers, mime_hdr_free); | ||
265 | PKCS7err(PKCS7_F_SMIME_READ_PKCS7,PKCS7_R_SIG_INVALID_MIME_TYPE); | ||
266 | ERR_add_error_data(2, "type: ", hdr->value); | ||
267 | sk_BIO_pop_free(parts, BIO_vfree); | ||
268 | return NULL; | ||
269 | } | ||
270 | sk_MIME_HEADER_pop_free(headers, mime_hdr_free); | ||
271 | /* Read in PKCS#7 */ | ||
272 | if(!(p7 = B64_read_PKCS7(p7in))) { | ||
273 | PKCS7err(PKCS7_F_SMIME_READ_PKCS7,PKCS7_R_PKCS7_SIG_PARSE_ERROR); | ||
274 | sk_BIO_pop_free(parts, BIO_vfree); | ||
275 | return NULL; | ||
276 | } | ||
277 | |||
278 | if(bcont) { | ||
279 | *bcont = sk_BIO_value(parts, 0); | ||
280 | BIO_free(p7in); | ||
281 | sk_BIO_free(parts); | ||
282 | } else sk_BIO_pop_free(parts, BIO_vfree); | ||
283 | return p7; | ||
284 | } | ||
285 | |||
286 | /* OK, if not multipart/signed try opaque signature */ | ||
287 | |||
288 | if (strcmp (hdr->value, "application/x-pkcs7-mime") && | ||
289 | strcmp (hdr->value, "application/pkcs7-mime")) { | ||
290 | PKCS7err(PKCS7_F_SMIME_READ_PKCS7,PKCS7_R_INVALID_MIME_TYPE); | ||
291 | ERR_add_error_data(2, "type: ", hdr->value); | ||
292 | sk_MIME_HEADER_pop_free(headers, mime_hdr_free); | ||
293 | return NULL; | ||
294 | } | ||
295 | |||
296 | sk_MIME_HEADER_pop_free(headers, mime_hdr_free); | ||
297 | |||
298 | if(!(p7 = B64_read_PKCS7(bio))) { | ||
299 | PKCS7err(PKCS7_F_SMIME_READ_PKCS7, PKCS7_R_PKCS7_PARSE_ERROR); | ||
300 | return NULL; | ||
301 | } | ||
302 | return p7; | ||
303 | |||
304 | } | ||
305 | |||
306 | /* Copy text from one BIO to another making the output CRLF at EOL */ | ||
307 | int SMIME_crlf_copy(BIO *in, BIO *out, int flags) | ||
308 | { | ||
309 | char eol; | ||
310 | int len; | ||
311 | char linebuf[MAX_SMLEN]; | ||
312 | if(flags & PKCS7_BINARY) { | ||
313 | while((len = BIO_read(in, linebuf, MAX_SMLEN)) > 0) | ||
314 | BIO_write(out, linebuf, len); | ||
315 | return 1; | ||
316 | } | ||
317 | if(flags & PKCS7_TEXT) BIO_printf(out, "Content-Type: text/plain\r\n\r\n"); | ||
318 | while ((len = BIO_gets(in, linebuf, MAX_SMLEN)) > 0) { | ||
319 | eol = 0; | ||
320 | while(iscrlf(linebuf[len - 1])) { | ||
321 | len--; | ||
322 | eol = 1; | ||
323 | } | ||
324 | BIO_write(out, linebuf, len); | ||
325 | if(eol) BIO_write(out, "\r\n", 2); | ||
326 | } | ||
327 | return 1; | ||
328 | } | ||
329 | |||
330 | /* Strip off headers if they are text/plain */ | ||
331 | int SMIME_text(BIO *in, BIO *out) | ||
332 | { | ||
333 | char iobuf[4096]; | ||
334 | int len; | ||
335 | STACK_OF(MIME_HEADER) *headers; | ||
336 | MIME_HEADER *hdr; | ||
337 | |||
338 | if (!(headers = mime_parse_hdr(in))) { | ||
339 | PKCS7err(PKCS7_F_SMIME_TEXT,PKCS7_R_MIME_PARSE_ERROR); | ||
340 | return 0; | ||
341 | } | ||
342 | if(!(hdr = mime_hdr_find(headers, "content-type")) || !hdr->value) { | ||
343 | PKCS7err(PKCS7_F_SMIME_TEXT,PKCS7_R_MIME_NO_CONTENT_TYPE); | ||
344 | sk_MIME_HEADER_pop_free(headers, mime_hdr_free); | ||
345 | return 0; | ||
346 | } | ||
347 | if (strcmp (hdr->value, "text/plain")) { | ||
348 | PKCS7err(PKCS7_F_SMIME_TEXT,PKCS7_R_INVALID_MIME_TYPE); | ||
349 | ERR_add_error_data(2, "type: ", hdr->value); | ||
350 | sk_MIME_HEADER_pop_free(headers, mime_hdr_free); | ||
351 | return 0; | ||
352 | } | ||
353 | sk_MIME_HEADER_pop_free(headers, mime_hdr_free); | ||
354 | while ((len = BIO_read(in, iobuf, sizeof(iobuf))) > 0) | ||
355 | BIO_write(out, iobuf, len); | ||
356 | return 1; | ||
357 | } | ||
358 | |||
359 | /* Split a multipart/XXX message body into component parts: result is | ||
360 | * canonical parts in a STACK of bios | ||
361 | */ | ||
362 | |||
363 | static int multi_split(BIO *bio, char *bound, STACK_OF(BIO) **ret) | ||
364 | { | ||
365 | char linebuf[MAX_SMLEN]; | ||
366 | int len, blen; | ||
367 | BIO *bpart = NULL; | ||
368 | STACK_OF(BIO) *parts; | ||
369 | char state, part, first; | ||
370 | |||
371 | blen = strlen(bound); | ||
372 | part = 0; | ||
373 | state = 0; | ||
374 | first = 1; | ||
375 | parts = sk_BIO_new_null(); | ||
376 | *ret = parts; | ||
377 | while ((len = BIO_gets(bio, linebuf, MAX_SMLEN)) > 0) { | ||
378 | state = mime_bound_check(linebuf, len, bound, blen); | ||
379 | if(state == 1) { | ||
380 | first = 1; | ||
381 | part++; | ||
382 | } else if(state == 2) { | ||
383 | sk_BIO_push(parts, bpart); | ||
384 | return 1; | ||
385 | } else if(part) { | ||
386 | if(first) { | ||
387 | first = 0; | ||
388 | if(bpart) sk_BIO_push(parts, bpart); | ||
389 | bpart = BIO_new(BIO_s_mem()); | ||
390 | |||
391 | } else BIO_write(bpart, "\r\n", 2); | ||
392 | /* Strip CR+LF from linebuf */ | ||
393 | while(iscrlf(linebuf[len - 1])) len--; | ||
394 | BIO_write(bpart, linebuf, len); | ||
395 | } | ||
396 | } | ||
397 | return 0; | ||
398 | } | ||
399 | |||
400 | static int iscrlf(char c) | ||
401 | { | ||
402 | if(c == '\r' || c == '\n') return 1; | ||
403 | return 0; | ||
404 | } | ||
405 | |||
406 | /* This is the big one: parse MIME header lines up to message body */ | ||
407 | |||
408 | #define MIME_INVALID 0 | ||
409 | #define MIME_START 1 | ||
410 | #define MIME_TYPE 2 | ||
411 | #define MIME_NAME 3 | ||
412 | #define MIME_VALUE 4 | ||
413 | #define MIME_QUOTE 5 | ||
414 | #define MIME_COMMENT 6 | ||
415 | |||
416 | |||
417 | static STACK_OF(MIME_HEADER) *mime_parse_hdr(BIO *bio) | ||
418 | { | ||
419 | char *p, *q, c; | ||
420 | char *ntmp; | ||
421 | char linebuf[MAX_SMLEN]; | ||
422 | MIME_HEADER *mhdr = NULL; | ||
423 | STACK_OF(MIME_HEADER) *headers; | ||
424 | int len, state, save_state = 0; | ||
425 | |||
426 | headers = sk_MIME_HEADER_new(mime_hdr_cmp); | ||
427 | while ((len = BIO_gets(bio, linebuf, MAX_SMLEN)) > 0) { | ||
428 | /* If whitespace at line start then continuation line */ | ||
429 | if(mhdr && isspace((unsigned char)linebuf[0])) state = MIME_NAME; | ||
430 | else state = MIME_START; | ||
431 | ntmp = NULL; | ||
432 | /* Go through all characters */ | ||
433 | for(p = linebuf, q = linebuf; (c = *p) && (c!='\r') && (c!='\n'); p++) { | ||
434 | |||
435 | /* State machine to handle MIME headers | ||
436 | * if this looks horrible that's because it *is* | ||
437 | */ | ||
438 | |||
439 | switch(state) { | ||
440 | case MIME_START: | ||
441 | if(c == ':') { | ||
442 | state = MIME_TYPE; | ||
443 | *p = 0; | ||
444 | ntmp = strip_ends(q); | ||
445 | q = p + 1; | ||
446 | } | ||
447 | break; | ||
448 | |||
449 | case MIME_TYPE: | ||
450 | if(c == ';') { | ||
451 | mime_debug("Found End Value\n"); | ||
452 | *p = 0; | ||
453 | mhdr = mime_hdr_new(ntmp, strip_ends(q)); | ||
454 | sk_MIME_HEADER_push(headers, mhdr); | ||
455 | ntmp = NULL; | ||
456 | q = p + 1; | ||
457 | state = MIME_NAME; | ||
458 | } else if(c == '(') { | ||
459 | save_state = state; | ||
460 | state = MIME_COMMENT; | ||
461 | } | ||
462 | break; | ||
463 | |||
464 | case MIME_COMMENT: | ||
465 | if(c == ')') { | ||
466 | state = save_state; | ||
467 | } | ||
468 | break; | ||
469 | |||
470 | case MIME_NAME: | ||
471 | if(c == '=') { | ||
472 | state = MIME_VALUE; | ||
473 | *p = 0; | ||
474 | ntmp = strip_ends(q); | ||
475 | q = p + 1; | ||
476 | } | ||
477 | break ; | ||
478 | |||
479 | case MIME_VALUE: | ||
480 | if(c == ';') { | ||
481 | state = MIME_NAME; | ||
482 | *p = 0; | ||
483 | mime_hdr_addparam(mhdr, ntmp, strip_ends(q)); | ||
484 | ntmp = NULL; | ||
485 | q = p + 1; | ||
486 | } else if (c == '"') { | ||
487 | mime_debug("Found Quote\n"); | ||
488 | state = MIME_QUOTE; | ||
489 | } else if(c == '(') { | ||
490 | save_state = state; | ||
491 | state = MIME_COMMENT; | ||
492 | } | ||
493 | break; | ||
494 | |||
495 | case MIME_QUOTE: | ||
496 | if(c == '"') { | ||
497 | mime_debug("Found Match Quote\n"); | ||
498 | state = MIME_VALUE; | ||
499 | } | ||
500 | break; | ||
501 | } | ||
502 | } | ||
503 | |||
504 | if(state == MIME_TYPE) { | ||
505 | mhdr = mime_hdr_new(ntmp, strip_ends(q)); | ||
506 | sk_MIME_HEADER_push(headers, mhdr); | ||
507 | } else if(state == MIME_VALUE) | ||
508 | mime_hdr_addparam(mhdr, ntmp, strip_ends(q)); | ||
509 | if(p == linebuf) break; /* Blank line means end of headers */ | ||
510 | } | ||
511 | |||
512 | return headers; | ||
513 | |||
514 | } | ||
515 | |||
516 | static char *strip_ends(char *name) | ||
517 | { | ||
518 | return strip_end(strip_start(name)); | ||
519 | } | ||
520 | |||
521 | /* Strip a parameter of whitespace from start of param */ | ||
522 | static char *strip_start(char *name) | ||
523 | { | ||
524 | char *p, c; | ||
525 | /* Look for first non white space or quote */ | ||
526 | for(p = name; (c = *p) ;p++) { | ||
527 | if(c == '"') { | ||
528 | /* Next char is start of string if non null */ | ||
529 | if(p[1]) return p + 1; | ||
530 | /* Else null string */ | ||
531 | return NULL; | ||
532 | } | ||
533 | if(!isspace((unsigned char)c)) return p; | ||
534 | } | ||
535 | return NULL; | ||
536 | } | ||
537 | |||
538 | /* As above but strip from end of string : maybe should handle brackets? */ | ||
539 | static char *strip_end(char *name) | ||
540 | { | ||
541 | char *p, c; | ||
542 | if(!name) return NULL; | ||
543 | /* Look for first non white space or quote */ | ||
544 | for(p = name + strlen(name) - 1; p >= name ;p--) { | ||
545 | c = *p; | ||
546 | if(c == '"') { | ||
547 | if(p - 1 == name) return NULL; | ||
548 | *p = 0; | ||
549 | return name; | ||
550 | } | ||
551 | if(isspace((unsigned char)c)) *p = 0; | ||
552 | else return name; | ||
553 | } | ||
554 | return NULL; | ||
555 | } | ||
556 | |||
557 | static MIME_HEADER *mime_hdr_new(char *name, char *value) | ||
558 | { | ||
559 | MIME_HEADER *mhdr; | ||
560 | char *tmpname, *tmpval, *p; | ||
561 | int c; | ||
562 | if(name) { | ||
563 | if(!(tmpname = BUF_strdup(name))) return NULL; | ||
564 | for(p = tmpname ; *p; p++) { | ||
565 | c = *p; | ||
566 | if(isupper(c)) { | ||
567 | c = tolower(c); | ||
568 | *p = c; | ||
569 | } | ||
570 | } | ||
571 | } else tmpname = NULL; | ||
572 | if(value) { | ||
573 | if(!(tmpval = BUF_strdup(value))) return NULL; | ||
574 | for(p = tmpval ; *p; p++) { | ||
575 | c = *p; | ||
576 | if(isupper(c)) { | ||
577 | c = tolower(c); | ||
578 | *p = c; | ||
579 | } | ||
580 | } | ||
581 | } else tmpval = NULL; | ||
582 | mhdr = (MIME_HEADER *) OPENSSL_malloc(sizeof(MIME_HEADER)); | ||
583 | if(!mhdr) return NULL; | ||
584 | mhdr->name = tmpname; | ||
585 | mhdr->value = tmpval; | ||
586 | if(!(mhdr->params = sk_MIME_PARAM_new(mime_param_cmp))) return NULL; | ||
587 | return mhdr; | ||
588 | } | ||
589 | |||
590 | static int mime_hdr_addparam(MIME_HEADER *mhdr, char *name, char *value) | ||
591 | { | ||
592 | char *tmpname, *tmpval, *p; | ||
593 | int c; | ||
594 | MIME_PARAM *mparam; | ||
595 | if(name) { | ||
596 | tmpname = BUF_strdup(name); | ||
597 | if(!tmpname) return 0; | ||
598 | for(p = tmpname ; *p; p++) { | ||
599 | c = *p; | ||
600 | if(isupper(c)) { | ||
601 | c = tolower(c); | ||
602 | *p = c; | ||
603 | } | ||
604 | } | ||
605 | } else tmpname = NULL; | ||
606 | if(value) { | ||
607 | tmpval = BUF_strdup(value); | ||
608 | if(!tmpval) return 0; | ||
609 | } else tmpval = NULL; | ||
610 | /* Parameter values are case sensitive so leave as is */ | ||
611 | mparam = (MIME_PARAM *) OPENSSL_malloc(sizeof(MIME_PARAM)); | ||
612 | if(!mparam) return 0; | ||
613 | mparam->param_name = tmpname; | ||
614 | mparam->param_value = tmpval; | ||
615 | sk_MIME_PARAM_push(mhdr->params, mparam); | ||
616 | return 1; | ||
617 | } | ||
618 | |||
619 | static int mime_hdr_cmp(const MIME_HEADER * const *a, | ||
620 | const MIME_HEADER * const *b) | ||
621 | { | ||
622 | return(strcmp((*a)->name, (*b)->name)); | ||
623 | } | ||
624 | |||
625 | static int mime_param_cmp(const MIME_PARAM * const *a, | ||
626 | const MIME_PARAM * const *b) | ||
627 | { | ||
628 | return(strcmp((*a)->param_name, (*b)->param_name)); | ||
629 | } | ||
630 | |||
631 | /* Find a header with a given name (if possible) */ | ||
632 | |||
633 | static MIME_HEADER *mime_hdr_find(STACK_OF(MIME_HEADER) *hdrs, char *name) | ||
634 | { | ||
635 | MIME_HEADER htmp; | ||
636 | int idx; | ||
637 | htmp.name = name; | ||
638 | idx = sk_MIME_HEADER_find(hdrs, &htmp); | ||
639 | if(idx < 0) return NULL; | ||
640 | return sk_MIME_HEADER_value(hdrs, idx); | ||
641 | } | ||
642 | |||
643 | static MIME_PARAM *mime_param_find(MIME_HEADER *hdr, char *name) | ||
644 | { | ||
645 | MIME_PARAM param; | ||
646 | int idx; | ||
647 | param.param_name = name; | ||
648 | idx = sk_MIME_PARAM_find(hdr->params, ¶m); | ||
649 | if(idx < 0) return NULL; | ||
650 | return sk_MIME_PARAM_value(hdr->params, idx); | ||
651 | } | ||
652 | |||
653 | static void mime_hdr_free(MIME_HEADER *hdr) | ||
654 | { | ||
655 | if(hdr->name) OPENSSL_free(hdr->name); | ||
656 | if(hdr->value) OPENSSL_free(hdr->value); | ||
657 | if(hdr->params) sk_MIME_PARAM_pop_free(hdr->params, mime_param_free); | ||
658 | OPENSSL_free(hdr); | ||
659 | } | ||
660 | |||
661 | static void mime_param_free(MIME_PARAM *param) | ||
662 | { | ||
663 | if(param->param_name) OPENSSL_free(param->param_name); | ||
664 | if(param->param_value) OPENSSL_free(param->param_value); | ||
665 | OPENSSL_free(param); | ||
666 | } | ||
667 | |||
668 | /* Check for a multipart boundary. Returns: | ||
669 | * 0 : no boundary | ||
670 | * 1 : part boundary | ||
671 | * 2 : final boundary | ||
672 | */ | ||
673 | static int mime_bound_check(char *line, int linelen, char *bound, int blen) | ||
674 | { | ||
675 | if(linelen == -1) linelen = strlen(line); | ||
676 | if(blen == -1) blen = strlen(bound); | ||
677 | /* Quickly eliminate if line length too short */ | ||
678 | if(blen + 2 > linelen) return 0; | ||
679 | /* Check for part boundary */ | ||
680 | if(!strncmp(line, "--", 2) && !strncmp(line + 2, bound, blen)) { | ||
681 | if(!strncmp(line + blen + 2, "--", 2)) return 2; | ||
682 | else return 1; | ||
683 | } | ||
684 | return 0; | ||
685 | } | ||
diff --git a/src/lib/libcrypto/pkcs7/pk7_smime.c b/src/lib/libcrypto/pkcs7/pk7_smime.c deleted file mode 100644 index 3d3214f5ee..0000000000 --- a/src/lib/libcrypto/pkcs7/pk7_smime.c +++ /dev/null | |||
@@ -1,432 +0,0 @@ | |||
1 | /* pk7_smime.c */ | ||
2 | /* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL | ||
3 | * project 1999. | ||
4 | */ | ||
5 | /* ==================================================================== | ||
6 | * Copyright (c) 1999 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 | ||
28 | * licensing@OpenSSL.org. | ||
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 | * This product includes cryptographic software written by Eric Young | ||
54 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
55 | * Hudson (tjh@cryptsoft.com). | ||
56 | * | ||
57 | */ | ||
58 | |||
59 | /* Simple PKCS#7 processing functions */ | ||
60 | |||
61 | #include <stdio.h> | ||
62 | #include "cryptlib.h" | ||
63 | #include <openssl/x509.h> | ||
64 | #include <openssl/x509v3.h> | ||
65 | |||
66 | PKCS7 *PKCS7_sign(X509 *signcert, EVP_PKEY *pkey, STACK_OF(X509) *certs, | ||
67 | BIO *data, int flags) | ||
68 | { | ||
69 | PKCS7 *p7; | ||
70 | PKCS7_SIGNER_INFO *si; | ||
71 | BIO *p7bio; | ||
72 | STACK_OF(X509_ALGOR) *smcap; | ||
73 | int i; | ||
74 | |||
75 | if(!X509_check_private_key(signcert, pkey)) { | ||
76 | PKCS7err(PKCS7_F_PKCS7_SIGN,PKCS7_R_PRIVATE_KEY_DOES_NOT_MATCH_CERTIFICATE); | ||
77 | return NULL; | ||
78 | } | ||
79 | |||
80 | if(!(p7 = PKCS7_new())) { | ||
81 | PKCS7err(PKCS7_F_PKCS7_SIGN,ERR_R_MALLOC_FAILURE); | ||
82 | return NULL; | ||
83 | } | ||
84 | |||
85 | PKCS7_set_type(p7, NID_pkcs7_signed); | ||
86 | |||
87 | PKCS7_content_new(p7, NID_pkcs7_data); | ||
88 | |||
89 | if (!(si = PKCS7_add_signature(p7,signcert,pkey,EVP_sha1()))) { | ||
90 | PKCS7err(PKCS7_F_PKCS7_SIGN,PKCS7_R_PKCS7_ADD_SIGNATURE_ERROR); | ||
91 | return NULL; | ||
92 | } | ||
93 | |||
94 | if(!(flags & PKCS7_NOCERTS)) { | ||
95 | PKCS7_add_certificate(p7, signcert); | ||
96 | if(certs) for(i = 0; i < sk_X509_num(certs); i++) | ||
97 | PKCS7_add_certificate(p7, sk_X509_value(certs, i)); | ||
98 | } | ||
99 | |||
100 | if(!(p7bio = PKCS7_dataInit(p7, NULL))) { | ||
101 | PKCS7err(PKCS7_F_PKCS7_SIGN,ERR_R_MALLOC_FAILURE); | ||
102 | return NULL; | ||
103 | } | ||
104 | |||
105 | |||
106 | SMIME_crlf_copy(data, p7bio, flags); | ||
107 | |||
108 | if(!(flags & PKCS7_NOATTR)) { | ||
109 | PKCS7_add_signed_attribute(si, NID_pkcs9_contentType, | ||
110 | V_ASN1_OBJECT, OBJ_nid2obj(NID_pkcs7_data)); | ||
111 | /* Add SMIMECapabilities */ | ||
112 | if(!(flags & PKCS7_NOSMIMECAP)) | ||
113 | { | ||
114 | if(!(smcap = sk_X509_ALGOR_new_null())) { | ||
115 | PKCS7err(PKCS7_F_PKCS7_SIGN,ERR_R_MALLOC_FAILURE); | ||
116 | return NULL; | ||
117 | } | ||
118 | #ifndef NO_DES | ||
119 | PKCS7_simple_smimecap (smcap, NID_des_ede3_cbc, -1); | ||
120 | #endif | ||
121 | #ifndef NO_RC2 | ||
122 | PKCS7_simple_smimecap (smcap, NID_rc2_cbc, 128); | ||
123 | PKCS7_simple_smimecap (smcap, NID_rc2_cbc, 64); | ||
124 | #endif | ||
125 | #ifndef NO_DES | ||
126 | PKCS7_simple_smimecap (smcap, NID_des_cbc, -1); | ||
127 | #endif | ||
128 | #ifndef NO_RC2 | ||
129 | PKCS7_simple_smimecap (smcap, NID_rc2_cbc, 40); | ||
130 | #endif | ||
131 | PKCS7_add_attrib_smimecap (si, smcap); | ||
132 | sk_X509_ALGOR_pop_free(smcap, X509_ALGOR_free); | ||
133 | } | ||
134 | } | ||
135 | |||
136 | if(flags & PKCS7_DETACHED)PKCS7_set_detached(p7, 1); | ||
137 | |||
138 | if (!PKCS7_dataFinal(p7,p7bio)) { | ||
139 | PKCS7err(PKCS7_F_PKCS7_SIGN,PKCS7_R_PKCS7_DATASIGN); | ||
140 | return NULL; | ||
141 | } | ||
142 | |||
143 | BIO_free_all(p7bio); | ||
144 | return p7; | ||
145 | } | ||
146 | |||
147 | int PKCS7_verify(PKCS7 *p7, STACK_OF(X509) *certs, X509_STORE *store, | ||
148 | BIO *indata, BIO *out, int flags) | ||
149 | { | ||
150 | STACK_OF(X509) *signers; | ||
151 | X509 *signer; | ||
152 | STACK_OF(PKCS7_SIGNER_INFO) *sinfos; | ||
153 | PKCS7_SIGNER_INFO *si; | ||
154 | X509_STORE_CTX cert_ctx; | ||
155 | char buf[4096]; | ||
156 | int i, j=0, k, ret = 0; | ||
157 | BIO *p7bio; | ||
158 | BIO *tmpout; | ||
159 | |||
160 | if(!p7) { | ||
161 | PKCS7err(PKCS7_F_PKCS7_VERIFY,PKCS7_R_INVALID_NULL_POINTER); | ||
162 | return 0; | ||
163 | } | ||
164 | |||
165 | if(!PKCS7_type_is_signed(p7)) { | ||
166 | PKCS7err(PKCS7_F_PKCS7_VERIFY,PKCS7_R_WRONG_CONTENT_TYPE); | ||
167 | return 0; | ||
168 | } | ||
169 | |||
170 | /* Check for no data and no content: no data to verify signature */ | ||
171 | if(PKCS7_get_detached(p7) && !indata) { | ||
172 | PKCS7err(PKCS7_F_PKCS7_VERIFY,PKCS7_R_NO_CONTENT); | ||
173 | return 0; | ||
174 | } | ||
175 | #if 0 | ||
176 | /* NB: this test commented out because some versions of Netscape | ||
177 | * illegally include zero length content when signing data. | ||
178 | */ | ||
179 | |||
180 | /* Check for data and content: two sets of data */ | ||
181 | if(!PKCS7_get_detached(p7) && indata) { | ||
182 | PKCS7err(PKCS7_F_PKCS7_VERIFY,PKCS7_R_CONTENT_AND_DATA_PRESENT); | ||
183 | return 0; | ||
184 | } | ||
185 | #endif | ||
186 | |||
187 | sinfos = PKCS7_get_signer_info(p7); | ||
188 | |||
189 | if(!sinfos || !sk_PKCS7_SIGNER_INFO_num(sinfos)) { | ||
190 | PKCS7err(PKCS7_F_PKCS7_VERIFY,PKCS7_R_NO_SIGNATURES_ON_DATA); | ||
191 | return 0; | ||
192 | } | ||
193 | |||
194 | |||
195 | signers = PKCS7_get0_signers(p7, certs, flags); | ||
196 | |||
197 | if(!signers) return 0; | ||
198 | |||
199 | /* Now verify the certificates */ | ||
200 | |||
201 | if (!(flags & PKCS7_NOVERIFY)) for (k = 0; k < sk_X509_num(signers); k++) { | ||
202 | signer = sk_X509_value (signers, k); | ||
203 | if (!(flags & PKCS7_NOCHAIN)) { | ||
204 | X509_STORE_CTX_init(&cert_ctx, store, signer, | ||
205 | p7->d.sign->cert); | ||
206 | X509_STORE_CTX_set_purpose(&cert_ctx, | ||
207 | X509_PURPOSE_SMIME_SIGN); | ||
208 | } else X509_STORE_CTX_init (&cert_ctx, store, signer, NULL); | ||
209 | i = X509_verify_cert(&cert_ctx); | ||
210 | if (i <= 0) j = X509_STORE_CTX_get_error(&cert_ctx); | ||
211 | X509_STORE_CTX_cleanup(&cert_ctx); | ||
212 | if (i <= 0) { | ||
213 | PKCS7err(PKCS7_F_PKCS7_VERIFY,PKCS7_R_CERTIFICATE_VERIFY_ERROR); | ||
214 | ERR_add_error_data(2, "Verify error:", | ||
215 | X509_verify_cert_error_string(j)); | ||
216 | sk_X509_free(signers); | ||
217 | return 0; | ||
218 | } | ||
219 | /* Check for revocation status here */ | ||
220 | } | ||
221 | |||
222 | p7bio=PKCS7_dataInit(p7,indata); | ||
223 | |||
224 | if(flags & PKCS7_TEXT) { | ||
225 | if(!(tmpout = BIO_new(BIO_s_mem()))) { | ||
226 | PKCS7err(PKCS7_F_PKCS7_VERIFY,ERR_R_MALLOC_FAILURE); | ||
227 | goto err; | ||
228 | } | ||
229 | } else tmpout = out; | ||
230 | |||
231 | /* We now have to 'read' from p7bio to calculate digests etc. */ | ||
232 | for (;;) | ||
233 | { | ||
234 | i=BIO_read(p7bio,buf,sizeof(buf)); | ||
235 | if (i <= 0) break; | ||
236 | if (tmpout) BIO_write(tmpout, buf, i); | ||
237 | } | ||
238 | |||
239 | if(flags & PKCS7_TEXT) { | ||
240 | if(!SMIME_text(tmpout, out)) { | ||
241 | PKCS7err(PKCS7_F_PKCS7_VERIFY,PKCS7_R_SMIME_TEXT_ERROR); | ||
242 | BIO_free(tmpout); | ||
243 | goto err; | ||
244 | } | ||
245 | BIO_free(tmpout); | ||
246 | } | ||
247 | |||
248 | /* Now Verify All Signatures */ | ||
249 | if (!(flags & PKCS7_NOSIGS)) | ||
250 | for (i=0; i<sk_PKCS7_SIGNER_INFO_num(sinfos); i++) | ||
251 | { | ||
252 | si=sk_PKCS7_SIGNER_INFO_value(sinfos,i); | ||
253 | signer = sk_X509_value (signers, i); | ||
254 | j=PKCS7_signatureVerify(p7bio,p7,si, signer); | ||
255 | if (j <= 0) { | ||
256 | PKCS7err(PKCS7_F_PKCS7_VERIFY,PKCS7_R_SIGNATURE_FAILURE); | ||
257 | goto err; | ||
258 | } | ||
259 | } | ||
260 | |||
261 | ret = 1; | ||
262 | |||
263 | err: | ||
264 | |||
265 | if(indata) BIO_pop(p7bio); | ||
266 | BIO_free_all(p7bio); | ||
267 | sk_X509_free(signers); | ||
268 | |||
269 | return ret; | ||
270 | } | ||
271 | |||
272 | STACK_OF(X509) *PKCS7_get0_signers(PKCS7 *p7, STACK_OF(X509) *certs, int flags) | ||
273 | { | ||
274 | STACK_OF(X509) *signers; | ||
275 | STACK_OF(PKCS7_SIGNER_INFO) *sinfos; | ||
276 | PKCS7_SIGNER_INFO *si; | ||
277 | PKCS7_ISSUER_AND_SERIAL *ias; | ||
278 | X509 *signer; | ||
279 | int i; | ||
280 | |||
281 | if(!p7) { | ||
282 | PKCS7err(PKCS7_F_PKCS7_GET0_SIGNERS,PKCS7_R_INVALID_NULL_POINTER); | ||
283 | return NULL; | ||
284 | } | ||
285 | |||
286 | if(!PKCS7_type_is_signed(p7)) { | ||
287 | PKCS7err(PKCS7_F_PKCS7_GET0_SIGNERS,PKCS7_R_WRONG_CONTENT_TYPE); | ||
288 | return NULL; | ||
289 | } | ||
290 | if(!(signers = sk_X509_new_null())) { | ||
291 | PKCS7err(PKCS7_F_PKCS7_GET0_SIGNERS,ERR_R_MALLOC_FAILURE); | ||
292 | return NULL; | ||
293 | } | ||
294 | |||
295 | /* Collect all the signers together */ | ||
296 | |||
297 | sinfos = PKCS7_get_signer_info(p7); | ||
298 | |||
299 | if(sk_PKCS7_SIGNER_INFO_num(sinfos) <= 0) { | ||
300 | PKCS7err(PKCS7_F_PKCS7_GET0_SIGNERS,PKCS7_R_NO_SIGNERS); | ||
301 | return 0; | ||
302 | } | ||
303 | |||
304 | for (i = 0; i < sk_PKCS7_SIGNER_INFO_num(sinfos); i++) | ||
305 | { | ||
306 | si = sk_PKCS7_SIGNER_INFO_value(sinfos, i); | ||
307 | ias = si->issuer_and_serial; | ||
308 | signer = NULL; | ||
309 | /* If any certificates passed they take priority */ | ||
310 | if (certs) signer = X509_find_by_issuer_and_serial (certs, | ||
311 | ias->issuer, ias->serial); | ||
312 | if (!signer && !(flags & PKCS7_NOINTERN) | ||
313 | && p7->d.sign->cert) signer = | ||
314 | X509_find_by_issuer_and_serial (p7->d.sign->cert, | ||
315 | ias->issuer, ias->serial); | ||
316 | if (!signer) { | ||
317 | PKCS7err(PKCS7_F_PKCS7_GET0_SIGNERS,PKCS7_R_SIGNER_CERTIFICATE_NOT_FOUND); | ||
318 | sk_X509_free(signers); | ||
319 | return 0; | ||
320 | } | ||
321 | |||
322 | sk_X509_push(signers, signer); | ||
323 | } | ||
324 | return signers; | ||
325 | } | ||
326 | |||
327 | |||
328 | /* Build a complete PKCS#7 enveloped data */ | ||
329 | |||
330 | PKCS7 *PKCS7_encrypt(STACK_OF(X509) *certs, BIO *in, EVP_CIPHER *cipher, | ||
331 | int flags) | ||
332 | { | ||
333 | PKCS7 *p7; | ||
334 | BIO *p7bio = NULL; | ||
335 | int i; | ||
336 | X509 *x509; | ||
337 | if(!(p7 = PKCS7_new())) { | ||
338 | PKCS7err(PKCS7_F_PKCS7_ENCRYPT,ERR_R_MALLOC_FAILURE); | ||
339 | return NULL; | ||
340 | } | ||
341 | |||
342 | PKCS7_set_type(p7, NID_pkcs7_enveloped); | ||
343 | if(!PKCS7_set_cipher(p7, cipher)) { | ||
344 | PKCS7err(PKCS7_F_PKCS7_ENCRYPT,PKCS7_R_ERROR_SETTING_CIPHER); | ||
345 | goto err; | ||
346 | } | ||
347 | |||
348 | for(i = 0; i < sk_X509_num(certs); i++) { | ||
349 | x509 = sk_X509_value(certs, i); | ||
350 | if(!PKCS7_add_recipient(p7, x509)) { | ||
351 | PKCS7err(PKCS7_F_PKCS7_ENCRYPT, | ||
352 | PKCS7_R_ERROR_ADDING_RECIPIENT); | ||
353 | goto err; | ||
354 | } | ||
355 | } | ||
356 | |||
357 | if(!(p7bio = PKCS7_dataInit(p7, NULL))) { | ||
358 | PKCS7err(PKCS7_F_PKCS7_ENCRYPT,ERR_R_MALLOC_FAILURE); | ||
359 | goto err; | ||
360 | } | ||
361 | |||
362 | SMIME_crlf_copy(in, p7bio, flags); | ||
363 | |||
364 | BIO_flush(p7bio); | ||
365 | |||
366 | if (!PKCS7_dataFinal(p7,p7bio)) { | ||
367 | PKCS7err(PKCS7_F_PKCS7_ENCRYPT,PKCS7_R_PKCS7_DATAFINAL_ERROR); | ||
368 | goto err; | ||
369 | } | ||
370 | BIO_free_all(p7bio); | ||
371 | |||
372 | return p7; | ||
373 | |||
374 | err: | ||
375 | |||
376 | BIO_free(p7bio); | ||
377 | PKCS7_free(p7); | ||
378 | return NULL; | ||
379 | |||
380 | } | ||
381 | |||
382 | int PKCS7_decrypt(PKCS7 *p7, EVP_PKEY *pkey, X509 *cert, BIO *data, int flags) | ||
383 | { | ||
384 | BIO *tmpmem; | ||
385 | int ret, i; | ||
386 | char buf[4096]; | ||
387 | |||
388 | if(!p7) { | ||
389 | PKCS7err(PKCS7_F_PKCS7_DECRYPT,PKCS7_R_INVALID_NULL_POINTER); | ||
390 | return 0; | ||
391 | } | ||
392 | |||
393 | if(!PKCS7_type_is_enveloped(p7)) { | ||
394 | PKCS7err(PKCS7_F_PKCS7_DECRYPT,PKCS7_R_WRONG_CONTENT_TYPE); | ||
395 | return 0; | ||
396 | } | ||
397 | |||
398 | if(!X509_check_private_key(cert, pkey)) { | ||
399 | PKCS7err(PKCS7_F_PKCS7_DECRYPT, | ||
400 | PKCS7_R_PRIVATE_KEY_DOES_NOT_MATCH_CERTIFICATE); | ||
401 | return 0; | ||
402 | } | ||
403 | |||
404 | if(!(tmpmem = PKCS7_dataDecode(p7, pkey, NULL, cert))) { | ||
405 | PKCS7err(PKCS7_F_PKCS7_DECRYPT, PKCS7_R_DECRYPT_ERROR); | ||
406 | return 0; | ||
407 | } | ||
408 | |||
409 | if (flags & PKCS7_TEXT) { | ||
410 | BIO *tmpbuf, *bread; | ||
411 | /* Encrypt BIOs can't do BIO_gets() so add a buffer BIO */ | ||
412 | if(!(tmpbuf = BIO_new(BIO_f_buffer()))) { | ||
413 | PKCS7err(PKCS7_F_PKCS7_DECRYPT, ERR_R_MALLOC_FAILURE); | ||
414 | return 0; | ||
415 | } | ||
416 | if(!(bread = BIO_push(tmpbuf, tmpmem))) { | ||
417 | PKCS7err(PKCS7_F_PKCS7_DECRYPT, ERR_R_MALLOC_FAILURE); | ||
418 | return 0; | ||
419 | } | ||
420 | ret = SMIME_text(bread, data); | ||
421 | BIO_free_all(bread); | ||
422 | return ret; | ||
423 | } else { | ||
424 | for(;;) { | ||
425 | i = BIO_read(tmpmem, buf, sizeof(buf)); | ||
426 | if(i <= 0) break; | ||
427 | BIO_write(data, buf, i); | ||
428 | } | ||
429 | BIO_free_all(tmpmem); | ||
430 | return 1; | ||
431 | } | ||
432 | } | ||
diff --git a/src/lib/libcrypto/pkcs7/pkcs7.h b/src/lib/libcrypto/pkcs7/pkcs7.h deleted file mode 100644 index 1b817e605d..0000000000 --- a/src/lib/libcrypto/pkcs7/pkcs7.h +++ /dev/null | |||
@@ -1,505 +0,0 @@ | |||
1 | /* crypto/pkcs7/pkcs7.h */ | ||
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
3 | * All rights reserved. | ||
4 | * | ||
5 | * This package is an SSL implementation written | ||
6 | * by Eric Young (eay@cryptsoft.com). | ||
7 | * The implementation was written so as to conform with Netscapes SSL. | ||
8 | * | ||
9 | * This library is free for commercial and non-commercial use as long as | ||
10 | * the following conditions are aheared to. The following conditions | ||
11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
13 | * included with this distribution is covered by the same copyright terms | ||
14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
15 | * | ||
16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
17 | * the code are not to be removed. | ||
18 | * If this package is used in a product, Eric Young should be given attribution | ||
19 | * as the author of the parts of the library used. | ||
20 | * This can be in the form of a textual message at program startup or | ||
21 | * in documentation (online or textual) provided with the package. | ||
22 | * | ||
23 | * Redistribution and use in source and binary forms, with or without | ||
24 | * modification, are permitted provided that the following conditions | ||
25 | * are met: | ||
26 | * 1. Redistributions of source code must retain the copyright | ||
27 | * notice, this list of conditions and the following disclaimer. | ||
28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
29 | * notice, this list of conditions and the following disclaimer in the | ||
30 | * documentation and/or other materials provided with the distribution. | ||
31 | * 3. All advertising materials mentioning features or use of this software | ||
32 | * must display the following acknowledgement: | ||
33 | * "This product includes cryptographic software written by | ||
34 | * Eric Young (eay@cryptsoft.com)" | ||
35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
36 | * being used are not cryptographic related :-). | ||
37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
38 | * the apps directory (application code) you must include an acknowledgement: | ||
39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
40 | * | ||
41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
51 | * SUCH DAMAGE. | ||
52 | * | ||
53 | * The licence and distribution terms for any publically available version or | ||
54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
55 | * copied and put under another distribution licence | ||
56 | * [including the GNU Public Licence.] | ||
57 | */ | ||
58 | |||
59 | #ifndef HEADER_PKCS7_H | ||
60 | #define HEADER_PKCS7_H | ||
61 | |||
62 | #include <openssl/bio.h> | ||
63 | #include <openssl/x509.h> | ||
64 | |||
65 | #include <openssl/symhacks.h> | ||
66 | |||
67 | #ifdef __cplusplus | ||
68 | extern "C" { | ||
69 | #endif | ||
70 | |||
71 | #ifdef WIN32 | ||
72 | /* Under Win32 thes are defined in wincrypt.h */ | ||
73 | #undef PKCS7_ISSUER_AND_SERIAL | ||
74 | #undef PKCS7_SIGNER_INFO | ||
75 | #endif | ||
76 | |||
77 | /* | ||
78 | Encryption_ID DES-CBC | ||
79 | Digest_ID MD5 | ||
80 | Digest_Encryption_ID rsaEncryption | ||
81 | Key_Encryption_ID rsaEncryption | ||
82 | */ | ||
83 | |||
84 | typedef struct pkcs7_issuer_and_serial_st | ||
85 | { | ||
86 | X509_NAME *issuer; | ||
87 | ASN1_INTEGER *serial; | ||
88 | } PKCS7_ISSUER_AND_SERIAL; | ||
89 | |||
90 | typedef struct pkcs7_signer_info_st | ||
91 | { | ||
92 | ASN1_INTEGER *version; /* version 1 */ | ||
93 | PKCS7_ISSUER_AND_SERIAL *issuer_and_serial; | ||
94 | X509_ALGOR *digest_alg; | ||
95 | STACK_OF(X509_ATTRIBUTE) *auth_attr; /* [ 0 ] */ | ||
96 | X509_ALGOR *digest_enc_alg; | ||
97 | ASN1_OCTET_STRING *enc_digest; | ||
98 | STACK_OF(X509_ATTRIBUTE) *unauth_attr; /* [ 1 ] */ | ||
99 | |||
100 | /* The private key to sign with */ | ||
101 | EVP_PKEY *pkey; | ||
102 | } PKCS7_SIGNER_INFO; | ||
103 | |||
104 | DECLARE_STACK_OF(PKCS7_SIGNER_INFO) | ||
105 | DECLARE_ASN1_SET_OF(PKCS7_SIGNER_INFO) | ||
106 | |||
107 | typedef struct pkcs7_recip_info_st | ||
108 | { | ||
109 | ASN1_INTEGER *version; /* version 0 */ | ||
110 | PKCS7_ISSUER_AND_SERIAL *issuer_and_serial; | ||
111 | X509_ALGOR *key_enc_algor; | ||
112 | ASN1_OCTET_STRING *enc_key; | ||
113 | X509 *cert; /* get the pub-key from this */ | ||
114 | } PKCS7_RECIP_INFO; | ||
115 | |||
116 | DECLARE_STACK_OF(PKCS7_RECIP_INFO) | ||
117 | DECLARE_ASN1_SET_OF(PKCS7_RECIP_INFO) | ||
118 | |||
119 | typedef struct pkcs7_signed_st | ||
120 | { | ||
121 | ASN1_INTEGER *version; /* version 1 */ | ||
122 | STACK_OF(X509_ALGOR) *md_algs; /* md used */ | ||
123 | STACK_OF(X509) *cert; /* [ 0 ] */ | ||
124 | STACK_OF(X509_CRL) *crl; /* [ 1 ] */ | ||
125 | STACK_OF(PKCS7_SIGNER_INFO) *signer_info; | ||
126 | |||
127 | struct pkcs7_st *contents; | ||
128 | } PKCS7_SIGNED; | ||
129 | /* The above structure is very very similar to PKCS7_SIGN_ENVELOPE. | ||
130 | * How about merging the two */ | ||
131 | |||
132 | typedef struct pkcs7_enc_content_st | ||
133 | { | ||
134 | ASN1_OBJECT *content_type; | ||
135 | X509_ALGOR *algorithm; | ||
136 | ASN1_OCTET_STRING *enc_data; /* [ 0 ] */ | ||
137 | const EVP_CIPHER *cipher; | ||
138 | } PKCS7_ENC_CONTENT; | ||
139 | |||
140 | typedef struct pkcs7_enveloped_st | ||
141 | { | ||
142 | ASN1_INTEGER *version; /* version 0 */ | ||
143 | STACK_OF(PKCS7_RECIP_INFO) *recipientinfo; | ||
144 | PKCS7_ENC_CONTENT *enc_data; | ||
145 | } PKCS7_ENVELOPE; | ||
146 | |||
147 | typedef struct pkcs7_signedandenveloped_st | ||
148 | { | ||
149 | ASN1_INTEGER *version; /* version 1 */ | ||
150 | STACK_OF(X509_ALGOR) *md_algs; /* md used */ | ||
151 | STACK_OF(X509) *cert; /* [ 0 ] */ | ||
152 | STACK_OF(X509_CRL) *crl; /* [ 1 ] */ | ||
153 | STACK_OF(PKCS7_SIGNER_INFO) *signer_info; | ||
154 | |||
155 | PKCS7_ENC_CONTENT *enc_data; | ||
156 | STACK_OF(PKCS7_RECIP_INFO) *recipientinfo; | ||
157 | } PKCS7_SIGN_ENVELOPE; | ||
158 | |||
159 | typedef struct pkcs7_digest_st | ||
160 | { | ||
161 | ASN1_INTEGER *version; /* version 0 */ | ||
162 | X509_ALGOR *md; /* md used */ | ||
163 | struct pkcs7_st *contents; | ||
164 | ASN1_OCTET_STRING *digest; | ||
165 | } PKCS7_DIGEST; | ||
166 | |||
167 | typedef struct pkcs7_encrypted_st | ||
168 | { | ||
169 | ASN1_INTEGER *version; /* version 0 */ | ||
170 | PKCS7_ENC_CONTENT *enc_data; | ||
171 | } PKCS7_ENCRYPT; | ||
172 | |||
173 | typedef struct pkcs7_st | ||
174 | { | ||
175 | /* The following is non NULL if it contains ASN1 encoding of | ||
176 | * this structure */ | ||
177 | unsigned char *asn1; | ||
178 | long length; | ||
179 | |||
180 | #define PKCS7_S_HEADER 0 | ||
181 | #define PKCS7_S_BODY 1 | ||
182 | #define PKCS7_S_TAIL 2 | ||
183 | int state; /* used during processing */ | ||
184 | |||
185 | int detached; | ||
186 | |||
187 | ASN1_OBJECT *type; | ||
188 | /* content as defined by the type */ | ||
189 | /* all encryption/message digests are applied to the 'contents', | ||
190 | * leaving out the 'type' field. */ | ||
191 | union { | ||
192 | char *ptr; | ||
193 | |||
194 | /* NID_pkcs7_data */ | ||
195 | ASN1_OCTET_STRING *data; | ||
196 | |||
197 | /* NID_pkcs7_signed */ | ||
198 | PKCS7_SIGNED *sign; | ||
199 | |||
200 | /* NID_pkcs7_enveloped */ | ||
201 | PKCS7_ENVELOPE *enveloped; | ||
202 | |||
203 | /* NID_pkcs7_signedAndEnveloped */ | ||
204 | PKCS7_SIGN_ENVELOPE *signed_and_enveloped; | ||
205 | |||
206 | /* NID_pkcs7_digest */ | ||
207 | PKCS7_DIGEST *digest; | ||
208 | |||
209 | /* NID_pkcs7_encrypted */ | ||
210 | PKCS7_ENCRYPT *encrypted; | ||
211 | |||
212 | /* Anything else */ | ||
213 | ASN1_TYPE *other; | ||
214 | } d; | ||
215 | } PKCS7; | ||
216 | |||
217 | DECLARE_STACK_OF(PKCS7) | ||
218 | DECLARE_ASN1_SET_OF(PKCS7) | ||
219 | DECLARE_PKCS12_STACK_OF(PKCS7) | ||
220 | |||
221 | #define PKCS7_OP_SET_DETACHED_SIGNATURE 1 | ||
222 | #define PKCS7_OP_GET_DETACHED_SIGNATURE 2 | ||
223 | |||
224 | #define PKCS7_get_signed_attributes(si) ((si)->auth_attr) | ||
225 | #define PKCS7_get_attributes(si) ((si)->unauth_attr) | ||
226 | |||
227 | #define PKCS7_type_is_signed(a) (OBJ_obj2nid((a)->type) == NID_pkcs7_signed) | ||
228 | #define PKCS7_type_is_enveloped(a) (OBJ_obj2nid((a)->type) == NID_pkcs7_enveloped) | ||
229 | #define PKCS7_type_is_signedAndEnveloped(a) \ | ||
230 | (OBJ_obj2nid((a)->type) == NID_pkcs7_signedAndEnveloped) | ||
231 | #define PKCS7_type_is_data(a) (OBJ_obj2nid((a)->type) == NID_pkcs7_data) | ||
232 | |||
233 | #define PKCS7_set_detached(p,v) \ | ||
234 | PKCS7_ctrl(p,PKCS7_OP_SET_DETACHED_SIGNATURE,v,NULL) | ||
235 | #define PKCS7_get_detached(p) \ | ||
236 | PKCS7_ctrl(p,PKCS7_OP_GET_DETACHED_SIGNATURE,0,NULL) | ||
237 | |||
238 | #ifdef SSLEAY_MACROS | ||
239 | #ifndef PKCS7_ISSUER_AND_SERIAL_digest | ||
240 | #define PKCS7_ISSUER_AND_SERIAL_digest(data,type,md,len) \ | ||
241 | ASN1_digest((int (*)())i2d_PKCS7_ISSUER_AND_SERIAL,type,\ | ||
242 | (char *)data,md,len) | ||
243 | #endif | ||
244 | #endif | ||
245 | |||
246 | /* S/MIME related flags */ | ||
247 | |||
248 | #define PKCS7_TEXT 0x1 | ||
249 | #define PKCS7_NOCERTS 0x2 | ||
250 | #define PKCS7_NOSIGS 0x4 | ||
251 | #define PKCS7_NOCHAIN 0x8 | ||
252 | #define PKCS7_NOINTERN 0x10 | ||
253 | #define PKCS7_NOVERIFY 0x20 | ||
254 | #define PKCS7_DETACHED 0x40 | ||
255 | #define PKCS7_BINARY 0x80 | ||
256 | #define PKCS7_NOATTR 0x100 | ||
257 | #define PKCS7_NOSMIMECAP 0x200 | ||
258 | |||
259 | /* Flags: for compatibility with older code */ | ||
260 | |||
261 | #define SMIME_TEXT PKCS7_TEXT | ||
262 | #define SMIME_NOCERTS PKCS7_NOCERTS | ||
263 | #define SMIME_NOSIGS PKCS7_NOSIGS | ||
264 | #define SMIME_NOCHAIN PKCS7_NOCHAIN | ||
265 | #define SMIME_NOINTERN PKCS7_NOINTERN | ||
266 | #define SMIME_NOVERIFY PKCS7_NOVERIFY | ||
267 | #define SMIME_DETACHED PKCS7_DETACHED | ||
268 | #define SMIME_BINARY PKCS7_BINARY | ||
269 | #define SMIME_NOATTR PKCS7_NOATTR | ||
270 | |||
271 | PKCS7_ISSUER_AND_SERIAL *PKCS7_ISSUER_AND_SERIAL_new(void ); | ||
272 | void PKCS7_ISSUER_AND_SERIAL_free( | ||
273 | PKCS7_ISSUER_AND_SERIAL *a); | ||
274 | int i2d_PKCS7_ISSUER_AND_SERIAL( | ||
275 | PKCS7_ISSUER_AND_SERIAL *a,unsigned char **pp); | ||
276 | PKCS7_ISSUER_AND_SERIAL *d2i_PKCS7_ISSUER_AND_SERIAL( | ||
277 | PKCS7_ISSUER_AND_SERIAL **a, | ||
278 | unsigned char **pp, long length); | ||
279 | |||
280 | #ifndef SSLEAY_MACROS | ||
281 | int PKCS7_ISSUER_AND_SERIAL_digest(PKCS7_ISSUER_AND_SERIAL *data,const EVP_MD *type, | ||
282 | unsigned char *md,unsigned int *len); | ||
283 | #ifndef NO_FP_API | ||
284 | PKCS7 *d2i_PKCS7_fp(FILE *fp,PKCS7 **p7); | ||
285 | int i2d_PKCS7_fp(FILE *fp,PKCS7 *p7); | ||
286 | #endif | ||
287 | PKCS7 *PKCS7_dup(PKCS7 *p7); | ||
288 | PKCS7 *d2i_PKCS7_bio(BIO *bp,PKCS7 **p7); | ||
289 | int i2d_PKCS7_bio(BIO *bp,PKCS7 *p7); | ||
290 | #endif | ||
291 | |||
292 | PKCS7_SIGNER_INFO *PKCS7_SIGNER_INFO_new(void); | ||
293 | void PKCS7_SIGNER_INFO_free(PKCS7_SIGNER_INFO *a); | ||
294 | int i2d_PKCS7_SIGNER_INFO(PKCS7_SIGNER_INFO *a, | ||
295 | unsigned char **pp); | ||
296 | PKCS7_SIGNER_INFO *d2i_PKCS7_SIGNER_INFO(PKCS7_SIGNER_INFO **a, | ||
297 | unsigned char **pp,long length); | ||
298 | |||
299 | PKCS7_RECIP_INFO *PKCS7_RECIP_INFO_new(void); | ||
300 | void PKCS7_RECIP_INFO_free(PKCS7_RECIP_INFO *a); | ||
301 | int i2d_PKCS7_RECIP_INFO(PKCS7_RECIP_INFO *a, | ||
302 | unsigned char **pp); | ||
303 | PKCS7_RECIP_INFO *d2i_PKCS7_RECIP_INFO(PKCS7_RECIP_INFO **a, | ||
304 | unsigned char **pp,long length); | ||
305 | |||
306 | PKCS7_SIGNED *PKCS7_SIGNED_new(void); | ||
307 | void PKCS7_SIGNED_free(PKCS7_SIGNED *a); | ||
308 | int i2d_PKCS7_SIGNED(PKCS7_SIGNED *a, | ||
309 | unsigned char **pp); | ||
310 | PKCS7_SIGNED *d2i_PKCS7_SIGNED(PKCS7_SIGNED **a, | ||
311 | unsigned char **pp,long length); | ||
312 | |||
313 | PKCS7_ENC_CONTENT *PKCS7_ENC_CONTENT_new(void); | ||
314 | void PKCS7_ENC_CONTENT_free(PKCS7_ENC_CONTENT *a); | ||
315 | int i2d_PKCS7_ENC_CONTENT(PKCS7_ENC_CONTENT *a, | ||
316 | unsigned char **pp); | ||
317 | PKCS7_ENC_CONTENT *d2i_PKCS7_ENC_CONTENT(PKCS7_ENC_CONTENT **a, | ||
318 | unsigned char **pp,long length); | ||
319 | |||
320 | PKCS7_ENVELOPE *PKCS7_ENVELOPE_new(void); | ||
321 | void PKCS7_ENVELOPE_free(PKCS7_ENVELOPE *a); | ||
322 | int i2d_PKCS7_ENVELOPE(PKCS7_ENVELOPE *a, | ||
323 | unsigned char **pp); | ||
324 | PKCS7_ENVELOPE *d2i_PKCS7_ENVELOPE(PKCS7_ENVELOPE **a, | ||
325 | unsigned char **pp,long length); | ||
326 | |||
327 | PKCS7_SIGN_ENVELOPE *PKCS7_SIGN_ENVELOPE_new(void); | ||
328 | void PKCS7_SIGN_ENVELOPE_free(PKCS7_SIGN_ENVELOPE *a); | ||
329 | int i2d_PKCS7_SIGN_ENVELOPE(PKCS7_SIGN_ENVELOPE *a, | ||
330 | unsigned char **pp); | ||
331 | PKCS7_SIGN_ENVELOPE *d2i_PKCS7_SIGN_ENVELOPE(PKCS7_SIGN_ENVELOPE **a, | ||
332 | unsigned char **pp,long length); | ||
333 | |||
334 | PKCS7_DIGEST *PKCS7_DIGEST_new(void); | ||
335 | void PKCS7_DIGEST_free(PKCS7_DIGEST *a); | ||
336 | int i2d_PKCS7_DIGEST(PKCS7_DIGEST *a, | ||
337 | unsigned char **pp); | ||
338 | PKCS7_DIGEST *d2i_PKCS7_DIGEST(PKCS7_DIGEST **a, | ||
339 | unsigned char **pp,long length); | ||
340 | |||
341 | PKCS7_ENCRYPT *PKCS7_ENCRYPT_new(void); | ||
342 | void PKCS7_ENCRYPT_free(PKCS7_ENCRYPT *a); | ||
343 | int i2d_PKCS7_ENCRYPT(PKCS7_ENCRYPT *a, | ||
344 | unsigned char **pp); | ||
345 | PKCS7_ENCRYPT *d2i_PKCS7_ENCRYPT(PKCS7_ENCRYPT **a, | ||
346 | unsigned char **pp,long length); | ||
347 | |||
348 | PKCS7 *PKCS7_new(void); | ||
349 | void PKCS7_free(PKCS7 *a); | ||
350 | void PKCS7_content_free(PKCS7 *a); | ||
351 | int i2d_PKCS7(PKCS7 *a, | ||
352 | unsigned char **pp); | ||
353 | PKCS7 *d2i_PKCS7(PKCS7 **a, | ||
354 | unsigned char **pp,long length); | ||
355 | |||
356 | void ERR_load_PKCS7_strings(void); | ||
357 | |||
358 | |||
359 | long PKCS7_ctrl(PKCS7 *p7, int cmd, long larg, char *parg); | ||
360 | |||
361 | int PKCS7_set_type(PKCS7 *p7, int type); | ||
362 | int PKCS7_set_content(PKCS7 *p7, PKCS7 *p7_data); | ||
363 | int PKCS7_SIGNER_INFO_set(PKCS7_SIGNER_INFO *p7i, X509 *x509, EVP_PKEY *pkey, | ||
364 | EVP_MD *dgst); | ||
365 | int PKCS7_add_signer(PKCS7 *p7, PKCS7_SIGNER_INFO *p7i); | ||
366 | int PKCS7_add_certificate(PKCS7 *p7, X509 *x509); | ||
367 | int PKCS7_add_crl(PKCS7 *p7, X509_CRL *x509); | ||
368 | int PKCS7_content_new(PKCS7 *p7, int nid); | ||
369 | int PKCS7_dataVerify(X509_STORE *cert_store, X509_STORE_CTX *ctx, | ||
370 | BIO *bio, PKCS7 *p7, PKCS7_SIGNER_INFO *si); | ||
371 | int PKCS7_signatureVerify(BIO *bio, PKCS7 *p7, PKCS7_SIGNER_INFO *si, | ||
372 | X509 *x509); | ||
373 | |||
374 | BIO *PKCS7_dataInit(PKCS7 *p7, BIO *bio); | ||
375 | int PKCS7_dataFinal(PKCS7 *p7, BIO *bio); | ||
376 | BIO *PKCS7_dataDecode(PKCS7 *p7, EVP_PKEY *pkey, BIO *in_bio, X509 *pcert); | ||
377 | |||
378 | |||
379 | PKCS7_SIGNER_INFO *PKCS7_add_signature(PKCS7 *p7, X509 *x509, | ||
380 | EVP_PKEY *pkey, EVP_MD *dgst); | ||
381 | X509 *PKCS7_cert_from_signer_info(PKCS7 *p7, PKCS7_SIGNER_INFO *si); | ||
382 | STACK_OF(PKCS7_SIGNER_INFO) *PKCS7_get_signer_info(PKCS7 *p7); | ||
383 | |||
384 | PKCS7_RECIP_INFO *PKCS7_add_recipient(PKCS7 *p7, X509 *x509); | ||
385 | int PKCS7_add_recipient_info(PKCS7 *p7, PKCS7_RECIP_INFO *ri); | ||
386 | int PKCS7_RECIP_INFO_set(PKCS7_RECIP_INFO *p7i, X509 *x509); | ||
387 | int PKCS7_set_cipher(PKCS7 *p7, const EVP_CIPHER *cipher); | ||
388 | |||
389 | PKCS7_ISSUER_AND_SERIAL *PKCS7_get_issuer_and_serial(PKCS7 *p7, int idx); | ||
390 | ASN1_OCTET_STRING *PKCS7_digest_from_attributes(STACK_OF(X509_ATTRIBUTE) *sk); | ||
391 | int PKCS7_add_signed_attribute(PKCS7_SIGNER_INFO *p7si,int nid,int type, | ||
392 | void *data); | ||
393 | int PKCS7_add_attribute (PKCS7_SIGNER_INFO *p7si, int nid, int atrtype, | ||
394 | void *value); | ||
395 | ASN1_TYPE *PKCS7_get_attribute(PKCS7_SIGNER_INFO *si, int nid); | ||
396 | ASN1_TYPE *PKCS7_get_signed_attribute(PKCS7_SIGNER_INFO *si, int nid); | ||
397 | int PKCS7_set_signed_attributes(PKCS7_SIGNER_INFO *p7si, | ||
398 | STACK_OF(X509_ATTRIBUTE) *sk); | ||
399 | int PKCS7_set_attributes(PKCS7_SIGNER_INFO *p7si,STACK_OF(X509_ATTRIBUTE) *sk); | ||
400 | |||
401 | |||
402 | PKCS7 *PKCS7_sign(X509 *signcert, EVP_PKEY *pkey, STACK_OF(X509) *certs, | ||
403 | BIO *data, int flags); | ||
404 | int PKCS7_verify(PKCS7 *p7, STACK_OF(X509) *certs, X509_STORE *store, | ||
405 | BIO *indata, BIO *out, int flags); | ||
406 | STACK_OF(X509) *PKCS7_get0_signers(PKCS7 *p7, STACK_OF(X509) *certs, int flags); | ||
407 | PKCS7 *PKCS7_encrypt(STACK_OF(X509) *certs, BIO *in, EVP_CIPHER *cipher, | ||
408 | int flags); | ||
409 | int PKCS7_decrypt(PKCS7 *p7, EVP_PKEY *pkey, X509 *cert, BIO *data, int flags); | ||
410 | |||
411 | int PKCS7_add_attrib_smimecap(PKCS7_SIGNER_INFO *si, | ||
412 | STACK_OF(X509_ALGOR) *cap); | ||
413 | STACK_OF(X509_ALGOR) *PKCS7_get_smimecap(PKCS7_SIGNER_INFO *si); | ||
414 | int PKCS7_simple_smimecap(STACK_OF(X509_ALGOR) *sk, int nid, int arg); | ||
415 | |||
416 | int SMIME_write_PKCS7(BIO *bio, PKCS7 *p7, BIO *data, int flags); | ||
417 | PKCS7 *SMIME_read_PKCS7(BIO *bio, BIO **bcont); | ||
418 | int SMIME_crlf_copy(BIO *in, BIO *out, int flags); | ||
419 | int SMIME_text(BIO *in, BIO *out); | ||
420 | |||
421 | /* BEGIN ERROR CODES */ | ||
422 | /* The following lines are auto generated by the script mkerr.pl. Any changes | ||
423 | * made after this point may be overwritten when the script is next run. | ||
424 | */ | ||
425 | |||
426 | /* Error codes for the PKCS7 functions. */ | ||
427 | |||
428 | /* Function codes. */ | ||
429 | #define PKCS7_F_B64_READ_PKCS7 120 | ||
430 | #define PKCS7_F_B64_WRITE_PKCS7 121 | ||
431 | #define PKCS7_F_PKCS7_ADD_ATTRIB_SMIMECAP 118 | ||
432 | #define PKCS7_F_PKCS7_ADD_CERTIFICATE 100 | ||
433 | #define PKCS7_F_PKCS7_ADD_CRL 101 | ||
434 | #define PKCS7_F_PKCS7_ADD_RECIPIENT_INFO 102 | ||
435 | #define PKCS7_F_PKCS7_ADD_SIGNER 103 | ||
436 | #define PKCS7_F_PKCS7_CTRL 104 | ||
437 | #define PKCS7_F_PKCS7_DATADECODE 112 | ||
438 | #define PKCS7_F_PKCS7_DATAINIT 105 | ||
439 | #define PKCS7_F_PKCS7_DATASIGN 106 | ||
440 | #define PKCS7_F_PKCS7_DATAVERIFY 107 | ||
441 | #define PKCS7_F_PKCS7_DECRYPT 114 | ||
442 | #define PKCS7_F_PKCS7_ENCRYPT 115 | ||
443 | #define PKCS7_F_PKCS7_GET0_SIGNERS 124 | ||
444 | #define PKCS7_F_PKCS7_SET_CIPHER 108 | ||
445 | #define PKCS7_F_PKCS7_SET_CONTENT 109 | ||
446 | #define PKCS7_F_PKCS7_SET_TYPE 110 | ||
447 | #define PKCS7_F_PKCS7_SIGN 116 | ||
448 | #define PKCS7_F_PKCS7_SIGNATUREVERIFY 113 | ||
449 | #define PKCS7_F_PKCS7_SIMPLE_SMIMECAP 119 | ||
450 | #define PKCS7_F_PKCS7_VERIFY 117 | ||
451 | #define PKCS7_F_SMIME_READ_PKCS7 122 | ||
452 | #define PKCS7_F_SMIME_TEXT 123 | ||
453 | |||
454 | /* Reason codes. */ | ||
455 | #define PKCS7_R_CERTIFICATE_VERIFY_ERROR 117 | ||
456 | #define PKCS7_R_CIPHER_HAS_NO_OBJECT_IDENTIFIER 144 | ||
457 | #define PKCS7_R_CIPHER_NOT_INITIALIZED 116 | ||
458 | #define PKCS7_R_CONTENT_AND_DATA_PRESENT 118 | ||
459 | #define PKCS7_R_DECODE_ERROR 130 | ||
460 | #define PKCS7_R_DECRYPTED_KEY_IS_WRONG_LENGTH 100 | ||
461 | #define PKCS7_R_DECRYPT_ERROR 119 | ||
462 | #define PKCS7_R_DIGEST_FAILURE 101 | ||
463 | #define PKCS7_R_ERROR_ADDING_RECIPIENT 120 | ||
464 | #define PKCS7_R_ERROR_SETTING_CIPHER 121 | ||
465 | #define PKCS7_R_INTERNAL_ERROR 102 | ||
466 | #define PKCS7_R_INVALID_MIME_TYPE 131 | ||
467 | #define PKCS7_R_INVALID_NULL_POINTER 143 | ||
468 | #define PKCS7_R_MIME_NO_CONTENT_TYPE 132 | ||
469 | #define PKCS7_R_MIME_PARSE_ERROR 133 | ||
470 | #define PKCS7_R_MIME_SIG_PARSE_ERROR 134 | ||
471 | #define PKCS7_R_MISSING_CERIPEND_INFO 103 | ||
472 | #define PKCS7_R_NO_CONTENT 122 | ||
473 | #define PKCS7_R_NO_CONTENT_TYPE 135 | ||
474 | #define PKCS7_R_NO_MULTIPART_BODY_FAILURE 136 | ||
475 | #define PKCS7_R_NO_MULTIPART_BOUNDARY 137 | ||
476 | #define PKCS7_R_NO_RECIPIENT_MATCHES_CERTIFICATE 115 | ||
477 | #define PKCS7_R_NO_SIGNATURES_ON_DATA 123 | ||
478 | #define PKCS7_R_NO_SIGNERS 142 | ||
479 | #define PKCS7_R_NO_SIG_CONTENT_TYPE 138 | ||
480 | #define PKCS7_R_OPERATION_NOT_SUPPORTED_ON_THIS_TYPE 104 | ||
481 | #define PKCS7_R_PKCS7_ADD_SIGNATURE_ERROR 124 | ||
482 | #define PKCS7_R_PKCS7_DATAFINAL_ERROR 125 | ||
483 | #define PKCS7_R_PKCS7_DATASIGN 126 | ||
484 | #define PKCS7_R_PKCS7_PARSE_ERROR 139 | ||
485 | #define PKCS7_R_PKCS7_SIG_PARSE_ERROR 140 | ||
486 | #define PKCS7_R_PRIVATE_KEY_DOES_NOT_MATCH_CERTIFICATE 127 | ||
487 | #define PKCS7_R_SIGNATURE_FAILURE 105 | ||
488 | #define PKCS7_R_SIGNER_CERTIFICATE_NOT_FOUND 128 | ||
489 | #define PKCS7_R_SIG_INVALID_MIME_TYPE 141 | ||
490 | #define PKCS7_R_SMIME_TEXT_ERROR 129 | ||
491 | #define PKCS7_R_UNABLE_TO_FIND_CERTIFICATE 106 | ||
492 | #define PKCS7_R_UNABLE_TO_FIND_MEM_BIO 107 | ||
493 | #define PKCS7_R_UNABLE_TO_FIND_MESSAGE_DIGEST 108 | ||
494 | #define PKCS7_R_UNKNOWN_DIGEST_TYPE 109 | ||
495 | #define PKCS7_R_UNKNOWN_OPERATION 110 | ||
496 | #define PKCS7_R_UNSUPPORTED_CIPHER_TYPE 111 | ||
497 | #define PKCS7_R_UNSUPPORTED_CONTENT_TYPE 112 | ||
498 | #define PKCS7_R_WRONG_CONTENT_TYPE 113 | ||
499 | #define PKCS7_R_WRONG_PKCS7_TYPE 114 | ||
500 | |||
501 | #ifdef __cplusplus | ||
502 | } | ||
503 | #endif | ||
504 | #endif | ||
505 | |||
diff --git a/src/lib/libcrypto/pkcs7/pkcs7err.c b/src/lib/libcrypto/pkcs7/pkcs7err.c deleted file mode 100644 index 8ded8913db..0000000000 --- a/src/lib/libcrypto/pkcs7/pkcs7err.c +++ /dev/null | |||
@@ -1,161 +0,0 @@ | |||
1 | /* crypto/pkcs7/pkcs7err.c */ | ||
2 | /* ==================================================================== | ||
3 | * Copyright (c) 1999 The OpenSSL Project. All rights reserved. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions | ||
7 | * are met: | ||
8 | * | ||
9 | * 1. Redistributions of source code must retain the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer. | ||
11 | * | ||
12 | * 2. Redistributions in binary form must reproduce the above copyright | ||
13 | * notice, this list of conditions and the following disclaimer in | ||
14 | * the documentation and/or other materials provided with the | ||
15 | * distribution. | ||
16 | * | ||
17 | * 3. All advertising materials mentioning features or use of this | ||
18 | * software must display the following acknowledgment: | ||
19 | * "This product includes software developed by the OpenSSL Project | ||
20 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" | ||
21 | * | ||
22 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
23 | * endorse or promote products derived from this software without | ||
24 | * prior written permission. For written permission, please contact | ||
25 | * openssl-core@OpenSSL.org. | ||
26 | * | ||
27 | * 5. Products derived from this software may not be called "OpenSSL" | ||
28 | * nor may "OpenSSL" appear in their names without prior written | ||
29 | * permission of the OpenSSL Project. | ||
30 | * | ||
31 | * 6. Redistributions of any form whatsoever must retain the following | ||
32 | * acknowledgment: | ||
33 | * "This product includes software developed by the OpenSSL Project | ||
34 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" | ||
35 | * | ||
36 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
37 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
38 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
39 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
40 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
41 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
42 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
43 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
44 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
45 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
46 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
47 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
48 | * ==================================================================== | ||
49 | * | ||
50 | * This product includes cryptographic software written by Eric Young | ||
51 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
52 | * Hudson (tjh@cryptsoft.com). | ||
53 | * | ||
54 | */ | ||
55 | |||
56 | /* NOTE: this file was auto generated by the mkerr.pl script: any changes | ||
57 | * made to it will be overwritten when the script next updates this file, | ||
58 | * only reason strings will be preserved. | ||
59 | */ | ||
60 | |||
61 | #include <stdio.h> | ||
62 | #include <openssl/err.h> | ||
63 | #include <openssl/pkcs7.h> | ||
64 | |||
65 | /* BEGIN ERROR CODES */ | ||
66 | #ifndef NO_ERR | ||
67 | static ERR_STRING_DATA PKCS7_str_functs[]= | ||
68 | { | ||
69 | {ERR_PACK(0,PKCS7_F_B64_READ_PKCS7,0), "B64_READ_PKCS7"}, | ||
70 | {ERR_PACK(0,PKCS7_F_B64_WRITE_PKCS7,0), "B64_WRITE_PKCS7"}, | ||
71 | {ERR_PACK(0,PKCS7_F_PKCS7_ADD_ATTRIB_SMIMECAP,0), "PKCS7_add_attrib_smimecap"}, | ||
72 | {ERR_PACK(0,PKCS7_F_PKCS7_ADD_CERTIFICATE,0), "PKCS7_add_certificate"}, | ||
73 | {ERR_PACK(0,PKCS7_F_PKCS7_ADD_CRL,0), "PKCS7_add_crl"}, | ||
74 | {ERR_PACK(0,PKCS7_F_PKCS7_ADD_RECIPIENT_INFO,0), "PKCS7_add_recipient_info"}, | ||
75 | {ERR_PACK(0,PKCS7_F_PKCS7_ADD_SIGNER,0), "PKCS7_add_signer"}, | ||
76 | {ERR_PACK(0,PKCS7_F_PKCS7_CTRL,0), "PKCS7_ctrl"}, | ||
77 | {ERR_PACK(0,PKCS7_F_PKCS7_DATADECODE,0), "PKCS7_dataDecode"}, | ||
78 | {ERR_PACK(0,PKCS7_F_PKCS7_DATAINIT,0), "PKCS7_dataInit"}, | ||
79 | {ERR_PACK(0,PKCS7_F_PKCS7_DATASIGN,0), "PKCS7_DATASIGN"}, | ||
80 | {ERR_PACK(0,PKCS7_F_PKCS7_DATAVERIFY,0), "PKCS7_dataVerify"}, | ||
81 | {ERR_PACK(0,PKCS7_F_PKCS7_DECRYPT,0), "PKCS7_decrypt"}, | ||
82 | {ERR_PACK(0,PKCS7_F_PKCS7_ENCRYPT,0), "PKCS7_encrypt"}, | ||
83 | {ERR_PACK(0,PKCS7_F_PKCS7_GET0_SIGNERS,0), "PKCS7_get0_signers"}, | ||
84 | {ERR_PACK(0,PKCS7_F_PKCS7_SET_CIPHER,0), "PKCS7_set_cipher"}, | ||
85 | {ERR_PACK(0,PKCS7_F_PKCS7_SET_CONTENT,0), "PKCS7_set_content"}, | ||
86 | {ERR_PACK(0,PKCS7_F_PKCS7_SET_TYPE,0), "PKCS7_set_type"}, | ||
87 | {ERR_PACK(0,PKCS7_F_PKCS7_SIGN,0), "PKCS7_sign"}, | ||
88 | {ERR_PACK(0,PKCS7_F_PKCS7_SIGNATUREVERIFY,0), "PKCS7_signatureVerify"}, | ||
89 | {ERR_PACK(0,PKCS7_F_PKCS7_SIMPLE_SMIMECAP,0), "PKCS7_simple_smimecap"}, | ||
90 | {ERR_PACK(0,PKCS7_F_PKCS7_VERIFY,0), "PKCS7_verify"}, | ||
91 | {ERR_PACK(0,PKCS7_F_SMIME_READ_PKCS7,0), "SMIME_read_PKCS7"}, | ||
92 | {ERR_PACK(0,PKCS7_F_SMIME_TEXT,0), "SMIME_text"}, | ||
93 | {0,NULL} | ||
94 | }; | ||
95 | |||
96 | static ERR_STRING_DATA PKCS7_str_reasons[]= | ||
97 | { | ||
98 | {PKCS7_R_CERTIFICATE_VERIFY_ERROR ,"certificate verify error"}, | ||
99 | {PKCS7_R_CIPHER_HAS_NO_OBJECT_IDENTIFIER ,"cipher has no object identifier"}, | ||
100 | {PKCS7_R_CIPHER_NOT_INITIALIZED ,"cipher not initialized"}, | ||
101 | {PKCS7_R_CONTENT_AND_DATA_PRESENT ,"content and data present"}, | ||
102 | {PKCS7_R_DECODE_ERROR ,"decode error"}, | ||
103 | {PKCS7_R_DECRYPTED_KEY_IS_WRONG_LENGTH ,"decrypted key is wrong length"}, | ||
104 | {PKCS7_R_DECRYPT_ERROR ,"decrypt error"}, | ||
105 | {PKCS7_R_DIGEST_FAILURE ,"digest failure"}, | ||
106 | {PKCS7_R_ERROR_ADDING_RECIPIENT ,"error adding recipient"}, | ||
107 | {PKCS7_R_ERROR_SETTING_CIPHER ,"error setting cipher"}, | ||
108 | {PKCS7_R_INTERNAL_ERROR ,"internal error"}, | ||
109 | {PKCS7_R_INVALID_MIME_TYPE ,"invalid mime type"}, | ||
110 | {PKCS7_R_INVALID_NULL_POINTER ,"invalid null pointer"}, | ||
111 | {PKCS7_R_MIME_NO_CONTENT_TYPE ,"mime no content type"}, | ||
112 | {PKCS7_R_MIME_PARSE_ERROR ,"mime parse error"}, | ||
113 | {PKCS7_R_MIME_SIG_PARSE_ERROR ,"mime sig parse error"}, | ||
114 | {PKCS7_R_MISSING_CERIPEND_INFO ,"missing ceripend info"}, | ||
115 | {PKCS7_R_NO_CONTENT ,"no content"}, | ||
116 | {PKCS7_R_NO_CONTENT_TYPE ,"no content type"}, | ||
117 | {PKCS7_R_NO_MULTIPART_BODY_FAILURE ,"no multipart body failure"}, | ||
118 | {PKCS7_R_NO_MULTIPART_BOUNDARY ,"no multipart boundary"}, | ||
119 | {PKCS7_R_NO_RECIPIENT_MATCHES_CERTIFICATE,"no recipient matches certificate"}, | ||
120 | {PKCS7_R_NO_SIGNATURES_ON_DATA ,"no signatures on data"}, | ||
121 | {PKCS7_R_NO_SIGNERS ,"no signers"}, | ||
122 | {PKCS7_R_NO_SIG_CONTENT_TYPE ,"no sig content type"}, | ||
123 | {PKCS7_R_OPERATION_NOT_SUPPORTED_ON_THIS_TYPE,"operation not supported on this type"}, | ||
124 | {PKCS7_R_PKCS7_ADD_SIGNATURE_ERROR ,"pkcs7 add signature error"}, | ||
125 | {PKCS7_R_PKCS7_DATAFINAL_ERROR ,"pkcs7 datafinal error"}, | ||
126 | {PKCS7_R_PKCS7_DATASIGN ,"pkcs7 datasign"}, | ||
127 | {PKCS7_R_PKCS7_PARSE_ERROR ,"pkcs7 parse error"}, | ||
128 | {PKCS7_R_PKCS7_SIG_PARSE_ERROR ,"pkcs7 sig parse error"}, | ||
129 | {PKCS7_R_PRIVATE_KEY_DOES_NOT_MATCH_CERTIFICATE,"private key does not match certificate"}, | ||
130 | {PKCS7_R_SIGNATURE_FAILURE ,"signature failure"}, | ||
131 | {PKCS7_R_SIGNER_CERTIFICATE_NOT_FOUND ,"signer certificate not found"}, | ||
132 | {PKCS7_R_SIG_INVALID_MIME_TYPE ,"sig invalid mime type"}, | ||
133 | {PKCS7_R_SMIME_TEXT_ERROR ,"smime text error"}, | ||
134 | {PKCS7_R_UNABLE_TO_FIND_CERTIFICATE ,"unable to find certificate"}, | ||
135 | {PKCS7_R_UNABLE_TO_FIND_MEM_BIO ,"unable to find mem bio"}, | ||
136 | {PKCS7_R_UNABLE_TO_FIND_MESSAGE_DIGEST ,"unable to find message digest"}, | ||
137 | {PKCS7_R_UNKNOWN_DIGEST_TYPE ,"unknown digest type"}, | ||
138 | {PKCS7_R_UNKNOWN_OPERATION ,"unknown operation"}, | ||
139 | {PKCS7_R_UNSUPPORTED_CIPHER_TYPE ,"unsupported cipher type"}, | ||
140 | {PKCS7_R_UNSUPPORTED_CONTENT_TYPE ,"unsupported content type"}, | ||
141 | {PKCS7_R_WRONG_CONTENT_TYPE ,"wrong content type"}, | ||
142 | {PKCS7_R_WRONG_PKCS7_TYPE ,"wrong pkcs7 type"}, | ||
143 | {0,NULL} | ||
144 | }; | ||
145 | |||
146 | #endif | ||
147 | |||
148 | void ERR_load_PKCS7_strings(void) | ||
149 | { | ||
150 | static int init=1; | ||
151 | |||
152 | if (init) | ||
153 | { | ||
154 | init=0; | ||
155 | #ifndef NO_ERR | ||
156 | ERR_load_strings(ERR_LIB_PKCS7,PKCS7_str_functs); | ||
157 | ERR_load_strings(ERR_LIB_PKCS7,PKCS7_str_reasons); | ||
158 | #endif | ||
159 | |||
160 | } | ||
161 | } | ||