diff options
author | Richard Levitte <levitte@openssl.org> | 2020-07-30 10:14:27 +0200 |
---|---|---|
committer | Richard Levitte <levitte@openssl.org> | 2020-08-20 12:33:53 +0200 |
commit | 6cc1dfca88c565ddacd9ea9aa8261ef9c0c37335 (patch) | |
tree | 8558fcaaa2e2cde3e372d5c65606d674af37f02d /providers/implementations/serializers/serializer_dh.c | |
parent | 22b814443eea4ef4ea86d5d5677601d6645606d9 (diff) | |
download | openssl-new-6cc1dfca88c565ddacd9ea9aa8261ef9c0c37335.tar.gz |
PROV: Fix DSA and DH private key serializers
If those private key serializer were given a key structure with just
the public key material, they crashed, because they tried to
de-reference NULL. This adds better checking.
Reviewed-by: Tomas Mraz <tmraz@fedoraproject.org>
(Merged from https://github.com/openssl/openssl/pull/12679)
Diffstat (limited to 'providers/implementations/serializers/serializer_dh.c')
-rw-r--r-- | providers/implementations/serializers/serializer_dh.c | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/providers/implementations/serializers/serializer_dh.c b/providers/implementations/serializers/serializer_dh.c index d63c8402f9..d1b1d27cf6 100644 --- a/providers/implementations/serializers/serializer_dh.c +++ b/providers/implementations/serializers/serializer_dh.c @@ -119,10 +119,15 @@ int ossl_prov_prepare_dh_params(const void *dh, int nid, int ossl_prov_dh_pub_to_der(const void *dh, unsigned char **pder) { - ASN1_INTEGER *pub_key = BN_to_ASN1_INTEGER(DH_get0_pub_key(dh), NULL); + const BIGNUM *bn = NULL; + ASN1_INTEGER *pub_key = NULL; int ret; - if (pub_key == NULL) { + if ((bn = DH_get0_pub_key(dh)) == NULL) { + ERR_raise(ERR_LIB_PROV, PROV_R_NOT_A_PUBLIC_KEY); + return 0; + } + if ((pub_key = BN_to_ASN1_INTEGER(bn, NULL)) == NULL) { ERR_raise(ERR_LIB_PROV, PROV_R_BN_ERROR); return 0; } @@ -135,10 +140,15 @@ int ossl_prov_dh_pub_to_der(const void *dh, unsigned char **pder) int ossl_prov_dh_priv_to_der(const void *dh, unsigned char **pder) { - ASN1_INTEGER *priv_key = BN_to_ASN1_INTEGER(DH_get0_priv_key(dh), NULL); + const BIGNUM *bn = NULL; + ASN1_INTEGER *priv_key = NULL; int ret; - if (priv_key == NULL) { + if ((bn = DH_get0_priv_key(dh)) == NULL) { + ERR_raise(ERR_LIB_PROV, PROV_R_NOT_A_PRIVATE_KEY); + return 0; + } + if ((priv_key = BN_to_ASN1_INTEGER(bn, NULL)) == NULL) { ERR_raise(ERR_LIB_PROV, PROV_R_BN_ERROR); return 0; } |