From: "Jarkko Sakkinen" <jarkko@kernel.org>
To: "Jan Stancek" <jstancek@redhat.com>, <dhowells@redhat.com>,
<dwmw2@infradead.org>, <zxu@redhat.com>,
<keyrings@vger.kernel.org>
Cc: <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH 2/3] sign-file,extract-cert: avoid using deprecated ERR_get_error_line()
Date: Tue, 13 Aug 2024 13:12:10 +0300 [thread overview]
Message-ID: <D3EPBYVJ9NZ2.2OI3EQVYKRRZI@kernel.org> (raw)
In-Reply-To: <6b7f84efe01b89a8a6cd35108a721224c22de8e1.1720728319.git.jstancek@redhat.com>
On Fri Jul 12, 2024 at 10:11 AM EEST, Jan Stancek wrote:
> ERR_get_error_line() is deprecated since OpenSSL 3.0.
>
> Use ERR_peek_error_line() instead, and combine display_openssl_errors()
> and drain_openssl_errors() to a single function where parameter decides
> if it should consume errors silently.
>
> Signed-off-by: Jan Stancek <jstancek@redhat.com>
> ---
> certs/extract-cert.c | 4 ++--
> scripts/sign-file.c | 6 +++---
> scripts/ssl-common.h | 23 ++++++++---------------
> 3 files changed, 13 insertions(+), 20 deletions(-)
>
> diff --git a/certs/extract-cert.c b/certs/extract-cert.c
> index 8e7ba9974a1f..61bbe0085671 100644
> --- a/certs/extract-cert.c
> +++ b/certs/extract-cert.c
> @@ -99,11 +99,11 @@ int main(int argc, char **argv)
> parms.cert = NULL;
>
> ENGINE_load_builtin_engines();
> - drain_openssl_errors();
> + drain_openssl_errors(__LINE__, 1);
> e = ENGINE_by_id("pkcs11");
> ERR(!e, "Load PKCS#11 ENGINE");
> if (ENGINE_init(e))
> - drain_openssl_errors();
> + drain_openssl_errors(__LINE__, 1);
> else
> ERR(1, "ENGINE_init");
> if (key_pass)
> diff --git a/scripts/sign-file.c b/scripts/sign-file.c
> index 39ba58db5d4e..bb3fdf1a617c 100644
> --- a/scripts/sign-file.c
> +++ b/scripts/sign-file.c
> @@ -114,11 +114,11 @@ static EVP_PKEY *read_private_key(const char *private_key_name)
> ENGINE *e;
>
> ENGINE_load_builtin_engines();
> - drain_openssl_errors();
> + drain_openssl_errors(__LINE__, 1);
> e = ENGINE_by_id("pkcs11");
> ERR(!e, "Load PKCS#11 ENGINE");
> if (ENGINE_init(e))
> - drain_openssl_errors();
> + drain_openssl_errors(__LINE__, 1);
> else
> ERR(1, "ENGINE_init");
> if (key_pass)
> @@ -273,7 +273,7 @@ int main(int argc, char **argv)
>
> /* Digest the module data. */
> OpenSSL_add_all_digests();
> - display_openssl_errors(__LINE__);
> + drain_openssl_errors(__LINE__, 0);
> digest_algo = EVP_get_digestbyname(hash_algo);
> ERR(!digest_algo, "EVP_get_digestbyname");
>
> diff --git a/scripts/ssl-common.h b/scripts/ssl-common.h
> index e6711c75ed91..2db0e181143c 100644
> --- a/scripts/ssl-common.h
> +++ b/scripts/ssl-common.h
> @@ -3,7 +3,7 @@
> * SSL helper functions shared by sign-file and extract-cert.
> */
>
> -static void display_openssl_errors(int l)
> +static void drain_openssl_errors(int l, int silent)
> {
> const char *file;
> char buf[120];
> @@ -11,28 +11,21 @@ static void display_openssl_errors(int l)
>
> if (ERR_peek_error() == 0)
> return;
> - fprintf(stderr, "At main.c:%d:\n", l);
> + if (!silent)
> + fprintf(stderr, "At main.c:%d:\n", l);
>
> - while ((e = ERR_get_error_line(&file, &line))) {
> + while ((e = ERR_peek_error_line(&file, &line))) {
> ERR_error_string(e, buf);
> - fprintf(stderr, "- SSL %s: %s:%d\n", buf, file, line);
> + if (!silent)
> + fprintf(stderr, "- SSL %s: %s:%d\n", buf, file, line);
> + ERR_get_error();
> }
> }
>
> -static void drain_openssl_errors(void)
> -{
> - const char *file;
> - int line;
> -
> - if (ERR_peek_error() == 0)
> - return;
> - while (ERR_get_error_line(&file, &line)) {}
> -}
> -
> #define ERR(cond, fmt, ...) \
> do { \
> bool __cond = (cond); \
> - display_openssl_errors(__LINE__); \
> + drain_openssl_errors(__LINE__, 0); \
> if (__cond) { \
> errx(1, fmt, ## __VA_ARGS__); \
> } \
Reviewed-by: Jarkko Sakkinen <jarkko@kernel.org>
BR, Jarkko
next prev parent reply other threads:[~2024-08-13 10:12 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-07-12 7:11 [PATCH 0/3] sign-file,extract-cert: switch to PROVIDER API for OpenSSL >= 3.0 Jan Stancek
2024-07-12 7:11 ` [PATCH 1/3] sign-file,extract-cert: move common SSL helper functions to a header Jan Stancek
2024-08-13 10:04 ` Jarkko Sakkinen
2024-07-12 7:11 ` [PATCH 2/3] sign-file,extract-cert: avoid using deprecated ERR_get_error_line() Jan Stancek
2024-08-13 10:12 ` Jarkko Sakkinen [this message]
2024-07-12 7:11 ` [PATCH 3/3] sign-file,extract-cert: use pkcs11 provider for OPENSSL MAJOR >= 3 Jan Stancek
2024-08-13 10:23 ` Jarkko Sakkinen
2024-08-02 13:10 ` [PATCH 0/3] sign-file,extract-cert: switch to PROVIDER API for OpenSSL >= 3.0 Herbert Xu
2024-08-02 17:59 ` Jarkko Sakkinen
2024-08-02 18:27 ` Jan Stancek
2024-08-02 19:54 ` Jarkko Sakkinen
2024-08-06 20:27 ` Neal Gompa
2024-09-20 11:42 ` Neal Gompa
2024-09-20 15:34 ` Jarkko Sakkinen
2024-09-20 20:05 ` Jan Stancek
2024-09-20 22:16 ` Jarkko Sakkinen
2024-09-03 8:11 ` R Nageswara Sastry
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=D3EPBYVJ9NZ2.2OI3EQVYKRRZI@kernel.org \
--to=jarkko@kernel.org \
--cc=dhowells@redhat.com \
--cc=dwmw2@infradead.org \
--cc=jstancek@redhat.com \
--cc=keyrings@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=zxu@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox