diff options
author | Richard Levitte <levitte@openssl.org> | 2020-10-28 17:35:48 +0100 |
---|---|---|
committer | Richard Levitte <levitte@openssl.org> | 2020-11-11 11:42:06 +0100 |
commit | 35426b2f9ca961c783ad882f1f2ede0d6fe2c232 (patch) | |
tree | e61e309f50a009911bfa17433f3e2e0b8290144f /crypto | |
parent | a5cc6616454701bfcdd1694e109389c764f6f31c (diff) |
Restore the legacy implementation of PEM_read_bio_DHparams()
It was an overstep to have it got through OSSL_STORE just to extract a
DH pointer from the resulting EVP_PKEY.
This partially reverts 1427d33cee59d6fe54efe1b5a322a1d7c8c03c20
Reviewed-by: Shane Lontis <shane.lontis@oracle.com>
(Merged from https://github.com/openssl/openssl/pull/13248)
Diffstat (limited to 'crypto')
-rw-r--r-- | crypto/pem/pem_all.c | 44 | ||||
-rw-r--r-- | crypto/pem/pem_pkey.c | 61 |
2 files changed, 44 insertions, 61 deletions
diff --git a/crypto/pem/pem_all.c b/crypto/pem/pem_all.c index bf7159a6ad..01c62d0222 100644 --- a/crypto/pem/pem_all.c +++ b/crypto/pem/pem_all.c @@ -179,5 +179,49 @@ EC_KEY *PEM_read_ECPrivateKey(FILE *fp, EC_KEY **eckey, pem_password_cb *cb, IMPLEMENT_PEM_write(DHparams, DH, PEM_STRING_DHPARAMS, DHparams) IMPLEMENT_PEM_write(DHxparams, DH, PEM_STRING_DHXPARAMS, DHxparams) + +/* Transparently read in PKCS#3 or X9.42 DH parameters */ + +DH *PEM_read_bio_DHparams(BIO *bp, DH **x, pem_password_cb *cb, void *u) +{ + char *nm = NULL; + const unsigned char *p = NULL; + unsigned char *data = NULL; + long len; + DH *ret = NULL; + + if (!PEM_bytes_read_bio(&data, &len, &nm, PEM_STRING_DHPARAMS, bp, cb, u)) + return NULL; + p = data; + + if (strcmp(nm, PEM_STRING_DHXPARAMS) == 0) + ret = d2i_DHxparams(x, &p, len); + else + ret = d2i_DHparams(x, &p, len); + + if (ret == NULL) + PEMerr(PEM_F_PEM_READ_BIO_DHPARAMS, ERR_R_ASN1_LIB); + OPENSSL_free(nm); + OPENSSL_free(data); + return ret; +} + +# ifndef OPENSSL_NO_STDIO +DH *PEM_read_DHparams(FILE *fp, DH **x, pem_password_cb *cb, void *u) +{ + BIO *b; + DH *ret; + + if ((b = BIO_new(BIO_s_file())) == NULL) { + PEMerr(PEM_F_PEM_READ_DHPARAMS, ERR_R_BUF_LIB); + return 0; + } + BIO_set_fp(b, fp, BIO_NOCLOSE); + ret = PEM_read_bio_DHparams(b, x, cb, u); + BIO_free(b); + return ret; +} +# endif + #endif IMPLEMENT_PEM_provided_write(PUBKEY, EVP_PKEY, PEM_STRING_PUBLIC, PUBKEY) diff --git a/crypto/pem/pem_pkey.c b/crypto/pem/pem_pkey.c index 91f6f30cf6..5ecae8651b 100644 --- a/crypto/pem/pem_pkey.c +++ b/crypto/pem/pem_pkey.c @@ -263,64 +263,3 @@ int PEM_write_PrivateKey(FILE *fp, const EVP_PKEY *x, const EVP_CIPHER *enc, } #endif - -#ifndef OPENSSL_NO_DH - -/* Transparently read in PKCS#3 or X9.42 DH parameters */ - -DH *PEM_read_bio_DHparams(BIO *bp, DH **x, pem_password_cb *cb, void *u) -{ - DH *ret = NULL; - EVP_PKEY *pkey = NULL; - OSSL_STORE_CTX *ctx = NULL; - OSSL_STORE_INFO *info = NULL; - UI_METHOD *ui_method = NULL; - - if ((ui_method = UI_UTIL_wrap_read_pem_callback(cb, 0)) == NULL) - return NULL; - - if ((ctx = OSSL_STORE_attach(bp, "file", NULL, NULL, ui_method, u, - NULL, NULL)) == NULL) - goto err; - - while (!OSSL_STORE_eof(ctx) && (info = OSSL_STORE_load(ctx)) != NULL) { - if (OSSL_STORE_INFO_get_type(info) == OSSL_STORE_INFO_PARAMS) { - pkey = OSSL_STORE_INFO_get0_PARAMS(info); - if (EVP_PKEY_id(pkey) == EVP_PKEY_DHX - || EVP_PKEY_id(pkey) == EVP_PKEY_DH) { - ret = EVP_PKEY_get1_DH(pkey); - break; - } - } - OSSL_STORE_INFO_free(info); - info = NULL; - } - - if (ret != NULL && x != NULL) - *x = ret; - - err: - OSSL_STORE_close(ctx); - UI_destroy_method(ui_method); - OSSL_STORE_INFO_free(info); - return ret; -} - -# ifndef OPENSSL_NO_STDIO -DH *PEM_read_DHparams(FILE *fp, DH **x, pem_password_cb *cb, void *u) -{ - BIO *b; - DH *ret; - - if ((b = BIO_new(BIO_s_file())) == NULL) { - PEMerr(PEM_F_PEM_READ_DHPARAMS, ERR_R_BUF_LIB); - return 0; - } - BIO_set_fp(b, fp, BIO_NOCLOSE); - ret = PEM_read_bio_DHparams(b, x, cb, u); - BIO_free(b); - return ret; -} -# endif - -#endif |