summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/pkcs7
diff options
context:
space:
mode:
authorcvs2svn <admin@example.com>2014-02-27 21:04:58 +0000
committercvs2svn <admin@example.com>2014-02-27 21:04:58 +0000
commit726818f36b5221c023cd04c4b90bdbc08e94cd96 (patch)
treecf8221f3aa5bf5a578ddf1ecf5677ad08c04d342 /src/lib/libcrypto/pkcs7
parent3b6d92e82b1421b811bcdec7f7fdfb31eeef18de (diff)
downloadopenbsd-OPENBSD_5_5_BASE.tar.gz
openbsd-OPENBSD_5_5_BASE.tar.bz2
openbsd-OPENBSD_5_5_BASE.zip
This commit was manufactured by cvs2git to create tag 'OPENBSD_5_5_BASE'.OPENBSD_5_5_BASE
Diffstat (limited to 'src/lib/libcrypto/pkcs7')
-rw-r--r--src/lib/libcrypto/pkcs7/bio_pk7.c69
-rw-r--r--src/lib/libcrypto/pkcs7/pk7_asn1.c247
-rw-r--r--src/lib/libcrypto/pkcs7/pk7_attr.c165
-rw-r--r--src/lib/libcrypto/pkcs7/pk7_doit.c1299
-rw-r--r--src/lib/libcrypto/pkcs7/pk7_lib.c665
-rw-r--r--src/lib/libcrypto/pkcs7/pk7_mime.c97
-rw-r--r--src/lib/libcrypto/pkcs7/pk7_smime.c606
-rw-r--r--src/lib/libcrypto/pkcs7/pkcs7.h499
-rw-r--r--src/lib/libcrypto/pkcs7/pkcs7err.c187
9 files changed, 0 insertions, 3834 deletions
diff --git a/src/lib/libcrypto/pkcs7/bio_pk7.c b/src/lib/libcrypto/pkcs7/bio_pk7.c
deleted file mode 100644
index c8d06d6cdc..0000000000
--- a/src/lib/libcrypto/pkcs7/bio_pk7.c
+++ /dev/null
@@ -1,69 +0,0 @@
1/* bio_pk7.c */
2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
3 * project.
4 */
5/* ====================================================================
6 * Copyright (c) 2008 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 */
54
55#include <openssl/asn1.h>
56#include <openssl/pkcs7.h>
57#include <openssl/bio.h>
58
59#ifndef OPENSSL_SYSNAME_NETWARE
60#include <memory.h>
61#endif
62#include <stdio.h>
63
64/* Streaming encode support for PKCS#7 */
65
66BIO *BIO_new_PKCS7(BIO *out, PKCS7 *p7)
67 {
68 return BIO_new_NDEF(out, (ASN1_VALUE *)p7, ASN1_ITEM_rptr(PKCS7));
69 }
diff --git a/src/lib/libcrypto/pkcs7/pk7_asn1.c b/src/lib/libcrypto/pkcs7/pk7_asn1.c
deleted file mode 100644
index b7ec2883cb..0000000000
--- a/src/lib/libcrypto/pkcs7/pk7_asn1.c
+++ /dev/null
@@ -1,247 +0,0 @@
1/* pk7_asn.c */
2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
3 * project 2000.
4 */
5/* ====================================================================
6 * Copyright (c) 2000 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/asn1t.h>
62#include <openssl/pkcs7.h>
63#include <openssl/x509.h>
64
65/* PKCS#7 ASN1 module */
66
67/* This is the ANY DEFINED BY table for the top level PKCS#7 structure */
68
69ASN1_ADB_TEMPLATE(p7default) = ASN1_EXP_OPT(PKCS7, d.other, ASN1_ANY, 0);
70
71ASN1_ADB(PKCS7) = {
72 ADB_ENTRY(NID_pkcs7_data, ASN1_NDEF_EXP_OPT(PKCS7, d.data, ASN1_OCTET_STRING_NDEF, 0)),
73 ADB_ENTRY(NID_pkcs7_signed, ASN1_NDEF_EXP_OPT(PKCS7, d.sign, PKCS7_SIGNED, 0)),
74 ADB_ENTRY(NID_pkcs7_enveloped, ASN1_NDEF_EXP_OPT(PKCS7, d.enveloped, PKCS7_ENVELOPE, 0)),
75 ADB_ENTRY(NID_pkcs7_signedAndEnveloped, ASN1_NDEF_EXP_OPT(PKCS7, d.signed_and_enveloped, PKCS7_SIGN_ENVELOPE, 0)),
76 ADB_ENTRY(NID_pkcs7_digest, ASN1_NDEF_EXP_OPT(PKCS7, d.digest, PKCS7_DIGEST, 0)),
77 ADB_ENTRY(NID_pkcs7_encrypted, ASN1_NDEF_EXP_OPT(PKCS7, d.encrypted, PKCS7_ENCRYPT, 0))
78} ASN1_ADB_END(PKCS7, 0, type, 0, &p7default_tt, NULL);
79
80/* PKCS#7 streaming support */
81static int pk7_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it,
82 void *exarg)
83{
84 ASN1_STREAM_ARG *sarg = exarg;
85 PKCS7 **pp7 = (PKCS7 **)pval;
86
87 switch(operation)
88 {
89
90 case ASN1_OP_STREAM_PRE:
91 if (PKCS7_stream(&sarg->boundary, *pp7) <= 0)
92 return 0;
93 case ASN1_OP_DETACHED_PRE:
94 sarg->ndef_bio = PKCS7_dataInit(*pp7, sarg->out);
95 if (!sarg->ndef_bio)
96 return 0;
97 break;
98
99 case ASN1_OP_STREAM_POST:
100 case ASN1_OP_DETACHED_POST:
101 if (PKCS7_dataFinal(*pp7, sarg->ndef_bio) <= 0)
102 return 0;
103 break;
104
105 }
106 return 1;
107}
108
109ASN1_NDEF_SEQUENCE_cb(PKCS7, pk7_cb) = {
110 ASN1_SIMPLE(PKCS7, type, ASN1_OBJECT),
111 ASN1_ADB_OBJECT(PKCS7)
112}ASN1_NDEF_SEQUENCE_END_cb(PKCS7, PKCS7)
113
114IMPLEMENT_ASN1_FUNCTIONS(PKCS7)
115IMPLEMENT_ASN1_NDEF_FUNCTION(PKCS7)
116IMPLEMENT_ASN1_DUP_FUNCTION(PKCS7)
117
118ASN1_NDEF_SEQUENCE(PKCS7_SIGNED) = {
119 ASN1_SIMPLE(PKCS7_SIGNED, version, ASN1_INTEGER),
120 ASN1_SET_OF(PKCS7_SIGNED, md_algs, X509_ALGOR),
121 ASN1_SIMPLE(PKCS7_SIGNED, contents, PKCS7),
122 ASN1_IMP_SEQUENCE_OF_OPT(PKCS7_SIGNED, cert, X509, 0),
123 ASN1_IMP_SET_OF_OPT(PKCS7_SIGNED, crl, X509_CRL, 1),
124 ASN1_SET_OF(PKCS7_SIGNED, signer_info, PKCS7_SIGNER_INFO)
125} ASN1_NDEF_SEQUENCE_END(PKCS7_SIGNED)
126
127IMPLEMENT_ASN1_FUNCTIONS(PKCS7_SIGNED)
128
129/* Minor tweak to operation: free up EVP_PKEY */
130static int si_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it,
131 void *exarg)
132{
133 if(operation == ASN1_OP_FREE_POST) {
134 PKCS7_SIGNER_INFO *si = (PKCS7_SIGNER_INFO *)*pval;
135 EVP_PKEY_free(si->pkey);
136 }
137 return 1;
138}
139
140ASN1_SEQUENCE_cb(PKCS7_SIGNER_INFO, si_cb) = {
141 ASN1_SIMPLE(PKCS7_SIGNER_INFO, version, ASN1_INTEGER),
142 ASN1_SIMPLE(PKCS7_SIGNER_INFO, issuer_and_serial, PKCS7_ISSUER_AND_SERIAL),
143 ASN1_SIMPLE(PKCS7_SIGNER_INFO, digest_alg, X509_ALGOR),
144 /* NB this should be a SET OF but we use a SEQUENCE OF so the
145 * original order * is retained when the structure is reencoded.
146 * Since the attributes are implicitly tagged this will not affect
147 * the encoding.
148 */
149 ASN1_IMP_SEQUENCE_OF_OPT(PKCS7_SIGNER_INFO, auth_attr, X509_ATTRIBUTE, 0),
150 ASN1_SIMPLE(PKCS7_SIGNER_INFO, digest_enc_alg, X509_ALGOR),
151 ASN1_SIMPLE(PKCS7_SIGNER_INFO, enc_digest, ASN1_OCTET_STRING),
152 ASN1_IMP_SET_OF_OPT(PKCS7_SIGNER_INFO, unauth_attr, X509_ATTRIBUTE, 1)
153} ASN1_SEQUENCE_END_cb(PKCS7_SIGNER_INFO, PKCS7_SIGNER_INFO)
154
155IMPLEMENT_ASN1_FUNCTIONS(PKCS7_SIGNER_INFO)
156
157ASN1_SEQUENCE(PKCS7_ISSUER_AND_SERIAL) = {
158 ASN1_SIMPLE(PKCS7_ISSUER_AND_SERIAL, issuer, X509_NAME),
159 ASN1_SIMPLE(PKCS7_ISSUER_AND_SERIAL, serial, ASN1_INTEGER)
160} ASN1_SEQUENCE_END(PKCS7_ISSUER_AND_SERIAL)
161
162IMPLEMENT_ASN1_FUNCTIONS(PKCS7_ISSUER_AND_SERIAL)
163
164ASN1_NDEF_SEQUENCE(PKCS7_ENVELOPE) = {
165 ASN1_SIMPLE(PKCS7_ENVELOPE, version, ASN1_INTEGER),
166 ASN1_SET_OF(PKCS7_ENVELOPE, recipientinfo, PKCS7_RECIP_INFO),
167 ASN1_SIMPLE(PKCS7_ENVELOPE, enc_data, PKCS7_ENC_CONTENT)
168} ASN1_NDEF_SEQUENCE_END(PKCS7_ENVELOPE)
169
170IMPLEMENT_ASN1_FUNCTIONS(PKCS7_ENVELOPE)
171
172/* Minor tweak to operation: free up X509 */
173static int ri_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it,
174 void *exarg)
175{
176 if(operation == ASN1_OP_FREE_POST) {
177 PKCS7_RECIP_INFO *ri = (PKCS7_RECIP_INFO *)*pval;
178 X509_free(ri->cert);
179 }
180 return 1;
181}
182
183ASN1_SEQUENCE_cb(PKCS7_RECIP_INFO, ri_cb) = {
184 ASN1_SIMPLE(PKCS7_RECIP_INFO, version, ASN1_INTEGER),
185 ASN1_SIMPLE(PKCS7_RECIP_INFO, issuer_and_serial, PKCS7_ISSUER_AND_SERIAL),
186 ASN1_SIMPLE(PKCS7_RECIP_INFO, key_enc_algor, X509_ALGOR),
187 ASN1_SIMPLE(PKCS7_RECIP_INFO, enc_key, ASN1_OCTET_STRING)
188} ASN1_SEQUENCE_END_cb(PKCS7_RECIP_INFO, PKCS7_RECIP_INFO)
189
190IMPLEMENT_ASN1_FUNCTIONS(PKCS7_RECIP_INFO)
191
192ASN1_NDEF_SEQUENCE(PKCS7_ENC_CONTENT) = {
193 ASN1_SIMPLE(PKCS7_ENC_CONTENT, content_type, ASN1_OBJECT),
194 ASN1_SIMPLE(PKCS7_ENC_CONTENT, algorithm, X509_ALGOR),
195 ASN1_IMP_OPT(PKCS7_ENC_CONTENT, enc_data, ASN1_OCTET_STRING_NDEF, 0)
196} ASN1_NDEF_SEQUENCE_END(PKCS7_ENC_CONTENT)
197
198IMPLEMENT_ASN1_FUNCTIONS(PKCS7_ENC_CONTENT)
199
200ASN1_NDEF_SEQUENCE(PKCS7_SIGN_ENVELOPE) = {
201 ASN1_SIMPLE(PKCS7_SIGN_ENVELOPE, version, ASN1_INTEGER),
202 ASN1_SET_OF(PKCS7_SIGN_ENVELOPE, recipientinfo, PKCS7_RECIP_INFO),
203 ASN1_SET_OF(PKCS7_SIGN_ENVELOPE, md_algs, X509_ALGOR),
204 ASN1_SIMPLE(PKCS7_SIGN_ENVELOPE, enc_data, PKCS7_ENC_CONTENT),
205 ASN1_IMP_SET_OF_OPT(PKCS7_SIGN_ENVELOPE, cert, X509, 0),
206 ASN1_IMP_SET_OF_OPT(PKCS7_SIGN_ENVELOPE, crl, X509_CRL, 1),
207 ASN1_SET_OF(PKCS7_SIGN_ENVELOPE, signer_info, PKCS7_SIGNER_INFO)
208} ASN1_NDEF_SEQUENCE_END(PKCS7_SIGN_ENVELOPE)
209
210IMPLEMENT_ASN1_FUNCTIONS(PKCS7_SIGN_ENVELOPE)
211
212ASN1_NDEF_SEQUENCE(PKCS7_ENCRYPT) = {
213 ASN1_SIMPLE(PKCS7_ENCRYPT, version, ASN1_INTEGER),
214 ASN1_SIMPLE(PKCS7_ENCRYPT, enc_data, PKCS7_ENC_CONTENT)
215} ASN1_NDEF_SEQUENCE_END(PKCS7_ENCRYPT)
216
217IMPLEMENT_ASN1_FUNCTIONS(PKCS7_ENCRYPT)
218
219ASN1_NDEF_SEQUENCE(PKCS7_DIGEST) = {
220 ASN1_SIMPLE(PKCS7_DIGEST, version, ASN1_INTEGER),
221 ASN1_SIMPLE(PKCS7_DIGEST, md, X509_ALGOR),
222 ASN1_SIMPLE(PKCS7_DIGEST, contents, PKCS7),
223 ASN1_SIMPLE(PKCS7_DIGEST, digest, ASN1_OCTET_STRING)
224} ASN1_NDEF_SEQUENCE_END(PKCS7_DIGEST)
225
226IMPLEMENT_ASN1_FUNCTIONS(PKCS7_DIGEST)
227
228/* Specials for authenticated attributes */
229
230/* When signing attributes we want to reorder them to match the sorted
231 * encoding.
232 */
233
234ASN1_ITEM_TEMPLATE(PKCS7_ATTR_SIGN) =
235 ASN1_EX_TEMPLATE_TYPE(ASN1_TFLG_SET_ORDER, 0, PKCS7_ATTRIBUTES, X509_ATTRIBUTE)
236ASN1_ITEM_TEMPLATE_END(PKCS7_ATTR_SIGN)
237
238/* When verifying attributes we need to use the received order. So
239 * we use SEQUENCE OF and tag it to SET OF
240 */
241
242ASN1_ITEM_TEMPLATE(PKCS7_ATTR_VERIFY) =
243 ASN1_EX_TEMPLATE_TYPE(ASN1_TFLG_SEQUENCE_OF | ASN1_TFLG_IMPTAG | ASN1_TFLG_UNIVERSAL,
244 V_ASN1_SET, PKCS7_ATTRIBUTES, X509_ATTRIBUTE)
245ASN1_ITEM_TEMPLATE_END(PKCS7_ATTR_VERIFY)
246
247IMPLEMENT_ASN1_PRINT_FUNCTION(PKCS7)
diff --git a/src/lib/libcrypto/pkcs7/pk7_attr.c b/src/lib/libcrypto/pkcs7/pk7_attr.c
deleted file mode 100644
index a97db51210..0000000000
--- a/src/lib/libcrypto/pkcs7/pk7_attr.c
+++ /dev/null
@@ -1,165 +0,0 @@
1/* pk7_attr.c */
2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
3 * project 2001.
4 */
5/* ====================================================================
6 * Copyright (c) 2001-2004 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include <stdlib.h>
61#include <openssl/bio.h>
62#include <openssl/asn1.h>
63#include <openssl/asn1t.h>
64#include <openssl/pem.h>
65#include <openssl/pkcs7.h>
66#include <openssl/x509.h>
67#include <openssl/err.h>
68
69int PKCS7_add_attrib_smimecap(PKCS7_SIGNER_INFO *si, STACK_OF(X509_ALGOR) *cap)
70{
71 ASN1_STRING *seq;
72 if(!(seq = ASN1_STRING_new())) {
73 PKCS7err(PKCS7_F_PKCS7_ADD_ATTRIB_SMIMECAP,ERR_R_MALLOC_FAILURE);
74 return 0;
75 }
76 seq->length = ASN1_item_i2d((ASN1_VALUE *)cap,&seq->data,
77 ASN1_ITEM_rptr(X509_ALGORS));
78 return PKCS7_add_signed_attribute(si, NID_SMIMECapabilities,
79 V_ASN1_SEQUENCE, seq);
80}
81
82STACK_OF(X509_ALGOR) *PKCS7_get_smimecap(PKCS7_SIGNER_INFO *si)
83 {
84 ASN1_TYPE *cap;
85 const unsigned char *p;
86
87 cap = PKCS7_get_signed_attribute(si, NID_SMIMECapabilities);
88 if (!cap || (cap->type != V_ASN1_SEQUENCE))
89 return NULL;
90 p = cap->value.sequence->data;
91 return (STACK_OF(X509_ALGOR) *)
92 ASN1_item_d2i(NULL, &p, cap->value.sequence->length,
93 ASN1_ITEM_rptr(X509_ALGORS));
94 }
95
96/* Basic smime-capabilities OID and optional integer arg */
97int PKCS7_simple_smimecap(STACK_OF(X509_ALGOR) *sk, int nid, int arg)
98{
99 X509_ALGOR *alg;
100
101 if(!(alg = X509_ALGOR_new())) {
102 PKCS7err(PKCS7_F_PKCS7_SIMPLE_SMIMECAP,ERR_R_MALLOC_FAILURE);
103 return 0;
104 }
105 ASN1_OBJECT_free(alg->algorithm);
106 alg->algorithm = OBJ_nid2obj (nid);
107 if (arg > 0) {
108 ASN1_INTEGER *nbit;
109 if(!(alg->parameter = ASN1_TYPE_new())) {
110 PKCS7err(PKCS7_F_PKCS7_SIMPLE_SMIMECAP,ERR_R_MALLOC_FAILURE);
111 return 0;
112 }
113 if(!(nbit = ASN1_INTEGER_new())) {
114 PKCS7err(PKCS7_F_PKCS7_SIMPLE_SMIMECAP,ERR_R_MALLOC_FAILURE);
115 return 0;
116 }
117 if(!ASN1_INTEGER_set (nbit, arg)) {
118 PKCS7err(PKCS7_F_PKCS7_SIMPLE_SMIMECAP,ERR_R_MALLOC_FAILURE);
119 return 0;
120 }
121 alg->parameter->value.integer = nbit;
122 alg->parameter->type = V_ASN1_INTEGER;
123 }
124 sk_X509_ALGOR_push (sk, alg);
125 return 1;
126}
127
128int PKCS7_add_attrib_content_type(PKCS7_SIGNER_INFO *si, ASN1_OBJECT *coid)
129 {
130 if (PKCS7_get_signed_attribute(si, NID_pkcs9_contentType))
131 return 0;
132 if (!coid)
133 coid = OBJ_nid2obj(NID_pkcs7_data);
134 return PKCS7_add_signed_attribute(si, NID_pkcs9_contentType,
135 V_ASN1_OBJECT, coid);
136 }
137
138int PKCS7_add0_attrib_signing_time(PKCS7_SIGNER_INFO *si, ASN1_TIME *t)
139 {
140 if (!t && !(t=X509_gmtime_adj(NULL,0)))
141 {
142 PKCS7err(PKCS7_F_PKCS7_ADD0_ATTRIB_SIGNING_TIME,
143 ERR_R_MALLOC_FAILURE);
144 return 0;
145 }
146 return PKCS7_add_signed_attribute(si, NID_pkcs9_signingTime,
147 V_ASN1_UTCTIME, t);
148 }
149
150int PKCS7_add1_attrib_digest(PKCS7_SIGNER_INFO *si,
151 const unsigned char *md, int mdlen)
152 {
153 ASN1_OCTET_STRING *os;
154 os = ASN1_OCTET_STRING_new();
155 if (!os)
156 return 0;
157 if (!ASN1_STRING_set(os, md, mdlen)
158 || !PKCS7_add_signed_attribute(si, NID_pkcs9_messageDigest,
159 V_ASN1_OCTET_STRING, os))
160 {
161 ASN1_OCTET_STRING_free(os);
162 return 0;
163 }
164 return 1;
165 }
diff --git a/src/lib/libcrypto/pkcs7/pk7_doit.c b/src/lib/libcrypto/pkcs7/pk7_doit.c
deleted file mode 100644
index 77fda3b82a..0000000000
--- a/src/lib/libcrypto/pkcs7/pk7_doit.c
+++ /dev/null
@@ -1,1299 +0,0 @@
1/* crypto/pkcs7/pk7_doit.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/rand.h>
62#include <openssl/objects.h>
63#include <openssl/x509.h>
64#include <openssl/x509v3.h>
65#include <openssl/err.h>
66
67static int add_attribute(STACK_OF(X509_ATTRIBUTE) **sk, int nid, int atrtype,
68 void *value);
69static ASN1_TYPE *get_attribute(STACK_OF(X509_ATTRIBUTE) *sk, int nid);
70
71static int PKCS7_type_is_other(PKCS7* p7)
72 {
73 int isOther=1;
74
75 int nid=OBJ_obj2nid(p7->type);
76
77 switch( nid )
78 {
79 case NID_pkcs7_data:
80 case NID_pkcs7_signed:
81 case NID_pkcs7_enveloped:
82 case NID_pkcs7_signedAndEnveloped:
83 case NID_pkcs7_digest:
84 case NID_pkcs7_encrypted:
85 isOther=0;
86 break;
87 default:
88 isOther=1;
89 }
90
91 return isOther;
92
93 }
94
95static ASN1_OCTET_STRING *PKCS7_get_octet_string(PKCS7 *p7)
96 {
97 if ( PKCS7_type_is_data(p7))
98 return p7->d.data;
99 if ( PKCS7_type_is_other(p7) && p7->d.other
100 && (p7->d.other->type == V_ASN1_OCTET_STRING))
101 return p7->d.other->value.octet_string;
102 return NULL;
103 }
104
105static int PKCS7_bio_add_digest(BIO **pbio, X509_ALGOR *alg)
106 {
107 BIO *btmp;
108 const EVP_MD *md;
109 if ((btmp=BIO_new(BIO_f_md())) == NULL)
110 {
111 PKCS7err(PKCS7_F_PKCS7_BIO_ADD_DIGEST,ERR_R_BIO_LIB);
112 goto err;
113 }
114
115 md=EVP_get_digestbyobj(alg->algorithm);
116 if (md == NULL)
117 {
118 PKCS7err(PKCS7_F_PKCS7_BIO_ADD_DIGEST,PKCS7_R_UNKNOWN_DIGEST_TYPE);
119 goto err;
120 }
121
122 BIO_set_md(btmp,md);
123 if (*pbio == NULL)
124 *pbio=btmp;
125 else if (!BIO_push(*pbio,btmp))
126 {
127 PKCS7err(PKCS7_F_PKCS7_BIO_ADD_DIGEST,ERR_R_BIO_LIB);
128 goto err;
129 }
130 btmp=NULL;
131
132 return 1;
133
134 err:
135 if (btmp)
136 BIO_free(btmp);
137 return 0;
138
139 }
140
141static int pkcs7_encode_rinfo(PKCS7_RECIP_INFO *ri,
142 unsigned char *key, int keylen)
143 {
144 EVP_PKEY_CTX *pctx = NULL;
145 EVP_PKEY *pkey = NULL;
146 unsigned char *ek = NULL;
147 int ret = 0;
148 size_t eklen;
149
150 pkey = X509_get_pubkey(ri->cert);
151
152 if (!pkey)
153 return 0;
154
155 pctx = EVP_PKEY_CTX_new(pkey, NULL);
156 if (!pctx)
157 return 0;
158
159 if (EVP_PKEY_encrypt_init(pctx) <= 0)
160 goto err;
161
162 if (EVP_PKEY_CTX_ctrl(pctx, -1, EVP_PKEY_OP_ENCRYPT,
163 EVP_PKEY_CTRL_PKCS7_ENCRYPT, 0, ri) <= 0)
164 {
165 PKCS7err(PKCS7_F_PKCS7_ENCODE_RINFO, PKCS7_R_CTRL_ERROR);
166 goto err;
167 }
168
169 if (EVP_PKEY_encrypt(pctx, NULL, &eklen, key, keylen) <= 0)
170 goto err;
171
172 ek = OPENSSL_malloc(eklen);
173
174 if (ek == NULL)
175 {
176 PKCS7err(PKCS7_F_PKCS7_ENCODE_RINFO, ERR_R_MALLOC_FAILURE);
177 goto err;
178 }
179
180 if (EVP_PKEY_encrypt(pctx, ek, &eklen, key, keylen) <= 0)
181 goto err;
182
183 ASN1_STRING_set0(ri->enc_key, ek, eklen);
184 ek = NULL;
185
186 ret = 1;
187
188 err:
189 if (pkey)
190 EVP_PKEY_free(pkey);
191 if (pctx)
192 EVP_PKEY_CTX_free(pctx);
193 if (ek)
194 OPENSSL_free(ek);
195 return ret;
196
197 }
198
199
200static int pkcs7_decrypt_rinfo(unsigned char **pek, int *peklen,
201 PKCS7_RECIP_INFO *ri, EVP_PKEY *pkey)
202 {
203 EVP_PKEY_CTX *pctx = NULL;
204 unsigned char *ek = NULL;
205 size_t eklen;
206
207 int ret = -1;
208
209 pctx = EVP_PKEY_CTX_new(pkey, NULL);
210 if (!pctx)
211 return -1;
212
213 if (EVP_PKEY_decrypt_init(pctx) <= 0)
214 goto err;
215
216 if (EVP_PKEY_CTX_ctrl(pctx, -1, EVP_PKEY_OP_DECRYPT,
217 EVP_PKEY_CTRL_PKCS7_DECRYPT, 0, ri) <= 0)
218 {
219 PKCS7err(PKCS7_F_PKCS7_DECRYPT_RINFO, PKCS7_R_CTRL_ERROR);
220 goto err;
221 }
222
223 if (EVP_PKEY_decrypt(pctx, NULL, &eklen,
224 ri->enc_key->data, ri->enc_key->length) <= 0)
225 goto err;
226
227 ek = OPENSSL_malloc(eklen);
228
229 if (ek == NULL)
230 {
231 PKCS7err(PKCS7_F_PKCS7_DECRYPT_RINFO, ERR_R_MALLOC_FAILURE);
232 goto err;
233 }
234
235 if (EVP_PKEY_decrypt(pctx, ek, &eklen,
236 ri->enc_key->data, ri->enc_key->length) <= 0)
237 {
238 ret = 0;
239 PKCS7err(PKCS7_F_PKCS7_DECRYPT_RINFO, ERR_R_EVP_LIB);
240 goto err;
241 }
242
243 ret = 1;
244
245 if (*pek)
246 {
247 OPENSSL_cleanse(*pek, *peklen);
248 OPENSSL_free(*pek);
249 }
250
251 *pek = ek;
252 *peklen = eklen;
253
254 err:
255 if (pctx)
256 EVP_PKEY_CTX_free(pctx);
257 if (!ret && ek)
258 OPENSSL_free(ek);
259
260 return ret;
261 }
262
263BIO *PKCS7_dataInit(PKCS7 *p7, BIO *bio)
264 {
265 int i;
266 BIO *out=NULL,*btmp=NULL;
267 X509_ALGOR *xa = NULL;
268 const EVP_CIPHER *evp_cipher=NULL;
269 STACK_OF(X509_ALGOR) *md_sk=NULL;
270 STACK_OF(PKCS7_RECIP_INFO) *rsk=NULL;
271 X509_ALGOR *xalg=NULL;
272 PKCS7_RECIP_INFO *ri=NULL;
273 ASN1_OCTET_STRING *os=NULL;
274
275 i=OBJ_obj2nid(p7->type);
276 p7->state=PKCS7_S_HEADER;
277
278 switch (i)
279 {
280 case NID_pkcs7_signed:
281 md_sk=p7->d.sign->md_algs;
282 os = PKCS7_get_octet_string(p7->d.sign->contents);
283 break;
284 case NID_pkcs7_signedAndEnveloped:
285 rsk=p7->d.signed_and_enveloped->recipientinfo;
286 md_sk=p7->d.signed_and_enveloped->md_algs;
287 xalg=p7->d.signed_and_enveloped->enc_data->algorithm;
288 evp_cipher=p7->d.signed_and_enveloped->enc_data->cipher;
289 if (evp_cipher == NULL)
290 {
291 PKCS7err(PKCS7_F_PKCS7_DATAINIT,
292 PKCS7_R_CIPHER_NOT_INITIALIZED);
293 goto err;
294 }
295 break;
296 case NID_pkcs7_enveloped:
297 rsk=p7->d.enveloped->recipientinfo;
298 xalg=p7->d.enveloped->enc_data->algorithm;
299 evp_cipher=p7->d.enveloped->enc_data->cipher;
300 if (evp_cipher == NULL)
301 {
302 PKCS7err(PKCS7_F_PKCS7_DATAINIT,
303 PKCS7_R_CIPHER_NOT_INITIALIZED);
304 goto err;
305 }
306 break;
307 case NID_pkcs7_digest:
308 xa = p7->d.digest->md;
309 os = PKCS7_get_octet_string(p7->d.digest->contents);
310 break;
311 case NID_pkcs7_data:
312 break;
313 default:
314 PKCS7err(PKCS7_F_PKCS7_DATAINIT,PKCS7_R_UNSUPPORTED_CONTENT_TYPE);
315 goto err;
316 }
317
318 for (i=0; i<sk_X509_ALGOR_num(md_sk); i++)
319 if (!PKCS7_bio_add_digest(&out, sk_X509_ALGOR_value(md_sk, i)))
320 goto err;
321
322 if (xa && !PKCS7_bio_add_digest(&out, xa))
323 goto err;
324
325 if (evp_cipher != NULL)
326 {
327 unsigned char key[EVP_MAX_KEY_LENGTH];
328 unsigned char iv[EVP_MAX_IV_LENGTH];
329 int keylen,ivlen;
330 EVP_CIPHER_CTX *ctx;
331
332 if ((btmp=BIO_new(BIO_f_cipher())) == NULL)
333 {
334 PKCS7err(PKCS7_F_PKCS7_DATAINIT,ERR_R_BIO_LIB);
335 goto err;
336 }
337 BIO_get_cipher_ctx(btmp, &ctx);
338 keylen=EVP_CIPHER_key_length(evp_cipher);
339 ivlen=EVP_CIPHER_iv_length(evp_cipher);
340 xalg->algorithm = OBJ_nid2obj(EVP_CIPHER_type(evp_cipher));
341 if (ivlen > 0)
342 if (RAND_pseudo_bytes(iv,ivlen) <= 0)
343 goto err;
344 if (EVP_CipherInit_ex(ctx, evp_cipher, NULL, NULL, NULL, 1)<=0)
345 goto err;
346 if (EVP_CIPHER_CTX_rand_key(ctx, key) <= 0)
347 goto err;
348 if (EVP_CipherInit_ex(ctx, NULL, NULL, key, iv, 1) <= 0)
349 goto err;
350
351 if (ivlen > 0) {
352 if (xalg->parameter == NULL) {
353 xalg->parameter = ASN1_TYPE_new();
354 if (xalg->parameter == NULL)
355 goto err;
356 }
357 if(EVP_CIPHER_param_to_asn1(ctx, xalg->parameter) < 0)
358 goto err;
359 }
360
361 /* Lets do the pub key stuff :-) */
362 for (i=0; i<sk_PKCS7_RECIP_INFO_num(rsk); i++)
363 {
364 ri=sk_PKCS7_RECIP_INFO_value(rsk,i);
365 if (pkcs7_encode_rinfo(ri, key, keylen) <= 0)
366 goto err;
367 }
368 OPENSSL_cleanse(key, keylen);
369
370 if (out == NULL)
371 out=btmp;
372 else
373 BIO_push(out,btmp);
374 btmp=NULL;
375 }
376
377 if (bio == NULL)
378 {
379 if (PKCS7_is_detached(p7))
380 bio=BIO_new(BIO_s_null());
381 else if (os && os->length > 0)
382 bio = BIO_new_mem_buf(os->data, os->length);
383 if(bio == NULL)
384 {
385 bio=BIO_new(BIO_s_mem());
386 if (bio == NULL)
387 goto err;
388 BIO_set_mem_eof_return(bio,0);
389 }
390 }
391 if (out)
392 BIO_push(out,bio);
393 else
394 out = bio;
395 bio=NULL;
396 if (0)
397 {
398err:
399 if (out != NULL)
400 BIO_free_all(out);
401 if (btmp != NULL)
402 BIO_free_all(btmp);
403 out=NULL;
404 }
405 return(out);
406 }
407
408static int pkcs7_cmp_ri(PKCS7_RECIP_INFO *ri, X509 *pcert)
409 {
410 int ret;
411 ret = X509_NAME_cmp(ri->issuer_and_serial->issuer,
412 pcert->cert_info->issuer);
413 if (ret)
414 return ret;
415 return M_ASN1_INTEGER_cmp(pcert->cert_info->serialNumber,
416 ri->issuer_and_serial->serial);
417 }
418
419/* int */
420BIO *PKCS7_dataDecode(PKCS7 *p7, EVP_PKEY *pkey, BIO *in_bio, X509 *pcert)
421 {
422 int i,j;
423 BIO *out=NULL,*btmp=NULL,*etmp=NULL,*bio=NULL;
424 X509_ALGOR *xa;
425 ASN1_OCTET_STRING *data_body=NULL;
426 const EVP_MD *evp_md;
427 const EVP_CIPHER *evp_cipher=NULL;
428 EVP_CIPHER_CTX *evp_ctx=NULL;
429 X509_ALGOR *enc_alg=NULL;
430 STACK_OF(X509_ALGOR) *md_sk=NULL;
431 STACK_OF(PKCS7_RECIP_INFO) *rsk=NULL;
432 PKCS7_RECIP_INFO *ri=NULL;
433 unsigned char *ek = NULL, *tkey = NULL;
434 int eklen = 0, tkeylen = 0;
435
436 i=OBJ_obj2nid(p7->type);
437 p7->state=PKCS7_S_HEADER;
438
439 switch (i)
440 {
441 case NID_pkcs7_signed:
442 data_body=PKCS7_get_octet_string(p7->d.sign->contents);
443 md_sk=p7->d.sign->md_algs;
444 break;
445 case NID_pkcs7_signedAndEnveloped:
446 rsk=p7->d.signed_and_enveloped->recipientinfo;
447 md_sk=p7->d.signed_and_enveloped->md_algs;
448 data_body=p7->d.signed_and_enveloped->enc_data->enc_data;
449 enc_alg=p7->d.signed_and_enveloped->enc_data->algorithm;
450 evp_cipher=EVP_get_cipherbyobj(enc_alg->algorithm);
451 if (evp_cipher == NULL)
452 {
453 PKCS7err(PKCS7_F_PKCS7_DATADECODE,PKCS7_R_UNSUPPORTED_CIPHER_TYPE);
454 goto err;
455 }
456 break;
457 case NID_pkcs7_enveloped:
458 rsk=p7->d.enveloped->recipientinfo;
459 enc_alg=p7->d.enveloped->enc_data->algorithm;
460 data_body=p7->d.enveloped->enc_data->enc_data;
461 evp_cipher=EVP_get_cipherbyobj(enc_alg->algorithm);
462 if (evp_cipher == NULL)
463 {
464 PKCS7err(PKCS7_F_PKCS7_DATADECODE,PKCS7_R_UNSUPPORTED_CIPHER_TYPE);
465 goto err;
466 }
467 break;
468 default:
469 PKCS7err(PKCS7_F_PKCS7_DATADECODE,PKCS7_R_UNSUPPORTED_CONTENT_TYPE);
470 goto err;
471 }
472
473 /* We will be checking the signature */
474 if (md_sk != NULL)
475 {
476 for (i=0; i<sk_X509_ALGOR_num(md_sk); i++)
477 {
478 xa=sk_X509_ALGOR_value(md_sk,i);
479 if ((btmp=BIO_new(BIO_f_md())) == NULL)
480 {
481 PKCS7err(PKCS7_F_PKCS7_DATADECODE,ERR_R_BIO_LIB);
482 goto err;
483 }
484
485 j=OBJ_obj2nid(xa->algorithm);
486 evp_md=EVP_get_digestbynid(j);
487 if (evp_md == NULL)
488 {
489 PKCS7err(PKCS7_F_PKCS7_DATADECODE,PKCS7_R_UNKNOWN_DIGEST_TYPE);
490 goto err;
491 }
492
493 BIO_set_md(btmp,evp_md);
494 if (out == NULL)
495 out=btmp;
496 else
497 BIO_push(out,btmp);
498 btmp=NULL;
499 }
500 }
501
502 if (evp_cipher != NULL)
503 {
504#if 0
505 unsigned char key[EVP_MAX_KEY_LENGTH];
506 unsigned char iv[EVP_MAX_IV_LENGTH];
507 unsigned char *p;
508 int keylen,ivlen;
509 int max;
510 X509_OBJECT ret;
511#endif
512
513 if ((etmp=BIO_new(BIO_f_cipher())) == NULL)
514 {
515 PKCS7err(PKCS7_F_PKCS7_DATADECODE,ERR_R_BIO_LIB);
516 goto err;
517 }
518
519 /* It was encrypted, we need to decrypt the secret key
520 * with the private key */
521
522 /* Find the recipientInfo which matches the passed certificate
523 * (if any)
524 */
525
526 if (pcert)
527 {
528 for (i=0; i<sk_PKCS7_RECIP_INFO_num(rsk); i++)
529 {
530 ri=sk_PKCS7_RECIP_INFO_value(rsk,i);
531 if (!pkcs7_cmp_ri(ri, pcert))
532 break;
533 ri=NULL;
534 }
535 if (ri == NULL)
536 {
537 PKCS7err(PKCS7_F_PKCS7_DATADECODE,
538 PKCS7_R_NO_RECIPIENT_MATCHES_CERTIFICATE);
539 goto err;
540 }
541 }
542
543 /* If we haven't got a certificate try each ri in turn */
544 if (pcert == NULL)
545 {
546 /* Always attempt to decrypt all rinfo even
547 * after sucess as a defence against MMA timing
548 * attacks.
549 */
550 for (i=0; i<sk_PKCS7_RECIP_INFO_num(rsk); i++)
551 {
552 ri=sk_PKCS7_RECIP_INFO_value(rsk,i);
553
554 if (pkcs7_decrypt_rinfo(&ek, &eklen,
555 ri, pkey) < 0)
556 goto err;
557 ERR_clear_error();
558 }
559 }
560 else
561 {
562 /* Only exit on fatal errors, not decrypt failure */
563 if (pkcs7_decrypt_rinfo(&ek, &eklen, ri, pkey) < 0)
564 goto err;
565 ERR_clear_error();
566 }
567
568 evp_ctx=NULL;
569 BIO_get_cipher_ctx(etmp,&evp_ctx);
570 if (EVP_CipherInit_ex(evp_ctx,evp_cipher,NULL,NULL,NULL,0) <= 0)
571 goto err;
572 if (EVP_CIPHER_asn1_to_param(evp_ctx,enc_alg->parameter) < 0)
573 goto err;
574 /* Generate random key as MMA defence */
575 tkeylen = EVP_CIPHER_CTX_key_length(evp_ctx);
576 tkey = OPENSSL_malloc(tkeylen);
577 if (!tkey)
578 goto err;
579 if (EVP_CIPHER_CTX_rand_key(evp_ctx, tkey) <= 0)
580 goto err;
581 if (ek == NULL)
582 {
583 ek = tkey;
584 eklen = tkeylen;
585 tkey = NULL;
586 }
587
588 if (eklen != EVP_CIPHER_CTX_key_length(evp_ctx)) {
589 /* Some S/MIME clients don't use the same key
590 * and effective key length. The key length is
591 * determined by the size of the decrypted RSA key.
592 */
593 if(!EVP_CIPHER_CTX_set_key_length(evp_ctx, eklen))
594 {
595 /* Use random key as MMA defence */
596 OPENSSL_cleanse(ek, eklen);
597 OPENSSL_free(ek);
598 ek = tkey;
599 eklen = tkeylen;
600 tkey = NULL;
601 }
602 }
603 /* Clear errors so we don't leak information useful in MMA */
604 ERR_clear_error();
605 if (EVP_CipherInit_ex(evp_ctx,NULL,NULL,ek,NULL,0) <= 0)
606 goto err;
607
608 if (ek)
609 {
610 OPENSSL_cleanse(ek,eklen);
611 OPENSSL_free(ek);
612 ek = NULL;
613 }
614 if (tkey)
615 {
616 OPENSSL_cleanse(tkey,tkeylen);
617 OPENSSL_free(tkey);
618 tkey = NULL;
619 }
620
621 if (out == NULL)
622 out=etmp;
623 else
624 BIO_push(out,etmp);
625 etmp=NULL;
626 }
627
628#if 1
629 if (PKCS7_is_detached(p7) || (in_bio != NULL))
630 {
631 bio=in_bio;
632 }
633 else
634 {
635#if 0
636 bio=BIO_new(BIO_s_mem());
637 /* We need to set this so that when we have read all
638 * the data, the encrypt BIO, if present, will read
639 * EOF and encode the last few bytes */
640 BIO_set_mem_eof_return(bio,0);
641
642 if (data_body->length > 0)
643 BIO_write(bio,(char *)data_body->data,data_body->length);
644#else
645 if (data_body->length > 0)
646 bio = BIO_new_mem_buf(data_body->data,data_body->length);
647 else {
648 bio=BIO_new(BIO_s_mem());
649 BIO_set_mem_eof_return(bio,0);
650 }
651 if (bio == NULL)
652 goto err;
653#endif
654 }
655 BIO_push(out,bio);
656 bio=NULL;
657#endif
658 if (0)
659 {
660err:
661 if (ek)
662 {
663 OPENSSL_cleanse(ek,eklen);
664 OPENSSL_free(ek);
665 }
666 if (tkey)
667 {
668 OPENSSL_cleanse(tkey,tkeylen);
669 OPENSSL_free(tkey);
670 }
671 if (out != NULL) BIO_free_all(out);
672 if (btmp != NULL) BIO_free_all(btmp);
673 if (etmp != NULL) BIO_free_all(etmp);
674 if (bio != NULL) BIO_free_all(bio);
675 out=NULL;
676 }
677 return(out);
678 }
679
680static BIO *PKCS7_find_digest(EVP_MD_CTX **pmd, BIO *bio, int nid)
681 {
682 for (;;)
683 {
684 bio=BIO_find_type(bio,BIO_TYPE_MD);
685 if (bio == NULL)
686 {
687 PKCS7err(PKCS7_F_PKCS7_FIND_DIGEST,PKCS7_R_UNABLE_TO_FIND_MESSAGE_DIGEST);
688 return NULL;
689 }
690 BIO_get_md_ctx(bio,pmd);
691 if (*pmd == NULL)
692 {
693 PKCS7err(PKCS7_F_PKCS7_FIND_DIGEST,ERR_R_INTERNAL_ERROR);
694 return NULL;
695 }
696 if (EVP_MD_CTX_type(*pmd) == nid)
697 return bio;
698 bio=BIO_next(bio);
699 }
700 return NULL;
701 }
702
703static int do_pkcs7_signed_attrib(PKCS7_SIGNER_INFO *si, EVP_MD_CTX *mctx)
704 {
705 unsigned char md_data[EVP_MAX_MD_SIZE];
706 unsigned int md_len;
707
708 /* Add signing time if not already present */
709 if (!PKCS7_get_signed_attribute(si, NID_pkcs9_signingTime))
710 {
711 if (!PKCS7_add0_attrib_signing_time(si, NULL))
712 {
713 PKCS7err(PKCS7_F_DO_PKCS7_SIGNED_ATTRIB,
714 ERR_R_MALLOC_FAILURE);
715 return 0;
716 }
717 }
718
719 /* Add digest */
720 if (!EVP_DigestFinal_ex(mctx, md_data,&md_len))
721 {
722 PKCS7err(PKCS7_F_DO_PKCS7_SIGNED_ATTRIB, ERR_R_EVP_LIB);
723 return 0;
724 }
725 if (!PKCS7_add1_attrib_digest(si, md_data, md_len))
726 {
727 PKCS7err(PKCS7_F_DO_PKCS7_SIGNED_ATTRIB, ERR_R_MALLOC_FAILURE);
728 return 0;
729 }
730
731 /* Now sign the attributes */
732 if (!PKCS7_SIGNER_INFO_sign(si))
733 return 0;
734
735 return 1;
736 }
737
738
739int PKCS7_dataFinal(PKCS7 *p7, BIO *bio)
740 {
741 int ret=0;
742 int i,j;
743 BIO *btmp;
744 PKCS7_SIGNER_INFO *si;
745 EVP_MD_CTX *mdc,ctx_tmp;
746 STACK_OF(X509_ATTRIBUTE) *sk;
747 STACK_OF(PKCS7_SIGNER_INFO) *si_sk=NULL;
748 ASN1_OCTET_STRING *os=NULL;
749
750 EVP_MD_CTX_init(&ctx_tmp);
751 i=OBJ_obj2nid(p7->type);
752 p7->state=PKCS7_S_HEADER;
753
754 switch (i)
755 {
756 case NID_pkcs7_data:
757 os = p7->d.data;
758 break;
759 case NID_pkcs7_signedAndEnveloped:
760 /* XXXXXXXXXXXXXXXX */
761 si_sk=p7->d.signed_and_enveloped->signer_info;
762 os = p7->d.signed_and_enveloped->enc_data->enc_data;
763 if (!os)
764 {
765 os=M_ASN1_OCTET_STRING_new();
766 if (!os)
767 {
768 PKCS7err(PKCS7_F_PKCS7_DATAFINAL,ERR_R_MALLOC_FAILURE);
769 goto err;
770 }
771 p7->d.signed_and_enveloped->enc_data->enc_data=os;
772 }
773 break;
774 case NID_pkcs7_enveloped:
775 /* XXXXXXXXXXXXXXXX */
776 os = p7->d.enveloped->enc_data->enc_data;
777 if (!os)
778 {
779 os=M_ASN1_OCTET_STRING_new();
780 if (!os)
781 {
782 PKCS7err(PKCS7_F_PKCS7_DATAFINAL,ERR_R_MALLOC_FAILURE);
783 goto err;
784 }
785 p7->d.enveloped->enc_data->enc_data=os;
786 }
787 break;
788 case NID_pkcs7_signed:
789 si_sk=p7->d.sign->signer_info;
790 os=PKCS7_get_octet_string(p7->d.sign->contents);
791 /* If detached data then the content is excluded */
792 if(PKCS7_type_is_data(p7->d.sign->contents) && p7->detached) {
793 M_ASN1_OCTET_STRING_free(os);
794 p7->d.sign->contents->d.data = NULL;
795 }
796 break;
797
798 case NID_pkcs7_digest:
799 os=PKCS7_get_octet_string(p7->d.digest->contents);
800 /* If detached data then the content is excluded */
801 if(PKCS7_type_is_data(p7->d.digest->contents) && p7->detached)
802 {
803 M_ASN1_OCTET_STRING_free(os);
804 p7->d.digest->contents->d.data = NULL;
805 }
806 break;
807
808 default:
809 PKCS7err(PKCS7_F_PKCS7_DATAFINAL,PKCS7_R_UNSUPPORTED_CONTENT_TYPE);
810 goto err;
811 }
812
813 if (si_sk != NULL)
814 {
815 for (i=0; i<sk_PKCS7_SIGNER_INFO_num(si_sk); i++)
816 {
817 si=sk_PKCS7_SIGNER_INFO_value(si_sk,i);
818 if (si->pkey == NULL)
819 continue;
820
821 j = OBJ_obj2nid(si->digest_alg->algorithm);
822
823 btmp=bio;
824
825 btmp = PKCS7_find_digest(&mdc, btmp, j);
826
827 if (btmp == NULL)
828 goto err;
829
830 /* We now have the EVP_MD_CTX, lets do the
831 * signing. */
832 if (!EVP_MD_CTX_copy_ex(&ctx_tmp,mdc))
833 goto err;
834
835 sk=si->auth_attr;
836
837 /* If there are attributes, we add the digest
838 * attribute and only sign the attributes */
839 if (sk_X509_ATTRIBUTE_num(sk) > 0)
840 {
841 if (!do_pkcs7_signed_attrib(si, &ctx_tmp))
842 goto err;
843 }
844 else
845 {
846 unsigned char *abuf = NULL;
847 unsigned int abuflen;
848 abuflen = EVP_PKEY_size(si->pkey);
849 abuf = OPENSSL_malloc(abuflen);
850 if (!abuf)
851 goto err;
852
853 if (!EVP_SignFinal(&ctx_tmp, abuf, &abuflen,
854 si->pkey))
855 {
856 PKCS7err(PKCS7_F_PKCS7_DATAFINAL,
857 ERR_R_EVP_LIB);
858 goto err;
859 }
860 ASN1_STRING_set0(si->enc_digest, abuf, abuflen);
861 }
862 }
863 }
864 else if (i == NID_pkcs7_digest)
865 {
866 unsigned char md_data[EVP_MAX_MD_SIZE];
867 unsigned int md_len;
868 if (!PKCS7_find_digest(&mdc, bio,
869 OBJ_obj2nid(p7->d.digest->md->algorithm)))
870 goto err;
871 if (!EVP_DigestFinal_ex(mdc,md_data,&md_len))
872 goto err;
873 M_ASN1_OCTET_STRING_set(p7->d.digest->digest, md_data, md_len);
874 }
875
876 if (!PKCS7_is_detached(p7) && !(os->flags & ASN1_STRING_FLAG_NDEF))
877 {
878 char *cont;
879 long contlen;
880 btmp=BIO_find_type(bio,BIO_TYPE_MEM);
881 if (btmp == NULL)
882 {
883 PKCS7err(PKCS7_F_PKCS7_DATAFINAL,PKCS7_R_UNABLE_TO_FIND_MEM_BIO);
884 goto err;
885 }
886 contlen = BIO_get_mem_data(btmp, &cont);
887 /* Mark the BIO read only then we can use its copy of the data
888 * instead of making an extra copy.
889 */
890 BIO_set_flags(btmp, BIO_FLAGS_MEM_RDONLY);
891 BIO_set_mem_eof_return(btmp, 0);
892 ASN1_STRING_set0(os, (unsigned char *)cont, contlen);
893 }
894 ret=1;
895err:
896 EVP_MD_CTX_cleanup(&ctx_tmp);
897 return(ret);
898 }
899
900int PKCS7_SIGNER_INFO_sign(PKCS7_SIGNER_INFO *si)
901 {
902 EVP_MD_CTX mctx;
903 EVP_PKEY_CTX *pctx;
904 unsigned char *abuf = NULL;
905 int alen;
906 size_t siglen;
907 const EVP_MD *md = NULL;
908
909 md = EVP_get_digestbyobj(si->digest_alg->algorithm);
910 if (md == NULL)
911 return 0;
912
913 EVP_MD_CTX_init(&mctx);
914 if (EVP_DigestSignInit(&mctx, &pctx, md,NULL, si->pkey) <= 0)
915 goto err;
916
917 if (EVP_PKEY_CTX_ctrl(pctx, -1, EVP_PKEY_OP_SIGN,
918 EVP_PKEY_CTRL_PKCS7_SIGN, 0, si) <= 0)
919 {
920 PKCS7err(PKCS7_F_PKCS7_SIGNER_INFO_SIGN, PKCS7_R_CTRL_ERROR);
921 goto err;
922 }
923
924 alen = ASN1_item_i2d((ASN1_VALUE *)si->auth_attr,&abuf,
925 ASN1_ITEM_rptr(PKCS7_ATTR_SIGN));
926 if(!abuf)
927 goto err;
928 if (EVP_DigestSignUpdate(&mctx,abuf,alen) <= 0)
929 goto err;
930 OPENSSL_free(abuf);
931 if (EVP_DigestSignFinal(&mctx, NULL, &siglen) <= 0)
932 goto err;
933 abuf = OPENSSL_malloc(siglen);
934 if(!abuf)
935 goto err;
936 if (EVP_DigestSignFinal(&mctx, abuf, &siglen) <= 0)
937 goto err;
938
939 if (EVP_PKEY_CTX_ctrl(pctx, -1, EVP_PKEY_OP_SIGN,
940 EVP_PKEY_CTRL_PKCS7_SIGN, 1, si) <= 0)
941 {
942 PKCS7err(PKCS7_F_PKCS7_SIGNER_INFO_SIGN, PKCS7_R_CTRL_ERROR);
943 goto err;
944 }
945
946 EVP_MD_CTX_cleanup(&mctx);
947
948 ASN1_STRING_set0(si->enc_digest, abuf, siglen);
949
950 return 1;
951
952 err:
953 if (abuf)
954 OPENSSL_free(abuf);
955 EVP_MD_CTX_cleanup(&mctx);
956 return 0;
957
958 }
959
960int PKCS7_dataVerify(X509_STORE *cert_store, X509_STORE_CTX *ctx, BIO *bio,
961 PKCS7 *p7, PKCS7_SIGNER_INFO *si)
962 {
963 PKCS7_ISSUER_AND_SERIAL *ias;
964 int ret=0,i;
965 STACK_OF(X509) *cert;
966 X509 *x509;
967
968 if (PKCS7_type_is_signed(p7))
969 {
970 cert=p7->d.sign->cert;
971 }
972 else if (PKCS7_type_is_signedAndEnveloped(p7))
973 {
974 cert=p7->d.signed_and_enveloped->cert;
975 }
976 else
977 {
978 PKCS7err(PKCS7_F_PKCS7_DATAVERIFY,PKCS7_R_WRONG_PKCS7_TYPE);
979 goto err;
980 }
981 /* XXXXXXXXXXXXXXXXXXXXXXX */
982 ias=si->issuer_and_serial;
983
984 x509=X509_find_by_issuer_and_serial(cert,ias->issuer,ias->serial);
985
986 /* were we able to find the cert in passed to us */
987 if (x509 == NULL)
988 {
989 PKCS7err(PKCS7_F_PKCS7_DATAVERIFY,PKCS7_R_UNABLE_TO_FIND_CERTIFICATE);
990 goto err;
991 }
992
993 /* Lets verify */
994 if(!X509_STORE_CTX_init(ctx,cert_store,x509,cert))
995 {
996 PKCS7err(PKCS7_F_PKCS7_DATAVERIFY,ERR_R_X509_LIB);
997 goto err;
998 }
999 X509_STORE_CTX_set_purpose(ctx, X509_PURPOSE_SMIME_SIGN);
1000 i=X509_verify_cert(ctx);
1001 if (i <= 0)
1002 {
1003 PKCS7err(PKCS7_F_PKCS7_DATAVERIFY,ERR_R_X509_LIB);
1004 X509_STORE_CTX_cleanup(ctx);
1005 goto err;
1006 }
1007 X509_STORE_CTX_cleanup(ctx);
1008
1009 return PKCS7_signatureVerify(bio, p7, si, x509);
1010 err:
1011 return ret;
1012 }
1013
1014int PKCS7_signatureVerify(BIO *bio, PKCS7 *p7, PKCS7_SIGNER_INFO *si,
1015 X509 *x509)
1016 {
1017 ASN1_OCTET_STRING *os;
1018 EVP_MD_CTX mdc_tmp,*mdc;
1019 int ret=0,i;
1020 int md_type;
1021 STACK_OF(X509_ATTRIBUTE) *sk;
1022 BIO *btmp;
1023 EVP_PKEY *pkey;
1024
1025 EVP_MD_CTX_init(&mdc_tmp);
1026
1027 if (!PKCS7_type_is_signed(p7) &&
1028 !PKCS7_type_is_signedAndEnveloped(p7)) {
1029 PKCS7err(PKCS7_F_PKCS7_SIGNATUREVERIFY,
1030 PKCS7_R_WRONG_PKCS7_TYPE);
1031 goto err;
1032 }
1033
1034 md_type=OBJ_obj2nid(si->digest_alg->algorithm);
1035
1036 btmp=bio;
1037 for (;;)
1038 {
1039 if ((btmp == NULL) ||
1040 ((btmp=BIO_find_type(btmp,BIO_TYPE_MD)) == NULL))
1041 {
1042 PKCS7err(PKCS7_F_PKCS7_SIGNATUREVERIFY,
1043 PKCS7_R_UNABLE_TO_FIND_MESSAGE_DIGEST);
1044 goto err;
1045 }
1046 BIO_get_md_ctx(btmp,&mdc);
1047 if (mdc == NULL)
1048 {
1049 PKCS7err(PKCS7_F_PKCS7_SIGNATUREVERIFY,
1050 ERR_R_INTERNAL_ERROR);
1051 goto err;
1052 }
1053 if (EVP_MD_CTX_type(mdc) == md_type)
1054 break;
1055 /* Workaround for some broken clients that put the signature
1056 * OID instead of the digest OID in digest_alg->algorithm
1057 */
1058 if (EVP_MD_pkey_type(EVP_MD_CTX_md(mdc)) == md_type)
1059 break;
1060 btmp=BIO_next(btmp);
1061 }
1062
1063 /* mdc is the digest ctx that we want, unless there are attributes,
1064 * in which case the digest is the signed attributes */
1065 if (!EVP_MD_CTX_copy_ex(&mdc_tmp,mdc))
1066 goto err;
1067
1068 sk=si->auth_attr;
1069 if ((sk != NULL) && (sk_X509_ATTRIBUTE_num(sk) != 0))
1070 {
1071 unsigned char md_dat[EVP_MAX_MD_SIZE], *abuf = NULL;
1072 unsigned int md_len;
1073 int alen;
1074 ASN1_OCTET_STRING *message_digest;
1075
1076 if (!EVP_DigestFinal_ex(&mdc_tmp,md_dat,&md_len))
1077 goto err;
1078 message_digest=PKCS7_digest_from_attributes(sk);
1079 if (!message_digest)
1080 {
1081 PKCS7err(PKCS7_F_PKCS7_SIGNATUREVERIFY,
1082 PKCS7_R_UNABLE_TO_FIND_MESSAGE_DIGEST);
1083 goto err;
1084 }
1085 if ((message_digest->length != (int)md_len) ||
1086 (memcmp(message_digest->data,md_dat,md_len)))
1087 {
1088#if 0
1089{
1090int ii;
1091for (ii=0; ii<message_digest->length; ii++)
1092 printf("%02X",message_digest->data[ii]); printf(" sent\n");
1093for (ii=0; ii<md_len; ii++) printf("%02X",md_dat[ii]); printf(" calc\n");
1094}
1095#endif
1096 PKCS7err(PKCS7_F_PKCS7_SIGNATUREVERIFY,
1097 PKCS7_R_DIGEST_FAILURE);
1098 ret= -1;
1099 goto err;
1100 }
1101
1102 if (!EVP_VerifyInit_ex(&mdc_tmp,EVP_get_digestbynid(md_type), NULL))
1103 goto err;
1104
1105 alen = ASN1_item_i2d((ASN1_VALUE *)sk, &abuf,
1106 ASN1_ITEM_rptr(PKCS7_ATTR_VERIFY));
1107 if (alen <= 0)
1108 {
1109 PKCS7err(PKCS7_F_PKCS7_SIGNATUREVERIFY,ERR_R_ASN1_LIB);
1110 ret = -1;
1111 goto err;
1112 }
1113 if (!EVP_VerifyUpdate(&mdc_tmp, abuf, alen))
1114 goto err;
1115
1116 OPENSSL_free(abuf);
1117 }
1118
1119 os=si->enc_digest;
1120 pkey = X509_get_pubkey(x509);
1121 if (!pkey)
1122 {
1123 ret = -1;
1124 goto err;
1125 }
1126
1127 i=EVP_VerifyFinal(&mdc_tmp,os->data,os->length, pkey);
1128 EVP_PKEY_free(pkey);
1129 if (i <= 0)
1130 {
1131 PKCS7err(PKCS7_F_PKCS7_SIGNATUREVERIFY,
1132 PKCS7_R_SIGNATURE_FAILURE);
1133 ret= -1;
1134 goto err;
1135 }
1136 else
1137 ret=1;
1138err:
1139 EVP_MD_CTX_cleanup(&mdc_tmp);
1140 return(ret);
1141 }
1142
1143PKCS7_ISSUER_AND_SERIAL *PKCS7_get_issuer_and_serial(PKCS7 *p7, int idx)
1144 {
1145 STACK_OF(PKCS7_RECIP_INFO) *rsk;
1146 PKCS7_RECIP_INFO *ri;
1147 int i;
1148
1149 i=OBJ_obj2nid(p7->type);
1150 if (i != NID_pkcs7_signedAndEnveloped)
1151 return NULL;
1152 if (p7->d.signed_and_enveloped == NULL)
1153 return NULL;
1154 rsk=p7->d.signed_and_enveloped->recipientinfo;
1155 if (rsk == NULL)
1156 return NULL;
1157 ri=sk_PKCS7_RECIP_INFO_value(rsk,0);
1158 if (sk_PKCS7_RECIP_INFO_num(rsk) <= idx) return(NULL);
1159 ri=sk_PKCS7_RECIP_INFO_value(rsk,idx);
1160 return(ri->issuer_and_serial);
1161 }
1162
1163ASN1_TYPE *PKCS7_get_signed_attribute(PKCS7_SIGNER_INFO *si, int nid)
1164 {
1165 return(get_attribute(si->auth_attr,nid));
1166 }
1167
1168ASN1_TYPE *PKCS7_get_attribute(PKCS7_SIGNER_INFO *si, int nid)
1169 {
1170 return(get_attribute(si->unauth_attr,nid));
1171 }
1172
1173static ASN1_TYPE *get_attribute(STACK_OF(X509_ATTRIBUTE) *sk, int nid)
1174 {
1175 int i;
1176 X509_ATTRIBUTE *xa;
1177 ASN1_OBJECT *o;
1178
1179 o=OBJ_nid2obj(nid);
1180 if (!o || !sk) return(NULL);
1181 for (i=0; i<sk_X509_ATTRIBUTE_num(sk); i++)
1182 {
1183 xa=sk_X509_ATTRIBUTE_value(sk,i);
1184 if (OBJ_cmp(xa->object,o) == 0)
1185 {
1186 if (!xa->single && sk_ASN1_TYPE_num(xa->value.set))
1187 return(sk_ASN1_TYPE_value(xa->value.set,0));
1188 else
1189 return(NULL);
1190 }
1191 }
1192 return(NULL);
1193 }
1194
1195ASN1_OCTET_STRING *PKCS7_digest_from_attributes(STACK_OF(X509_ATTRIBUTE) *sk)
1196{
1197 ASN1_TYPE *astype;
1198 if(!(astype = get_attribute(sk, NID_pkcs9_messageDigest))) return NULL;
1199 return astype->value.octet_string;
1200}
1201
1202int PKCS7_set_signed_attributes(PKCS7_SIGNER_INFO *p7si,
1203 STACK_OF(X509_ATTRIBUTE) *sk)
1204 {
1205 int i;
1206
1207 if (p7si->auth_attr != NULL)
1208 sk_X509_ATTRIBUTE_pop_free(p7si->auth_attr,X509_ATTRIBUTE_free);
1209 p7si->auth_attr=sk_X509_ATTRIBUTE_dup(sk);
1210 if (p7si->auth_attr == NULL)
1211 return 0;
1212 for (i=0; i<sk_X509_ATTRIBUTE_num(sk); i++)
1213 {
1214 if ((sk_X509_ATTRIBUTE_set(p7si->auth_attr,i,
1215 X509_ATTRIBUTE_dup(sk_X509_ATTRIBUTE_value(sk,i))))
1216 == NULL)
1217 return(0);
1218 }
1219 return(1);
1220 }
1221
1222int PKCS7_set_attributes(PKCS7_SIGNER_INFO *p7si, STACK_OF(X509_ATTRIBUTE) *sk)
1223 {
1224 int i;
1225
1226 if (p7si->unauth_attr != NULL)
1227 sk_X509_ATTRIBUTE_pop_free(p7si->unauth_attr,
1228 X509_ATTRIBUTE_free);
1229 p7si->unauth_attr=sk_X509_ATTRIBUTE_dup(sk);
1230 if (p7si->unauth_attr == NULL)
1231 return 0;
1232 for (i=0; i<sk_X509_ATTRIBUTE_num(sk); i++)
1233 {
1234 if ((sk_X509_ATTRIBUTE_set(p7si->unauth_attr,i,
1235 X509_ATTRIBUTE_dup(sk_X509_ATTRIBUTE_value(sk,i))))
1236 == NULL)
1237 return(0);
1238 }
1239 return(1);
1240 }
1241
1242int PKCS7_add_signed_attribute(PKCS7_SIGNER_INFO *p7si, int nid, int atrtype,
1243 void *value)
1244 {
1245 return(add_attribute(&(p7si->auth_attr),nid,atrtype,value));
1246 }
1247
1248int PKCS7_add_attribute(PKCS7_SIGNER_INFO *p7si, int nid, int atrtype,
1249 void *value)
1250 {
1251 return(add_attribute(&(p7si->unauth_attr),nid,atrtype,value));
1252 }
1253
1254static int add_attribute(STACK_OF(X509_ATTRIBUTE) **sk, int nid, int atrtype,
1255 void *value)
1256 {
1257 X509_ATTRIBUTE *attr=NULL;
1258
1259 if (*sk == NULL)
1260 {
1261 *sk = sk_X509_ATTRIBUTE_new_null();
1262 if (*sk == NULL)
1263 return 0;
1264new_attrib:
1265 if (!(attr=X509_ATTRIBUTE_create(nid,atrtype,value)))
1266 return 0;
1267 if (!sk_X509_ATTRIBUTE_push(*sk,attr))
1268 {
1269 X509_ATTRIBUTE_free(attr);
1270 return 0;
1271 }
1272 }
1273 else
1274 {
1275 int i;
1276
1277 for (i=0; i<sk_X509_ATTRIBUTE_num(*sk); i++)
1278 {
1279 attr=sk_X509_ATTRIBUTE_value(*sk,i);
1280 if (OBJ_obj2nid(attr->object) == nid)
1281 {
1282 X509_ATTRIBUTE_free(attr);
1283 attr=X509_ATTRIBUTE_create(nid,atrtype,value);
1284 if (attr == NULL)
1285 return 0;
1286 if (!sk_X509_ATTRIBUTE_set(*sk,i,attr))
1287 {
1288 X509_ATTRIBUTE_free(attr);
1289 return 0;
1290 }
1291 goto end;
1292 }
1293 }
1294 goto new_attrib;
1295 }
1296end:
1297 return(1);
1298 }
1299
diff --git a/src/lib/libcrypto/pkcs7/pk7_lib.c b/src/lib/libcrypto/pkcs7/pk7_lib.c
deleted file mode 100644
index d411269b50..0000000000
--- a/src/lib/libcrypto/pkcs7/pk7_lib.c
+++ /dev/null
@@ -1,665 +0,0 @@
1/* crypto/pkcs7/pk7_lib.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/objects.h>
62#include <openssl/x509.h>
63#include "asn1_locl.h"
64
65long PKCS7_ctrl(PKCS7 *p7, int cmd, long larg, char *parg)
66 {
67 int nid;
68 long ret;
69
70 nid=OBJ_obj2nid(p7->type);
71
72 switch (cmd)
73 {
74 case PKCS7_OP_SET_DETACHED_SIGNATURE:
75 if (nid == NID_pkcs7_signed)
76 {
77 ret=p7->detached=(int)larg;
78 if (ret && PKCS7_type_is_data(p7->d.sign->contents))
79 {
80 ASN1_OCTET_STRING *os;
81 os=p7->d.sign->contents->d.data;
82 ASN1_OCTET_STRING_free(os);
83 p7->d.sign->contents->d.data = NULL;
84 }
85 }
86 else
87 {
88 PKCS7err(PKCS7_F_PKCS7_CTRL,PKCS7_R_OPERATION_NOT_SUPPORTED_ON_THIS_TYPE);
89 ret=0;
90 }
91 break;
92 case PKCS7_OP_GET_DETACHED_SIGNATURE:
93 if (nid == NID_pkcs7_signed)
94 {
95 if(!p7->d.sign || !p7->d.sign->contents->d.ptr)
96 ret = 1;
97 else ret = 0;
98
99 p7->detached = ret;
100 }
101 else
102 {
103 PKCS7err(PKCS7_F_PKCS7_CTRL,PKCS7_R_OPERATION_NOT_SUPPORTED_ON_THIS_TYPE);
104 ret=0;
105 }
106
107 break;
108 default:
109 PKCS7err(PKCS7_F_PKCS7_CTRL,PKCS7_R_UNKNOWN_OPERATION);
110 ret=0;
111 }
112 return(ret);
113 }
114
115int PKCS7_content_new(PKCS7 *p7, int type)
116 {
117 PKCS7 *ret=NULL;
118
119 if ((ret=PKCS7_new()) == NULL) goto err;
120 if (!PKCS7_set_type(ret,type)) goto err;
121 if (!PKCS7_set_content(p7,ret)) goto err;
122
123 return(1);
124err:
125 if (ret != NULL) PKCS7_free(ret);
126 return(0);
127 }
128
129int PKCS7_set_content(PKCS7 *p7, PKCS7 *p7_data)
130 {
131 int i;
132
133 i=OBJ_obj2nid(p7->type);
134 switch (i)
135 {
136 case NID_pkcs7_signed:
137 if (p7->d.sign->contents != NULL)
138 PKCS7_free(p7->d.sign->contents);
139 p7->d.sign->contents=p7_data;
140 break;
141 case NID_pkcs7_digest:
142 if (p7->d.digest->contents != NULL)
143 PKCS7_free(p7->d.digest->contents);
144 p7->d.digest->contents=p7_data;
145 break;
146 case NID_pkcs7_data:
147 case NID_pkcs7_enveloped:
148 case NID_pkcs7_signedAndEnveloped:
149 case NID_pkcs7_encrypted:
150 default:
151 PKCS7err(PKCS7_F_PKCS7_SET_CONTENT,PKCS7_R_UNSUPPORTED_CONTENT_TYPE);
152 goto err;
153 }
154 return(1);
155err:
156 return(0);
157 }
158
159int PKCS7_set_type(PKCS7 *p7, int type)
160 {
161 ASN1_OBJECT *obj;
162
163 /*PKCS7_content_free(p7);*/
164 obj=OBJ_nid2obj(type); /* will not fail */
165
166 switch (type)
167 {
168 case NID_pkcs7_signed:
169 p7->type=obj;
170 if ((p7->d.sign=PKCS7_SIGNED_new()) == NULL)
171 goto err;
172 if (!ASN1_INTEGER_set(p7->d.sign->version,1))
173 {
174 PKCS7_SIGNED_free(p7->d.sign);
175 p7->d.sign=NULL;
176 goto err;
177 }
178 break;
179 case NID_pkcs7_data:
180 p7->type=obj;
181 if ((p7->d.data=M_ASN1_OCTET_STRING_new()) == NULL)
182 goto err;
183 break;
184 case NID_pkcs7_signedAndEnveloped:
185 p7->type=obj;
186 if ((p7->d.signed_and_enveloped=PKCS7_SIGN_ENVELOPE_new())
187 == NULL) goto err;
188 ASN1_INTEGER_set(p7->d.signed_and_enveloped->version,1);
189 if (!ASN1_INTEGER_set(p7->d.signed_and_enveloped->version,1))
190 goto err;
191 p7->d.signed_and_enveloped->enc_data->content_type
192 = OBJ_nid2obj(NID_pkcs7_data);
193 break;
194 case NID_pkcs7_enveloped:
195 p7->type=obj;
196 if ((p7->d.enveloped=PKCS7_ENVELOPE_new())
197 == NULL) goto err;
198 if (!ASN1_INTEGER_set(p7->d.enveloped->version,0))
199 goto err;
200 p7->d.enveloped->enc_data->content_type
201 = OBJ_nid2obj(NID_pkcs7_data);
202 break;
203 case NID_pkcs7_encrypted:
204 p7->type=obj;
205 if ((p7->d.encrypted=PKCS7_ENCRYPT_new())
206 == NULL) goto err;
207 if (!ASN1_INTEGER_set(p7->d.encrypted->version,0))
208 goto err;
209 p7->d.encrypted->enc_data->content_type
210 = OBJ_nid2obj(NID_pkcs7_data);
211 break;
212
213 case NID_pkcs7_digest:
214 p7->type=obj;
215 if ((p7->d.digest=PKCS7_DIGEST_new())
216 == NULL) goto err;
217 if (!ASN1_INTEGER_set(p7->d.digest->version,0))
218 goto err;
219 break;
220 default:
221 PKCS7err(PKCS7_F_PKCS7_SET_TYPE,PKCS7_R_UNSUPPORTED_CONTENT_TYPE);
222 goto err;
223 }
224 return(1);
225err:
226 return(0);
227 }
228
229int PKCS7_set0_type_other(PKCS7 *p7, int type, ASN1_TYPE *other)
230 {
231 p7->type = OBJ_nid2obj(type);
232 p7->d.other = other;
233 return 1;
234 }
235
236int PKCS7_add_signer(PKCS7 *p7, PKCS7_SIGNER_INFO *psi)
237 {
238 int i,j,nid;
239 X509_ALGOR *alg;
240 STACK_OF(PKCS7_SIGNER_INFO) *signer_sk;
241 STACK_OF(X509_ALGOR) *md_sk;
242
243 i=OBJ_obj2nid(p7->type);
244 switch (i)
245 {
246 case NID_pkcs7_signed:
247 signer_sk= p7->d.sign->signer_info;
248 md_sk= p7->d.sign->md_algs;
249 break;
250 case NID_pkcs7_signedAndEnveloped:
251 signer_sk= p7->d.signed_and_enveloped->signer_info;
252 md_sk= p7->d.signed_and_enveloped->md_algs;
253 break;
254 default:
255 PKCS7err(PKCS7_F_PKCS7_ADD_SIGNER,PKCS7_R_WRONG_CONTENT_TYPE);
256 return(0);
257 }
258
259 nid=OBJ_obj2nid(psi->digest_alg->algorithm);
260
261 /* If the digest is not currently listed, add it */
262 j=0;
263 for (i=0; i<sk_X509_ALGOR_num(md_sk); i++)
264 {
265 alg=sk_X509_ALGOR_value(md_sk,i);
266 if (OBJ_obj2nid(alg->algorithm) == nid)
267 {
268 j=1;
269 break;
270 }
271 }
272 if (!j) /* we need to add another algorithm */
273 {
274 if(!(alg=X509_ALGOR_new())
275 || !(alg->parameter = ASN1_TYPE_new()))
276 {
277 X509_ALGOR_free(alg);
278 PKCS7err(PKCS7_F_PKCS7_ADD_SIGNER,ERR_R_MALLOC_FAILURE);
279 return(0);
280 }
281 alg->algorithm=OBJ_nid2obj(nid);
282 alg->parameter->type = V_ASN1_NULL;
283 if (!sk_X509_ALGOR_push(md_sk,alg))
284 {
285 X509_ALGOR_free(alg);
286 return 0;
287 }
288 }
289
290 if (!sk_PKCS7_SIGNER_INFO_push(signer_sk,psi))
291 return 0;
292 return(1);
293 }
294
295int PKCS7_add_certificate(PKCS7 *p7, X509 *x509)
296 {
297 int i;
298 STACK_OF(X509) **sk;
299
300 i=OBJ_obj2nid(p7->type);
301 switch (i)
302 {
303 case NID_pkcs7_signed:
304 sk= &(p7->d.sign->cert);
305 break;
306 case NID_pkcs7_signedAndEnveloped:
307 sk= &(p7->d.signed_and_enveloped->cert);
308 break;
309 default:
310 PKCS7err(PKCS7_F_PKCS7_ADD_CERTIFICATE,PKCS7_R_WRONG_CONTENT_TYPE);
311 return(0);
312 }
313
314 if (*sk == NULL)
315 *sk=sk_X509_new_null();
316 if (*sk == NULL)
317 {
318 PKCS7err(PKCS7_F_PKCS7_ADD_CERTIFICATE, ERR_R_MALLOC_FAILURE);
319 return 0;
320 }
321 CRYPTO_add(&x509->references,1,CRYPTO_LOCK_X509);
322 if (!sk_X509_push(*sk,x509))
323 {
324 X509_free(x509);
325 return 0;
326 }
327 return(1);
328 }
329
330int PKCS7_add_crl(PKCS7 *p7, X509_CRL *crl)
331 {
332 int i;
333 STACK_OF(X509_CRL) **sk;
334
335 i=OBJ_obj2nid(p7->type);
336 switch (i)
337 {
338 case NID_pkcs7_signed:
339 sk= &(p7->d.sign->crl);
340 break;
341 case NID_pkcs7_signedAndEnveloped:
342 sk= &(p7->d.signed_and_enveloped->crl);
343 break;
344 default:
345 PKCS7err(PKCS7_F_PKCS7_ADD_CRL,PKCS7_R_WRONG_CONTENT_TYPE);
346 return(0);
347 }
348
349 if (*sk == NULL)
350 *sk=sk_X509_CRL_new_null();
351 if (*sk == NULL)
352 {
353 PKCS7err(PKCS7_F_PKCS7_ADD_CRL,ERR_R_MALLOC_FAILURE);
354 return 0;
355 }
356
357 CRYPTO_add(&crl->references,1,CRYPTO_LOCK_X509_CRL);
358 if (!sk_X509_CRL_push(*sk,crl))
359 {
360 X509_CRL_free(crl);
361 return 0;
362 }
363 return(1);
364 }
365
366int PKCS7_SIGNER_INFO_set(PKCS7_SIGNER_INFO *p7i, X509 *x509, EVP_PKEY *pkey,
367 const EVP_MD *dgst)
368 {
369 int ret;
370
371 /* We now need to add another PKCS7_SIGNER_INFO entry */
372 if (!ASN1_INTEGER_set(p7i->version,1))
373 goto err;
374 if (!X509_NAME_set(&p7i->issuer_and_serial->issuer,
375 X509_get_issuer_name(x509)))
376 goto err;
377
378 /* because ASN1_INTEGER_set is used to set a 'long' we will do
379 * things the ugly way. */
380 M_ASN1_INTEGER_free(p7i->issuer_and_serial->serial);
381 if (!(p7i->issuer_and_serial->serial=
382 M_ASN1_INTEGER_dup(X509_get_serialNumber(x509))))
383 goto err;
384
385 /* lets keep the pkey around for a while */
386 CRYPTO_add(&pkey->references,1,CRYPTO_LOCK_EVP_PKEY);
387 p7i->pkey=pkey;
388
389 /* Set the algorithms */
390
391 X509_ALGOR_set0(p7i->digest_alg, OBJ_nid2obj(EVP_MD_type(dgst)),
392 V_ASN1_NULL, NULL);
393
394 if (pkey->ameth && pkey->ameth->pkey_ctrl)
395 {
396 ret = pkey->ameth->pkey_ctrl(pkey, ASN1_PKEY_CTRL_PKCS7_SIGN,
397 0, p7i);
398 if (ret > 0)
399 return 1;
400 if (ret != -2)
401 {
402 PKCS7err(PKCS7_F_PKCS7_SIGNER_INFO_SET,
403 PKCS7_R_SIGNING_CTRL_FAILURE);
404 return 0;
405 }
406 }
407 PKCS7err(PKCS7_F_PKCS7_SIGNER_INFO_SET,
408 PKCS7_R_SIGNING_NOT_SUPPORTED_FOR_THIS_KEY_TYPE);
409err:
410 return 0;
411 }
412
413PKCS7_SIGNER_INFO *PKCS7_add_signature(PKCS7 *p7, X509 *x509, EVP_PKEY *pkey,
414 const EVP_MD *dgst)
415 {
416 PKCS7_SIGNER_INFO *si = NULL;
417
418 if (dgst == NULL)
419 {
420 int def_nid;
421 if (EVP_PKEY_get_default_digest_nid(pkey, &def_nid) <= 0)
422 goto err;
423 dgst = EVP_get_digestbynid(def_nid);
424 if (dgst == NULL)
425 {
426 PKCS7err(PKCS7_F_PKCS7_ADD_SIGNATURE,
427 PKCS7_R_NO_DEFAULT_DIGEST);
428 goto err;
429 }
430 }
431
432 if ((si=PKCS7_SIGNER_INFO_new()) == NULL) goto err;
433 if (!PKCS7_SIGNER_INFO_set(si,x509,pkey,dgst)) goto err;
434 if (!PKCS7_add_signer(p7,si)) goto err;
435 return(si);
436err:
437 if (si)
438 PKCS7_SIGNER_INFO_free(si);
439 return(NULL);
440 }
441
442int PKCS7_set_digest(PKCS7 *p7, const EVP_MD *md)
443 {
444 if (PKCS7_type_is_digest(p7))
445 {
446 if(!(p7->d.digest->md->parameter = ASN1_TYPE_new()))
447 {
448 PKCS7err(PKCS7_F_PKCS7_SET_DIGEST,ERR_R_MALLOC_FAILURE);
449 return 0;
450 }
451 p7->d.digest->md->parameter->type = V_ASN1_NULL;
452 p7->d.digest->md->algorithm = OBJ_nid2obj(EVP_MD_nid(md));
453 return 1;
454 }
455
456 PKCS7err(PKCS7_F_PKCS7_SET_DIGEST,PKCS7_R_WRONG_CONTENT_TYPE);
457 return 1;
458 }
459
460STACK_OF(PKCS7_SIGNER_INFO) *PKCS7_get_signer_info(PKCS7 *p7)
461 {
462 if (PKCS7_type_is_signed(p7))
463 {
464 return(p7->d.sign->signer_info);
465 }
466 else if (PKCS7_type_is_signedAndEnveloped(p7))
467 {
468 return(p7->d.signed_and_enveloped->signer_info);
469 }
470 else
471 return(NULL);
472 }
473
474void PKCS7_SIGNER_INFO_get0_algs(PKCS7_SIGNER_INFO *si, EVP_PKEY **pk,
475 X509_ALGOR **pdig, X509_ALGOR **psig)
476 {
477 if (pk)
478 *pk = si->pkey;
479 if (pdig)
480 *pdig = si->digest_alg;
481 if (psig)
482 *psig = si->digest_enc_alg;
483 }
484
485void PKCS7_RECIP_INFO_get0_alg(PKCS7_RECIP_INFO *ri, X509_ALGOR **penc)
486 {
487 if (penc)
488 *penc = ri->key_enc_algor;
489 }
490
491PKCS7_RECIP_INFO *PKCS7_add_recipient(PKCS7 *p7, X509 *x509)
492 {
493 PKCS7_RECIP_INFO *ri;
494
495 if ((ri=PKCS7_RECIP_INFO_new()) == NULL) goto err;
496 if (!PKCS7_RECIP_INFO_set(ri,x509)) goto err;
497 if (!PKCS7_add_recipient_info(p7,ri)) goto err;
498 return ri;
499err:
500 if (ri)
501 PKCS7_RECIP_INFO_free(ri);
502 return NULL;
503 }
504
505int PKCS7_add_recipient_info(PKCS7 *p7, PKCS7_RECIP_INFO *ri)
506 {
507 int i;
508 STACK_OF(PKCS7_RECIP_INFO) *sk;
509
510 i=OBJ_obj2nid(p7->type);
511 switch (i)
512 {
513 case NID_pkcs7_signedAndEnveloped:
514 sk= p7->d.signed_and_enveloped->recipientinfo;
515 break;
516 case NID_pkcs7_enveloped:
517 sk= p7->d.enveloped->recipientinfo;
518 break;
519 default:
520 PKCS7err(PKCS7_F_PKCS7_ADD_RECIPIENT_INFO,PKCS7_R_WRONG_CONTENT_TYPE);
521 return(0);
522 }
523
524 if (!sk_PKCS7_RECIP_INFO_push(sk,ri))
525 return 0;
526 return(1);
527 }
528
529int PKCS7_RECIP_INFO_set(PKCS7_RECIP_INFO *p7i, X509 *x509)
530 {
531 int ret;
532 EVP_PKEY *pkey = NULL;
533 if (!ASN1_INTEGER_set(p7i->version,0))
534 return 0;
535 if (!X509_NAME_set(&p7i->issuer_and_serial->issuer,
536 X509_get_issuer_name(x509)))
537 return 0;
538
539 M_ASN1_INTEGER_free(p7i->issuer_and_serial->serial);
540 if (!(p7i->issuer_and_serial->serial=
541 M_ASN1_INTEGER_dup(X509_get_serialNumber(x509))))
542 return 0;
543
544 pkey = X509_get_pubkey(x509);
545
546 if (!pkey || !pkey->ameth || !pkey->ameth->pkey_ctrl)
547 {
548 PKCS7err(PKCS7_F_PKCS7_RECIP_INFO_SET,
549 PKCS7_R_ENCRYPTION_NOT_SUPPORTED_FOR_THIS_KEY_TYPE);
550 goto err;
551 }
552
553 ret = pkey->ameth->pkey_ctrl(pkey, ASN1_PKEY_CTRL_PKCS7_ENCRYPT,
554 0, p7i);
555 if (ret == -2)
556 {
557 PKCS7err(PKCS7_F_PKCS7_RECIP_INFO_SET,
558 PKCS7_R_ENCRYPTION_NOT_SUPPORTED_FOR_THIS_KEY_TYPE);
559 goto err;
560 }
561 if (ret <= 0)
562 {
563 PKCS7err(PKCS7_F_PKCS7_RECIP_INFO_SET,
564 PKCS7_R_ENCRYPTION_CTRL_FAILURE);
565 goto err;
566 }
567
568 EVP_PKEY_free(pkey);
569
570 CRYPTO_add(&x509->references,1,CRYPTO_LOCK_X509);
571 p7i->cert=x509;
572
573 return 1;
574
575 err:
576 if (pkey)
577 EVP_PKEY_free(pkey);
578 return 0;
579 }
580
581X509 *PKCS7_cert_from_signer_info(PKCS7 *p7, PKCS7_SIGNER_INFO *si)
582 {
583 if (PKCS7_type_is_signed(p7))
584 return(X509_find_by_issuer_and_serial(p7->d.sign->cert,
585 si->issuer_and_serial->issuer,
586 si->issuer_and_serial->serial));
587 else
588 return(NULL);
589 }
590
591int PKCS7_set_cipher(PKCS7 *p7, const EVP_CIPHER *cipher)
592 {
593 int i;
594 PKCS7_ENC_CONTENT *ec;
595
596 i=OBJ_obj2nid(p7->type);
597 switch (i)
598 {
599 case NID_pkcs7_signedAndEnveloped:
600 ec=p7->d.signed_and_enveloped->enc_data;
601 break;
602 case NID_pkcs7_enveloped:
603 ec=p7->d.enveloped->enc_data;
604 break;
605 default:
606 PKCS7err(PKCS7_F_PKCS7_SET_CIPHER,PKCS7_R_WRONG_CONTENT_TYPE);
607 return(0);
608 }
609
610 /* Check cipher OID exists and has data in it*/
611 i = EVP_CIPHER_type(cipher);
612 if(i == NID_undef) {
613 PKCS7err(PKCS7_F_PKCS7_SET_CIPHER,PKCS7_R_CIPHER_HAS_NO_OBJECT_IDENTIFIER);
614 return(0);
615 }
616
617 ec->cipher = cipher;
618 return 1;
619 }
620
621int PKCS7_stream(unsigned char ***boundary, PKCS7 *p7)
622 {
623 ASN1_OCTET_STRING *os = NULL;
624
625 switch (OBJ_obj2nid(p7->type))
626 {
627 case NID_pkcs7_data:
628 os = p7->d.data;
629 break;
630
631 case NID_pkcs7_signedAndEnveloped:
632 os = p7->d.signed_and_enveloped->enc_data->enc_data;
633 if (os == NULL)
634 {
635 os=M_ASN1_OCTET_STRING_new();
636 p7->d.signed_and_enveloped->enc_data->enc_data=os;
637 }
638 break;
639
640 case NID_pkcs7_enveloped:
641 os = p7->d.enveloped->enc_data->enc_data;
642 if (os == NULL)
643 {
644 os=M_ASN1_OCTET_STRING_new();
645 p7->d.enveloped->enc_data->enc_data=os;
646 }
647 break;
648
649 case NID_pkcs7_signed:
650 os=p7->d.sign->contents->d.data;
651 break;
652
653 default:
654 os = NULL;
655 break;
656 }
657
658 if (os == NULL)
659 return 0;
660
661 os->flags |= ASN1_STRING_FLAG_NDEF;
662 *boundary = &os->data;
663
664 return 1;
665 }
diff --git a/src/lib/libcrypto/pkcs7/pk7_mime.c b/src/lib/libcrypto/pkcs7/pk7_mime.c
deleted file mode 100644
index 938f79a646..0000000000
--- a/src/lib/libcrypto/pkcs7/pk7_mime.c
+++ /dev/null
@@ -1,97 +0,0 @@
1/* pk7_mime.c */
2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
3 * project.
4 */
5/* ====================================================================
6 * Copyright (c) 1999-2005 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 */
54
55#include <stdio.h>
56#include <ctype.h>
57#include "cryptlib.h"
58#include <openssl/rand.h>
59#include <openssl/x509.h>
60#include <openssl/asn1.h>
61
62/* PKCS#7 wrappers round generalised stream and MIME routines */
63
64int i2d_PKCS7_bio_stream(BIO *out, PKCS7 *p7, BIO *in, int flags)
65 {
66 return i2d_ASN1_bio_stream(out, (ASN1_VALUE *)p7, in, flags,
67 ASN1_ITEM_rptr(PKCS7));
68 }
69
70int PEM_write_bio_PKCS7_stream(BIO *out, PKCS7 *p7, BIO *in, int flags)
71 {
72 return PEM_write_bio_ASN1_stream(out, (ASN1_VALUE *) p7, in, flags,
73 "PKCS7",
74 ASN1_ITEM_rptr(PKCS7));
75 }
76
77int SMIME_write_PKCS7(BIO *bio, PKCS7 *p7, BIO *data, int flags)
78 {
79 STACK_OF(X509_ALGOR) *mdalgs;
80 int ctype_nid = OBJ_obj2nid(p7->type);
81 if (ctype_nid == NID_pkcs7_signed)
82 mdalgs = p7->d.sign->md_algs;
83 else
84 mdalgs = NULL;
85
86 flags ^= SMIME_OLDMIME;
87
88
89 return SMIME_write_ASN1(bio, (ASN1_VALUE *)p7, data, flags,
90 ctype_nid, NID_undef, mdalgs,
91 ASN1_ITEM_rptr(PKCS7));
92 }
93
94PKCS7 *SMIME_read_PKCS7(BIO *bio, BIO **bcont)
95 {
96 return (PKCS7 *)SMIME_read_ASN1(bio, bcont, ASN1_ITEM_rptr(PKCS7));
97 }
diff --git a/src/lib/libcrypto/pkcs7/pk7_smime.c b/src/lib/libcrypto/pkcs7/pk7_smime.c
deleted file mode 100644
index a5104f8d05..0000000000
--- a/src/lib/libcrypto/pkcs7/pk7_smime.c
+++ /dev/null
@@ -1,606 +0,0 @@
1/* pk7_smime.c */
2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
3 * project.
4 */
5/* ====================================================================
6 * Copyright (c) 1999-2004 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59/* Simple PKCS#7 processing functions */
60
61#include <stdio.h>
62#include "cryptlib.h"
63#include <openssl/x509.h>
64#include <openssl/x509v3.h>
65
66static int pkcs7_copy_existing_digest(PKCS7 *p7, PKCS7_SIGNER_INFO *si);
67
68PKCS7 *PKCS7_sign(X509 *signcert, EVP_PKEY *pkey, STACK_OF(X509) *certs,
69 BIO *data, int flags)
70{
71 PKCS7 *p7;
72 int i;
73
74 if(!(p7 = PKCS7_new()))
75 {
76 PKCS7err(PKCS7_F_PKCS7_SIGN,ERR_R_MALLOC_FAILURE);
77 return NULL;
78 }
79
80 if (!PKCS7_set_type(p7, NID_pkcs7_signed))
81 goto err;
82
83 if (!PKCS7_content_new(p7, NID_pkcs7_data))
84 goto err;
85
86 if (pkey && !PKCS7_sign_add_signer(p7, signcert, pkey, NULL, flags))
87 {
88 PKCS7err(PKCS7_F_PKCS7_SIGN,PKCS7_R_PKCS7_ADD_SIGNER_ERROR);
89 goto err;
90 }
91
92 if(!(flags & PKCS7_NOCERTS))
93 {
94 for(i = 0; i < sk_X509_num(certs); i++)
95 {
96 if (!PKCS7_add_certificate(p7, sk_X509_value(certs, i)))
97 goto err;
98 }
99 }
100
101 if(flags & PKCS7_DETACHED)
102 PKCS7_set_detached(p7, 1);
103
104 if (flags & (PKCS7_STREAM|PKCS7_PARTIAL))
105 return p7;
106
107 if (PKCS7_final(p7, data, flags))
108 return p7;
109
110 err:
111 PKCS7_free(p7);
112 return NULL;
113}
114
115int PKCS7_final(PKCS7 *p7, BIO *data, int flags)
116 {
117 BIO *p7bio;
118 int ret = 0;
119 if (!(p7bio = PKCS7_dataInit(p7, NULL)))
120 {
121 PKCS7err(PKCS7_F_PKCS7_FINAL,ERR_R_MALLOC_FAILURE);
122 return 0;
123 }
124
125 SMIME_crlf_copy(data, p7bio, flags);
126
127 (void)BIO_flush(p7bio);
128
129
130 if (!PKCS7_dataFinal(p7,p7bio))
131 {
132 PKCS7err(PKCS7_F_PKCS7_FINAL,PKCS7_R_PKCS7_DATASIGN);
133 goto err;
134 }
135
136 ret = 1;
137
138 err:
139 BIO_free_all(p7bio);
140
141 return ret;
142
143 }
144
145/* Check to see if a cipher exists and if so add S/MIME capabilities */
146
147static int add_cipher_smcap(STACK_OF(X509_ALGOR) *sk, int nid, int arg)
148 {
149 if (EVP_get_cipherbynid(nid))
150 return PKCS7_simple_smimecap(sk, nid, arg);
151 return 1;
152 }
153
154static int add_digest_smcap(STACK_OF(X509_ALGOR) *sk, int nid, int arg)
155 {
156 if (EVP_get_digestbynid(nid))
157 return PKCS7_simple_smimecap(sk, nid, arg);
158 return 1;
159 }
160
161PKCS7_SIGNER_INFO *PKCS7_sign_add_signer(PKCS7 *p7, X509 *signcert,
162 EVP_PKEY *pkey, const EVP_MD *md,
163 int flags)
164 {
165 PKCS7_SIGNER_INFO *si = NULL;
166 STACK_OF(X509_ALGOR) *smcap = NULL;
167 if(!X509_check_private_key(signcert, pkey))
168 {
169 PKCS7err(PKCS7_F_PKCS7_SIGN_ADD_SIGNER,
170 PKCS7_R_PRIVATE_KEY_DOES_NOT_MATCH_CERTIFICATE);
171 return NULL;
172 }
173
174 if (!(si = PKCS7_add_signature(p7,signcert,pkey, md)))
175 {
176 PKCS7err(PKCS7_F_PKCS7_SIGN_ADD_SIGNER,
177 PKCS7_R_PKCS7_ADD_SIGNATURE_ERROR);
178 return NULL;
179 }
180
181 if(!(flags & PKCS7_NOCERTS))
182 {
183 if (!PKCS7_add_certificate(p7, signcert))
184 goto err;
185 }
186
187 if(!(flags & PKCS7_NOATTR))
188 {
189 if (!PKCS7_add_attrib_content_type(si, NULL))
190 goto err;
191 /* Add SMIMECapabilities */
192 if(!(flags & PKCS7_NOSMIMECAP))
193 {
194 if(!(smcap = sk_X509_ALGOR_new_null()))
195 {
196 PKCS7err(PKCS7_F_PKCS7_SIGN_ADD_SIGNER,
197 ERR_R_MALLOC_FAILURE);
198 goto err;
199 }
200 if (!add_cipher_smcap(smcap, NID_aes_256_cbc, -1)
201 || !add_digest_smcap(smcap, NID_id_GostR3411_94, -1)
202 || !add_cipher_smcap(smcap, NID_id_Gost28147_89, -1)
203 || !add_cipher_smcap(smcap, NID_aes_192_cbc, -1)
204 || !add_cipher_smcap(smcap, NID_aes_128_cbc, -1)
205 || !add_cipher_smcap(smcap, NID_des_ede3_cbc, -1)
206 || !add_cipher_smcap(smcap, NID_rc2_cbc, 128)
207 || !add_cipher_smcap(smcap, NID_rc2_cbc, 64)
208 || !add_cipher_smcap(smcap, NID_des_cbc, -1)
209 || !add_cipher_smcap(smcap, NID_rc2_cbc, 40)
210 || !PKCS7_add_attrib_smimecap (si, smcap))
211 goto err;
212 sk_X509_ALGOR_pop_free(smcap, X509_ALGOR_free);
213 smcap = NULL;
214 }
215 if (flags & PKCS7_REUSE_DIGEST)
216 {
217 if (!pkcs7_copy_existing_digest(p7, si))
218 goto err;
219 if (!(flags & PKCS7_PARTIAL) &&
220 !PKCS7_SIGNER_INFO_sign(si))
221 goto err;
222 }
223 }
224 return si;
225 err:
226 if (smcap)
227 sk_X509_ALGOR_pop_free(smcap, X509_ALGOR_free);
228 return NULL;
229 }
230
231/* Search for a digest matching SignerInfo digest type and if found
232 * copy across.
233 */
234
235static int pkcs7_copy_existing_digest(PKCS7 *p7, PKCS7_SIGNER_INFO *si)
236 {
237 int i;
238 STACK_OF(PKCS7_SIGNER_INFO) *sinfos;
239 PKCS7_SIGNER_INFO *sitmp;
240 ASN1_OCTET_STRING *osdig = NULL;
241 sinfos = PKCS7_get_signer_info(p7);
242 for (i = 0; i < sk_PKCS7_SIGNER_INFO_num(sinfos); i++)
243 {
244 sitmp = sk_PKCS7_SIGNER_INFO_value(sinfos, i);
245 if (si == sitmp)
246 break;
247 if (sk_X509_ATTRIBUTE_num(sitmp->auth_attr) <= 0)
248 continue;
249 if (!OBJ_cmp(si->digest_alg->algorithm,
250 sitmp->digest_alg->algorithm))
251 {
252 osdig = PKCS7_digest_from_attributes(sitmp->auth_attr);
253 break;
254 }
255
256 }
257
258 if (osdig)
259 return PKCS7_add1_attrib_digest(si, osdig->data, osdig->length);
260
261 PKCS7err(PKCS7_F_PKCS7_COPY_EXISTING_DIGEST,
262 PKCS7_R_NO_MATCHING_DIGEST_TYPE_FOUND);
263 return 0;
264 }
265
266int PKCS7_verify(PKCS7 *p7, STACK_OF(X509) *certs, X509_STORE *store,
267 BIO *indata, BIO *out, int flags)
268{
269 STACK_OF(X509) *signers;
270 X509 *signer;
271 STACK_OF(PKCS7_SIGNER_INFO) *sinfos;
272 PKCS7_SIGNER_INFO *si;
273 X509_STORE_CTX cert_ctx;
274 char buf[4096];
275 int i, j=0, k, ret = 0;
276 BIO *p7bio;
277 BIO *tmpin, *tmpout;
278
279 if(!p7) {
280 PKCS7err(PKCS7_F_PKCS7_VERIFY,PKCS7_R_INVALID_NULL_POINTER);
281 return 0;
282 }
283
284 if(!PKCS7_type_is_signed(p7)) {
285 PKCS7err(PKCS7_F_PKCS7_VERIFY,PKCS7_R_WRONG_CONTENT_TYPE);
286 return 0;
287 }
288
289 /* Check for no data and no content: no data to verify signature */
290 if(PKCS7_get_detached(p7) && !indata) {
291 PKCS7err(PKCS7_F_PKCS7_VERIFY,PKCS7_R_NO_CONTENT);
292 return 0;
293 }
294#if 0
295 /* NB: this test commented out because some versions of Netscape
296 * illegally include zero length content when signing data.
297 */
298
299 /* Check for data and content: two sets of data */
300 if(!PKCS7_get_detached(p7) && indata) {
301 PKCS7err(PKCS7_F_PKCS7_VERIFY,PKCS7_R_CONTENT_AND_DATA_PRESENT);
302 return 0;
303 }
304#endif
305
306 sinfos = PKCS7_get_signer_info(p7);
307
308 if(!sinfos || !sk_PKCS7_SIGNER_INFO_num(sinfos)) {
309 PKCS7err(PKCS7_F_PKCS7_VERIFY,PKCS7_R_NO_SIGNATURES_ON_DATA);
310 return 0;
311 }
312
313
314 signers = PKCS7_get0_signers(p7, certs, flags);
315
316 if(!signers) return 0;
317
318 /* Now verify the certificates */
319
320 if (!(flags & PKCS7_NOVERIFY)) for (k = 0; k < sk_X509_num(signers); k++) {
321 signer = sk_X509_value (signers, k);
322 if (!(flags & PKCS7_NOCHAIN)) {
323 if(!X509_STORE_CTX_init(&cert_ctx, store, signer,
324 p7->d.sign->cert))
325 {
326 PKCS7err(PKCS7_F_PKCS7_VERIFY,ERR_R_X509_LIB);
327 sk_X509_free(signers);
328 return 0;
329 }
330 X509_STORE_CTX_set_default(&cert_ctx, "smime_sign");
331 } else if(!X509_STORE_CTX_init (&cert_ctx, store, signer, NULL)) {
332 PKCS7err(PKCS7_F_PKCS7_VERIFY,ERR_R_X509_LIB);
333 sk_X509_free(signers);
334 return 0;
335 }
336 if (!(flags & PKCS7_NOCRL))
337 X509_STORE_CTX_set0_crls(&cert_ctx, p7->d.sign->crl);
338 i = X509_verify_cert(&cert_ctx);
339 if (i <= 0) j = X509_STORE_CTX_get_error(&cert_ctx);
340 X509_STORE_CTX_cleanup(&cert_ctx);
341 if (i <= 0) {
342 PKCS7err(PKCS7_F_PKCS7_VERIFY,PKCS7_R_CERTIFICATE_VERIFY_ERROR);
343 ERR_add_error_data(2, "Verify error:",
344 X509_verify_cert_error_string(j));
345 sk_X509_free(signers);
346 return 0;
347 }
348 /* Check for revocation status here */
349 }
350
351 /* Performance optimization: if the content is a memory BIO then
352 * store its contents in a temporary read only memory BIO. This
353 * avoids potentially large numbers of slow copies of data which will
354 * occur when reading from a read write memory BIO when signatures
355 * are calculated.
356 */
357
358 if (indata && (BIO_method_type(indata) == BIO_TYPE_MEM))
359 {
360 char *ptr;
361 long len;
362 len = BIO_get_mem_data(indata, &ptr);
363 tmpin = BIO_new_mem_buf(ptr, len);
364 if (tmpin == NULL)
365 {
366 PKCS7err(PKCS7_F_PKCS7_VERIFY,ERR_R_MALLOC_FAILURE);
367 return 0;
368 }
369 }
370 else
371 tmpin = indata;
372
373
374 if (!(p7bio=PKCS7_dataInit(p7,tmpin)))
375 goto err;
376
377 if(flags & PKCS7_TEXT) {
378 if(!(tmpout = BIO_new(BIO_s_mem()))) {
379 PKCS7err(PKCS7_F_PKCS7_VERIFY,ERR_R_MALLOC_FAILURE);
380 goto err;
381 }
382 BIO_set_mem_eof_return(tmpout, 0);
383 } else tmpout = out;
384
385 /* We now have to 'read' from p7bio to calculate digests etc. */
386 for (;;)
387 {
388 i=BIO_read(p7bio,buf,sizeof(buf));
389 if (i <= 0) break;
390 if (tmpout) BIO_write(tmpout, buf, i);
391 }
392
393 if(flags & PKCS7_TEXT) {
394 if(!SMIME_text(tmpout, out)) {
395 PKCS7err(PKCS7_F_PKCS7_VERIFY,PKCS7_R_SMIME_TEXT_ERROR);
396 BIO_free(tmpout);
397 goto err;
398 }
399 BIO_free(tmpout);
400 }
401
402 /* Now Verify All Signatures */
403 if (!(flags & PKCS7_NOSIGS))
404 for (i=0; i<sk_PKCS7_SIGNER_INFO_num(sinfos); i++)
405 {
406 si=sk_PKCS7_SIGNER_INFO_value(sinfos,i);
407 signer = sk_X509_value (signers, i);
408 j=PKCS7_signatureVerify(p7bio,p7,si, signer);
409 if (j <= 0) {
410 PKCS7err(PKCS7_F_PKCS7_VERIFY,PKCS7_R_SIGNATURE_FAILURE);
411 goto err;
412 }
413 }
414
415 ret = 1;
416
417 err:
418
419 if (tmpin == indata)
420 {
421 if (indata) BIO_pop(p7bio);
422 }
423 BIO_free_all(p7bio);
424
425 sk_X509_free(signers);
426
427 return ret;
428}
429
430STACK_OF(X509) *PKCS7_get0_signers(PKCS7 *p7, STACK_OF(X509) *certs, int flags)
431{
432 STACK_OF(X509) *signers;
433 STACK_OF(PKCS7_SIGNER_INFO) *sinfos;
434 PKCS7_SIGNER_INFO *si;
435 PKCS7_ISSUER_AND_SERIAL *ias;
436 X509 *signer;
437 int i;
438
439 if(!p7) {
440 PKCS7err(PKCS7_F_PKCS7_GET0_SIGNERS,PKCS7_R_INVALID_NULL_POINTER);
441 return NULL;
442 }
443
444 if(!PKCS7_type_is_signed(p7)) {
445 PKCS7err(PKCS7_F_PKCS7_GET0_SIGNERS,PKCS7_R_WRONG_CONTENT_TYPE);
446 return NULL;
447 }
448
449 /* Collect all the signers together */
450
451 sinfos = PKCS7_get_signer_info(p7);
452
453 if(sk_PKCS7_SIGNER_INFO_num(sinfos) <= 0) {
454 PKCS7err(PKCS7_F_PKCS7_GET0_SIGNERS,PKCS7_R_NO_SIGNERS);
455 return 0;
456 }
457
458 if(!(signers = sk_X509_new_null())) {
459 PKCS7err(PKCS7_F_PKCS7_GET0_SIGNERS,ERR_R_MALLOC_FAILURE);
460 return NULL;
461 }
462
463 for (i = 0; i < sk_PKCS7_SIGNER_INFO_num(sinfos); i++)
464 {
465 si = sk_PKCS7_SIGNER_INFO_value(sinfos, i);
466 ias = si->issuer_and_serial;
467 signer = NULL;
468 /* If any certificates passed they take priority */
469 if (certs) signer = X509_find_by_issuer_and_serial (certs,
470 ias->issuer, ias->serial);
471 if (!signer && !(flags & PKCS7_NOINTERN)
472 && p7->d.sign->cert) signer =
473 X509_find_by_issuer_and_serial (p7->d.sign->cert,
474 ias->issuer, ias->serial);
475 if (!signer) {
476 PKCS7err(PKCS7_F_PKCS7_GET0_SIGNERS,PKCS7_R_SIGNER_CERTIFICATE_NOT_FOUND);
477 sk_X509_free(signers);
478 return 0;
479 }
480
481 if (!sk_X509_push(signers, signer)) {
482 sk_X509_free(signers);
483 return NULL;
484 }
485 }
486 return signers;
487}
488
489
490/* Build a complete PKCS#7 enveloped data */
491
492PKCS7 *PKCS7_encrypt(STACK_OF(X509) *certs, BIO *in, const EVP_CIPHER *cipher,
493 int flags)
494{
495 PKCS7 *p7;
496 BIO *p7bio = NULL;
497 int i;
498 X509 *x509;
499 if(!(p7 = PKCS7_new())) {
500 PKCS7err(PKCS7_F_PKCS7_ENCRYPT,ERR_R_MALLOC_FAILURE);
501 return NULL;
502 }
503
504 if (!PKCS7_set_type(p7, NID_pkcs7_enveloped))
505 goto err;
506 if (!PKCS7_set_cipher(p7, cipher)) {
507 PKCS7err(PKCS7_F_PKCS7_ENCRYPT,PKCS7_R_ERROR_SETTING_CIPHER);
508 goto err;
509 }
510
511 for(i = 0; i < sk_X509_num(certs); i++) {
512 x509 = sk_X509_value(certs, i);
513 if(!PKCS7_add_recipient(p7, x509)) {
514 PKCS7err(PKCS7_F_PKCS7_ENCRYPT,
515 PKCS7_R_ERROR_ADDING_RECIPIENT);
516 goto err;
517 }
518 }
519
520 if (flags & PKCS7_STREAM)
521 return p7;
522
523 if (PKCS7_final(p7, in, flags))
524 return p7;
525
526 err:
527
528 BIO_free_all(p7bio);
529 PKCS7_free(p7);
530 return NULL;
531
532}
533
534int PKCS7_decrypt(PKCS7 *p7, EVP_PKEY *pkey, X509 *cert, BIO *data, int flags)
535{
536 BIO *tmpmem;
537 int ret, i;
538 char buf[4096];
539
540 if(!p7) {
541 PKCS7err(PKCS7_F_PKCS7_DECRYPT,PKCS7_R_INVALID_NULL_POINTER);
542 return 0;
543 }
544
545 if(!PKCS7_type_is_enveloped(p7)) {
546 PKCS7err(PKCS7_F_PKCS7_DECRYPT,PKCS7_R_WRONG_CONTENT_TYPE);
547 return 0;
548 }
549
550 if(cert && !X509_check_private_key(cert, pkey)) {
551 PKCS7err(PKCS7_F_PKCS7_DECRYPT,
552 PKCS7_R_PRIVATE_KEY_DOES_NOT_MATCH_CERTIFICATE);
553 return 0;
554 }
555
556 if(!(tmpmem = PKCS7_dataDecode(p7, pkey, NULL, cert))) {
557 PKCS7err(PKCS7_F_PKCS7_DECRYPT, PKCS7_R_DECRYPT_ERROR);
558 return 0;
559 }
560
561 if (flags & PKCS7_TEXT) {
562 BIO *tmpbuf, *bread;
563 /* Encrypt BIOs can't do BIO_gets() so add a buffer BIO */
564 if(!(tmpbuf = BIO_new(BIO_f_buffer()))) {
565 PKCS7err(PKCS7_F_PKCS7_DECRYPT, ERR_R_MALLOC_FAILURE);
566 BIO_free_all(tmpmem);
567 return 0;
568 }
569 if(!(bread = BIO_push(tmpbuf, tmpmem))) {
570 PKCS7err(PKCS7_F_PKCS7_DECRYPT, ERR_R_MALLOC_FAILURE);
571 BIO_free_all(tmpbuf);
572 BIO_free_all(tmpmem);
573 return 0;
574 }
575 ret = SMIME_text(bread, data);
576 if (ret > 0 && BIO_method_type(tmpmem) == BIO_TYPE_CIPHER)
577 {
578 if (!BIO_get_cipher_status(tmpmem))
579 ret = 0;
580 }
581 BIO_free_all(bread);
582 return ret;
583 } else {
584 for(;;) {
585 i = BIO_read(tmpmem, buf, sizeof(buf));
586 if(i <= 0)
587 {
588 ret = 1;
589 if (BIO_method_type(tmpmem) == BIO_TYPE_CIPHER)
590 {
591 if (!BIO_get_cipher_status(tmpmem))
592 ret = 0;
593 }
594
595 break;
596 }
597 if (BIO_write(data, buf, i) != i)
598 {
599 ret = 0;
600 break;
601 }
602 }
603 BIO_free_all(tmpmem);
604 return ret;
605 }
606}
diff --git a/src/lib/libcrypto/pkcs7/pkcs7.h b/src/lib/libcrypto/pkcs7/pkcs7.h
deleted file mode 100644
index e4d443193c..0000000000
--- a/src/lib/libcrypto/pkcs7/pkcs7.h
+++ /dev/null
@@ -1,499 +0,0 @@
1/* crypto/pkcs7/pkcs7.h */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#ifndef HEADER_PKCS7_H
60#define HEADER_PKCS7_H
61
62#include <openssl/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
69#ifdef __cplusplus
70extern "C" {
71#endif
72
73#ifdef OPENSSL_SYS_WIN32
74/* Under Win32 thes are defined in wincrypt.h */
75#undef PKCS7_ISSUER_AND_SERIAL
76#undef PKCS7_SIGNER_INFO
77#endif
78
79/*
80Encryption_ID DES-CBC
81Digest_ID MD5
82Digest_Encryption_ID rsaEncryption
83Key_Encryption_ID rsaEncryption
84*/
85
86typedef struct pkcs7_issuer_and_serial_st
87 {
88 X509_NAME *issuer;
89 ASN1_INTEGER *serial;
90 } PKCS7_ISSUER_AND_SERIAL;
91
92typedef struct pkcs7_signer_info_st
93 {
94 ASN1_INTEGER *version; /* version 1 */
95 PKCS7_ISSUER_AND_SERIAL *issuer_and_serial;
96 X509_ALGOR *digest_alg;
97 STACK_OF(X509_ATTRIBUTE) *auth_attr; /* [ 0 ] */
98 X509_ALGOR *digest_enc_alg;
99 ASN1_OCTET_STRING *enc_digest;
100 STACK_OF(X509_ATTRIBUTE) *unauth_attr; /* [ 1 ] */
101
102 /* The private key to sign with */
103 EVP_PKEY *pkey;
104 } PKCS7_SIGNER_INFO;
105
106DECLARE_STACK_OF(PKCS7_SIGNER_INFO)
107DECLARE_ASN1_SET_OF(PKCS7_SIGNER_INFO)
108
109typedef struct pkcs7_recip_info_st
110 {
111 ASN1_INTEGER *version; /* version 0 */
112 PKCS7_ISSUER_AND_SERIAL *issuer_and_serial;
113 X509_ALGOR *key_enc_algor;
114 ASN1_OCTET_STRING *enc_key;
115 X509 *cert; /* get the pub-key from this */
116 } PKCS7_RECIP_INFO;
117
118DECLARE_STACK_OF(PKCS7_RECIP_INFO)
119DECLARE_ASN1_SET_OF(PKCS7_RECIP_INFO)
120
121typedef struct pkcs7_signed_st
122 {
123 ASN1_INTEGER *version; /* version 1 */
124 STACK_OF(X509_ALGOR) *md_algs; /* md used */
125 STACK_OF(X509) *cert; /* [ 0 ] */
126 STACK_OF(X509_CRL) *crl; /* [ 1 ] */
127 STACK_OF(PKCS7_SIGNER_INFO) *signer_info;
128
129 struct pkcs7_st *contents;
130 } PKCS7_SIGNED;
131/* The above structure is very very similar to PKCS7_SIGN_ENVELOPE.
132 * How about merging the two */
133
134typedef struct pkcs7_enc_content_st
135 {
136 ASN1_OBJECT *content_type;
137 X509_ALGOR *algorithm;
138 ASN1_OCTET_STRING *enc_data; /* [ 0 ] */
139 const EVP_CIPHER *cipher;
140 } PKCS7_ENC_CONTENT;
141
142typedef struct pkcs7_enveloped_st
143 {
144 ASN1_INTEGER *version; /* version 0 */
145 STACK_OF(PKCS7_RECIP_INFO) *recipientinfo;
146 PKCS7_ENC_CONTENT *enc_data;
147 } PKCS7_ENVELOPE;
148
149typedef struct pkcs7_signedandenveloped_st
150 {
151 ASN1_INTEGER *version; /* version 1 */
152 STACK_OF(X509_ALGOR) *md_algs; /* md used */
153 STACK_OF(X509) *cert; /* [ 0 ] */
154 STACK_OF(X509_CRL) *crl; /* [ 1 ] */
155 STACK_OF(PKCS7_SIGNER_INFO) *signer_info;
156
157 PKCS7_ENC_CONTENT *enc_data;
158 STACK_OF(PKCS7_RECIP_INFO) *recipientinfo;
159 } PKCS7_SIGN_ENVELOPE;
160
161typedef struct pkcs7_digest_st
162 {
163 ASN1_INTEGER *version; /* version 0 */
164 X509_ALGOR *md; /* md used */
165 struct pkcs7_st *contents;
166 ASN1_OCTET_STRING *digest;
167 } PKCS7_DIGEST;
168
169typedef struct pkcs7_encrypted_st
170 {
171 ASN1_INTEGER *version; /* version 0 */
172 PKCS7_ENC_CONTENT *enc_data;
173 } PKCS7_ENCRYPT;
174
175typedef struct pkcs7_st
176 {
177 /* The following is non NULL if it contains ASN1 encoding of
178 * this structure */
179 unsigned char *asn1;
180 long length;
181
182#define PKCS7_S_HEADER 0
183#define PKCS7_S_BODY 1
184#define PKCS7_S_TAIL 2
185 int state; /* used during processing */
186
187 int detached;
188
189 ASN1_OBJECT *type;
190 /* content as defined by the type */
191 /* all encryption/message digests are applied to the 'contents',
192 * leaving out the 'type' field. */
193 union {
194 char *ptr;
195
196 /* NID_pkcs7_data */
197 ASN1_OCTET_STRING *data;
198
199 /* NID_pkcs7_signed */
200 PKCS7_SIGNED *sign;
201
202 /* NID_pkcs7_enveloped */
203 PKCS7_ENVELOPE *enveloped;
204
205 /* NID_pkcs7_signedAndEnveloped */
206 PKCS7_SIGN_ENVELOPE *signed_and_enveloped;
207
208 /* NID_pkcs7_digest */
209 PKCS7_DIGEST *digest;
210
211 /* NID_pkcs7_encrypted */
212 PKCS7_ENCRYPT *encrypted;
213
214 /* Anything else */
215 ASN1_TYPE *other;
216 } d;
217 } PKCS7;
218
219DECLARE_STACK_OF(PKCS7)
220DECLARE_ASN1_SET_OF(PKCS7)
221DECLARE_PKCS12_STACK_OF(PKCS7)
222
223#define PKCS7_OP_SET_DETACHED_SIGNATURE 1
224#define PKCS7_OP_GET_DETACHED_SIGNATURE 2
225
226#define PKCS7_get_signed_attributes(si) ((si)->auth_attr)
227#define PKCS7_get_attributes(si) ((si)->unauth_attr)
228
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)
234#define PKCS7_type_is_data(a) (OBJ_obj2nid((a)->type) == NID_pkcs7_data)
235#define PKCS7_type_is_digest(a) (OBJ_obj2nid((a)->type) == NID_pkcs7_digest)
236#define PKCS7_type_is_encrypted(a) \
237 (OBJ_obj2nid((a)->type) == NID_pkcs7_encrypted)
238
239#define PKCS7_type_is_digest(a) (OBJ_obj2nid((a)->type) == NID_pkcs7_digest)
240
241#define PKCS7_set_detached(p,v) \
242 PKCS7_ctrl(p,PKCS7_OP_SET_DETACHED_SIGNATURE,v,NULL)
243#define PKCS7_get_detached(p) \
244 PKCS7_ctrl(p,PKCS7_OP_GET_DETACHED_SIGNATURE,0,NULL)
245
246#define PKCS7_is_detached(p7) (PKCS7_type_is_signed(p7) && PKCS7_get_detached(p7))
247
248/* S/MIME related flags */
249
250#define PKCS7_TEXT 0x1
251#define PKCS7_NOCERTS 0x2
252#define PKCS7_NOSIGS 0x4
253#define PKCS7_NOCHAIN 0x8
254#define PKCS7_NOINTERN 0x10
255#define PKCS7_NOVERIFY 0x20
256#define PKCS7_DETACHED 0x40
257#define PKCS7_BINARY 0x80
258#define PKCS7_NOATTR 0x100
259#define PKCS7_NOSMIMECAP 0x200
260#define PKCS7_NOOLDMIMETYPE 0x400
261#define PKCS7_CRLFEOL 0x800
262#define PKCS7_STREAM 0x1000
263#define PKCS7_NOCRL 0x2000
264#define PKCS7_PARTIAL 0x4000
265#define PKCS7_REUSE_DIGEST 0x8000
266
267/* Flags: for compatibility with older code */
268
269#define SMIME_TEXT PKCS7_TEXT
270#define SMIME_NOCERTS PKCS7_NOCERTS
271#define SMIME_NOSIGS PKCS7_NOSIGS
272#define SMIME_NOCHAIN PKCS7_NOCHAIN
273#define SMIME_NOINTERN PKCS7_NOINTERN
274#define SMIME_NOVERIFY PKCS7_NOVERIFY
275#define SMIME_DETACHED PKCS7_DETACHED
276#define SMIME_BINARY PKCS7_BINARY
277#define SMIME_NOATTR PKCS7_NOATTR
278
279DECLARE_ASN1_FUNCTIONS(PKCS7_ISSUER_AND_SERIAL)
280
281int PKCS7_ISSUER_AND_SERIAL_digest(PKCS7_ISSUER_AND_SERIAL *data,const EVP_MD *type,
282 unsigned char *md,unsigned int *len);
283#ifndef OPENSSL_NO_FP_API
284PKCS7 *d2i_PKCS7_fp(FILE *fp,PKCS7 **p7);
285int i2d_PKCS7_fp(FILE *fp,PKCS7 *p7);
286#endif
287PKCS7 *PKCS7_dup(PKCS7 *p7);
288PKCS7 *d2i_PKCS7_bio(BIO *bp,PKCS7 **p7);
289int i2d_PKCS7_bio(BIO *bp,PKCS7 *p7);
290int i2d_PKCS7_bio_stream(BIO *out, PKCS7 *p7, BIO *in, int flags);
291int PEM_write_bio_PKCS7_stream(BIO *out, PKCS7 *p7, BIO *in, int flags);
292
293DECLARE_ASN1_FUNCTIONS(PKCS7_SIGNER_INFO)
294DECLARE_ASN1_FUNCTIONS(PKCS7_RECIP_INFO)
295DECLARE_ASN1_FUNCTIONS(PKCS7_SIGNED)
296DECLARE_ASN1_FUNCTIONS(PKCS7_ENC_CONTENT)
297DECLARE_ASN1_FUNCTIONS(PKCS7_ENVELOPE)
298DECLARE_ASN1_FUNCTIONS(PKCS7_SIGN_ENVELOPE)
299DECLARE_ASN1_FUNCTIONS(PKCS7_DIGEST)
300DECLARE_ASN1_FUNCTIONS(PKCS7_ENCRYPT)
301DECLARE_ASN1_FUNCTIONS(PKCS7)
302
303DECLARE_ASN1_ITEM(PKCS7_ATTR_SIGN)
304DECLARE_ASN1_ITEM(PKCS7_ATTR_VERIFY)
305
306DECLARE_ASN1_NDEF_FUNCTION(PKCS7)
307DECLARE_ASN1_PRINT_FUNCTION(PKCS7)
308
309long PKCS7_ctrl(PKCS7 *p7, int cmd, long larg, char *parg);
310
311int PKCS7_set_type(PKCS7 *p7, int type);
312int PKCS7_set0_type_other(PKCS7 *p7, int type, ASN1_TYPE *other);
313int PKCS7_set_content(PKCS7 *p7, PKCS7 *p7_data);
314int PKCS7_SIGNER_INFO_set(PKCS7_SIGNER_INFO *p7i, X509 *x509, EVP_PKEY *pkey,
315 const EVP_MD *dgst);
316int PKCS7_SIGNER_INFO_sign(PKCS7_SIGNER_INFO *si);
317int PKCS7_add_signer(PKCS7 *p7, PKCS7_SIGNER_INFO *p7i);
318int PKCS7_add_certificate(PKCS7 *p7, X509 *x509);
319int PKCS7_add_crl(PKCS7 *p7, X509_CRL *x509);
320int PKCS7_content_new(PKCS7 *p7, int nid);
321int PKCS7_dataVerify(X509_STORE *cert_store, X509_STORE_CTX *ctx,
322 BIO *bio, PKCS7 *p7, PKCS7_SIGNER_INFO *si);
323int PKCS7_signatureVerify(BIO *bio, PKCS7 *p7, PKCS7_SIGNER_INFO *si,
324 X509 *x509);
325
326BIO *PKCS7_dataInit(PKCS7 *p7, BIO *bio);
327int PKCS7_dataFinal(PKCS7 *p7, BIO *bio);
328BIO *PKCS7_dataDecode(PKCS7 *p7, EVP_PKEY *pkey, BIO *in_bio, X509 *pcert);
329
330
331PKCS7_SIGNER_INFO *PKCS7_add_signature(PKCS7 *p7, X509 *x509,
332 EVP_PKEY *pkey, const EVP_MD *dgst);
333X509 *PKCS7_cert_from_signer_info(PKCS7 *p7, PKCS7_SIGNER_INFO *si);
334int PKCS7_set_digest(PKCS7 *p7, const EVP_MD *md);
335STACK_OF(PKCS7_SIGNER_INFO) *PKCS7_get_signer_info(PKCS7 *p7);
336
337PKCS7_RECIP_INFO *PKCS7_add_recipient(PKCS7 *p7, X509 *x509);
338void PKCS7_SIGNER_INFO_get0_algs(PKCS7_SIGNER_INFO *si, EVP_PKEY **pk,
339 X509_ALGOR **pdig, X509_ALGOR **psig);
340void PKCS7_RECIP_INFO_get0_alg(PKCS7_RECIP_INFO *ri, X509_ALGOR **penc);
341int PKCS7_add_recipient_info(PKCS7 *p7, PKCS7_RECIP_INFO *ri);
342int PKCS7_RECIP_INFO_set(PKCS7_RECIP_INFO *p7i, X509 *x509);
343int PKCS7_set_cipher(PKCS7 *p7, const EVP_CIPHER *cipher);
344int PKCS7_stream(unsigned char ***boundary, PKCS7 *p7);
345
346PKCS7_ISSUER_AND_SERIAL *PKCS7_get_issuer_and_serial(PKCS7 *p7, int idx);
347ASN1_OCTET_STRING *PKCS7_digest_from_attributes(STACK_OF(X509_ATTRIBUTE) *sk);
348int PKCS7_add_signed_attribute(PKCS7_SIGNER_INFO *p7si,int nid,int type,
349 void *data);
350int PKCS7_add_attribute (PKCS7_SIGNER_INFO *p7si, int nid, int atrtype,
351 void *value);
352ASN1_TYPE *PKCS7_get_attribute(PKCS7_SIGNER_INFO *si, int nid);
353ASN1_TYPE *PKCS7_get_signed_attribute(PKCS7_SIGNER_INFO *si, int nid);
354int PKCS7_set_signed_attributes(PKCS7_SIGNER_INFO *p7si,
355 STACK_OF(X509_ATTRIBUTE) *sk);
356int PKCS7_set_attributes(PKCS7_SIGNER_INFO *p7si,STACK_OF(X509_ATTRIBUTE) *sk);
357
358
359PKCS7 *PKCS7_sign(X509 *signcert, EVP_PKEY *pkey, STACK_OF(X509) *certs,
360 BIO *data, int flags);
361
362PKCS7_SIGNER_INFO *PKCS7_sign_add_signer(PKCS7 *p7,
363 X509 *signcert, EVP_PKEY *pkey, const EVP_MD *md,
364 int flags);
365
366int PKCS7_final(PKCS7 *p7, BIO *data, int flags);
367int PKCS7_verify(PKCS7 *p7, STACK_OF(X509) *certs, X509_STORE *store,
368 BIO *indata, BIO *out, int flags);
369STACK_OF(X509) *PKCS7_get0_signers(PKCS7 *p7, STACK_OF(X509) *certs, int flags);
370PKCS7 *PKCS7_encrypt(STACK_OF(X509) *certs, BIO *in, const EVP_CIPHER *cipher,
371 int flags);
372int PKCS7_decrypt(PKCS7 *p7, EVP_PKEY *pkey, X509 *cert, BIO *data, int flags);
373
374int PKCS7_add_attrib_smimecap(PKCS7_SIGNER_INFO *si,
375 STACK_OF(X509_ALGOR) *cap);
376STACK_OF(X509_ALGOR) *PKCS7_get_smimecap(PKCS7_SIGNER_INFO *si);
377int PKCS7_simple_smimecap(STACK_OF(X509_ALGOR) *sk, int nid, int arg);
378
379int PKCS7_add_attrib_content_type(PKCS7_SIGNER_INFO *si, ASN1_OBJECT *coid);
380int PKCS7_add0_attrib_signing_time(PKCS7_SIGNER_INFO *si, ASN1_TIME *t);
381int PKCS7_add1_attrib_digest(PKCS7_SIGNER_INFO *si,
382 const unsigned char *md, int mdlen);
383
384int SMIME_write_PKCS7(BIO *bio, PKCS7 *p7, BIO *data, int flags);
385PKCS7 *SMIME_read_PKCS7(BIO *bio, BIO **bcont);
386
387BIO *BIO_new_PKCS7(BIO *out, PKCS7 *p7);
388
389
390/* BEGIN ERROR CODES */
391/* The following lines are auto generated by the script mkerr.pl. Any changes
392 * made after this point may be overwritten when the script is next run.
393 */
394void ERR_load_PKCS7_strings(void);
395
396/* Error codes for the PKCS7 functions. */
397
398/* Function codes. */
399#define PKCS7_F_B64_READ_PKCS7 120
400#define PKCS7_F_B64_WRITE_PKCS7 121
401#define PKCS7_F_DO_PKCS7_SIGNED_ATTRIB 136
402#define PKCS7_F_I2D_PKCS7_BIO_STREAM 140
403#define PKCS7_F_PKCS7_ADD0_ATTRIB_SIGNING_TIME 135
404#define PKCS7_F_PKCS7_ADD_ATTRIB_SMIMECAP 118
405#define PKCS7_F_PKCS7_ADD_CERTIFICATE 100
406#define PKCS7_F_PKCS7_ADD_CRL 101
407#define PKCS7_F_PKCS7_ADD_RECIPIENT_INFO 102
408#define PKCS7_F_PKCS7_ADD_SIGNATURE 131
409#define PKCS7_F_PKCS7_ADD_SIGNER 103
410#define PKCS7_F_PKCS7_BIO_ADD_DIGEST 125
411#define PKCS7_F_PKCS7_COPY_EXISTING_DIGEST 138
412#define PKCS7_F_PKCS7_CTRL 104
413#define PKCS7_F_PKCS7_DATADECODE 112
414#define PKCS7_F_PKCS7_DATAFINAL 128
415#define PKCS7_F_PKCS7_DATAINIT 105
416#define PKCS7_F_PKCS7_DATASIGN 106
417#define PKCS7_F_PKCS7_DATAVERIFY 107
418#define PKCS7_F_PKCS7_DECRYPT 114
419#define PKCS7_F_PKCS7_DECRYPT_RINFO 133
420#define PKCS7_F_PKCS7_ENCODE_RINFO 132
421#define PKCS7_F_PKCS7_ENCRYPT 115
422#define PKCS7_F_PKCS7_FINAL 134
423#define PKCS7_F_PKCS7_FIND_DIGEST 127
424#define PKCS7_F_PKCS7_GET0_SIGNERS 124
425#define PKCS7_F_PKCS7_RECIP_INFO_SET 130
426#define PKCS7_F_PKCS7_SET_CIPHER 108
427#define PKCS7_F_PKCS7_SET_CONTENT 109
428#define PKCS7_F_PKCS7_SET_DIGEST 126
429#define PKCS7_F_PKCS7_SET_TYPE 110
430#define PKCS7_F_PKCS7_SIGN 116
431#define PKCS7_F_PKCS7_SIGNATUREVERIFY 113
432#define PKCS7_F_PKCS7_SIGNER_INFO_SET 129
433#define PKCS7_F_PKCS7_SIGNER_INFO_SIGN 139
434#define PKCS7_F_PKCS7_SIGN_ADD_SIGNER 137
435#define PKCS7_F_PKCS7_SIMPLE_SMIMECAP 119
436#define PKCS7_F_PKCS7_VERIFY 117
437#define PKCS7_F_SMIME_READ_PKCS7 122
438#define PKCS7_F_SMIME_TEXT 123
439
440/* Reason codes. */
441#define PKCS7_R_CERTIFICATE_VERIFY_ERROR 117
442#define PKCS7_R_CIPHER_HAS_NO_OBJECT_IDENTIFIER 144
443#define PKCS7_R_CIPHER_NOT_INITIALIZED 116
444#define PKCS7_R_CONTENT_AND_DATA_PRESENT 118
445#define PKCS7_R_CTRL_ERROR 152
446#define PKCS7_R_DECODE_ERROR 130
447#define PKCS7_R_DECRYPTED_KEY_IS_WRONG_LENGTH 100
448#define PKCS7_R_DECRYPT_ERROR 119
449#define PKCS7_R_DIGEST_FAILURE 101
450#define PKCS7_R_ENCRYPTION_CTRL_FAILURE 149
451#define PKCS7_R_ENCRYPTION_NOT_SUPPORTED_FOR_THIS_KEY_TYPE 150
452#define PKCS7_R_ERROR_ADDING_RECIPIENT 120
453#define PKCS7_R_ERROR_SETTING_CIPHER 121
454#define PKCS7_R_INVALID_MIME_TYPE 131
455#define PKCS7_R_INVALID_NULL_POINTER 143
456#define PKCS7_R_MIME_NO_CONTENT_TYPE 132
457#define PKCS7_R_MIME_PARSE_ERROR 133
458#define PKCS7_R_MIME_SIG_PARSE_ERROR 134
459#define PKCS7_R_MISSING_CERIPEND_INFO 103
460#define PKCS7_R_NO_CONTENT 122
461#define PKCS7_R_NO_CONTENT_TYPE 135
462#define PKCS7_R_NO_DEFAULT_DIGEST 151
463#define PKCS7_R_NO_MATCHING_DIGEST_TYPE_FOUND 154
464#define PKCS7_R_NO_MULTIPART_BODY_FAILURE 136
465#define PKCS7_R_NO_MULTIPART_BOUNDARY 137
466#define PKCS7_R_NO_RECIPIENT_MATCHES_CERTIFICATE 115
467#define PKCS7_R_NO_RECIPIENT_MATCHES_KEY 146
468#define PKCS7_R_NO_SIGNATURES_ON_DATA 123
469#define PKCS7_R_NO_SIGNERS 142
470#define PKCS7_R_NO_SIG_CONTENT_TYPE 138
471#define PKCS7_R_OPERATION_NOT_SUPPORTED_ON_THIS_TYPE 104
472#define PKCS7_R_PKCS7_ADD_SIGNATURE_ERROR 124
473#define PKCS7_R_PKCS7_ADD_SIGNER_ERROR 153
474#define PKCS7_R_PKCS7_DATAFINAL 126
475#define PKCS7_R_PKCS7_DATAFINAL_ERROR 125
476#define PKCS7_R_PKCS7_DATASIGN 145
477#define PKCS7_R_PKCS7_PARSE_ERROR 139
478#define PKCS7_R_PKCS7_SIG_PARSE_ERROR 140
479#define PKCS7_R_PRIVATE_KEY_DOES_NOT_MATCH_CERTIFICATE 127
480#define PKCS7_R_SIGNATURE_FAILURE 105
481#define PKCS7_R_SIGNER_CERTIFICATE_NOT_FOUND 128
482#define PKCS7_R_SIGNING_CTRL_FAILURE 147
483#define PKCS7_R_SIGNING_NOT_SUPPORTED_FOR_THIS_KEY_TYPE 148
484#define PKCS7_R_SIG_INVALID_MIME_TYPE 141
485#define PKCS7_R_SMIME_TEXT_ERROR 129
486#define PKCS7_R_UNABLE_TO_FIND_CERTIFICATE 106
487#define PKCS7_R_UNABLE_TO_FIND_MEM_BIO 107
488#define PKCS7_R_UNABLE_TO_FIND_MESSAGE_DIGEST 108
489#define PKCS7_R_UNKNOWN_DIGEST_TYPE 109
490#define PKCS7_R_UNKNOWN_OPERATION 110
491#define PKCS7_R_UNSUPPORTED_CIPHER_TYPE 111
492#define PKCS7_R_UNSUPPORTED_CONTENT_TYPE 112
493#define PKCS7_R_WRONG_CONTENT_TYPE 113
494#define PKCS7_R_WRONG_PKCS7_TYPE 114
495
496#ifdef __cplusplus
497}
498#endif
499#endif
diff --git a/src/lib/libcrypto/pkcs7/pkcs7err.c b/src/lib/libcrypto/pkcs7/pkcs7err.c
deleted file mode 100644
index d0af32a265..0000000000
--- a/src/lib/libcrypto/pkcs7/pkcs7err.c
+++ /dev/null
@@ -1,187 +0,0 @@
1/* crypto/pkcs7/pkcs7err.c */
2/* ====================================================================
3 * Copyright (c) 1999-2007 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * openssl-core@OpenSSL.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 * This product includes cryptographic software written by Eric Young
51 * (eay@cryptsoft.com). This product includes software written by Tim
52 * Hudson (tjh@cryptsoft.com).
53 *
54 */
55
56/* NOTE: this file was auto generated by the mkerr.pl script: any changes
57 * made to it will be overwritten when the script next updates this file,
58 * only reason strings will be preserved.
59 */
60
61#include <stdio.h>
62#include <openssl/err.h>
63#include <openssl/pkcs7.h>
64
65/* BEGIN ERROR CODES */
66#ifndef OPENSSL_NO_ERR
67
68#define ERR_FUNC(func) ERR_PACK(ERR_LIB_PKCS7,func,0)
69#define ERR_REASON(reason) ERR_PACK(ERR_LIB_PKCS7,0,reason)
70
71static ERR_STRING_DATA PKCS7_str_functs[]=
72 {
73{ERR_FUNC(PKCS7_F_B64_READ_PKCS7), "B64_READ_PKCS7"},
74{ERR_FUNC(PKCS7_F_B64_WRITE_PKCS7), "B64_WRITE_PKCS7"},
75{ERR_FUNC(PKCS7_F_DO_PKCS7_SIGNED_ATTRIB), "DO_PKCS7_SIGNED_ATTRIB"},
76{ERR_FUNC(PKCS7_F_I2D_PKCS7_BIO_STREAM), "i2d_PKCS7_bio_stream"},
77{ERR_FUNC(PKCS7_F_PKCS7_ADD0_ATTRIB_SIGNING_TIME), "PKCS7_add0_attrib_signing_time"},
78{ERR_FUNC(PKCS7_F_PKCS7_ADD_ATTRIB_SMIMECAP), "PKCS7_add_attrib_smimecap"},
79{ERR_FUNC(PKCS7_F_PKCS7_ADD_CERTIFICATE), "PKCS7_add_certificate"},
80{ERR_FUNC(PKCS7_F_PKCS7_ADD_CRL), "PKCS7_add_crl"},
81{ERR_FUNC(PKCS7_F_PKCS7_ADD_RECIPIENT_INFO), "PKCS7_add_recipient_info"},
82{ERR_FUNC(PKCS7_F_PKCS7_ADD_SIGNATURE), "PKCS7_add_signature"},
83{ERR_FUNC(PKCS7_F_PKCS7_ADD_SIGNER), "PKCS7_add_signer"},
84{ERR_FUNC(PKCS7_F_PKCS7_BIO_ADD_DIGEST), "PKCS7_BIO_ADD_DIGEST"},
85{ERR_FUNC(PKCS7_F_PKCS7_COPY_EXISTING_DIGEST), "PKCS7_COPY_EXISTING_DIGEST"},
86{ERR_FUNC(PKCS7_F_PKCS7_CTRL), "PKCS7_ctrl"},
87{ERR_FUNC(PKCS7_F_PKCS7_DATADECODE), "PKCS7_dataDecode"},
88{ERR_FUNC(PKCS7_F_PKCS7_DATAFINAL), "PKCS7_dataFinal"},
89{ERR_FUNC(PKCS7_F_PKCS7_DATAINIT), "PKCS7_dataInit"},
90{ERR_FUNC(PKCS7_F_PKCS7_DATASIGN), "PKCS7_DATASIGN"},
91{ERR_FUNC(PKCS7_F_PKCS7_DATAVERIFY), "PKCS7_dataVerify"},
92{ERR_FUNC(PKCS7_F_PKCS7_DECRYPT), "PKCS7_decrypt"},
93{ERR_FUNC(PKCS7_F_PKCS7_DECRYPT_RINFO), "PKCS7_DECRYPT_RINFO"},
94{ERR_FUNC(PKCS7_F_PKCS7_ENCODE_RINFO), "PKCS7_ENCODE_RINFO"},
95{ERR_FUNC(PKCS7_F_PKCS7_ENCRYPT), "PKCS7_encrypt"},
96{ERR_FUNC(PKCS7_F_PKCS7_FINAL), "PKCS7_final"},
97{ERR_FUNC(PKCS7_F_PKCS7_FIND_DIGEST), "PKCS7_FIND_DIGEST"},
98{ERR_FUNC(PKCS7_F_PKCS7_GET0_SIGNERS), "PKCS7_get0_signers"},
99{ERR_FUNC(PKCS7_F_PKCS7_RECIP_INFO_SET), "PKCS7_RECIP_INFO_set"},
100{ERR_FUNC(PKCS7_F_PKCS7_SET_CIPHER), "PKCS7_set_cipher"},
101{ERR_FUNC(PKCS7_F_PKCS7_SET_CONTENT), "PKCS7_set_content"},
102{ERR_FUNC(PKCS7_F_PKCS7_SET_DIGEST), "PKCS7_set_digest"},
103{ERR_FUNC(PKCS7_F_PKCS7_SET_TYPE), "PKCS7_set_type"},
104{ERR_FUNC(PKCS7_F_PKCS7_SIGN), "PKCS7_sign"},
105{ERR_FUNC(PKCS7_F_PKCS7_SIGNATUREVERIFY), "PKCS7_signatureVerify"},
106{ERR_FUNC(PKCS7_F_PKCS7_SIGNER_INFO_SET), "PKCS7_SIGNER_INFO_set"},
107{ERR_FUNC(PKCS7_F_PKCS7_SIGNER_INFO_SIGN), "PKCS7_SIGNER_INFO_sign"},
108{ERR_FUNC(PKCS7_F_PKCS7_SIGN_ADD_SIGNER), "PKCS7_sign_add_signer"},
109{ERR_FUNC(PKCS7_F_PKCS7_SIMPLE_SMIMECAP), "PKCS7_simple_smimecap"},
110{ERR_FUNC(PKCS7_F_PKCS7_VERIFY), "PKCS7_verify"},
111{ERR_FUNC(PKCS7_F_SMIME_READ_PKCS7), "SMIME_read_PKCS7"},
112{ERR_FUNC(PKCS7_F_SMIME_TEXT), "SMIME_text"},
113{0,NULL}
114 };
115
116static ERR_STRING_DATA PKCS7_str_reasons[]=
117 {
118{ERR_REASON(PKCS7_R_CERTIFICATE_VERIFY_ERROR),"certificate verify error"},
119{ERR_REASON(PKCS7_R_CIPHER_HAS_NO_OBJECT_IDENTIFIER),"cipher has no object identifier"},
120{ERR_REASON(PKCS7_R_CIPHER_NOT_INITIALIZED),"cipher not initialized"},
121{ERR_REASON(PKCS7_R_CONTENT_AND_DATA_PRESENT),"content and data present"},
122{ERR_REASON(PKCS7_R_CTRL_ERROR) ,"ctrl error"},
123{ERR_REASON(PKCS7_R_DECODE_ERROR) ,"decode error"},
124{ERR_REASON(PKCS7_R_DECRYPTED_KEY_IS_WRONG_LENGTH),"decrypted key is wrong length"},
125{ERR_REASON(PKCS7_R_DECRYPT_ERROR) ,"decrypt error"},
126{ERR_REASON(PKCS7_R_DIGEST_FAILURE) ,"digest failure"},
127{ERR_REASON(PKCS7_R_ENCRYPTION_CTRL_FAILURE),"encryption ctrl failure"},
128{ERR_REASON(PKCS7_R_ENCRYPTION_NOT_SUPPORTED_FOR_THIS_KEY_TYPE),"encryption not supported for this key type"},
129{ERR_REASON(PKCS7_R_ERROR_ADDING_RECIPIENT),"error adding recipient"},
130{ERR_REASON(PKCS7_R_ERROR_SETTING_CIPHER),"error setting cipher"},
131{ERR_REASON(PKCS7_R_INVALID_MIME_TYPE) ,"invalid mime type"},
132{ERR_REASON(PKCS7_R_INVALID_NULL_POINTER),"invalid null pointer"},
133{ERR_REASON(PKCS7_R_MIME_NO_CONTENT_TYPE),"mime no content type"},
134{ERR_REASON(PKCS7_R_MIME_PARSE_ERROR) ,"mime parse error"},
135{ERR_REASON(PKCS7_R_MIME_SIG_PARSE_ERROR),"mime sig parse error"},
136{ERR_REASON(PKCS7_R_MISSING_CERIPEND_INFO),"missing ceripend info"},
137{ERR_REASON(PKCS7_R_NO_CONTENT) ,"no content"},
138{ERR_REASON(PKCS7_R_NO_CONTENT_TYPE) ,"no content type"},
139{ERR_REASON(PKCS7_R_NO_DEFAULT_DIGEST) ,"no default digest"},
140{ERR_REASON(PKCS7_R_NO_MATCHING_DIGEST_TYPE_FOUND),"no matching digest type found"},
141{ERR_REASON(PKCS7_R_NO_MULTIPART_BODY_FAILURE),"no multipart body failure"},
142{ERR_REASON(PKCS7_R_NO_MULTIPART_BOUNDARY),"no multipart boundary"},
143{ERR_REASON(PKCS7_R_NO_RECIPIENT_MATCHES_CERTIFICATE),"no recipient matches certificate"},
144{ERR_REASON(PKCS7_R_NO_RECIPIENT_MATCHES_KEY),"no recipient matches key"},
145{ERR_REASON(PKCS7_R_NO_SIGNATURES_ON_DATA),"no signatures on data"},
146{ERR_REASON(PKCS7_R_NO_SIGNERS) ,"no signers"},
147{ERR_REASON(PKCS7_R_NO_SIG_CONTENT_TYPE) ,"no sig content type"},
148{ERR_REASON(PKCS7_R_OPERATION_NOT_SUPPORTED_ON_THIS_TYPE),"operation not supported on this type"},
149{ERR_REASON(PKCS7_R_PKCS7_ADD_SIGNATURE_ERROR),"pkcs7 add signature error"},
150{ERR_REASON(PKCS7_R_PKCS7_ADD_SIGNER_ERROR),"pkcs7 add signer error"},
151{ERR_REASON(PKCS7_R_PKCS7_DATAFINAL) ,"pkcs7 datafinal"},
152{ERR_REASON(PKCS7_R_PKCS7_DATAFINAL_ERROR),"pkcs7 datafinal error"},
153{ERR_REASON(PKCS7_R_PKCS7_DATASIGN) ,"pkcs7 datasign"},
154{ERR_REASON(PKCS7_R_PKCS7_PARSE_ERROR) ,"pkcs7 parse error"},
155{ERR_REASON(PKCS7_R_PKCS7_SIG_PARSE_ERROR),"pkcs7 sig parse error"},
156{ERR_REASON(PKCS7_R_PRIVATE_KEY_DOES_NOT_MATCH_CERTIFICATE),"private key does not match certificate"},
157{ERR_REASON(PKCS7_R_SIGNATURE_FAILURE) ,"signature failure"},
158{ERR_REASON(PKCS7_R_SIGNER_CERTIFICATE_NOT_FOUND),"signer certificate not found"},
159{ERR_REASON(PKCS7_R_SIGNING_CTRL_FAILURE),"signing ctrl failure"},
160{ERR_REASON(PKCS7_R_SIGNING_NOT_SUPPORTED_FOR_THIS_KEY_TYPE),"signing not supported for this key type"},
161{ERR_REASON(PKCS7_R_SIG_INVALID_MIME_TYPE),"sig invalid mime type"},
162{ERR_REASON(PKCS7_R_SMIME_TEXT_ERROR) ,"smime text error"},
163{ERR_REASON(PKCS7_R_UNABLE_TO_FIND_CERTIFICATE),"unable to find certificate"},
164{ERR_REASON(PKCS7_R_UNABLE_TO_FIND_MEM_BIO),"unable to find mem bio"},
165{ERR_REASON(PKCS7_R_UNABLE_TO_FIND_MESSAGE_DIGEST),"unable to find message digest"},
166{ERR_REASON(PKCS7_R_UNKNOWN_DIGEST_TYPE) ,"unknown digest type"},
167{ERR_REASON(PKCS7_R_UNKNOWN_OPERATION) ,"unknown operation"},
168{ERR_REASON(PKCS7_R_UNSUPPORTED_CIPHER_TYPE),"unsupported cipher type"},
169{ERR_REASON(PKCS7_R_UNSUPPORTED_CONTENT_TYPE),"unsupported content type"},
170{ERR_REASON(PKCS7_R_WRONG_CONTENT_TYPE) ,"wrong content type"},
171{ERR_REASON(PKCS7_R_WRONG_PKCS7_TYPE) ,"wrong pkcs7 type"},
172{0,NULL}
173 };
174
175#endif
176
177void ERR_load_PKCS7_strings(void)
178 {
179#ifndef OPENSSL_NO_ERR
180
181 if (ERR_func_error_string(PKCS7_str_functs[0].error) == NULL)
182 {
183 ERR_load_strings(0,PKCS7_str_functs);
184 ERR_load_strings(0,PKCS7_str_reasons);
185 }
186#endif
187 }