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