diff options
Diffstat (limited to 'src/lib')
-rw-r--r-- | src/lib/libcrypto/ts/ts_rsp_verify.c | 48 |
1 files changed, 28 insertions, 20 deletions
diff --git a/src/lib/libcrypto/ts/ts_rsp_verify.c b/src/lib/libcrypto/ts/ts_rsp_verify.c index 27515adf68..c745a2c51f 100644 --- a/src/lib/libcrypto/ts/ts_rsp_verify.c +++ b/src/lib/libcrypto/ts/ts_rsp_verify.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: ts_rsp_verify.c,v 1.19 2021/05/01 13:13:45 tb Exp $ */ | 1 | /* $OpenBSD: ts_rsp_verify.c,v 1.20 2021/05/02 15:33:33 tb Exp $ */ |
2 | /* Written by Zoltan Glozik (zglozik@stones.com) for the OpenSSL | 2 | /* Written by Zoltan Glozik (zglozik@stones.com) for the OpenSSL |
3 | * project 2002. | 3 | * project 2002. |
4 | */ | 4 | */ |
@@ -593,35 +593,40 @@ TS_check_policy(ASN1_OBJECT *req_oid, TS_TST_INFO *tst_info) | |||
593 | } | 593 | } |
594 | 594 | ||
595 | static int | 595 | static int |
596 | TS_compute_imprint(BIO *data, TS_TST_INFO *tst_info, X509_ALGOR **md_alg, | 596 | TS_compute_imprint(BIO *data, TS_TST_INFO *tst_info, X509_ALGOR **out_md_alg, |
597 | unsigned char **imprint, unsigned *imprint_len) | 597 | unsigned char **out_imprint, unsigned int *out_imprint_len) |
598 | { | 598 | { |
599 | TS_MSG_IMPRINT *msg_imprint = TS_TST_INFO_get_msg_imprint(tst_info); | 599 | TS_MSG_IMPRINT *msg_imprint; |
600 | X509_ALGOR *md_alg_resp = TS_MSG_IMPRINT_get_algo(msg_imprint); | 600 | X509_ALGOR *md_alg_resp; |
601 | X509_ALGOR *md_alg = NULL; | ||
602 | unsigned char *imprint = NULL; | ||
603 | unsigned int imprint_len = 0; | ||
601 | const EVP_MD *md; | 604 | const EVP_MD *md; |
602 | EVP_MD_CTX md_ctx; | 605 | EVP_MD_CTX md_ctx; |
603 | unsigned char buffer[4096]; | 606 | unsigned char buffer[4096]; |
604 | int length; | 607 | int length; |
605 | 608 | ||
606 | *md_alg = NULL; | 609 | *out_md_alg = NULL; |
607 | *imprint = NULL; | 610 | *out_imprint = NULL; |
611 | *out_imprint_len = 0; | ||
608 | 612 | ||
609 | /* Return the MD algorithm of the response. */ | 613 | /* Retrieve the MD algorithm of the response. */ |
610 | if (!(*md_alg = X509_ALGOR_dup(md_alg_resp))) | 614 | msg_imprint = TS_TST_INFO_get_msg_imprint(tst_info); |
615 | md_alg_resp = TS_MSG_IMPRINT_get_algo(msg_imprint); | ||
616 | if ((md_alg = X509_ALGOR_dup(md_alg_resp)) == NULL) | ||
611 | goto err; | 617 | goto err; |
612 | 618 | ||
613 | /* Getting the MD object. */ | 619 | /* Getting the MD object. */ |
614 | if (!(md = EVP_get_digestbyobj((*md_alg)->algorithm))) { | 620 | if ((md = EVP_get_digestbyobj((md_alg)->algorithm)) == NULL) { |
615 | TSerror(TS_R_UNSUPPORTED_MD_ALGORITHM); | 621 | TSerror(TS_R_UNSUPPORTED_MD_ALGORITHM); |
616 | goto err; | 622 | goto err; |
617 | } | 623 | } |
618 | 624 | ||
619 | /* Compute message digest. */ | 625 | /* Compute message digest. */ |
620 | length = EVP_MD_size(md); | 626 | if ((length = EVP_MD_size(md)) < 0) |
621 | if (length < 0) | ||
622 | goto err; | 627 | goto err; |
623 | *imprint_len = length; | 628 | imprint_len = length; |
624 | if (!(*imprint = malloc(*imprint_len))) { | 629 | if ((imprint = malloc(imprint_len)) == NULL) { |
625 | TSerror(ERR_R_MALLOC_FAILURE); | 630 | TSerror(ERR_R_MALLOC_FAILURE); |
626 | goto err; | 631 | goto err; |
627 | } | 632 | } |
@@ -632,17 +637,20 @@ TS_compute_imprint(BIO *data, TS_TST_INFO *tst_info, X509_ALGOR **md_alg, | |||
632 | if (!EVP_DigestUpdate(&md_ctx, buffer, length)) | 637 | if (!EVP_DigestUpdate(&md_ctx, buffer, length)) |
633 | goto err; | 638 | goto err; |
634 | } | 639 | } |
635 | if (!EVP_DigestFinal(&md_ctx, *imprint, NULL)) | 640 | if (!EVP_DigestFinal(&md_ctx, imprint, NULL)) |
636 | goto err; | 641 | goto err; |
637 | 642 | ||
643 | *out_md_alg = md_alg; | ||
644 | md_alg = NULL; | ||
645 | *out_imprint = imprint; | ||
646 | imprint = NULL; | ||
647 | *out_imprint_len = imprint_len; | ||
648 | |||
638 | return 1; | 649 | return 1; |
639 | 650 | ||
640 | err: | 651 | err: |
641 | X509_ALGOR_free(*md_alg); | 652 | X509_ALGOR_free(md_alg); |
642 | *md_alg = NULL; | 653 | free(imprint); |
643 | free(*imprint); | ||
644 | *imprint = NULL; | ||
645 | *imprint_len = 0; | ||
646 | return 0; | 654 | return 0; |
647 | } | 655 | } |
648 | 656 | ||