From 604247bf75571c1c3fb6a1723346c61acd957221 Mon Sep 17 00:00:00 2001 From: Tomas Mraz Date: Fri, 13 Jan 2023 17:59:52 +0100 Subject: Do not create DSA keys without parameters by decoder Reviewed-by: Paul Dale Reviewed-by: Matt Caswell --- crypto/x509/x_pubkey.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'crypto') diff --git a/crypto/x509/x_pubkey.c b/crypto/x509/x_pubkey.c index 89184fc910..6726cac857 100644 --- a/crypto/x509/x_pubkey.c +++ b/crypto/x509/x_pubkey.c @@ -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; -- cgit v1.2.1