diff options
author | op <> | 2023-06-18 11:43:03 +0000 |
---|---|---|
committer | op <> | 2023-06-18 11:43:03 +0000 |
commit | 727678bac9040805562e79cfeca4ee4b953bd557 (patch) | |
tree | cc3e371985ef9f03635d4ad74f97569e0f8bd591 | |
parent | 2810e2ca8ccbcc1d5ea8e11a8475a66e01d25b73 (diff) | |
download | openbsd-727678bac9040805562e79cfeca4ee4b953bd557.tar.gz openbsd-727678bac9040805562e79cfeca4ee4b953bd557.tar.bz2 openbsd-727678bac9040805562e79cfeca4ee4b953bd557.zip |
libtls: switch ECDSA_METHOD usage to EC_KEY_METHOD
smtpd and the bits it needs in libtls are the only consumer left of
ECDSA_METHOD, which is long deprecated. This paves the way for the
removal in libcrypto.
The diff is from gilles' work on OpenSMTPD-portable, libretls had a
similar diff.
ok tb@, jsing@
-rw-r--r-- | src/lib/libtls/tls.c | 10 | ||||
-rw-r--r-- | src/lib/libtls/tls_internal.h | 4 | ||||
-rw-r--r-- | src/lib/libtls/tls_signer.c | 15 |
3 files changed, 12 insertions, 17 deletions
diff --git a/src/lib/libtls/tls.c b/src/lib/libtls/tls.c index 989339dc03..8444169bdc 100644 --- a/src/lib/libtls/tls.c +++ b/src/lib/libtls/tls.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: tls.c,v 1.96 2023/05/25 07:46:21 op Exp $ */ | 1 | /* $OpenBSD: tls.c,v 1.97 2023/06/18 11:43:03 op Exp $ */ |
2 | /* | 2 | /* |
3 | * Copyright (c) 2014 Joel Sing <jsing@openbsd.org> | 3 | * Copyright (c) 2014 Joel Sing <jsing@openbsd.org> |
4 | * | 4 | * |
@@ -389,7 +389,7 @@ static int | |||
389 | tls_keypair_setup_pkey(struct tls *ctx, struct tls_keypair *keypair, EVP_PKEY *pkey) | 389 | tls_keypair_setup_pkey(struct tls *ctx, struct tls_keypair *keypair, EVP_PKEY *pkey) |
390 | { | 390 | { |
391 | RSA_METHOD *rsa_method; | 391 | RSA_METHOD *rsa_method; |
392 | ECDSA_METHOD *ecdsa_method; | 392 | EC_KEY_METHOD *ecdsa_method; |
393 | RSA *rsa = NULL; | 393 | RSA *rsa = NULL; |
394 | EC_KEY *eckey = NULL; | 394 | EC_KEY *eckey = NULL; |
395 | int ret = -1; | 395 | int ret = -1; |
@@ -427,15 +427,15 @@ tls_keypair_setup_pkey(struct tls *ctx, struct tls_keypair *keypair, EVP_PKEY *p | |||
427 | break; | 427 | break; |
428 | case EVP_PKEY_EC: | 428 | case EVP_PKEY_EC: |
429 | if ((eckey = EVP_PKEY_get1_EC_KEY(pkey)) == NULL || | 429 | if ((eckey = EVP_PKEY_get1_EC_KEY(pkey)) == NULL || |
430 | ECDSA_set_ex_data(eckey, 0, keypair->pubkey_hash) == 0) { | 430 | EC_KEY_set_ex_data(eckey, 0, keypair->pubkey_hash) == 0) { |
431 | tls_set_errorx(ctx, "EC key setup failure"); | 431 | tls_set_errorx(ctx, "EC key setup failure"); |
432 | goto err; | 432 | goto err; |
433 | } | 433 | } |
434 | if (ctx->config->sign_cb != NULL) { | 434 | if (ctx->config->sign_cb != NULL) { |
435 | ecdsa_method = tls_signer_ecdsa_method(); | 435 | ecdsa_method = tls_signer_ecdsa_method(); |
436 | if (ecdsa_method == NULL || | 436 | if (ecdsa_method == NULL || |
437 | ECDSA_set_ex_data(eckey, 1, ctx->config) == 0 || | 437 | EC_KEY_set_ex_data(eckey, 1, ctx->config) == 0 || |
438 | ECDSA_set_method(eckey, ecdsa_method) == 0) { | 438 | EC_KEY_set_method(eckey, ecdsa_method) == 0) { |
439 | tls_set_errorx(ctx, "failed to setup EC key"); | 439 | tls_set_errorx(ctx, "failed to setup EC key"); |
440 | goto err; | 440 | goto err; |
441 | } | 441 | } |
diff --git a/src/lib/libtls/tls_internal.h b/src/lib/libtls/tls_internal.h index f4c23f64e6..af081a079a 100644 --- a/src/lib/libtls/tls_internal.h +++ b/src/lib/libtls/tls_internal.h | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: tls_internal.h,v 1.81 2023/04/09 18:26:26 tb Exp $ */ | 1 | /* $OpenBSD: tls_internal.h,v 1.82 2023/06/18 11:43:03 op Exp $ */ |
2 | /* | 2 | /* |
3 | * Copyright (c) 2014 Jeremie Courreges-Anglas <jca@openbsd.org> | 3 | * Copyright (c) 2014 Jeremie Courreges-Anglas <jca@openbsd.org> |
4 | * Copyright (c) 2014 Joel Sing <jsing@openbsd.org> | 4 | * Copyright (c) 2014 Joel Sing <jsing@openbsd.org> |
@@ -298,7 +298,7 @@ int tls_cert_pubkey_hash(X509 *_cert, char **_hash); | |||
298 | int tls_password_cb(char *_buf, int _size, int _rwflag, void *_u); | 298 | int tls_password_cb(char *_buf, int _size, int _rwflag, void *_u); |
299 | 299 | ||
300 | RSA_METHOD *tls_signer_rsa_method(void); | 300 | RSA_METHOD *tls_signer_rsa_method(void); |
301 | ECDSA_METHOD *tls_signer_ecdsa_method(void); | 301 | EC_KEY_METHOD *tls_signer_ecdsa_method(void); |
302 | 302 | ||
303 | #define TLS_PADDING_NONE 0 | 303 | #define TLS_PADDING_NONE 0 |
304 | #define TLS_PADDING_RSA_PKCS1 1 | 304 | #define TLS_PADDING_RSA_PKCS1 1 |
diff --git a/src/lib/libtls/tls_signer.c b/src/lib/libtls/tls_signer.c index f6005d3e07..372fa77819 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.5 2023/04/09 18:26:26 tb Exp $ */ | 1 | /* $OpenBSD: tls_signer.c,v 1.6 2023/06/18 11:43:03 op Exp $ */ |
2 | /* | 2 | /* |
3 | * Copyright (c) 2021 Eric Faurot <eric@openbsd.org> | 3 | * Copyright (c) 2021 Eric Faurot <eric@openbsd.org> |
4 | * | 4 | * |
@@ -419,26 +419,21 @@ tls_ecdsa_do_sign(const unsigned char *dgst, int dgst_len, const BIGNUM *inv, | |||
419 | return (NULL); | 419 | return (NULL); |
420 | } | 420 | } |
421 | 421 | ||
422 | ECDSA_METHOD * | 422 | EC_KEY_METHOD * |
423 | tls_signer_ecdsa_method(void) | 423 | tls_signer_ecdsa_method(void) |
424 | { | 424 | { |
425 | static ECDSA_METHOD *ecdsa_method = NULL; | 425 | static EC_KEY_METHOD *ecdsa_method = NULL; |
426 | 426 | ||
427 | pthread_mutex_lock(&signer_method_lock); | 427 | pthread_mutex_lock(&signer_method_lock); |
428 | 428 | ||
429 | if (ecdsa_method != NULL) | 429 | if (ecdsa_method != NULL) |
430 | goto out; | 430 | goto out; |
431 | 431 | ||
432 | ecdsa_method = calloc(1, sizeof(*ecdsa_method)); | 432 | ecdsa_method = EC_KEY_METHOD_new(NULL); |
433 | if (ecdsa_method == NULL) | 433 | if (ecdsa_method == NULL) |
434 | goto out; | 434 | goto out; |
435 | 435 | ||
436 | ecdsa_method->ecdsa_do_sign = tls_ecdsa_do_sign; | 436 | EC_KEY_METHOD_set_sign(ecdsa_method, NULL, NULL, tls_ecdsa_do_sign); |
437 | ecdsa_method->name = strdup("libtls ECDSA method"); | ||
438 | if (ecdsa_method->name == NULL) { | ||
439 | free(ecdsa_method); | ||
440 | ecdsa_method = NULL; | ||
441 | } | ||
442 | 437 | ||
443 | out: | 438 | out: |
444 | pthread_mutex_unlock(&signer_method_lock); | 439 | pthread_mutex_unlock(&signer_method_lock); |