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