Skip to content

Commit

Permalink
Do not create DSA keys without parameters by decoder
Browse files Browse the repository at this point in the history
Reviewed-by: Paul Dale <pauli@openssl.org>
Reviewed-by: Matt Caswell <matt@openssl.org>
  • Loading branch information
t8m committed Feb 7, 2023
1 parent 9ac82e2 commit 604247b
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
24 changes: 24 additions & 0 deletions crypto/x509/x_pubkey.c
Expand Up @@ -748,6 +748,30 @@ DSA *d2i_DSA_PUBKEY(DSA **a, const unsigned char **pp, long length)
return key;
}

/* Called from decoders; disallows provided DSA keys without parameters. */
DSA *ossl_d2i_DSA_PUBKEY(DSA **a, const unsigned char **pp, long length)
{
DSA *key = NULL;
const unsigned char *data;
const BIGNUM *p, *q, *g;

data = *pp;
key = d2i_DSA_PUBKEY(NULL, &data, length);
if (key == NULL)
return NULL;
DSA_get0_pqg(key, &p, &q, &g);
if (p == NULL || q == NULL || g == NULL) {
DSA_free(key);
return NULL;
}
*pp = data;
if (a != NULL) {
DSA_free(*a);
*a = key;
}
return key;
}

int i2d_DSA_PUBKEY(const DSA *a, unsigned char **pp)
{
EVP_PKEY *pktmp;
Expand Down
3 changes: 3 additions & 0 deletions include/crypto/x509.h
Expand Up @@ -339,6 +339,9 @@ void ossl_X509_PUBKEY_INTERNAL_free(X509_PUBKEY *xpub);

RSA *ossl_d2i_RSA_PSS_PUBKEY(RSA **a, const unsigned char **pp, long length);
int ossl_i2d_RSA_PSS_PUBKEY(const RSA *a, unsigned char **pp);
# ifndef OPENSSL_NO_DSA
DSA *ossl_d2i_DSA_PUBKEY(DSA **a, const unsigned char **pp, long length);
# endif /* OPENSSL_NO_DSA */
# ifndef OPENSSL_NO_DH
DH *ossl_d2i_DH_PUBKEY(DH **a, const unsigned char **pp, long length);
int ossl_i2d_DH_PUBKEY(const DH *a, unsigned char **pp);
Expand Down
2 changes: 1 addition & 1 deletion providers/implementations/encode_decode/decode_der2key.c
Expand Up @@ -375,7 +375,7 @@ static void *dsa_d2i_PKCS8(void **key, const unsigned char **der, long der_len,
(key_from_pkcs8_t *)ossl_dsa_key_from_pkcs8);
}

# define dsa_d2i_PUBKEY (d2i_of_void *)d2i_DSA_PUBKEY
# define dsa_d2i_PUBKEY (d2i_of_void *)ossl_d2i_DSA_PUBKEY
# define dsa_free (free_key_fn *)DSA_free
# define dsa_check NULL

Expand Down

0 comments on commit 604247b

Please sign in to comment.