summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/engine/eng_openssl.c
diff options
context:
space:
mode:
authortb <>2023-07-28 09:53:55 +0000
committertb <>2023-07-28 09:53:55 +0000
commitd4949db8e78438e8bb53c9c1297b068ac0df7827 (patch)
tree307457e0cf8fc786fb4c80edc29a92d5677d406e /src/lib/libcrypto/engine/eng_openssl.c
parent681b4eb7a5896143c26eac201c041f6f22357b18 (diff)
downloadopenbsd-d4949db8e78438e8bb53c9c1297b068ac0df7827.tar.gz
openbsd-d4949db8e78438e8bb53c9c1297b068ac0df7827.tar.bz2
openbsd-d4949db8e78438e8bb53c9c1297b068ac0df7827.zip
Set OPENSSL_NO_ENGINE, remove engine code
ENGINE was special. It's horrible code even by the low standards of this library. Some ports may now try to use the stubs which will fail, but the fallout from this should be minimal. Of course there are various language bindings that expose the ENGINE API. OpenSSL 3 disabling ENGINE by default will likely help fixing this at some point. ok jsing
Diffstat (limited to 'src/lib/libcrypto/engine/eng_openssl.c')
-rw-r--r--src/lib/libcrypto/engine/eng_openssl.c400
1 files changed, 0 insertions, 400 deletions
diff --git a/src/lib/libcrypto/engine/eng_openssl.c b/src/lib/libcrypto/engine/eng_openssl.c
deleted file mode 100644
index 6162b715f0..0000000000
--- a/src/lib/libcrypto/engine/eng_openssl.c
+++ /dev/null
@@ -1,400 +0,0 @@
1/* $OpenBSD: eng_openssl.c,v 1.19 2023/07/28 09:22:26 tb Exp $ */
2/* Written by Geoff Thorpe (geoff@geoffthorpe.net) for the OpenSSL
3 * project 2000.
4 */
5/* ====================================================================
6 * Copyright (c) 1999-2001 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58/* ====================================================================
59 * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED.
60 * ECDH support in OpenSSL originally developed by
61 * SUN MICROSYSTEMS, INC., and contributed to the OpenSSL project.
62 */
63
64#include <stdio.h>
65#include <string.h>
66
67#include <openssl/opensslconf.h>
68
69#include <openssl/crypto.h>
70#include <openssl/engine.h>
71#include <openssl/err.h>
72#include <openssl/evp.h>
73#include <openssl/pem.h>
74#include <openssl/rand.h>
75
76#ifndef OPENSSL_NO_DH
77#include <openssl/dh.h>
78#endif
79#ifndef OPENSSL_NO_DSA
80#include <openssl/dsa.h>
81#endif
82#ifndef OPENSSL_NO_RSA
83#include <openssl/rsa.h>
84#endif
85
86#include "evp_local.h"
87
88/* This testing gunk is implemented (and explained) lower down. It also assumes
89 * the application explicitly calls "ENGINE_load_openssl()" because this is no
90 * longer automatic in ENGINE_load_builtin_engines(). */
91#define TEST_ENG_OPENSSL_RC4
92#define TEST_ENG_OPENSSL_PKEY
93/* #define TEST_ENG_OPENSSL_RC4_OTHERS */
94#define TEST_ENG_OPENSSL_RC4_P_INIT
95/* #define TEST_ENG_OPENSSL_RC4_P_CIPHER */
96#define TEST_ENG_OPENSSL_SHA
97/* #define TEST_ENG_OPENSSL_SHA_OTHERS */
98/* #define TEST_ENG_OPENSSL_SHA_P_INIT */
99/* #define TEST_ENG_OPENSSL_SHA_P_UPDATE */
100/* #define TEST_ENG_OPENSSL_SHA_P_FINAL */
101
102/* Now check what of those algorithms are actually enabled */
103#ifdef OPENSSL_NO_RC4
104#undef TEST_ENG_OPENSSL_RC4
105#undef TEST_ENG_OPENSSL_RC4_OTHERS
106#undef TEST_ENG_OPENSSL_RC4_P_INIT
107#undef TEST_ENG_OPENSSL_RC4_P_CIPHER
108#endif
109#if defined(OPENSSL_NO_SHA) || defined(OPENSSL_NO_SHA1)
110#undef TEST_ENG_OPENSSL_SHA
111#undef TEST_ENG_OPENSSL_SHA_OTHERS
112#undef TEST_ENG_OPENSSL_SHA_P_INIT
113#undef TEST_ENG_OPENSSL_SHA_P_UPDATE
114#undef TEST_ENG_OPENSSL_SHA_P_FINAL
115#endif
116
117#ifdef TEST_ENG_OPENSSL_RC4
118static int openssl_ciphers(ENGINE *e, const EVP_CIPHER **cipher,
119 const int **nids, int nid);
120#endif
121#ifdef TEST_ENG_OPENSSL_SHA
122static int openssl_digests(ENGINE *e, const EVP_MD **digest,
123 const int **nids, int nid);
124#endif
125
126#ifdef TEST_ENG_OPENSSL_PKEY
127static EVP_PKEY *openssl_load_privkey(ENGINE *eng, const char *key_id,
128 UI_METHOD *ui_method, void *callback_data);
129#endif
130
131/* The constants used when creating the ENGINE */
132static const char *engine_openssl_id = "openssl";
133static const char *engine_openssl_name = "Software engine support";
134
135/* This internal function is used by ENGINE_openssl() and possibly by the
136 * "dynamic" ENGINE support too */
137static int
138bind_helper(ENGINE *e)
139{
140 if (!ENGINE_set_id(e, engine_openssl_id) ||
141 !ENGINE_set_name(e, engine_openssl_name)
142#ifndef TEST_ENG_OPENSSL_NO_ALGORITHMS
143#ifndef OPENSSL_NO_RSA
144 || !ENGINE_set_RSA(e, RSA_get_default_method())
145#endif
146#ifndef OPENSSL_NO_DSA
147 || !ENGINE_set_DSA(e, DSA_get_default_method())
148#endif
149#ifndef OPENSSL_NO_DH
150 || !ENGINE_set_DH(e, DH_get_default_method())
151#endif
152 || !ENGINE_set_RAND(e, RAND_SSLeay())
153#ifdef TEST_ENG_OPENSSL_RC4
154 || !ENGINE_set_ciphers(e, openssl_ciphers)
155#endif
156#ifdef TEST_ENG_OPENSSL_SHA
157 || !ENGINE_set_digests(e, openssl_digests)
158#endif
159#endif
160#ifdef TEST_ENG_OPENSSL_PKEY
161 || !ENGINE_set_load_privkey_function(e, openssl_load_privkey)
162#endif
163 )
164 return 0;
165 /* If we add errors to this ENGINE, ensure the error handling is setup here */
166 /* openssl_load_error_strings(); */
167 return 1;
168}
169
170static ENGINE *
171engine_openssl(void)
172{
173 ENGINE *ret = ENGINE_new();
174
175 if (ret == NULL)
176 return NULL;
177 if (!bind_helper(ret)) {
178 ENGINE_free(ret);
179 return NULL;
180 }
181 return ret;
182}
183
184void
185ENGINE_load_openssl(void)
186{
187 ENGINE *toadd = engine_openssl();
188
189 if (toadd == NULL)
190 return;
191 (void) ENGINE_add(toadd);
192 /* If the "add" worked, it gets a structural reference. So either way,
193 * we release our just-created reference. */
194 ENGINE_free(toadd);
195 ERR_clear_error();
196}
197
198/* This stuff is needed if this ENGINE is being compiled into a self-contained
199 * shared-library. */
200#ifdef ENGINE_DYNAMIC_SUPPORT
201static int
202bind_fn(ENGINE *e, const char *id)
203{
204 if (id && (strcmp(id, engine_openssl_id) != 0))
205 return 0;
206 if (!bind_helper(e))
207 return 0;
208 return 1;
209}
210IMPLEMENT_DYNAMIC_CHECK_FN()
211IMPLEMENT_DYNAMIC_BIND_FN(bind_fn)
212#endif /* ENGINE_DYNAMIC_SUPPORT */
213
214#ifdef TEST_ENG_OPENSSL_RC4
215/* This section of code compiles an "alternative implementation" of two modes of
216 * RC4 into this ENGINE. The result is that EVP_CIPHER operation for "rc4"
217 * should under normal circumstances go via this support rather than the default
218 * EVP support. There are other symbols to tweak the testing;
219 * TEST_ENC_OPENSSL_RC4_OTHERS - print a one line message to stderr each time
220 * we're asked for a cipher we don't support (should not happen).
221 * TEST_ENG_OPENSSL_RC4_P_INIT - print a one line message to stderr each time
222 * the "init_key" handler is called.
223 * TEST_ENG_OPENSSL_RC4_P_CIPHER - ditto for the "cipher" handler.
224 */
225#include <openssl/rc4.h>
226#define TEST_RC4_KEY_SIZE 16
227static int test_cipher_nids[] = {NID_rc4, NID_rc4_40};
228static int test_cipher_nids_number = 2;
229
230typedef struct {
231 unsigned char key[TEST_RC4_KEY_SIZE];
232 RC4_KEY ks;
233} TEST_RC4_KEY;
234
235#define test(ctx) ((TEST_RC4_KEY *)(ctx)->cipher_data)
236static int
237test_rc4_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
238 const unsigned char *iv, int enc)
239{
240#ifdef TEST_ENG_OPENSSL_RC4_P_INIT
241 fprintf(stderr, "(TEST_ENG_OPENSSL_RC4) test_init_key() called\n");
242#endif
243 memcpy(&test(ctx)->key[0], key, EVP_CIPHER_CTX_key_length(ctx));
244 RC4_set_key(&test(ctx)->ks, EVP_CIPHER_CTX_key_length(ctx),
245 test(ctx)->key);
246 return 1;
247}
248
249static int
250test_rc4_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
251 const unsigned char *in, size_t inl)
252{
253#ifdef TEST_ENG_OPENSSL_RC4_P_CIPHER
254 fprintf(stderr, "(TEST_ENG_OPENSSL_RC4) test_cipher() called\n");
255#endif
256 RC4(&test(ctx)->ks, inl, in, out);
257 return 1;
258}
259
260static const EVP_CIPHER test_r4_cipher = {
261 NID_rc4,
262 1, TEST_RC4_KEY_SIZE, 0,
263 EVP_CIPH_VARIABLE_LENGTH,
264 test_rc4_init_key,
265 test_rc4_cipher,
266 NULL,
267 sizeof(TEST_RC4_KEY),
268 NULL,
269 NULL,
270 NULL,
271 NULL
272};
273
274static const EVP_CIPHER test_r4_40_cipher = {
275 NID_rc4_40,
276 1,5 /* 40 bit */,0,
277 EVP_CIPH_VARIABLE_LENGTH,
278 test_rc4_init_key,
279 test_rc4_cipher,
280 NULL,
281 sizeof(TEST_RC4_KEY),
282 NULL,
283 NULL,
284 NULL,
285 NULL
286};
287
288static int
289openssl_ciphers(ENGINE *e, const EVP_CIPHER **cipher, const int **nids, int nid)
290{
291 if (!cipher) {
292 /* We are returning a list of supported nids */
293 *nids = test_cipher_nids;
294 return test_cipher_nids_number;
295 }
296 /* We are being asked for a specific cipher */
297 if (nid == NID_rc4)
298 *cipher = &test_r4_cipher;
299 else if (nid == NID_rc4_40)
300 *cipher = &test_r4_40_cipher;
301 else {
302#ifdef TEST_ENG_OPENSSL_RC4_OTHERS
303 fprintf(stderr, "(TEST_ENG_OPENSSL_RC4) returning NULL for "
304 "nid %d\n", nid);
305#endif
306 *cipher = NULL;
307 return 0;
308 }
309 return 1;
310}
311#endif
312
313#ifdef TEST_ENG_OPENSSL_SHA
314/* Much the same sort of comment as for TEST_ENG_OPENSSL_RC4 */
315#include <openssl/sha.h>
316static int test_digest_nids[] = {NID_sha1};
317static int test_digest_nids_number = 1;
318
319static int
320test_sha1_init(EVP_MD_CTX *ctx)
321{
322#ifdef TEST_ENG_OPENSSL_SHA_P_INIT
323 fprintf(stderr, "(TEST_ENG_OPENSSL_SHA) test_sha1_init() called\n");
324#endif
325 return SHA1_Init(ctx->md_data);
326}
327
328static int
329test_sha1_update(EVP_MD_CTX *ctx, const void *data, size_t count)
330{
331#ifdef TEST_ENG_OPENSSL_SHA_P_UPDATE
332 fprintf(stderr, "(TEST_ENG_OPENSSL_SHA) test_sha1_update() called\n");
333#endif
334 return SHA1_Update(ctx->md_data, data, count);
335}
336
337static int
338test_sha1_final(EVP_MD_CTX *ctx, unsigned char *md)
339{
340#ifdef TEST_ENG_OPENSSL_SHA_P_FINAL
341 fprintf(stderr, "(TEST_ENG_OPENSSL_SHA) test_sha1_final() called\n");
342#endif
343 return SHA1_Final(md, ctx->md_data);
344}
345
346static const EVP_MD test_sha_md = {
347 .type = NID_sha1,
348 .pkey_type = NID_sha1WithRSAEncryption,
349 .md_size = SHA_DIGEST_LENGTH,
350 .flags = 0,
351 .init = test_sha1_init,
352 .update = test_sha1_update,
353 .final = test_sha1_final,
354 .copy = NULL,
355 .cleanup = NULL,
356 .block_size = SHA_CBLOCK,
357 .ctx_size = sizeof(EVP_MD *) + sizeof(SHA_CTX),
358};
359
360static int
361openssl_digests(ENGINE *e, const EVP_MD **digest, const int **nids, int nid)
362{
363 if (!digest) {
364 /* We are returning a list of supported nids */
365 *nids = test_digest_nids;
366 return test_digest_nids_number;
367 }
368 /* We are being asked for a specific digest */
369 if (nid == NID_sha1)
370 *digest = &test_sha_md;
371 else {
372#ifdef TEST_ENG_OPENSSL_SHA_OTHERS
373 fprintf(stderr, "(TEST_ENG_OPENSSL_SHA) returning NULL for "
374 "nid %d\n", nid);
375#endif
376 *digest = NULL;
377 return 0;
378 }
379 return 1;
380}
381#endif
382
383#ifdef TEST_ENG_OPENSSL_PKEY
384static EVP_PKEY *
385openssl_load_privkey(ENGINE *eng, const char *key_id, UI_METHOD *ui_method,
386 void *callback_data)
387{
388 BIO *in;
389 EVP_PKEY *key;
390
391 fprintf(stderr, "(TEST_ENG_OPENSSL_PKEY)Loading Private key %s\n",
392 key_id);
393 in = BIO_new_file(key_id, "r");
394 if (!in)
395 return NULL;
396 key = PEM_read_bio_PrivateKey(in, NULL, 0, NULL);
397 BIO_free(in);
398 return key;
399}
400#endif