aboutsummaryrefslogtreecommitdiffstats
path: root/crypto/ts/ts_rsp_verify.c
diff options
context:
space:
mode:
authorTomas Mraz <tomas@openssl.org>2021-04-26 12:08:27 +0200
committerTomas Mraz <tomas@openssl.org>2021-04-28 09:38:31 +0200
commiteaf8a40d97d642ccd2c55fbf8bb8ee3242aec04a (patch)
tree23ef2d3756c42a91841270eb74330a8840dbf5d0 /crypto/ts/ts_rsp_verify.c
parentc0a79e9836a9aa30912978f69fab3b3bb3a8ddc5 (diff)
downloadopenssl-eaf8a40d97d642ccd2c55fbf8bb8ee3242aec04a.tar.gz
Prefer fetch over legacy get_digestby/get_cipherby
Fixes #14198 Reviewed-by: Richard Levitte <levitte@openssl.org> (Merged from https://github.com/openssl/openssl/pull/15028)
Diffstat (limited to 'crypto/ts/ts_rsp_verify.c')
-rw-r--r--crypto/ts/ts_rsp_verify.c26
1 files changed, 21 insertions, 5 deletions
diff --git a/crypto/ts/ts_rsp_verify.c b/crypto/ts/ts_rsp_verify.c
index f307e29fda..09daa2a449 100644
--- a/crypto/ts/ts_rsp_verify.c
+++ b/crypto/ts/ts_rsp_verify.c
@@ -8,12 +8,13 @@
*/
#include <stdio.h>
-#include "internal/cryptlib.h"
#include <openssl/objects.h>
#include <openssl/ts.h>
#include <openssl/pkcs7.h>
-#include "ts_local.h"
+#include "internal/cryptlib.h"
+#include "internal/sizes.h"
#include "crypto/ess.h"
+#include "ts_local.h"
static int ts_verify_cert(X509_STORE *store, STACK_OF(X509) *untrusted,
X509 *signer, STACK_OF(X509) **chain);
@@ -395,9 +396,10 @@ static int ts_compute_imprint(BIO *data, TS_TST_INFO *tst_info,
{
TS_MSG_IMPRINT *msg_imprint = tst_info->msg_imprint;
X509_ALGOR *md_alg_resp = msg_imprint->hash_algo;
- const EVP_MD *md;
+ EVP_MD *md = NULL;
EVP_MD_CTX *md_ctx = NULL;
unsigned char buffer[4096];
+ char name[OSSL_MAX_NAME_SIZE];
int length;
*md_alg = NULL;
@@ -405,10 +407,21 @@ static int ts_compute_imprint(BIO *data, TS_TST_INFO *tst_info,
if ((*md_alg = X509_ALGOR_dup(md_alg_resp)) == NULL)
goto err;
- if ((md = EVP_get_digestbyobj((*md_alg)->algorithm)) == NULL) {
- ERR_raise(ERR_LIB_TS, TS_R_UNSUPPORTED_MD_ALGORITHM);
+
+ OBJ_obj2txt(name, sizeof(name), md_alg_resp->algorithm, 0);
+
+ (void)ERR_set_mark();
+ md = EVP_MD_fetch(NULL, name, NULL);
+
+ if (md == NULL)
+ md = (EVP_MD *)EVP_get_digestbyname(name);
+
+ if (md == NULL) {
+ (void)ERR_clear_last_mark();
goto err;
}
+ (void)ERR_pop_to_mark();
+
length = EVP_MD_size(md);
if (length < 0)
goto err;
@@ -425,6 +438,8 @@ static int ts_compute_imprint(BIO *data, TS_TST_INFO *tst_info,
}
if (!EVP_DigestInit(md_ctx, md))
goto err;
+ EVP_MD_free(md);
+ md = NULL;
while ((length = BIO_read(data, buffer, sizeof(buffer))) > 0) {
if (!EVP_DigestUpdate(md_ctx, buffer, length))
goto err;
@@ -436,6 +451,7 @@ static int ts_compute_imprint(BIO *data, TS_TST_INFO *tst_info,
return 1;
err:
EVP_MD_CTX_free(md_ctx);
+ EVP_MD_free(md);
X509_ALGOR_free(*md_alg);
*md_alg = NULL;
OPENSSL_free(*imprint);