Skip to content

Commit

Permalink
Fix encoding of DHX parameters files
Browse files Browse the repository at this point in the history
We were getting confused with DHX parameters and encoding them as PKCS3
DH parameters instead.

Reviewed-by: Shane Lontis <[email protected]>
(Merged from openssl#13050)
  • Loading branch information
mattcaswell committed Oct 8, 2020
1 parent db554ae commit 3861ac3
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions providers/implementations/encode_decode/encode_key2any.c
Original file line number Diff line number Diff line change
Expand Up @@ -319,12 +319,23 @@ static int dh_priv_to_der(const void *dh, unsigned char **pder)

static int dh_params_to_der_bio(BIO *out, const void *key)
{
return i2d_DHparams_bio(out, key);
int type =
DH_test_flags(key, DH_FLAG_TYPE_DHX) ? EVP_PKEY_DHX : EVP_PKEY_DH;

if (type == EVP_PKEY_DH)
return i2d_DHparams_bio(out, key);
return i2d_DHxparams_bio(out, key);
}

static int dh_params_to_pem_bio(BIO *out, const void *key)
{
return PEM_write_bio_DHparams(out, key);
int type =
DH_test_flags(key, DH_FLAG_TYPE_DHX) ? EVP_PKEY_DHX : EVP_PKEY_DH;

if (type == EVP_PKEY_DH)
return PEM_write_bio_DHparams(out, key);

return PEM_write_bio_DHxparams(out, key);
}

static int dh_check_key_type(const void *key, int expected_type)
Expand Down Expand Up @@ -940,8 +951,8 @@ static int key2any_encode_params(struct key2any_ctx_st *ctx,
#ifndef OPENSSL_NO_DH
MAKE_ENCODER(dh, dh, EVP_PKEY_DH, der);
MAKE_ENCODER(dh, dh, EVP_PKEY_DH, pem);
MAKE_ENCODER(dhx, dh, EVP_PKEY_DH, der);
MAKE_ENCODER(dhx, dh, EVP_PKEY_DH, pem);
MAKE_ENCODER(dhx, dh, EVP_PKEY_DHX, der);
MAKE_ENCODER(dhx, dh, EVP_PKEY_DHX, pem);
#endif
#ifndef OPENSSL_NO_DSA
MAKE_ENCODER(dsa, dsa, EVP_PKEY_DSA, der);
Expand Down

0 comments on commit 3861ac3

Please sign in to comment.