diff options
author | tb <> | 2022-02-03 17:44:04 +0000 |
---|---|---|
committer | tb <> | 2022-02-03 17:44:04 +0000 |
commit | 99e959b3452e5b44dc52e0e6e87b7e4ec42147af (patch) | |
tree | d64d65e1fd6a83904267a56b4660fb0e0411b465 /src/usr.bin/openssl/ca.c | |
parent | 355870caa2e034326f5b6b4df6b18cf93e907bc7 (diff) | |
download | openbsd-99e959b3452e5b44dc52e0e6e87b7e4ec42147af.tar.gz openbsd-99e959b3452e5b44dc52e0e6e87b7e4ec42147af.tar.bz2 openbsd-99e959b3452e5b44dc52e0e6e87b7e4ec42147af.zip |
Use X509_*get0_pubkey() wherever possible to simplify and clean up
the code. Also add error checking where possible.
ok jsing
Diffstat (limited to 'src/usr.bin/openssl/ca.c')
-rw-r--r-- | src/usr.bin/openssl/ca.c | 20 |
1 files changed, 6 insertions, 14 deletions
diff --git a/src/usr.bin/openssl/ca.c b/src/usr.bin/openssl/ca.c index c711f8b4b2..bbc5403e3c 100644 --- a/src/usr.bin/openssl/ca.c +++ b/src/usr.bin/openssl/ca.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: ca.c,v 1.52 2021/11/21 22:34:30 tb Exp $ */ | 1 | /* $OpenBSD: ca.c,v 1.53 2022/02/03 17:44:04 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 | * |
@@ -1633,12 +1633,11 @@ certify(X509 **xret, char *infile, EVP_PKEY *pkey, X509 *x509, | |||
1633 | ok = 0; | 1633 | ok = 0; |
1634 | goto err; | 1634 | goto err; |
1635 | } | 1635 | } |
1636 | if ((pktmp = X509_REQ_get_pubkey(req)) == NULL) { | 1636 | if ((pktmp = X509_REQ_get0_pubkey(req)) == NULL) { |
1637 | BIO_printf(bio_err, "error unpacking public key\n"); | 1637 | BIO_printf(bio_err, "error unpacking public key\n"); |
1638 | goto err; | 1638 | goto err; |
1639 | } | 1639 | } |
1640 | i = X509_REQ_verify(req, pktmp); | 1640 | i = X509_REQ_verify(req, pktmp); |
1641 | EVP_PKEY_free(pktmp); | ||
1642 | if (i < 0) { | 1641 | if (i < 0) { |
1643 | ok = 0; | 1642 | ok = 0; |
1644 | BIO_printf(bio_err, "Signature verification problems....\n"); | 1643 | BIO_printf(bio_err, "Signature verification problems....\n"); |
@@ -1688,12 +1687,11 @@ certify_cert(X509 **xret, char *infile, EVP_PKEY *pkey, X509 *x509, | |||
1688 | 1687 | ||
1689 | BIO_printf(bio_err, "Check that the request matches the signature\n"); | 1688 | BIO_printf(bio_err, "Check that the request matches the signature\n"); |
1690 | 1689 | ||
1691 | if ((pktmp = X509_get_pubkey(req)) == NULL) { | 1690 | if ((pktmp = X509_get0_pubkey(req)) == NULL) { |
1692 | BIO_printf(bio_err, "error unpacking public key\n"); | 1691 | BIO_printf(bio_err, "error unpacking public key\n"); |
1693 | goto err; | 1692 | goto err; |
1694 | } | 1693 | } |
1695 | i = X509_verify(req, pktmp); | 1694 | i = X509_verify(req, pktmp); |
1696 | EVP_PKEY_free(pktmp); | ||
1697 | if (i < 0) { | 1695 | if (i < 0) { |
1698 | ok = 0; | 1696 | ok = 0; |
1699 | BIO_printf(bio_err, "Signature verification problems....\n"); | 1697 | BIO_printf(bio_err, "Signature verification problems....\n"); |
@@ -1997,13 +1995,10 @@ do_body(X509 **xret, EVP_PKEY *pkey, X509 *x509, const EVP_MD *dgst, | |||
1997 | if (!X509_set_subject_name(ret, subject)) | 1995 | if (!X509_set_subject_name(ret, subject)) |
1998 | goto err; | 1996 | goto err; |
1999 | 1997 | ||
2000 | pktmp = X509_REQ_get_pubkey(req); | 1998 | if ((pktmp = X509_REQ_get0_pubkey(req)) == NULL) |
2001 | if (pktmp == NULL) | ||
2002 | goto err; | 1999 | goto err; |
2003 | 2000 | ||
2004 | i = X509_set_pubkey(ret, pktmp); | 2001 | if (!X509_set_pubkey(ret, pktmp)) |
2005 | EVP_PKEY_free(pktmp); | ||
2006 | if (!i) | ||
2007 | goto err; | 2002 | goto err; |
2008 | 2003 | ||
2009 | /* Lets add the extensions, if there are any */ | 2004 | /* Lets add the extensions, if there are any */ |
@@ -2226,18 +2221,15 @@ do_body(X509 **xret, EVP_PKEY *pkey, X509 *x509, const EVP_MD *dgst, | |||
2226 | } | 2221 | } |
2227 | } | 2222 | } |
2228 | 2223 | ||
2229 | pktmp = X509_get_pubkey(ret); | 2224 | if ((pktmp = X509_get0_pubkey(ret)) == NULL) |
2230 | if (pktmp == NULL) | ||
2231 | goto err; | 2225 | goto err; |
2232 | 2226 | ||
2233 | if (EVP_PKEY_missing_parameters(pktmp) && | 2227 | if (EVP_PKEY_missing_parameters(pktmp) && |
2234 | !EVP_PKEY_missing_parameters(pkey)) { | 2228 | !EVP_PKEY_missing_parameters(pkey)) { |
2235 | if (!EVP_PKEY_copy_parameters(pktmp, pkey)) { | 2229 | if (!EVP_PKEY_copy_parameters(pktmp, pkey)) { |
2236 | EVP_PKEY_free(pktmp); | ||
2237 | goto err; | 2230 | goto err; |
2238 | } | 2231 | } |
2239 | } | 2232 | } |
2240 | EVP_PKEY_free(pktmp); | ||
2241 | 2233 | ||
2242 | if (!do_X509_sign(bio_err, ret, pkey, dgst, sigopts)) | 2234 | if (!do_X509_sign(bio_err, ret, pkey, dgst, sigopts)) |
2243 | goto err; | 2235 | goto err; |