diff options
author | tb <> | 2021-12-12 20:42:37 +0000 |
---|---|---|
committer | tb <> | 2021-12-12 20:42:37 +0000 |
commit | a4968ecaa0c133519b712101e5aa091916a3a845 (patch) | |
tree | eda7fe74c8b4084274519b84b3ea4b1dfb75a233 /src | |
parent | e7011c1623e5129361ba13223cfb852ade779697 (diff) | |
download | openbsd-a4968ecaa0c133519b712101e5aa091916a3a845.tar.gz openbsd-a4968ecaa0c133519b712101e5aa091916a3a845.tar.bz2 openbsd-a4968ecaa0c133519b712101e5aa091916a3a845.zip |
Convert req.c to compile with opaque EVP_MD_CTX.
ok inoguchi
Diffstat (limited to 'src')
-rw-r--r-- | src/usr.bin/openssl/req.c | 68 |
1 files changed, 43 insertions, 25 deletions
diff --git a/src/usr.bin/openssl/req.c b/src/usr.bin/openssl/req.c index 4ab091a097..a1190304a0 100644 --- a/src/usr.bin/openssl/req.c +++ b/src/usr.bin/openssl/req.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: req.c,v 1.21 2021/10/23 11:36:44 tb Exp $ */ | 1 | /* $OpenBSD: req.c,v 1.22 2021/12/12 20:42:37 tb Exp $ */ |
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) |
3 | * All rights reserved. | 3 | * All rights reserved. |
4 | * | 4 | * |
@@ -1049,19 +1049,22 @@ req_main(int argc, char **argv) | |||
1049 | EVP_PKEY *tpubkey; | 1049 | EVP_PKEY *tpubkey; |
1050 | 1050 | ||
1051 | if (req_config.x509) | 1051 | if (req_config.x509) |
1052 | tpubkey = X509_get_pubkey(x509ss); | 1052 | tpubkey = X509_get0_pubkey(x509ss); |
1053 | else | 1053 | else |
1054 | tpubkey = X509_REQ_get_pubkey(req); | 1054 | tpubkey = X509_REQ_get0_pubkey(req); |
1055 | if (tpubkey == NULL) { | 1055 | if (tpubkey == NULL) { |
1056 | fprintf(stdout, "Modulus=unavailable\n"); | 1056 | fprintf(stdout, "Modulus=unavailable\n"); |
1057 | goto end; | 1057 | goto end; |
1058 | } | 1058 | } |
1059 | fprintf(stdout, "Modulus="); | 1059 | fprintf(stdout, "Modulus="); |
1060 | if (EVP_PKEY_base_id(tpubkey) == EVP_PKEY_RSA) | 1060 | if (EVP_PKEY_base_id(tpubkey) == EVP_PKEY_RSA) { |
1061 | BN_print(out, tpubkey->pkey.rsa->n); | 1061 | const BIGNUM *n = NULL; |
1062 | else | 1062 | |
1063 | RSA_get0_key(EVP_PKEY_get0_RSA(tpubkey), &n, NULL, NULL); | ||
1064 | |||
1065 | BN_print(out, n); | ||
1066 | } else | ||
1063 | fprintf(stdout, "Wrong Algorithm type"); | 1067 | fprintf(stdout, "Wrong Algorithm type"); |
1064 | EVP_PKEY_free(tpubkey); | ||
1065 | fprintf(stdout, "\n"); | 1068 | fprintf(stdout, "\n"); |
1066 | } | 1069 | } |
1067 | if (!req_config.noout && !req_config.x509) { | 1070 | if (!req_config.noout && !req_config.x509) { |
@@ -1760,14 +1763,19 @@ int | |||
1760 | do_X509_sign(BIO * err, X509 * x, EVP_PKEY * pkey, const EVP_MD * md, | 1763 | do_X509_sign(BIO * err, X509 * x, EVP_PKEY * pkey, const EVP_MD * md, |
1761 | STACK_OF(OPENSSL_STRING) * sigopts) | 1764 | STACK_OF(OPENSSL_STRING) * sigopts) |
1762 | { | 1765 | { |
1766 | EVP_MD_CTX *mctx; | ||
1763 | int rv; | 1767 | int rv; |
1764 | EVP_MD_CTX mctx; | 1768 | |
1765 | EVP_MD_CTX_init(&mctx); | 1769 | if ((mctx = EVP_MD_CTX_new()) == NULL) |
1766 | rv = do_sign_init(err, &mctx, pkey, md, sigopts); | 1770 | return 0; |
1771 | |||
1772 | rv = do_sign_init(err, mctx, pkey, md, sigopts); | ||
1767 | if (rv > 0) | 1773 | if (rv > 0) |
1768 | rv = X509_sign_ctx(x, &mctx); | 1774 | rv = X509_sign_ctx(x, mctx); |
1769 | EVP_MD_CTX_cleanup(&mctx); | 1775 | |
1770 | return rv > 0 ? 1 : 0; | 1776 | EVP_MD_CTX_free(mctx); |
1777 | |||
1778 | return rv > 0; | ||
1771 | } | 1779 | } |
1772 | 1780 | ||
1773 | 1781 | ||
@@ -1775,14 +1783,19 @@ int | |||
1775 | do_X509_REQ_sign(BIO * err, X509_REQ * x, EVP_PKEY * pkey, const EVP_MD * md, | 1783 | do_X509_REQ_sign(BIO * err, X509_REQ * x, EVP_PKEY * pkey, const EVP_MD * md, |
1776 | STACK_OF(OPENSSL_STRING) * sigopts) | 1784 | STACK_OF(OPENSSL_STRING) * sigopts) |
1777 | { | 1785 | { |
1786 | EVP_MD_CTX *mctx; | ||
1778 | int rv; | 1787 | int rv; |
1779 | EVP_MD_CTX mctx; | 1788 | |
1780 | EVP_MD_CTX_init(&mctx); | 1789 | if ((mctx = EVP_MD_CTX_new()) == NULL) |
1781 | rv = do_sign_init(err, &mctx, pkey, md, sigopts); | 1790 | return 0; |
1791 | |||
1792 | rv = do_sign_init(err, mctx, pkey, md, sigopts); | ||
1782 | if (rv > 0) | 1793 | if (rv > 0) |
1783 | rv = X509_REQ_sign_ctx(x, &mctx); | 1794 | rv = X509_REQ_sign_ctx(x, mctx); |
1784 | EVP_MD_CTX_cleanup(&mctx); | 1795 | |
1785 | return rv > 0 ? 1 : 0; | 1796 | EVP_MD_CTX_free(mctx); |
1797 | |||
1798 | return rv > 0; | ||
1786 | } | 1799 | } |
1787 | 1800 | ||
1788 | 1801 | ||
@@ -1792,13 +1805,18 @@ do_X509_CRL_sign(BIO * err, X509_CRL * x, EVP_PKEY * pkey, const EVP_MD * md, | |||
1792 | STACK_OF(OPENSSL_STRING) * sigopts) | 1805 | STACK_OF(OPENSSL_STRING) * sigopts) |
1793 | { | 1806 | { |
1794 | int rv; | 1807 | int rv; |
1795 | EVP_MD_CTX mctx; | 1808 | EVP_MD_CTX *mctx; |
1796 | EVP_MD_CTX_init(&mctx); | 1809 | |
1797 | rv = do_sign_init(err, &mctx, pkey, md, sigopts); | 1810 | if ((mctx = EVP_MD_CTX_new()) == NULL) |
1811 | return 0; | ||
1812 | |||
1813 | rv = do_sign_init(err, mctx, pkey, md, sigopts); | ||
1798 | if (rv > 0) | 1814 | if (rv > 0) |
1799 | rv = X509_CRL_sign_ctx(x, &mctx); | 1815 | rv = X509_CRL_sign_ctx(x, mctx); |
1800 | EVP_MD_CTX_cleanup(&mctx); | 1816 | |
1801 | return rv > 0 ? 1 : 0; | 1817 | EVP_MD_CTX_free(mctx); |
1818 | |||
1819 | return rv > 0; | ||
1802 | } | 1820 | } |
1803 | 1821 | ||
1804 | static unsigned long | 1822 | static unsigned long |