diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/lib/libcrypto/Makefile | 4 | ||||
-rw-r--r-- | src/lib/libcrypto/asn1/asn1.h | 15 | ||||
-rw-r--r-- | src/lib/libcrypto/asn1/n_pkey.c | 435 | ||||
-rw-r--r-- | src/lib/libcrypto/asn1/x_nx509.c | 113 | ||||
-rw-r--r-- | src/lib/libcrypto/rsa/rsa.h | 14 |
5 files changed, 3 insertions, 578 deletions
diff --git a/src/lib/libcrypto/Makefile b/src/lib/libcrypto/Makefile index be22c4e9e6..6bbe8ad9de 100644 --- a/src/lib/libcrypto/Makefile +++ b/src/lib/libcrypto/Makefile | |||
@@ -1,4 +1,4 @@ | |||
1 | # $OpenBSD: Makefile,v 1.69 2022/01/14 07:52:24 tb Exp $ | 1 | # $OpenBSD: Makefile,v 1.70 2022/01/14 08:12:31 tb Exp $ |
2 | 2 | ||
3 | LIB= crypto | 3 | LIB= crypto |
4 | LIBREBUILD=y | 4 | LIBREBUILD=y |
@@ -62,11 +62,9 @@ SRCS+= a_print.c a_type.c a_string.c | |||
62 | SRCS+= a_enum.c a_utf8.c a_mbstr.c a_strex.c | 62 | SRCS+= a_enum.c a_utf8.c a_mbstr.c a_strex.c |
63 | SRCS+= x_algor.c x_val.c x_pubkey.c x_sig.c x_req.c x_attrib.c x_bignum.c | 63 | SRCS+= x_algor.c x_val.c x_pubkey.c x_sig.c x_req.c x_attrib.c x_bignum.c |
64 | SRCS+= x_long.c x_name.c x_x509.c x_x509a.c x_crl.c x_info.c x_spki.c nsseq.c | 64 | SRCS+= x_long.c x_name.c x_x509.c x_x509a.c x_crl.c x_info.c x_spki.c nsseq.c |
65 | SRCS+= x_nx509.c | ||
66 | SRCS+= t_req.c t_x509.c t_x509a.c t_crl.c t_pkey.c t_spki.c | 65 | SRCS+= t_req.c t_x509.c t_x509a.c t_crl.c t_pkey.c t_spki.c |
67 | SRCS+= tasn_new.c tasn_fre.c tasn_enc.c tasn_dec.c tasn_utl.c tasn_typ.c | 66 | SRCS+= tasn_new.c tasn_fre.c tasn_enc.c tasn_dec.c tasn_utl.c tasn_typ.c |
68 | SRCS+= tasn_prn.c ameth_lib.c | 67 | SRCS+= tasn_prn.c ameth_lib.c |
69 | SRCS+= n_pkey.c | ||
70 | SRCS+= x_pkey.c x_exten.c bio_asn1.c bio_ndef.c asn_mime.c | 68 | SRCS+= x_pkey.c x_exten.c bio_asn1.c bio_ndef.c asn_mime.c |
71 | SRCS+= asn1_gen.c asn1_par.c asn1_old_lib.c asn1_err.c a_strnid.c | 69 | SRCS+= asn1_gen.c asn1_par.c asn1_old_lib.c asn1_err.c a_strnid.c |
72 | SRCS+= p5_pbe.c p5_pbev2.c p8_pkey.c asn_moid.c | 70 | SRCS+= p5_pbe.c p5_pbev2.c p8_pkey.c asn_moid.c |
diff --git a/src/lib/libcrypto/asn1/asn1.h b/src/lib/libcrypto/asn1/asn1.h index 2e854f511e..3f587fe5a0 100644 --- a/src/lib/libcrypto/asn1/asn1.h +++ b/src/lib/libcrypto/asn1/asn1.h | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: asn1.h,v 1.60 2022/01/14 08:09:18 tb Exp $ */ | 1 | /* $OpenBSD: asn1.h,v 1.61 2022/01/14 08:12:31 tb Exp $ */ |
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) |
3 | * All rights reserved. | 3 | * All rights reserved. |
4 | * | 4 | * |
@@ -484,11 +484,6 @@ ASN1_SEQUENCE_ANY *d2i_ASN1_SET_ANY(ASN1_SEQUENCE_ANY **a, const unsigned char * | |||
484 | int i2d_ASN1_SET_ANY(const ASN1_SEQUENCE_ANY *a, unsigned char **out); | 484 | int i2d_ASN1_SET_ANY(const ASN1_SEQUENCE_ANY *a, unsigned char **out); |
485 | extern const ASN1_ITEM ASN1_SET_ANY_it; | 485 | extern const ASN1_ITEM ASN1_SET_ANY_it; |
486 | 486 | ||
487 | typedef struct NETSCAPE_X509_st { | ||
488 | ASN1_OCTET_STRING *header; | ||
489 | X509 *cert; | ||
490 | } NETSCAPE_X509; | ||
491 | |||
492 | /* This is used to contain a list of bit names */ | 487 | /* This is used to contain a list of bit names */ |
493 | typedef struct BIT_STRING_BITNAME_st { | 488 | typedef struct BIT_STRING_BITNAME_st { |
494 | int bitnum; | 489 | int bitnum; |
@@ -850,14 +845,6 @@ int ASN1_parse_dump(BIO *bp, const unsigned char *pp, long len, int indent, int | |||
850 | unsigned long ASN1_tag2bit(int tag); | 845 | unsigned long ASN1_tag2bit(int tag); |
851 | const char *ASN1_tag2str(int tag); | 846 | const char *ASN1_tag2str(int tag); |
852 | 847 | ||
853 | /* Used to load and write netscape format cert */ | ||
854 | |||
855 | NETSCAPE_X509 *NETSCAPE_X509_new(void); | ||
856 | void NETSCAPE_X509_free(NETSCAPE_X509 *a); | ||
857 | NETSCAPE_X509 *d2i_NETSCAPE_X509(NETSCAPE_X509 **a, const unsigned char **in, long len); | ||
858 | int i2d_NETSCAPE_X509(NETSCAPE_X509 *a, unsigned char **out); | ||
859 | extern const ASN1_ITEM NETSCAPE_X509_it; | ||
860 | |||
861 | int ASN1_UNIVERSALSTRING_to_string(ASN1_UNIVERSALSTRING *s); | 848 | int ASN1_UNIVERSALSTRING_to_string(ASN1_UNIVERSALSTRING *s); |
862 | 849 | ||
863 | int ASN1_TYPE_set_octetstring(ASN1_TYPE *a, const unsigned char *data, int len); | 850 | int ASN1_TYPE_set_octetstring(ASN1_TYPE *a, const unsigned char *data, int len); |
diff --git a/src/lib/libcrypto/asn1/n_pkey.c b/src/lib/libcrypto/asn1/n_pkey.c deleted file mode 100644 index 40d8fa4240..0000000000 --- a/src/lib/libcrypto/asn1/n_pkey.c +++ /dev/null | |||
@@ -1,435 +0,0 @@ | |||
1 | /* $OpenBSD: n_pkey.c,v 1.35 2021/12/25 13:17:48 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 | #include <stdio.h> | ||
60 | #include <string.h> | ||
61 | |||
62 | #include <openssl/opensslconf.h> | ||
63 | |||
64 | #ifndef OPENSSL_NO_RSA | ||
65 | #include <openssl/asn1t.h> | ||
66 | #include <openssl/err.h> | ||
67 | #include <openssl/evp.h> | ||
68 | #include <openssl/objects.h> | ||
69 | #include <openssl/rsa.h> | ||
70 | #include <openssl/x509.h> | ||
71 | |||
72 | #include "evp_locl.h" | ||
73 | #include "x509_lcl.h" | ||
74 | |||
75 | #ifndef OPENSSL_NO_RC4 | ||
76 | |||
77 | typedef struct netscape_pkey_st { | ||
78 | long version; | ||
79 | X509_ALGOR *algor; | ||
80 | ASN1_OCTET_STRING *private_key; | ||
81 | } NETSCAPE_PKEY; | ||
82 | |||
83 | typedef struct netscape_encrypted_pkey_st { | ||
84 | ASN1_OCTET_STRING *os; | ||
85 | /* This is the same structure as DigestInfo so use it: | ||
86 | * although this isn't really anything to do with | ||
87 | * digests. | ||
88 | */ | ||
89 | X509_SIG *enckey; | ||
90 | } NETSCAPE_ENCRYPTED_PKEY; | ||
91 | |||
92 | |||
93 | static const ASN1_AUX NETSCAPE_ENCRYPTED_PKEY_aux = { | ||
94 | .flags = ASN1_AFLG_BROKEN, | ||
95 | }; | ||
96 | static const ASN1_TEMPLATE NETSCAPE_ENCRYPTED_PKEY_seq_tt[] = { | ||
97 | { | ||
98 | .offset = offsetof(NETSCAPE_ENCRYPTED_PKEY, os), | ||
99 | .field_name = "os", | ||
100 | .item = &ASN1_OCTET_STRING_it, | ||
101 | }, | ||
102 | { | ||
103 | .offset = offsetof(NETSCAPE_ENCRYPTED_PKEY, enckey), | ||
104 | .field_name = "enckey", | ||
105 | .item = &X509_SIG_it, | ||
106 | }, | ||
107 | }; | ||
108 | |||
109 | const ASN1_ITEM NETSCAPE_ENCRYPTED_PKEY_it = { | ||
110 | .itype = ASN1_ITYPE_SEQUENCE, | ||
111 | .utype = V_ASN1_SEQUENCE, | ||
112 | .templates = NETSCAPE_ENCRYPTED_PKEY_seq_tt, | ||
113 | .tcount = sizeof(NETSCAPE_ENCRYPTED_PKEY_seq_tt) / sizeof(ASN1_TEMPLATE), | ||
114 | .funcs = &NETSCAPE_ENCRYPTED_PKEY_aux, | ||
115 | .size = sizeof(NETSCAPE_ENCRYPTED_PKEY), | ||
116 | .sname = "NETSCAPE_ENCRYPTED_PKEY", | ||
117 | }; | ||
118 | |||
119 | NETSCAPE_ENCRYPTED_PKEY *NETSCAPE_ENCRYPTED_PKEY_new(void); | ||
120 | void NETSCAPE_ENCRYPTED_PKEY_free(NETSCAPE_ENCRYPTED_PKEY *a); | ||
121 | NETSCAPE_ENCRYPTED_PKEY *d2i_NETSCAPE_ENCRYPTED_PKEY(NETSCAPE_ENCRYPTED_PKEY **a, const unsigned char **in, long len); | ||
122 | int i2d_NETSCAPE_ENCRYPTED_PKEY(const NETSCAPE_ENCRYPTED_PKEY *a, unsigned char **out); | ||
123 | |||
124 | NETSCAPE_ENCRYPTED_PKEY * | ||
125 | d2i_NETSCAPE_ENCRYPTED_PKEY(NETSCAPE_ENCRYPTED_PKEY **a, const unsigned char **in, long len) | ||
126 | { | ||
127 | return (NETSCAPE_ENCRYPTED_PKEY *)ASN1_item_d2i((ASN1_VALUE **)a, in, len, | ||
128 | &NETSCAPE_ENCRYPTED_PKEY_it); | ||
129 | } | ||
130 | |||
131 | int | ||
132 | i2d_NETSCAPE_ENCRYPTED_PKEY(const NETSCAPE_ENCRYPTED_PKEY *a, unsigned char **out) | ||
133 | { | ||
134 | return ASN1_item_i2d((ASN1_VALUE *)a, out, &NETSCAPE_ENCRYPTED_PKEY_it); | ||
135 | } | ||
136 | |||
137 | NETSCAPE_ENCRYPTED_PKEY * | ||
138 | NETSCAPE_ENCRYPTED_PKEY_new(void) | ||
139 | { | ||
140 | return (NETSCAPE_ENCRYPTED_PKEY *)ASN1_item_new(&NETSCAPE_ENCRYPTED_PKEY_it); | ||
141 | } | ||
142 | |||
143 | void | ||
144 | NETSCAPE_ENCRYPTED_PKEY_free(NETSCAPE_ENCRYPTED_PKEY *a) | ||
145 | { | ||
146 | ASN1_item_free((ASN1_VALUE *)a, &NETSCAPE_ENCRYPTED_PKEY_it); | ||
147 | } | ||
148 | |||
149 | static const ASN1_TEMPLATE NETSCAPE_PKEY_seq_tt[] = { | ||
150 | { | ||
151 | .offset = offsetof(NETSCAPE_PKEY, version), | ||
152 | .field_name = "version", | ||
153 | .item = &LONG_it, | ||
154 | }, | ||
155 | { | ||
156 | .offset = offsetof(NETSCAPE_PKEY, algor), | ||
157 | .field_name = "algor", | ||
158 | .item = &X509_ALGOR_it, | ||
159 | }, | ||
160 | { | ||
161 | .offset = offsetof(NETSCAPE_PKEY, private_key), | ||
162 | .field_name = "private_key", | ||
163 | .item = &ASN1_OCTET_STRING_it, | ||
164 | }, | ||
165 | }; | ||
166 | |||
167 | const ASN1_ITEM NETSCAPE_PKEY_it = { | ||
168 | .itype = ASN1_ITYPE_SEQUENCE, | ||
169 | .utype = V_ASN1_SEQUENCE, | ||
170 | .templates = NETSCAPE_PKEY_seq_tt, | ||
171 | .tcount = sizeof(NETSCAPE_PKEY_seq_tt) / sizeof(ASN1_TEMPLATE), | ||
172 | .size = sizeof(NETSCAPE_PKEY), | ||
173 | .sname = "NETSCAPE_PKEY", | ||
174 | }; | ||
175 | |||
176 | NETSCAPE_PKEY *NETSCAPE_PKEY_new(void); | ||
177 | void NETSCAPE_PKEY_free(NETSCAPE_PKEY *a); | ||
178 | NETSCAPE_PKEY *d2i_NETSCAPE_PKEY(NETSCAPE_PKEY **a, const unsigned char **in, long len); | ||
179 | int i2d_NETSCAPE_PKEY(const NETSCAPE_PKEY *a, unsigned char **out); | ||
180 | |||
181 | NETSCAPE_PKEY * | ||
182 | d2i_NETSCAPE_PKEY(NETSCAPE_PKEY **a, const unsigned char **in, long len) | ||
183 | { | ||
184 | return (NETSCAPE_PKEY *)ASN1_item_d2i((ASN1_VALUE **)a, in, len, | ||
185 | &NETSCAPE_PKEY_it); | ||
186 | } | ||
187 | |||
188 | int | ||
189 | i2d_NETSCAPE_PKEY(const NETSCAPE_PKEY *a, unsigned char **out) | ||
190 | { | ||
191 | return ASN1_item_i2d((ASN1_VALUE *)a, out, &NETSCAPE_PKEY_it); | ||
192 | } | ||
193 | |||
194 | NETSCAPE_PKEY * | ||
195 | NETSCAPE_PKEY_new(void) | ||
196 | { | ||
197 | return (NETSCAPE_PKEY *)ASN1_item_new(&NETSCAPE_PKEY_it); | ||
198 | } | ||
199 | |||
200 | void | ||
201 | NETSCAPE_PKEY_free(NETSCAPE_PKEY *a) | ||
202 | { | ||
203 | ASN1_item_free((ASN1_VALUE *)a, &NETSCAPE_PKEY_it); | ||
204 | } | ||
205 | |||
206 | static RSA *d2i_RSA_NET_2(RSA **a, ASN1_OCTET_STRING *os, | ||
207 | int (*cb)(char *buf, int len, const char *prompt, int verify), int sgckey); | ||
208 | |||
209 | int | ||
210 | i2d_Netscape_RSA(const RSA *a, unsigned char **pp, | ||
211 | int (*cb)(char *buf, int len, const char *prompt, int verify)) | ||
212 | { | ||
213 | return i2d_RSA_NET(a, pp, cb, 0); | ||
214 | } | ||
215 | |||
216 | int | ||
217 | i2d_RSA_NET(const RSA *a, unsigned char **pp, | ||
218 | int (*cb)(char *buf, int len, const char *prompt, int verify), int sgckey) | ||
219 | { | ||
220 | int i, j, ret = 0; | ||
221 | int rsalen, pkeylen, olen; | ||
222 | NETSCAPE_PKEY *pkey = NULL; | ||
223 | NETSCAPE_ENCRYPTED_PKEY *enckey = NULL; | ||
224 | unsigned char buf[256], *zz; | ||
225 | unsigned char key[EVP_MAX_KEY_LENGTH]; | ||
226 | EVP_CIPHER_CTX ctx; | ||
227 | EVP_CIPHER_CTX_init(&ctx); | ||
228 | |||
229 | if (a == NULL) | ||
230 | return (0); | ||
231 | |||
232 | if ((pkey = NETSCAPE_PKEY_new()) == NULL) | ||
233 | goto err; | ||
234 | if ((enckey = NETSCAPE_ENCRYPTED_PKEY_new()) == NULL) | ||
235 | goto err; | ||
236 | pkey->version = 0; | ||
237 | |||
238 | pkey->algor->algorithm = OBJ_nid2obj(NID_rsaEncryption); | ||
239 | if ((pkey->algor->parameter = ASN1_TYPE_new()) == NULL) | ||
240 | goto err; | ||
241 | pkey->algor->parameter->type = V_ASN1_NULL; | ||
242 | |||
243 | rsalen = i2d_RSAPrivateKey(a, NULL); | ||
244 | |||
245 | /* Fake some octet strings just for the initial length | ||
246 | * calculation. | ||
247 | */ | ||
248 | pkey->private_key->length = rsalen; | ||
249 | pkeylen = i2d_NETSCAPE_PKEY(pkey, NULL); | ||
250 | enckey->enckey->digest->length = pkeylen; | ||
251 | enckey->os->length = 11; /* "private-key" */ | ||
252 | enckey->enckey->algor->algorithm = OBJ_nid2obj(NID_rc4); | ||
253 | if ((enckey->enckey->algor->parameter = ASN1_TYPE_new()) == NULL) | ||
254 | goto err; | ||
255 | enckey->enckey->algor->parameter->type = V_ASN1_NULL; | ||
256 | |||
257 | if (pp == NULL) { | ||
258 | olen = i2d_NETSCAPE_ENCRYPTED_PKEY(enckey, NULL); | ||
259 | NETSCAPE_PKEY_free(pkey); | ||
260 | NETSCAPE_ENCRYPTED_PKEY_free(enckey); | ||
261 | return olen; | ||
262 | } | ||
263 | |||
264 | /* Since its RC4 encrypted length is actual length */ | ||
265 | if ((zz = malloc(rsalen)) == NULL) { | ||
266 | ASN1error(ERR_R_MALLOC_FAILURE); | ||
267 | goto err; | ||
268 | } | ||
269 | |||
270 | pkey->private_key->data = zz; | ||
271 | /* Write out private key encoding */ | ||
272 | i2d_RSAPrivateKey(a, &zz); | ||
273 | |||
274 | if ((zz = malloc(pkeylen)) == NULL) { | ||
275 | ASN1error(ERR_R_MALLOC_FAILURE); | ||
276 | goto err; | ||
277 | } | ||
278 | |||
279 | enckey->enckey->digest->data = zz; | ||
280 | if (!ASN1_STRING_set(enckey->os, "private-key", -1)) { | ||
281 | ASN1error(ERR_R_MALLOC_FAILURE); | ||
282 | goto err; | ||
283 | } | ||
284 | i2d_NETSCAPE_PKEY(pkey, &zz); | ||
285 | |||
286 | /* Wipe the private key encoding */ | ||
287 | explicit_bzero(pkey->private_key->data, rsalen); | ||
288 | |||
289 | if (cb == NULL) | ||
290 | cb = EVP_read_pw_string; | ||
291 | i = cb((char *)buf, sizeof(buf), "Enter Private Key password:", 1); | ||
292 | if (i != 0) { | ||
293 | ASN1error(ASN1_R_BAD_PASSWORD_READ); | ||
294 | goto err; | ||
295 | } | ||
296 | i = strlen((char *)buf); | ||
297 | /* If the key is used for SGC the algorithm is modified a little. */ | ||
298 | if (sgckey) { | ||
299 | if (!EVP_Digest(buf, i, buf, NULL, EVP_md5(), NULL)) | ||
300 | goto err; | ||
301 | memcpy(buf + 16, "SGCKEYSALT", 10); | ||
302 | i = 26; | ||
303 | } | ||
304 | |||
305 | if (!EVP_BytesToKey(EVP_rc4(), EVP_md5(), NULL, buf, i,1, key, NULL)) | ||
306 | goto err; | ||
307 | explicit_bzero(buf, sizeof(buf)); | ||
308 | |||
309 | /* Encrypt private key in place */ | ||
310 | zz = enckey->enckey->digest->data; | ||
311 | if (!EVP_EncryptInit_ex(&ctx, EVP_rc4(), NULL, key, NULL)) | ||
312 | goto err; | ||
313 | if (!EVP_EncryptUpdate(&ctx, zz, &i, zz, pkeylen)) | ||
314 | goto err; | ||
315 | if (!EVP_EncryptFinal_ex(&ctx, zz + i, &j)) | ||
316 | goto err; | ||
317 | |||
318 | ret = i2d_NETSCAPE_ENCRYPTED_PKEY(enckey, pp); | ||
319 | err: | ||
320 | EVP_CIPHER_CTX_cleanup(&ctx); | ||
321 | NETSCAPE_ENCRYPTED_PKEY_free(enckey); | ||
322 | NETSCAPE_PKEY_free(pkey); | ||
323 | return (ret); | ||
324 | } | ||
325 | |||
326 | |||
327 | RSA * | ||
328 | d2i_Netscape_RSA(RSA **a, const unsigned char **pp, long length, | ||
329 | int (*cb)(char *buf, int len, const char *prompt, int verify)) | ||
330 | { | ||
331 | return d2i_RSA_NET(a, pp, length, cb, 0); | ||
332 | } | ||
333 | |||
334 | RSA * | ||
335 | d2i_RSA_NET(RSA **a, const unsigned char **pp, long length, | ||
336 | int (*cb)(char *buf, int len, const char *prompt, int verify), int sgckey) | ||
337 | { | ||
338 | RSA *ret = NULL; | ||
339 | const unsigned char *p; | ||
340 | NETSCAPE_ENCRYPTED_PKEY *enckey = NULL; | ||
341 | |||
342 | p = *pp; | ||
343 | |||
344 | enckey = d2i_NETSCAPE_ENCRYPTED_PKEY(NULL, &p, length); | ||
345 | if (!enckey) { | ||
346 | ASN1error(ASN1_R_DECODING_ERROR); | ||
347 | return NULL; | ||
348 | } | ||
349 | |||
350 | /* XXX 11 == strlen("private-key") */ | ||
351 | if (enckey->os->length != 11 || | ||
352 | memcmp("private-key", enckey->os->data, 11) != 0) { | ||
353 | ASN1error(ASN1_R_PRIVATE_KEY_HEADER_MISSING); | ||
354 | goto err; | ||
355 | } | ||
356 | if (OBJ_obj2nid(enckey->enckey->algor->algorithm) != NID_rc4) { | ||
357 | ASN1error(ASN1_R_UNSUPPORTED_ENCRYPTION_ALGORITHM); | ||
358 | goto err; | ||
359 | } | ||
360 | if (cb == NULL) | ||
361 | cb = EVP_read_pw_string; | ||
362 | if ((ret = d2i_RSA_NET_2(a, enckey->enckey->digest, cb, | ||
363 | sgckey)) == NULL) | ||
364 | goto err; | ||
365 | |||
366 | *pp = p; | ||
367 | |||
368 | err: | ||
369 | NETSCAPE_ENCRYPTED_PKEY_free(enckey); | ||
370 | return ret; | ||
371 | |||
372 | } | ||
373 | |||
374 | static RSA * | ||
375 | d2i_RSA_NET_2(RSA **a, ASN1_OCTET_STRING *os, | ||
376 | int (*cb)(char *buf, int len, const char *prompt, int verify), int sgckey) | ||
377 | { | ||
378 | NETSCAPE_PKEY *pkey = NULL; | ||
379 | RSA *ret = NULL; | ||
380 | int i, j; | ||
381 | unsigned char buf[256]; | ||
382 | const unsigned char *zz; | ||
383 | unsigned char key[EVP_MAX_KEY_LENGTH]; | ||
384 | EVP_CIPHER_CTX ctx; | ||
385 | EVP_CIPHER_CTX_init(&ctx); | ||
386 | |||
387 | i=cb((char *)buf, sizeof(buf), "Enter Private Key password:",0); | ||
388 | if (i != 0) { | ||
389 | ASN1error(ASN1_R_BAD_PASSWORD_READ); | ||
390 | goto err; | ||
391 | } | ||
392 | |||
393 | i = strlen((char *)buf); | ||
394 | if (sgckey){ | ||
395 | if (!EVP_Digest(buf, i, buf, NULL, EVP_md5(), NULL)) | ||
396 | goto err; | ||
397 | memcpy(buf + 16, "SGCKEYSALT", 10); | ||
398 | i = 26; | ||
399 | } | ||
400 | |||
401 | if (!EVP_BytesToKey(EVP_rc4(), EVP_md5(), NULL, buf, i,1, key, NULL)) | ||
402 | goto err; | ||
403 | explicit_bzero(buf, sizeof(buf)); | ||
404 | |||
405 | if (!EVP_DecryptInit_ex(&ctx, EVP_rc4(), NULL, key, NULL)) | ||
406 | goto err; | ||
407 | if (!EVP_DecryptUpdate(&ctx, os->data, &i, os->data, os->length)) | ||
408 | goto err; | ||
409 | if (!EVP_DecryptFinal_ex(&ctx, &(os->data[i]), &j)) | ||
410 | goto err; | ||
411 | os->length = i + j; | ||
412 | |||
413 | zz = os->data; | ||
414 | |||
415 | if ((pkey = d2i_NETSCAPE_PKEY(NULL, &zz, os->length)) == NULL) { | ||
416 | ASN1error(ASN1_R_UNABLE_TO_DECODE_RSA_PRIVATE_KEY); | ||
417 | goto err; | ||
418 | } | ||
419 | |||
420 | zz = pkey->private_key->data; | ||
421 | if ((ret = d2i_RSAPrivateKey(a, &zz, | ||
422 | pkey->private_key->length)) == NULL) { | ||
423 | ASN1error(ASN1_R_UNABLE_TO_DECODE_RSA_KEY); | ||
424 | goto err; | ||
425 | } | ||
426 | |||
427 | err: | ||
428 | EVP_CIPHER_CTX_cleanup(&ctx); | ||
429 | NETSCAPE_PKEY_free(pkey); | ||
430 | return (ret); | ||
431 | } | ||
432 | |||
433 | #endif /* OPENSSL_NO_RC4 */ | ||
434 | |||
435 | #endif | ||
diff --git a/src/lib/libcrypto/asn1/x_nx509.c b/src/lib/libcrypto/asn1/x_nx509.c deleted file mode 100644 index 7e18be8c79..0000000000 --- a/src/lib/libcrypto/asn1/x_nx509.c +++ /dev/null | |||
@@ -1,113 +0,0 @@ | |||
1 | /* $OpenBSD: x_nx509.c,v 1.6 2015/02/11 04:00:39 jsing Exp $ */ | ||
2 | /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL | ||
3 | * project 2005. | ||
4 | */ | ||
5 | /* ==================================================================== | ||
6 | * Copyright (c) 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 | * 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 <stddef.h> | ||
60 | #include <openssl/x509.h> | ||
61 | #include <openssl/asn1.h> | ||
62 | #include <openssl/asn1t.h> | ||
63 | |||
64 | /* Old netscape certificate wrapper format */ | ||
65 | |||
66 | static const ASN1_TEMPLATE NETSCAPE_X509_seq_tt[] = { | ||
67 | { | ||
68 | .offset = offsetof(NETSCAPE_X509, header), | ||
69 | .field_name = "header", | ||
70 | .item = &ASN1_OCTET_STRING_it, | ||
71 | }, | ||
72 | { | ||
73 | .flags = ASN1_TFLG_OPTIONAL, | ||
74 | .offset = offsetof(NETSCAPE_X509, cert), | ||
75 | .field_name = "cert", | ||
76 | .item = &X509_it, | ||
77 | }, | ||
78 | }; | ||
79 | |||
80 | const ASN1_ITEM NETSCAPE_X509_it = { | ||
81 | .itype = ASN1_ITYPE_SEQUENCE, | ||
82 | .utype = V_ASN1_SEQUENCE, | ||
83 | .templates = NETSCAPE_X509_seq_tt, | ||
84 | .tcount = sizeof(NETSCAPE_X509_seq_tt) / sizeof(ASN1_TEMPLATE), | ||
85 | .size = sizeof(NETSCAPE_X509), | ||
86 | .sname = "NETSCAPE_X509", | ||
87 | }; | ||
88 | |||
89 | |||
90 | NETSCAPE_X509 * | ||
91 | d2i_NETSCAPE_X509(NETSCAPE_X509 **a, const unsigned char **in, long len) | ||
92 | { | ||
93 | return (NETSCAPE_X509 *)ASN1_item_d2i((ASN1_VALUE **)a, in, len, | ||
94 | &NETSCAPE_X509_it); | ||
95 | } | ||
96 | |||
97 | int | ||
98 | i2d_NETSCAPE_X509(NETSCAPE_X509 *a, unsigned char **out) | ||
99 | { | ||
100 | return ASN1_item_i2d((ASN1_VALUE *)a, out, &NETSCAPE_X509_it); | ||
101 | } | ||
102 | |||
103 | NETSCAPE_X509 * | ||
104 | NETSCAPE_X509_new(void) | ||
105 | { | ||
106 | return (NETSCAPE_X509 *)ASN1_item_new(&NETSCAPE_X509_it); | ||
107 | } | ||
108 | |||
109 | void | ||
110 | NETSCAPE_X509_free(NETSCAPE_X509 *a) | ||
111 | { | ||
112 | ASN1_item_free((ASN1_VALUE *)a, &NETSCAPE_X509_it); | ||
113 | } | ||
diff --git a/src/lib/libcrypto/rsa/rsa.h b/src/lib/libcrypto/rsa/rsa.h index daefcb85b2..e01e6ba553 100644 --- a/src/lib/libcrypto/rsa/rsa.h +++ b/src/lib/libcrypto/rsa/rsa.h | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: rsa.h,v 1.53 2022/01/14 07:49:49 tb Exp $ */ | 1 | /* $OpenBSD: rsa.h,v 1.54 2022/01/14 08:12:31 tb Exp $ */ |
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) |
3 | * All rights reserved. | 3 | * All rights reserved. |
4 | * | 4 | * |
@@ -380,18 +380,6 @@ int RSA_print_fp(FILE *fp, const RSA *r, int offset); | |||
380 | int RSA_print(BIO *bp, const RSA *r, int offset); | 380 | int RSA_print(BIO *bp, const RSA *r, int offset); |
381 | #endif | 381 | #endif |
382 | 382 | ||
383 | #ifndef OPENSSL_NO_RC4 | ||
384 | int i2d_RSA_NET(const RSA *a, unsigned char **pp, | ||
385 | int (*cb)(char *buf, int len, const char *prompt, int verify), int sgckey); | ||
386 | RSA *d2i_RSA_NET(RSA **a, const unsigned char **pp, long length, | ||
387 | int (*cb)(char *buf, int len, const char *prompt, int verify), int sgckey); | ||
388 | |||
389 | int i2d_Netscape_RSA(const RSA *a, unsigned char **pp, | ||
390 | int (*cb)(char *buf, int len, const char *prompt, int verify)); | ||
391 | RSA *d2i_Netscape_RSA(RSA **a, const unsigned char **pp, long length, | ||
392 | int (*cb)(char *buf, int len, const char *prompt, int verify)); | ||
393 | #endif | ||
394 | |||
395 | /* The following 2 functions sign and verify a X509_SIG ASN1 object | 383 | /* The following 2 functions sign and verify a X509_SIG ASN1 object |
396 | * inside PKCS#1 padded RSA encryption */ | 384 | * inside PKCS#1 padded RSA encryption */ |
397 | int RSA_sign(int type, const unsigned char *m, unsigned int m_length, | 385 | int RSA_sign(int type, const unsigned char *m, unsigned int m_length, |