summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortb <>2023-06-18 17:50:28 +0000
committertb <>2023-06-18 17:50:28 +0000
commited9558e47b61cf3390cda693f01afa48b775003a (patch)
treefe798daf9a9417a5e95118e774aa68b2ff748ab9
parent90d71a9e40be2f46f642829af37b1bd2b6d292f3 (diff)
downloadopenbsd-ed9558e47b61cf3390cda693f01afa48b775003a.tar.gz
openbsd-ed9558e47b61cf3390cda693f01afa48b775003a.tar.bz2
openbsd-ed9558e47b61cf3390cda693f01afa48b775003a.zip
tls_signer: reinstate the default EC_KEY methods
Previously, we would set the ECDSA_METHOD on the EC_KEY, which, by way of lovely indirection in our three crypto/ec* directories ended up having no effect on the default methods. Now that we set a new EC_KEY_METHOD, we need to make sure we still have the other handlers that we might need. Like so many things that were made opaque in the 1.1 re"design", the accessors were written without actual application code in mind. In particular, EC_KEY_METHOD lacks a dup(). This means we get to fetch the default methods with getters and then set them again on the new method. This is particularly awesome because once someone adds a new method to the opaque struct, all applications will have to adapt and do a get/set dance. So far this is very reminiscent of PostgreSQL with BIO_meth_* https://github.com/postgres/postgres/blob/a14e75eb0b6a73821e0d66c0d407372ec8376105/src/interfaces/libpq/fe-secure-openssl.c#L1921-L1928 Only it's worse here because someone wanted to be smart and save a few public functions, so we have to use getters that get several functions at once. Which in turn means we need to have function pointers with the precise signatures which are part of the struct that was made opaque. We will add a EC_KEY_METHOD_dup() in the next bump, but for now this is the best fix we can have. Whenever you think you've seen the worst turds in this code base, you find another one that could serve as an exemplar. ok jsing op
-rw-r--r--src/lib/libtls/tls_signer.c31
1 files changed, 29 insertions, 2 deletions
diff --git a/src/lib/libtls/tls_signer.c b/src/lib/libtls/tls_signer.c
index c1b60bfcc4..78206d1223 100644
--- a/src/lib/libtls/tls_signer.c
+++ b/src/lib/libtls/tls_signer.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: tls_signer.c,v 1.7 2023/06/18 17:24:09 tb Exp $ */ 1/* $OpenBSD: tls_signer.c,v 1.8 2023/06/18 17:50:28 tb Exp $ */
2/* 2/*
3 * Copyright (c) 2021 Eric Faurot <eric@openbsd.org> 3 * Copyright (c) 2021 Eric Faurot <eric@openbsd.org>
4 * 4 *
@@ -423,6 +423,20 @@ EC_KEY_METHOD *
423tls_signer_ecdsa_method(void) 423tls_signer_ecdsa_method(void)
424{ 424{
425 static EC_KEY_METHOD *ecdsa_method = NULL; 425 static EC_KEY_METHOD *ecdsa_method = NULL;
426 const EC_KEY_METHOD *default_method;
427 int (*keygen)(EC_KEY *key);
428 int (*compute_key)(void *out, size_t outlen, const EC_POINT *pub_key,
429 EC_KEY *ecdh, void *(*KDF) (const void *in, size_t inlen, void *out,
430 size_t *outlen));
431 int (*sign)(int type, const unsigned char *dgst, int dlen,
432 unsigned char *sig, unsigned int *siglen,
433 const BIGNUM *kinv, const BIGNUM *r, EC_KEY *eckey);
434 int (*sign_setup)(EC_KEY *eckey, BN_CTX *ctx_in,
435 BIGNUM **kinvp, BIGNUM **rp);
436 int (*verify)(int type, const unsigned char *dgst, int dgst_len,
437 const unsigned char *sigbuf, int sig_len, EC_KEY *eckey);
438 int (*verify_sig)(const unsigned char *dgst, int dgst_len,
439 const ECDSA_SIG *sig, EC_KEY *eckey);
426 440
427 pthread_mutex_lock(&signer_method_lock); 441 pthread_mutex_lock(&signer_method_lock);
428 442
@@ -433,7 +447,20 @@ tls_signer_ecdsa_method(void)
433 if (ecdsa_method == NULL) 447 if (ecdsa_method == NULL)
434 goto out; 448 goto out;
435 449
436 EC_KEY_METHOD_set_sign(ecdsa_method, NULL, NULL, tls_ecdsa_do_sign); 450 default_method = EC_KEY_get_default_method();
451
452 EC_KEY_METHOD_get_keygen(default_method, &keygen);
453 EC_KEY_METHOD_set_keygen(ecdsa_method, keygen);
454
455 EC_KEY_METHOD_get_compute_key(default_method, &compute_key);
456 EC_KEY_METHOD_set_compute_key(ecdsa_method, compute_key);
457
458 EC_KEY_METHOD_get_sign(default_method, &sign, &sign_setup, NULL);
459 EC_KEY_METHOD_set_sign(ecdsa_method, sign, sign_setup,
460 tls_ecdsa_do_sign);
461
462 EC_KEY_METHOD_get_verify(default_method, &verify, &verify_sig);
463 EC_KEY_METHOD_set_verify(ecdsa_method, verify, verify_sig);
437 464
438 out: 465 out:
439 pthread_mutex_unlock(&signer_method_lock); 466 pthread_mutex_unlock(&signer_method_lock);