Skip to contentSkip to conversation

Add support for OpenSSL Provider API

PATCH Superseded Eddie Kovsky 5 participants 15 messages Jan 20 – Apr 28

v3 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 Add support for OpenSSL Provider API

The Engine API has been deprecated since the release of OpenSSL 3.0. End users have been advised to migrate to the new Provider interface. Several distributions have already removed support for engines, which is preventing U-Boot from being compiled in those environments.

Add support for the Provider API while continuing to support the existing Engine API on distros shipping older releases of OpenSSL.

This is based on similar work contributed by Jan Stancek updating Linux to use the Provider interface.

commit 558bdc45dfb2669e1741384a0c80be9c82fa052c
Author: Jan Stancek <[email protected]>
Date: Fri Sep 20 19:52:48 2024 +0300

sign-file,extract-cert: use pkcs11 provider for OPENSSL MAJOR >= 3

The changes have been tested with the FIT signature verification vboot tests on Fedora 42 and Debian 13. All 30 tests pass with both the legacy Engine library installed and with the Provider API.

---
Changes in v3:
- Removed Kconfig option
- Changed macro symbol from CONFIG_OPENSSL_NO_DEPRECATED to USE_PKCS11_PROVIDER or USE_PKCS11_ENGINE
v2: https://lore.kernel.org/u-boot/[email protected]/

Changes in v2:
- Remove default for new Kconfig option
- Use #ifdef instead of IS_ENABLED macro
- Remove comment after #endif
- Remove unrelated checkpatch cleanup of 'sslErr' variable name
v1: https://lore.kernel.org/u-boot/[email protected]/

---
 lib/aes/aes-encrypt.c |  4 +-
 lib/rsa/rsa-sign.c    | 95 ++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 97 insertions(+), 2 deletions(-)
lib/aes/aes-encrypt.c +3 -1
index 90e1407b4f09..4fc4ce232478 100644
@@ -16,7 +16,9 @@
 #include <openssl/err.h>
 #include <openssl/ssl.h>
 #include <openssl/evp.h>
-#include <openssl/engine.h>
+#if !defined(OPENSSL_NO_ENGINE) && !defined(OPENSSL_NO_DEPRECATED_3_0)
+# include <openssl/engine.h>
+#endif
 #include <uboot_aes.h>
 
 #if OPENSSL_VERSION_NUMBER >= 0x10000000L
lib/rsa/rsa-sign.c +94 -1

212 lines not on this page · raw message

Signature · 1 line
2.52.0
#1 lore raw

Hi Eddie,

Thank you for the patch.

Quoted 15 lines · Eddie Kovsky

The Engine API has been deprecated since the release of OpenSSL 3.0. End users have been advised to migrate to the new Provider interface. Several distributions have already removed support for engines, which is preventing U-Boot from being compiled in those environments.

Add support for the Provider API while continuing to support the existing Engine API on distros shipping older releases of OpenSSL.

This is based on similar work contributed by Jan Stancek updating Linux to use the Provider interface.

commit 558bdc45dfb2669e1741384a0c80be9c82fa052c
Author: Jan Stancek <[email protected]>
Date: Fri Sep 20 19:52:48 2024 +0300

Quoted 7 lines

sign-file,extract-cert: use pkcs11 provider for OPENSSL MAJOR >= 3

The changes have been tested with the FIT signature verification vboot tests on Fedora 42 and Debian 13. All 30 tests pass with both the legacy Engine library installed and with the Provider API.

As a follow-up, can we look into reverting/removing commit 3a8b919932fd ("tools: avoid OpenSSL deprecation warnings") ?

This looks much better than v2 in my opinion.

Some additional comments below:

lib/rsa/rsa-sign.c static int rsa_engine_get_pub_key(const char *keydir, const char *name,

Quoted 103 lines

---
Changes in v3:
- Removed Kconfig option
- Changed macro symbol from CONFIG_OPENSSL_NO_DEPRECATED to USE_PKCS11_PROVIDER or USE_PKCS11_ENGINE
v2: https://lore.kernel.org/u-boot/[email protected]/

Changes in v2:
- Remove default for new Kconfig option
- Use #ifdef instead of IS_ENABLED macro
- Remove comment after #endif
- Remove unrelated checkpatch cleanup of 'sslErr' variable name
v1: https://lore.kernel.org/u-boot/[email protected]/

---
 lib/aes/aes-encrypt.c |  4 +-
 lib/rsa/rsa-sign.c    | 95 ++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 97 insertions(+), 2 deletions(-)
lib/aes/aes-encrypt.c +3 -1
index 90e1407b4f09..4fc4ce232478 100644
@@ -16,7 +16,9 @@
 #include <openssl/err.h>
 #include <openssl/ssl.h>
 #include <openssl/evp.h>
-#include <openssl/engine.h>
+#if !defined(OPENSSL_NO_ENGINE) && !defined(OPENSSL_NO_DEPRECATED_3_0)
+# include <openssl/engine.h>
+#endif
 #include <uboot_aes.h>
 
 #if OPENSSL_VERSION_NUMBER >= 0x10000000L
lib/rsa/rsa-sign.c +43 -1
index 0e38c9e802fd..31269db65950 100644
@@ -19,7 +19,47 @@
 #include <openssl/err.h>
 #include <openssl/ssl.h>
 #include <openssl/evp.h>
-#include <openssl/engine.h>
+#if OPENSSL_VERSION_MAJOR >= 3
+# define USE_PKCS11_PROVIDER
+# include <err.h>
+# include <openssl/provider.h>
+# include <openssl/store.h>
+#else
+# if !defined(OPENSSL_NO_ENGINE) && !defined(OPENSSL_NO_DEPRECATED_3_0)
+#  define USE_PKCS11_ENGINE
+#  include <openssl/engine.h>
+# endif
+#endif
+
+#ifdef USE_PKCS11_PROVIDER
+#define ERR(cond, fmt, ...)				\
+	do {						\
+		bool __cond = (cond);			\
+		drain_openssl_errors(__LINE__, 0);	\
+		if (__cond) {				\
+			errx(1, fmt, ## __VA_ARGS__);	\
+		}					\
+	} while (0)
+
+static void drain_openssl_errors(int l, int silent)
+{
+	const char *file;
+	char buf[120];
+	int e, line;
+
+	if (ERR_peek_error() == 0)
+		return;
+	if (!silent)
+		fprintf(stderr, "At main.c:%d:\n", l);
+
+	while ((e = ERR_peek_error_line(&file, &line))) {
+		ERR_error_string(e, buf);
+		if (!silent)
+			fprintf(stderr, "- SSL %s: %s:%d\n", buf, file, line);
+		ERR_get_error();
+	}
+}
+#endif
 
 static int rsa_err(const char *msg)
 {
@@ -98,6 +138,7 @@ err_cert:
  * @evpp	Returns EVP_PKEY object, or NULL on failure
  * Return: 0 if ok, -ve on error (in which case *evpp will be set to NULL)
  */
+#ifdef USE_PKCS11_ENGINE
 static int rsa_engine_get_pub_key(const char *keydir, const char *name,
 				  ENGINE *engine, EVP_PKEY **evpp)
 {
@@ -157,6 +198,7 @@ static int rsa_engine_get_pub_key(const char *keydir, const char *name,
 
 	return 0;
 }
+#endif
 
 /**
  * rsa_get_pub_key() - read a public key
@@ -170,8 +212,10 @@ static int rsa_engine_get_pub_key(const char *keydir, const char *name,

With this change, the ENGINE pointer might be NULL (or undefined). Can we please update the documentation comment to reflect this?

For example, we could reword as:
* @engine Engine to use or NULL when using pcks11 provider

lib/rsa/rsa-sign.c static int rsa_engine_get_pub_key(const char *keydir, const char *name, · line 220

Quoted 9 lines
lib/rsa/rsa-sign.c +2 -0
 static int rsa_get_pub_key(const char *keydir, const char *name,
 			   ENGINE *engine, EVP_PKEY **evpp)
 {
+#ifdef USE_PKCS11_ENGINE
 	if (engine)
 		return rsa_engine_get_pub_key(keydir, name, engine, evpp);
+#endif
 	return rsa_pem_get_pub_key(keydir, name, evpp);
 }

Actually, looking even closer at this function, it's seems to be called only once.

Why can't we drop this function alltogether and call rsa_engine_get_pub_key() / rsa_pem_get_pub_key() directly in rsa_add_verify_data() ?

Reason I'm asking: in rsa_add_verify_data(), ENGINE *e is not used when we use PROVIDER. It seems weird (and error prone) to pass a NULL pointer to a function that does not need that argument

Quoted 40 lines
lib/rsa/rsa-sign.c +31 -0
@@ -207,6 +251,37 @@ static int rsa_pem_get_priv_key(const char *keydir, const char *name,
 		return -ENOENT;
 	}
 
+#ifdef USE_PKCS11_PROVIDER
+	EVP_PKEY *private_key = NULL;
+	OSSL_STORE_CTX *store;
+
+	if (!OSSL_PROVIDER_try_load(NULL, "pkcs11", true))
+		ERR(1, "OSSL_PROVIDER_try_load(pkcs11)");
+	if (!OSSL_PROVIDER_try_load(NULL, "default", true))
+		ERR(1, "OSSL_PROVIDER_try_load(default)");
+
+	store = OSSL_STORE_open(path, NULL, NULL, NULL, NULL);
+	ERR(!store, "OSSL_STORE_open");
+
+	while (!OSSL_STORE_eof(store)) {
+		OSSL_STORE_INFO *info = OSSL_STORE_load(store);
+
+		if (!info) {
+			drain_openssl_errors(__LINE__, 0);
+			continue;
+		}
+		if (OSSL_STORE_INFO_get_type(info) == OSSL_STORE_INFO_PKEY) {
+			private_key = OSSL_STORE_INFO_get1_PKEY(info);
+			ERR(!private_key, "OSSL_STORE_INFO_get1_PKEY");
+		}
+		OSSL_STORE_INFO_free(info);
+		if (private_key)
+			break;
+	}
+	OSSL_STORE_close(store);
+
+	*evpp = private_key;
+#else
 	if (!PEM_read_PrivateKey(f, evpp, NULL, path)) {
 		rsa_err("Failure reading private key");
 		fclose(f);

lib/rsa/rsa-sign.c static int rsa_pem_get_priv_key(const char *keydir, const char *name, · line 293

Quoted 5 lines
lib/rsa/rsa-sign.c +1 -0
@@ -214,6 +289,7 @@ static int rsa_pem_get_priv_key(const char *keydir, const char *name,
 	}
 	fclose(f);
 
+#endif
 	return 0;

This block should be

fclose(f);
+#endif

return 0;

(not having a blank line between the fclose and the #endif)

Quoted 19 lines
lib/rsa/rsa-sign.c +2 -0
 }
 
@@ -226,6 +302,7 @@ static int rsa_pem_get_priv_key(const char *keydir, const char *name,
  * @evpp	Returns EVP_PKEY object, or NULL on failure
  * Return: 0 if ok, -ve on error (in which case *evpp will be set to NULL)
  */
+#ifdef USE_PKCS11_ENGINE
 static int rsa_engine_get_priv_key(const char *keydir, const char *name,
 				   const char *keyfile,
 				   ENGINE *engine, EVP_PKEY **evpp)
@@ -293,6 +370,7 @@ static int rsa_engine_get_priv_key(const char *keydir, const char *name,
 
 	return 0;
 }
+#endif
 
 /**
  * rsa_get_priv_key() - read a private key

lib/rsa/rsa-sign.c static int rsa_engine_get_priv_key(const char *keydir, const char *name, · line 392

Quoted 9 lines
lib/rsa/rsa-sign.c +2 -0
@@ -306,9 +384,11 @@ static int rsa_engine_get_priv_key(const char *keydir, const char *name,
 static int rsa_get_priv_key(const char *keydir, const char *name,
 			    const char *keyfile, ENGINE *engine, EVP_PKEY **evpp)
 {
+#ifdef USE_PKCS11_ENGINE
 	if (engine)
 		return rsa_engine_get_priv_key(keydir, name, keyfile, engine,
 					       evpp);
+#endif
 	return rsa_pem_get_priv_key(keydir, name, keyfile, evpp);

Same remark as for rsa_engine_get_pub_key. Can't we drop this static function? It's only called once.

Maybe do a cleanup patch first, that gets rid of the static functions and then do the provider support in a second patch of the same series?

I think it will reduce the amount of #ifdefs, which seems a good argument.

#2 lore raw
Quoted 4 lines · Mattijs Korpershoek

Hi Eddie,

Thank you for the patch.

Hi Mattijs

Thanks for the review.

Quoted 19 lines · Eddie Kovsky
Quoted 18 lines

The Engine API has been deprecated since the release of OpenSSL 3.0. End users have been advised to migrate to the new Provider interface. Several distributions have already removed support for engines, which is preventing U-Boot from being compiled in those environments.

Add support for the Provider API while continuing to support the existing Engine API on distros shipping older releases of OpenSSL.

This is based on similar work contributed by Jan Stancek updating Linux to use the Provider interface.

commit 558bdc45dfb2669e1741384a0c80be9c82fa052c
Author: Jan Stancek <[email protected]>
Date: Fri Sep 20 19:52:48 2024 +0300

sign-file,extract-cert: use pkcs11 provider for OPENSSL MAJOR >= 3

Quoted 9 lines
Quoted 5 lines

The changes have been tested with the FIT signature verification vboot tests on Fedora 42 and Debian 13. All 30 tests pass with both the legacy Engine library installed and with the Provider API.

As a follow-up, can we look into reverting/removing commit 3a8b919932fd ("tools: avoid OpenSSL deprecation warnings") ?

Yes, we could certainly revert this once we've determined it's no longer needed for CI. But it's outside the scope of what I'm proposing for this patch.

Quoted 111 lines

This looks much better than v2 in my opinion.

Some additional comments below:

lib/rsa/rsa-sign.c static int rsa_engine_get_pub_key(const char *keydir, const char *name,

Quoted 103 lines

---
Changes in v3:
- Removed Kconfig option
- Changed macro symbol from CONFIG_OPENSSL_NO_DEPRECATED to USE_PKCS11_PROVIDER or USE_PKCS11_ENGINE
v2: https://lore.kernel.org/u-boot/[email protected]/

Changes in v2:
- Remove default for new Kconfig option
- Use #ifdef instead of IS_ENABLED macro
- Remove comment after #endif
- Remove unrelated checkpatch cleanup of 'sslErr' variable name
v1: https://lore.kernel.org/u-boot/[email protected]/

---
 lib/aes/aes-encrypt.c |  4 +-
 lib/rsa/rsa-sign.c    | 95 ++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 97 insertions(+), 2 deletions(-)
lib/aes/aes-encrypt.c +3 -1
index 90e1407b4f09..4fc4ce232478 100644
@@ -16,7 +16,9 @@
 #include <openssl/err.h>
 #include <openssl/ssl.h>
 #include <openssl/evp.h>
-#include <openssl/engine.h>
+#if !defined(OPENSSL_NO_ENGINE) && !defined(OPENSSL_NO_DEPRECATED_3_0)
+# include <openssl/engine.h>
+#endif
 #include <uboot_aes.h>
 
 #if OPENSSL_VERSION_NUMBER >= 0x10000000L
lib/rsa/rsa-sign.c +43 -1
index 0e38c9e802fd..31269db65950 100644
@@ -19,7 +19,47 @@
 #include <openssl/err.h>
 #include <openssl/ssl.h>
 #include <openssl/evp.h>
-#include <openssl/engine.h>
+#if OPENSSL_VERSION_MAJOR >= 3
+# define USE_PKCS11_PROVIDER
+# include <err.h>
+# include <openssl/provider.h>
+# include <openssl/store.h>
+#else
+# if !defined(OPENSSL_NO_ENGINE) && !defined(OPENSSL_NO_DEPRECATED_3_0)
+#  define USE_PKCS11_ENGINE
+#  include <openssl/engine.h>
+# endif
+#endif
+
+#ifdef USE_PKCS11_PROVIDER
+#define ERR(cond, fmt, ...)				\
+	do {						\
+		bool __cond = (cond);			\
+		drain_openssl_errors(__LINE__, 0);	\
+		if (__cond) {				\
+			errx(1, fmt, ## __VA_ARGS__);	\
+		}					\
+	} while (0)
+
+static void drain_openssl_errors(int l, int silent)
+{
+	const char *file;
+	char buf[120];
+	int e, line;
+
+	if (ERR_peek_error() == 0)
+		return;
+	if (!silent)
+		fprintf(stderr, "At main.c:%d:\n", l);
+
+	while ((e = ERR_peek_error_line(&file, &line))) {
+		ERR_error_string(e, buf);
+		if (!silent)
+			fprintf(stderr, "- SSL %s: %s:%d\n", buf, file, line);
+		ERR_get_error();
+	}
+}
+#endif
 
 static int rsa_err(const char *msg)
 {
@@ -98,6 +138,7 @@ err_cert:
  * @evpp	Returns EVP_PKEY object, or NULL on failure
  * Return: 0 if ok, -ve on error (in which case *evpp will be set to NULL)
  */
+#ifdef USE_PKCS11_ENGINE
 static int rsa_engine_get_pub_key(const char *keydir, const char *name,
 				  ENGINE *engine, EVP_PKEY **evpp)
 {
@@ -157,6 +198,7 @@ static int rsa_engine_get_pub_key(const char *keydir, const char *name,
 
 	return 0;
 }
+#endif
 
 /**
  * rsa_get_pub_key() - read a public key
@@ -170,8 +212,10 @@ static int rsa_engine_get_pub_key(const char *keydir, const char *name,

With this change, the ENGINE pointer might be NULL (or undefined). Can we please update the documentation comment to reflect this?

Quoted 3 lines

For example, we could reword as:
* @engine Engine to use or NULL when using pcks11 provider

Sure, I can update the comment for v4.

Quoted 13 lines

lib/rsa/rsa-sign.c static int rsa_engine_get_pub_key(const char *keydir, const char *name, · line 220

Quoted 9 lines
lib/rsa/rsa-sign.c +2 -0
 static int rsa_get_pub_key(const char *keydir, const char *name,
 			   ENGINE *engine, EVP_PKEY **evpp)
 {
+#ifdef USE_PKCS11_ENGINE
 	if (engine)
 		return rsa_engine_get_pub_key(keydir, name, engine, evpp);
+#endif
 	return rsa_pem_get_pub_key(keydir, name, evpp);
 }

Actually, looking even closer at this function, it's seems to be called only once.

Quoted 8 lines

Why can't we drop this function alltogether and call rsa_engine_get_pub_key() / rsa_pem_get_pub_key() directly in rsa_add_verify_data() ?

Reason I'm asking: in rsa_add_verify_data(), ENGINE *e is not used when we use PROVIDER. It seems weird (and error prone) to pass a NULL pointer to a function that does not need that argument

Yes, we could drop rsa_get_pub_key(). It is set up as a helper function and only called once from rsa_add_verify_data().

But I am hesitant to make any changes to the RSA API in this file. I want to limit the scope of this patch so that the existing code is unchanged for users of the Engine API. And I think removing this function would require adding more #ifdefs around the error handling in rsa_add_verify_data().

Quoted 53 lines
Quoted 40 lines
lib/rsa/rsa-sign.c +31 -0
@@ -207,6 +251,37 @@ static int rsa_pem_get_priv_key(const char *keydir, const char *name,
 		return -ENOENT;
 	}
 
+#ifdef USE_PKCS11_PROVIDER
+	EVP_PKEY *private_key = NULL;
+	OSSL_STORE_CTX *store;
+
+	if (!OSSL_PROVIDER_try_load(NULL, "pkcs11", true))
+		ERR(1, "OSSL_PROVIDER_try_load(pkcs11)");
+	if (!OSSL_PROVIDER_try_load(NULL, "default", true))
+		ERR(1, "OSSL_PROVIDER_try_load(default)");
+
+	store = OSSL_STORE_open(path, NULL, NULL, NULL, NULL);
+	ERR(!store, "OSSL_STORE_open");
+
+	while (!OSSL_STORE_eof(store)) {
+		OSSL_STORE_INFO *info = OSSL_STORE_load(store);
+
+		if (!info) {
+			drain_openssl_errors(__LINE__, 0);
+			continue;
+		}
+		if (OSSL_STORE_INFO_get_type(info) == OSSL_STORE_INFO_PKEY) {
+			private_key = OSSL_STORE_INFO_get1_PKEY(info);
+			ERR(!private_key, "OSSL_STORE_INFO_get1_PKEY");
+		}
+		OSSL_STORE_INFO_free(info);
+		if (private_key)
+			break;
+	}
+	OSSL_STORE_close(store);
+
+	*evpp = private_key;
+#else
 	if (!PEM_read_PrivateKey(f, evpp, NULL, path)) {
 		rsa_err("Failure reading private key");
 		fclose(f);

lib/rsa/rsa-sign.c static int rsa_pem_get_priv_key(const char *keydir, const char *name, · line 293

Quoted 5 lines
lib/rsa/rsa-sign.c +1 -0
@@ -214,6 +289,7 @@ static int rsa_pem_get_priv_key(const char *keydir, const char *name,
 	}
 	fclose(f);
 
+#endif
 	return 0;

This block should be

lib/rsa/rsa-sign.c +1 -0
 	fclose(f);
+#endif
 
 	return 0;
Quoted 3 lines

(not having a blank line between the fclose and the #endif)

Quoted 1 line
lib/rsa/rsa-sign.c +0 -0
 }

I'll clean that up in v4.

Quoted 31 lines
Quoted 18 lines
lib/rsa/rsa-sign.c +2 -0
@@ -226,6 +302,7 @@ static int rsa_pem_get_priv_key(const char *keydir, const char *name,
  * @evpp	Returns EVP_PKEY object, or NULL on failure
  * Return: 0 if ok, -ve on error (in which case *evpp will be set to NULL)
  */
+#ifdef USE_PKCS11_ENGINE
 static int rsa_engine_get_priv_key(const char *keydir, const char *name,
 				   const char *keyfile,
 				   ENGINE *engine, EVP_PKEY **evpp)
@@ -293,6 +370,7 @@ static int rsa_engine_get_priv_key(const char *keydir, const char *name,
 
 	return 0;
 }
+#endif
 
 /**
  * rsa_get_priv_key() - read a private key

lib/rsa/rsa-sign.c static int rsa_engine_get_priv_key(const char *keydir, const char *name, · line 392

Quoted 9 lines
lib/rsa/rsa-sign.c +2 -0
@@ -306,9 +384,11 @@ static int rsa_engine_get_priv_key(const char *keydir, const char *name,
 static int rsa_get_priv_key(const char *keydir, const char *name,
 			    const char *keyfile, ENGINE *engine, EVP_PKEY **evpp)
 {
+#ifdef USE_PKCS11_ENGINE
 	if (engine)
 		return rsa_engine_get_priv_key(keydir, name, keyfile, engine,
 					       evpp);
+#endif
 	return rsa_pem_get_priv_key(keydir, name, keyfile, evpp);

Same remark as for rsa_engine_get_pub_key. Can't we drop this static function? It's only called once.

Quoted 6 lines

Maybe do a cleanup patch first, that gets rid of the static functions and then do the provider support in a second patch of the same series?

I think it will reduce the amount of #ifdefs, which seems a good argument.

Again, I am trying to limit the scope of this proposal to preserve the existing code. If we remove the helper function rsa_get_priv_key() then the #ifdef guards also have to move inside the caller rsa_sign(). And since we would no longer be able to check the return value of rsa_get_priv_key() additional guards would be needed to recreate the return value logic that's already in the helper function.

Eddie

#3 lore raw
Quoted 34 lines · Eddie Kovsky
Quoted 4 lines · Mattijs Korpershoek

Hi Eddie,

Thank you for the patch.

Hi Mattijs

Thanks for the review.

Quoted 24 lines · Eddie Kovsky
Quoted 23 lines

The Engine API has been deprecated since the release of OpenSSL 3.0. End users have been advised to migrate to the new Provider interface. Several distributions have already removed support for engines, which is preventing U-Boot from being compiled in those environments.

Add support for the Provider API while continuing to support the existing Engine API on distros shipping older releases of OpenSSL.

This is based on similar work contributed by Jan Stancek updating Linux to use the Provider interface.

commit 558bdc45dfb2669e1741384a0c80be9c82fa052c
Author: Jan Stancek <[email protected]>
Date: Fri Sep 20 19:52:48 2024 +0300

sign-file,extract-cert: use pkcs11 provider for OPENSSL MAJOR >= 3

The changes have been tested with the FIT signature verification vboot tests on Fedora 42 and Debian 13. All 30 tests pass with both the legacy Engine library installed and with the Provider API.

[snip]

Quoted 1 line

Sure, I can update the comment for v4.

Since we're talking about v4, can you please make sure that for v4 it:
- Passes CI https://docs.u-boot.org/en/latest/develop/ci_testing.html as that will cover some non-Linux host builds.
- See if you can get access to a FreeBSD or OpenBSD host and make sure the tools build still works there too? I was hoping Mark would have commented / tested-by v3 because I do want to make sure the libressl case still builds. At worst case, I have a freebie Oracle VM that's FreeBSD based, so you can maybe spin one of those up as well?

Thanks!

Signature · 1 line
Tom
#4 lore raw

Hi all,

Thanks Eddie for the effort on doing this.

Quoted 40 lines · Tom Rini
Quoted 34 lines · Eddie Kovsky
Quoted 4 lines · Mattijs Korpershoek

Hi Eddie,

Thank you for the patch.

Hi Mattijs

Thanks for the review.

Quoted 24 lines · Eddie Kovsky
Quoted 23 lines

The Engine API has been deprecated since the release of OpenSSL 3.0. End users have been advised to migrate to the new Provider interface. Several distributions have already removed support for engines, which is preventing U-Boot from being compiled in those environments.

Add support for the Provider API while continuing to support the existing Engine API on distros shipping older releases of OpenSSL.

This is based on similar work contributed by Jan Stancek updating Linux to use the Provider interface.

commit 558bdc45dfb2669e1741384a0c80be9c82fa052c
Author: Jan Stancek <[email protected]>
Date: Fri Sep 20 19:52:48 2024 +0300

sign-file,extract-cert: use pkcs11 provider for OPENSSL MAJOR >= 3

The changes have been tested with the FIT signature verification vboot tests on Fedora 42 and Debian 13. All 30 tests pass with both the legacy Engine library installed and with the Provider API.

[snip]

Quoted 1 line

Sure, I can update the comment for v4.

Quoted 9 lines

Since we're talking about v4, can you please make sure that for v4 it:
- Passes CI https://docs.u-boot.org/en/latest/develop/ci_testing.html as that will cover some non-Linux host builds.
- See if you can get access to a FreeBSD or OpenBSD host and make sure the tools build still works there too? I was hoping Mark would have commented / tested-by v3 because I do want to make sure the libressl case still builds. At worst case, I have a freebie Oracle VM that's FreeBSD based, so you can maybe spin one of those up as well?

I wanted to provide some context on my testing efforts. I have successfully tested these patches on Fedora and CentOS Stream 10, where the engine support is already deprecated. These changes are quite important because we are currently carrying them as a downstream patch for some RPM packages.

Regarding testing on OpenBSD and FreeBSD ( it uses openssl 3.0 by default ), I tried, but I ran into some build issues that I couldn't quickly resolve due to my limited experience with those environments. Instead, I decided to test with an alpine+libressl container and can confirm that the build of the tools does not break with these patches applied, which should cover the libressl case you were concerned about.

   # make tools
   # ldd tools/mkimage
   /lib/ld-musl-x86_64.so.1 (0x7f12975f5000)
   libssl.so.60 => /usr/lib/libssl.so.60 (0x7f12973a4000)
   libcrypto.so.57 => /usr/lib/libcrypto.so.57 (0x7f129722a000)
   libc.musl-x86_64.so.1 => /lib/ld-musl-x86_64.so.1 (0x7f12975f5000)
   # strings /usr/lib/libcrypto.so.57 | grep -i "libressl"
   LibreSSL 4.2.1
   %s/libressl.cnf

I'm happy to provide my tested-by tag if it helps move the patch along. Feel free to include it in v4.

Thanks,

Enric

Quoted 4 lines

Thanks!

--
Tom

#5 lore raw
Quoted 76 lines · Enric Balletbo i Serra

Hi all,

Thanks Eddie for the effort on doing this.

Quoted 40 lines · Tom Rini
Quoted 34 lines · Eddie Kovsky
Quoted 4 lines · Mattijs Korpershoek

Hi Eddie,

Thank you for the patch.

Hi Mattijs

Thanks for the review.

Quoted 24 lines · Eddie Kovsky
Quoted 23 lines

The Engine API has been deprecated since the release of OpenSSL 3.0. End users have been advised to migrate to the new Provider interface. Several distributions have already removed support for engines, which is preventing U-Boot from being compiled in those environments.

Add support for the Provider API while continuing to support the existing Engine API on distros shipping older releases of OpenSSL.

This is based on similar work contributed by Jan Stancek updating Linux to use the Provider interface.

commit 558bdc45dfb2669e1741384a0c80be9c82fa052c
Author: Jan Stancek <[email protected]>
Date: Fri Sep 20 19:52:48 2024 +0300

sign-file,extract-cert: use pkcs11 provider for OPENSSL MAJOR >= 3

The changes have been tested with the FIT signature verification vboot tests on Fedora 42 and Debian 13. All 30 tests pass with both the legacy Engine library installed and with the Provider API.

[snip]

Quoted 1 line

Sure, I can update the comment for v4.

Quoted 9 lines

Since we're talking about v4, can you please make sure that for v4 it:
- Passes CI https://docs.u-boot.org/en/latest/develop/ci_testing.html as that will cover some non-Linux host builds.
- See if you can get access to a FreeBSD or OpenBSD host and make sure the tools build still works there too? I was hoping Mark would have commented / tested-by v3 because I do want to make sure the libressl case still builds. At worst case, I have a freebie Oracle VM that's FreeBSD based, so you can maybe spin one of those up as well?

I wanted to provide some context on my testing efforts. I have successfully tested these patches on Fedora and CentOS Stream 10, where the engine support is already deprecated. These changes are quite important because we are currently carrying them as a downstream patch for some RPM packages.

Regarding testing on OpenBSD and FreeBSD ( it uses openssl 3.0 by default ), I tried, but I ran into some build issues that I couldn't quickly resolve due to my limited experience with those environments. Instead, I decided to test with an alpine+libressl container and can confirm that the build of the tools does not break with these patches applied, which should cover the libressl case you were concerned about.

   # make tools
   # ldd tools/mkimage
   /lib/ld-musl-x86_64.so.1 (0x7f12975f5000)
   libssl.so.60 => /usr/lib/libssl.so.60 (0x7f12973a4000)
   libcrypto.so.57 => /usr/lib/libcrypto.so.57 (0x7f129722a000)
   libc.musl-x86_64.so.1 => /lib/ld-musl-x86_64.so.1 (0x7f12975f5000)
Quoted 8 lines
   # strings /usr/lib/libcrypto.so.57 | grep -i "libressl"
   LibreSSL 4.2.1
   %s/libressl.cnf

I'm happy to provide my tested-by tag if it helps move the patch along. Feel free to include it in v4.

Thanks for doing that, I appreciate it. I'm much more confident the BSD cases will be fine now. I still really want to see v4 put through CI first just to catch any other oddities.

Signature · 1 line
Tom
#6 lore raw
In reply to Enric Balletbo i Serra
Quoted 2 lines

From: Enric Balletbo i Serra <[email protected]>
Date: Tue, 24 Feb 2026 13:08:23 +0100

Hi,

Quoted 54 lines

Hi all,

Thanks Eddie for the effort on doing this.

Quoted 49 lines · Tom Rini
Quoted 34 lines · Eddie Kovsky
Quoted 4 lines · Mattijs Korpershoek

Hi Eddie,

Thank you for the patch.

Hi Mattijs

Thanks for the review.

Quoted 24 lines · Eddie Kovsky
Quoted 23 lines

The Engine API has been deprecated since the release of OpenSSL 3.0. End users have been advised to migrate to the new Provider interface. Several distributions have already removed support for engines, which is preventing U-Boot from being compiled in those environments.

Add support for the Provider API while continuing to support the existing Engine API on distros shipping older releases of OpenSSL.

This is based on similar work contributed by Jan Stancek updating Linux to use the Provider interface.

commit 558bdc45dfb2669e1741384a0c80be9c82fa052c
Author: Jan Stancek <[email protected]>
Date: Fri Sep 20 19:52:48 2024 +0300

sign-file,extract-cert: use pkcs11 provider for OPENSSL MAJOR >= 3

The changes have been tested with the FIT signature verification vboot tests on Fedora 42 and Debian 13. All 30 tests pass with both the legacy Engine library installed and with the Provider API.

[snip]

Quoted 1 line

Sure, I can update the comment for v4.

Since we're talking about v4, can you please make sure that for v4 it:
- Passes CI https://docs.u-boot.org/en/latest/develop/ci_testing.html as that will cover some non-Linux host builds.
- See if you can get access to a FreeBSD or OpenBSD host and make sure the tools build still works there too? I was hoping Mark would have commented / tested-by v3 because I do want to make sure the libressl case still builds. At worst case, I have a freebie Oracle VM that's FreeBSD based, so you can maybe spin one of those up as well?

Sorry, I've been a bit busy the last weeks. But I threw this on top of today's master and built a few of my favourite targets. There seems to no regressions in the build experience.

Quoted 39 lines

I wanted to provide some context on my testing efforts. I have successfully tested these patches on Fedora and CentOS Stream 10, where the engine support is already deprecated. These changes are quite important because we are currently carrying them as a downstream patch for some RPM packages.

Regarding testing on OpenBSD and FreeBSD ( it uses openssl 3.0 by default ), I tried, but I ran into some build issues that I couldn't quickly resolve due to my limited experience with those environments. Instead, I decided to test with an alpine+libressl container and can confirm that the build of the tools does not break with these patches applied, which should cover the libressl case you were concerned about.

   # make tools
   # ldd tools/mkimage
   /lib/ld-musl-x86_64.so.1 (0x7f12975f5000)
   libssl.so.60 => /usr/lib/libssl.so.60 (0x7f12973a4000)
   libcrypto.so.57 => /usr/lib/libcrypto.so.57 (0x7f129722a000)
   libc.musl-x86_64.so.1 => /lib/ld-musl-x86_64.so.1 (0x7f12975f5000)
   # strings /usr/lib/libcrypto.so.57 | grep -i "libressl"
   LibreSSL 4.2.1
   %s/libressl.cnf

I'm happy to provide my tested-by tag if it helps move the patch along. Feel free to include it in v4.

Thanks,

Enric

Quoted 4 lines

Thanks!

--
Tom

#14 lore raw
In reply to Eddie Kovsky

Hi Eddie,

Quoted 35 lines · Eddie Kovsky
Quoted 4 lines · Mattijs Korpershoek

Hi Eddie,

Thank you for the patch.

Hi Mattijs

Thanks for the review.

Quoted 25 lines · Eddie Kovsky
Quoted 23 lines

The Engine API has been deprecated since the release of OpenSSL 3.0. End users have been advised to migrate to the new Provider interface. Several distributions have already removed support for engines, which is preventing U-Boot from being compiled in those environments.

Add support for the Provider API while continuing to support the existing Engine API on distros shipping older releases of OpenSSL.

This is based on similar work contributed by Jan Stancek updating Linux to use the Provider interface.

commit 558bdc45dfb2669e1741384a0c80be9c82fa052c
Author: Jan Stancek <[email protected]>
Date: Fri Sep 20 19:52:48 2024 +0300

sign-file,extract-cert: use pkcs11 provider for OPENSSL MAJOR >= 3

The changes have been tested with the FIT signature verification vboot tests on Fedora 42 and Debian 13. All 30 tests pass with both the legacy Engine library installed and with the Provider API.

Quoted 7 lines
Quoted 3 lines

As a follow-up, can we look into reverting/removing commit 3a8b919932fd ("tools: avoid OpenSSL deprecation warnings") ?

Yes, we could certainly revert this once we've determined it's no longer needed for CI. But it's outside the scope of what I'm proposing for this patch.

Yes agreed, this can be done later on and is out of scope for this patch.

Quoted 139 lines
Quoted 112 lines

This looks much better than v2 in my opinion.

Some additional comments below:

lib/rsa/rsa-sign.c static int rsa_engine_get_pub_key(const char *keydir, const char *name,

Quoted 103 lines

---
Changes in v3:
- Removed Kconfig option
- Changed macro symbol from CONFIG_OPENSSL_NO_DEPRECATED to USE_PKCS11_PROVIDER or USE_PKCS11_ENGINE
v2: https://lore.kernel.org/u-boot/[email protected]/

Changes in v2:
- Remove default for new Kconfig option
- Use #ifdef instead of IS_ENABLED macro
- Remove comment after #endif
- Remove unrelated checkpatch cleanup of 'sslErr' variable name
v1: https://lore.kernel.org/u-boot/[email protected]/

---
 lib/aes/aes-encrypt.c |  4 +-
 lib/rsa/rsa-sign.c    | 95 ++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 97 insertions(+), 2 deletions(-)
lib/aes/aes-encrypt.c +3 -1
index 90e1407b4f09..4fc4ce232478 100644
@@ -16,7 +16,9 @@
 #include <openssl/err.h>
 #include <openssl/ssl.h>
 #include <openssl/evp.h>
-#include <openssl/engine.h>
+#if !defined(OPENSSL_NO_ENGINE) && !defined(OPENSSL_NO_DEPRECATED_3_0)
+# include <openssl/engine.h>
+#endif
 #include <uboot_aes.h>
 
 #if OPENSSL_VERSION_NUMBER >= 0x10000000L
lib/rsa/rsa-sign.c +43 -1
index 0e38c9e802fd..31269db65950 100644
@@ -19,7 +19,47 @@
 #include <openssl/err.h>
 #include <openssl/ssl.h>
 #include <openssl/evp.h>
-#include <openssl/engine.h>
+#if OPENSSL_VERSION_MAJOR >= 3
+# define USE_PKCS11_PROVIDER
+# include <err.h>
+# include <openssl/provider.h>
+# include <openssl/store.h>
+#else
+# if !defined(OPENSSL_NO_ENGINE) && !defined(OPENSSL_NO_DEPRECATED_3_0)
+#  define USE_PKCS11_ENGINE
+#  include <openssl/engine.h>
+# endif
+#endif
+
+#ifdef USE_PKCS11_PROVIDER
+#define ERR(cond, fmt, ...)				\
+	do {						\
+		bool __cond = (cond);			\
+		drain_openssl_errors(__LINE__, 0);	\
+		if (__cond) {				\
+			errx(1, fmt, ## __VA_ARGS__);	\
+		}					\
+	} while (0)
+
+static void drain_openssl_errors(int l, int silent)
+{
+	const char *file;
+	char buf[120];
+	int e, line;
+
+	if (ERR_peek_error() == 0)
+		return;
+	if (!silent)
+		fprintf(stderr, "At main.c:%d:\n", l);
+
+	while ((e = ERR_peek_error_line(&file, &line))) {
+		ERR_error_string(e, buf);
+		if (!silent)
+			fprintf(stderr, "- SSL %s: %s:%d\n", buf, file, line);
+		ERR_get_error();
+	}
+}
+#endif
 
 static int rsa_err(const char *msg)
 {
@@ -98,6 +138,7 @@ err_cert:
  * @evpp	Returns EVP_PKEY object, or NULL on failure
  * Return: 0 if ok, -ve on error (in which case *evpp will be set to NULL)
  */
+#ifdef USE_PKCS11_ENGINE
 static int rsa_engine_get_pub_key(const char *keydir, const char *name,
 				  ENGINE *engine, EVP_PKEY **evpp)
 {
@@ -157,6 +198,7 @@ static int rsa_engine_get_pub_key(const char *keydir, const char *name,
 
 	return 0;
 }
+#endif
 
 /**
  * rsa_get_pub_key() - read a public key
@@ -170,8 +212,10 @@ static int rsa_engine_get_pub_key(const char *keydir, const char *name,

With this change, the ENGINE pointer might be NULL (or undefined). Can we please update the documentation comment to reflect this?

Quoted 3 lines

For example, we could reword as:
* @engine Engine to use or NULL when using pcks11 provider

Sure, I can update the comment for v4.

Quoted 13 lines

lib/rsa/rsa-sign.c static int rsa_engine_get_pub_key(const char *keydir, const char *name, · line 220

Quoted 9 lines
lib/rsa/rsa-sign.c +2 -0
 static int rsa_get_pub_key(const char *keydir, const char *name,
 			   ENGINE *engine, EVP_PKEY **evpp)
 {
+#ifdef USE_PKCS11_ENGINE
 	if (engine)
 		return rsa_engine_get_pub_key(keydir, name, engine, evpp);
+#endif
 	return rsa_pem_get_pub_key(keydir, name, evpp);
 }

Actually, looking even closer at this function, it's seems to be called only once.

Quoted 8 lines

Why can't we drop this function alltogether and call rsa_engine_get_pub_key() / rsa_pem_get_pub_key() directly in rsa_add_verify_data() ?

Reason I'm asking: in rsa_add_verify_data(), ENGINE *e is not used when we use PROVIDER. It seems weird (and error prone) to pass a NULL pointer to a function that does not need that argument

Quoted 8 lines

Yes, we could drop rsa_get_pub_key(). It is set up as a helper function and only called once from rsa_add_verify_data().

But I am hesitant to make any changes to the RSA API in this file. I want to limit the scope of this patch so that the existing code is unchanged for users of the Engine API. And I think removing this function would require adding more #ifdefs around the error handling in rsa_add_verify_data().

I'm fine as well if you keep it this way.

Quoted 97 lines
Quoted 54 lines
Quoted 41 lines
lib/rsa/rsa-sign.c +31 -0
@@ -207,6 +251,37 @@ static int rsa_pem_get_priv_key(const char *keydir, const char *name,
 		return -ENOENT;
 	}
 
+#ifdef USE_PKCS11_PROVIDER
+	EVP_PKEY *private_key = NULL;
+	OSSL_STORE_CTX *store;
+
+	if (!OSSL_PROVIDER_try_load(NULL, "pkcs11", true))
+		ERR(1, "OSSL_PROVIDER_try_load(pkcs11)");
+	if (!OSSL_PROVIDER_try_load(NULL, "default", true))
+		ERR(1, "OSSL_PROVIDER_try_load(default)");
+
+	store = OSSL_STORE_open(path, NULL, NULL, NULL, NULL);
+	ERR(!store, "OSSL_STORE_open");
+
+	while (!OSSL_STORE_eof(store)) {
+		OSSL_STORE_INFO *info = OSSL_STORE_load(store);
+
+		if (!info) {
+			drain_openssl_errors(__LINE__, 0);
+			continue;
+		}
+		if (OSSL_STORE_INFO_get_type(info) == OSSL_STORE_INFO_PKEY) {
+			private_key = OSSL_STORE_INFO_get1_PKEY(info);
+			ERR(!private_key, "OSSL_STORE_INFO_get1_PKEY");
+		}
+		OSSL_STORE_INFO_free(info);
+		if (private_key)
+			break;
+	}
+	OSSL_STORE_close(store);
+
+	*evpp = private_key;
+#else
 	if (!PEM_read_PrivateKey(f, evpp, NULL, path)) {
 		rsa_err("Failure reading private key");
 		fclose(f);

lib/rsa/rsa-sign.c static int rsa_pem_get_priv_key(const char *keydir, const char *name, · line 293

Quoted 5 lines
lib/rsa/rsa-sign.c +1 -0
@@ -214,6 +289,7 @@ static int rsa_pem_get_priv_key(const char *keydir, const char *name,
 	}
 	fclose(f);
 
+#endif
 	return 0;

This block should be

lib/rsa/rsa-sign.c +1 -0
 	fclose(f);
+#endif
 
 	return 0;
Quoted 3 lines

(not having a blank line between the fclose and the #endif)

Quoted 1 line
lib/rsa/rsa-sign.c +0 -0
 }

I'll clean that up in v4.

Quoted 31 lines
Quoted 18 lines
lib/rsa/rsa-sign.c +2 -0
@@ -226,6 +302,7 @@ static int rsa_pem_get_priv_key(const char *keydir, const char *name,
  * @evpp	Returns EVP_PKEY object, or NULL on failure
  * Return: 0 if ok, -ve on error (in which case *evpp will be set to NULL)
  */
+#ifdef USE_PKCS11_ENGINE
 static int rsa_engine_get_priv_key(const char *keydir, const char *name,
 				   const char *keyfile,
 				   ENGINE *engine, EVP_PKEY **evpp)
@@ -293,6 +370,7 @@ static int rsa_engine_get_priv_key(const char *keydir, const char *name,
 
 	return 0;
 }
+#endif
 
 /**
  * rsa_get_priv_key() - read a private key

lib/rsa/rsa-sign.c static int rsa_engine_get_priv_key(const char *keydir, const char *name, · line 392

Quoted 9 lines
lib/rsa/rsa-sign.c +2 -0
@@ -306,9 +384,11 @@ static int rsa_engine_get_priv_key(const char *keydir, const char *name,
 static int rsa_get_priv_key(const char *keydir, const char *name,
 			    const char *keyfile, ENGINE *engine, EVP_PKEY **evpp)
 {
+#ifdef USE_PKCS11_ENGINE
 	if (engine)
 		return rsa_engine_get_priv_key(keydir, name, keyfile, engine,
 					       evpp);
+#endif
 	return rsa_pem_get_priv_key(keydir, name, keyfile, evpp);

Same remark as for rsa_engine_get_pub_key. Can't we drop this static function? It's only called once.

Quoted 6 lines

Maybe do a cleanup patch first, that gets rid of the static functions and then do the provider support in a second patch of the same series?

I think it will reduce the amount of #ifdefs, which seems a good argument.

Quoted 6 lines

Again, I am trying to limit the scope of this proposal to preserve the existing code. If we remove the helper function rsa_get_priv_key() then the #ifdef guards also have to move inside the caller rsa_sign(). And since we would no longer be able to check the return value of rsa_get_priv_key() additional guards would be needed to recreate the return value logic that's already in the helper function.

No worries, I'm fine if you keep it this way for v4.

Quoted 3 lines

Eddie

#8 lore raw
In reply to Eddie Kovsky
Quoted 43 lines · Eddie Kovsky
Quoted 31 lines · Tom Rini
Quoted 29 lines · Eddie Kovsky
Quoted 4 lines · Mattijs Korpershoek

Hi Eddie,

Thank you for the patch.

Hi Mattijs

Thanks for the review.

Quoted 19 lines · Eddie Kovsky
Quoted 18 lines

The Engine API has been deprecated since the release of OpenSSL 3.0. End users have been advised to migrate to the new Provider interface. Several distributions have already removed support for engines, which is preventing U-Boot from being compiled in those environments.

Add support for the Provider API while continuing to support the existing Engine API on distros shipping older releases of OpenSSL.

This is based on similar work contributed by Jan Stancek updating Linux to use the Provider interface.

commit 558bdc45dfb2669e1741384a0c80be9c82fa052c
Author: Jan Stancek <[email protected]>
Date: Fri Sep 20 19:52:48 2024 +0300

sign-file,extract-cert: use pkcs11 provider for OPENSSL MAJOR >= 3

Quoted 7 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

The changes have been tested with the FIT signature verification vboot tests on Fedora 42 and Debian 13. All 30 tests pass with both the legacy Engine library installed and with the Provider API.

[snip]

Quoted 1 line

Sure, I can update the comment for v4.

Hi Tom

Quoted 1 line
Quoted 7 lines
Quoted 3 lines

Since we're talking about v4, can you please make sure that for v4 it:
- Passes CI https://docs.u-boot.org/en/latest/develop/ci_testing.html as that will cover some non-Linux host builds.

I don't have resources available to set up a Gitlab runner. Based on the documentation you provided it seems like this wouldn't be effective for me as a non-custodian.

Yes, correct, today using Azure is the easy option.

Quoted 4 lines

I did use GitHub to trigger an Azure pipeline. There was one failure and several errors in the binman Command Line test.

    https://github.com/u-boot/u-boot/pull/875/checks?check_run_id=65015204887

And the full log is:
https://dev.azure.com/u-boot/u-boot/_build/results?buildId=12893&view=logs&j=c59aff74-743b-5f08-f408-4a608a489153&t=f2ea3536-b291-5a39-ad92-0220c9b8101a

and so yes, it's from your changes.

Quoted 3 lines

These are PKCS11 errors, so of course I thought my patch was to blame. But I'm seeing the same errors on Debian 13 running 'binman test' manually on the master branch.

Some of the tests are indeed more frustrating than others to run either outside of CI, or outside of the containers, or both. I would recommend looking at the portion of .azure-pipelines.yml for that job for the steps to replicate, and if it doesn't work inside of your host (and
https://docs.u-boot.org/en/latest/build/gcc.html is still missing things) it's easiest to just pull and run the CI container.

Quoted 11 lines
Quoted 6 lines

- See if you can get access to a FreeBSD or OpenBSD host and make sure the tools build still works there too? I was hoping Mark would have commented / tested-by v3 because I do want to make sure the libressl case still builds. At worst case, I have a freebie Oracle VM that's FreeBSD based, so you can maybe spin one of those up as well?

I spent some time again setting up OpenBSD and FreeBSD virtual machines, but I was unable to reproduce the build environment for U-Boot. But thanks to Enric and Mark's work it looks like we have the LibreSSL use case covered now.

Yes, thanks.

Signature · 1 line
Tom
#7 lore raw
In reply to Tom Rini
Quoted 31 lines · Tom Rini
Quoted 29 lines · Eddie Kovsky
Quoted 4 lines · Mattijs Korpershoek

Hi Eddie,

Thank you for the patch.

Hi Mattijs

Thanks for the review.

Quoted 19 lines · Eddie Kovsky
Quoted 18 lines

The Engine API has been deprecated since the release of OpenSSL 3.0. End users have been advised to migrate to the new Provider interface. Several distributions have already removed support for engines, which is preventing U-Boot from being compiled in those environments.

Add support for the Provider API while continuing to support the existing Engine API on distros shipping older releases of OpenSSL.

This is based on similar work contributed by Jan Stancek updating Linux to use the Provider interface.

commit 558bdc45dfb2669e1741384a0c80be9c82fa052c
Author: Jan Stancek <[email protected]>
Date: Fri Sep 20 19:52:48 2024 +0300

sign-file,extract-cert: use pkcs11 provider for OPENSSL MAJOR >= 3

Quoted 7 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

The changes have been tested with the FIT signature verification vboot tests on Fedora 42 and Debian 13. All 30 tests pass with both the legacy Engine library installed and with the Provider API.

[snip]

Quoted 1 line

Sure, I can update the comment for v4.

Hi Tom

Quoted 4 lines

Since we're talking about v4, can you please make sure that for v4 it:
- Passes CI https://docs.u-boot.org/en/latest/develop/ci_testing.html as that will cover some non-Linux host builds.

I don't have resources available to set up a Gitlab runner. Based on the documentation you provided it seems like this wouldn't be effective for me as a non-custodian.

I did use GitHub to trigger an Azure pipeline. There was one failure and several errors in the binman Command Line test.

    https://github.com/u-boot/u-boot/pull/875/checks?check_run_id=65015204887

These are PKCS11 errors, so of course I thought my patch was to blame. But I'm seeing the same errors on Debian 13 running 'binman test' manually on the master branch.

Quoted 6 lines

- See if you can get access to a FreeBSD or OpenBSD host and make sure the tools build still works there too? I was hoping Mark would have commented / tested-by v3 because I do want to make sure the libressl case still builds. At worst case, I have a freebie Oracle VM that's FreeBSD based, so you can maybe spin one of those up as well?

I spent some time again setting up OpenBSD and FreeBSD virtual machines, but I was unable to reproduce the build environment for U-Boot. But thanks to Enric and Mark's work it looks like we have the LibreSSL use case covered now.

Eddie

#9 lore raw
In reply to Tom Rini
Quoted 82 lines · Tom Rini
Quoted 43 lines · Eddie Kovsky
Quoted 31 lines · Tom Rini
Quoted 29 lines · Eddie Kovsky
Quoted 4 lines · Mattijs Korpershoek

Hi Eddie,

Thank you for the patch.

Hi Mattijs

Thanks for the review.

Quoted 19 lines · Eddie Kovsky
Quoted 18 lines

The Engine API has been deprecated since the release of OpenSSL 3.0. End users have been advised to migrate to the new Provider interface. Several distributions have already removed support for engines, which is preventing U-Boot from being compiled in those environments.

Add support for the Provider API while continuing to support the existing Engine API on distros shipping older releases of OpenSSL.

This is based on similar work contributed by Jan Stancek updating Linux to use the Provider interface.

commit 558bdc45dfb2669e1741384a0c80be9c82fa052c
Author: Jan Stancek <[email protected]>
Date: Fri Sep 20 19:52:48 2024 +0300

sign-file,extract-cert: use pkcs11 provider for OPENSSL MAJOR >= 3

Quoted 7 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

The changes have been tested with the FIT signature verification vboot tests on Fedora 42 and Debian 13. All 30 tests pass with both the legacy Engine library installed and with the Provider API.

[snip]

Quoted 1 line

Sure, I can update the comment for v4.

Hi Tom

Quoted 1 line
Quoted 7 lines
Quoted 3 lines

Since we're talking about v4, can you please make sure that for v4 it:
- Passes CI https://docs.u-boot.org/en/latest/develop/ci_testing.html as that will cover some non-Linux host builds.

I don't have resources available to set up a Gitlab runner. Based on the documentation you provided it seems like this wouldn't be effective for me as a non-custodian.

Yes, correct, today using Azure is the easy option.

Quoted 4 lines

I did use GitHub to trigger an Azure pipeline. There was one failure and several errors in the binman Command Line test.

    https://github.com/u-boot/u-boot/pull/875/checks?check_run_id=65015204887

And the full log is:
https://dev.azure.com/u-boot/u-boot/_build/results?buildId=12893&view=logs&j=c59aff74-743b-5f08-f408-4a608a489153&t=f2ea3536-b291-5a39-ad92-0220c9b8101a

and so yes, it's from your changes.

Quoted 3 lines

These are PKCS11 errors, so of course I thought my patch was to blame. But I'm seeing the same errors on Debian 13 running 'binman test' manually on the master branch.

Some of the tests are indeed more frustrating than others to run either outside of CI, or outside of the containers, or both. I would recommend looking at the portion of .azure-pipelines.yml for that job for the steps to replicate, and if it doesn't work inside of your host (and
https://docs.u-boot.org/en/latest/build/gcc.html is still missing things) it's easiest to just pull and run the CI container.

Quoted 7 lines
Quoted 6 lines

- See if you can get access to a FreeBSD or OpenBSD host and make sure the tools build still works there too? I was hoping Mark would have commented / tested-by v3 because I do want to make sure the libressl case still builds. At worst case, I have a freebie Oracle VM that's FreeBSD based, so you can maybe spin one of those up as well?

Quoted 9 lines
Quoted 4 lines

I spent some time again setting up OpenBSD and FreeBSD virtual machines, but I was unable to reproduce the build environment for U-Boot. But thanks to Enric and Mark's work it looks like we have the LibreSSL use case covered now.

Yes, thanks.

Signature · 1 line
Tom

I finally got to the bottom of this. Debian/Ubuntu ship OpenSSL backends separately. The CI environment is missing the 'pkcs11-provider' package, which is causing the binman tests to fail.

    $ apt show pkcs11-provider
    Package: pkcs11-provider
    Version: 1.0-3
    Priority: optional
    Section: libs
    Maintainer: Luca Boccassi <[email protected]>
    Installed-Size: 410 kB
    Depends: libc6 (>= 2.34), libssl3t64 (>= 3.0.7~)
    Homepage: https://github.com/latchset/pkcs11-provider
    Download-Size: 125 kB
    APT-Manual-Installed: yes
    APT-Sources: http://ftp.debian.org/debian stable/main amd64 Packages
    Description: OpenSSL 3 provider for PKCS11
    With this provider for OpenSSL you can use the OpenSSL library
    (version 3) and command line tools with any PKCS11 implementation as
    backend for the crypto operations.

With this package installed the SSL errors logged on Azure are no longer reproducible.

The results from the first pipeline expired while I was investigating this. I reran the CI job so you can see the error messages.

    https://dev.azure.com/u-boot/u-boot/_build/results?buildId=13035&view=logs&j=c59aff74-743b-5f08-f408-4a608a489153&t=f2ea3536-b291-5a39-ad92-0220c9b8101a

I have looked into the .azure-pipelines.yml file, but it's not clear to me how to configure the CI to install extra packages.

Eddie

#10 lore raw
Quoted 116 lines · Eddie Kovsky
Quoted 82 lines · Tom Rini
Quoted 43 lines · Eddie Kovsky
Quoted 31 lines · Tom Rini
Quoted 29 lines · Eddie Kovsky
Quoted 4 lines · Mattijs Korpershoek

Hi Eddie,

Thank you for the patch.

Hi Mattijs

Thanks for the review.

Quoted 19 lines · Eddie Kovsky
Quoted 18 lines

The Engine API has been deprecated since the release of OpenSSL 3.0. End users have been advised to migrate to the new Provider interface. Several distributions have already removed support for engines, which is preventing U-Boot from being compiled in those environments.

Add support for the Provider API while continuing to support the existing Engine API on distros shipping older releases of OpenSSL.

This is based on similar work contributed by Jan Stancek updating Linux to use the Provider interface.

commit 558bdc45dfb2669e1741384a0c80be9c82fa052c
Author: Jan Stancek <[email protected]>
Date: Fri Sep 20 19:52:48 2024 +0300

sign-file,extract-cert: use pkcs11 provider for OPENSSL MAJOR >= 3

Quoted 7 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

The changes have been tested with the FIT signature verification vboot tests on Fedora 42 and Debian 13. All 30 tests pass with both the legacy Engine library installed and with the Provider API.

[snip]

Quoted 1 line

Sure, I can update the comment for v4.

Hi Tom

Quoted 1 line
Quoted 7 lines
Quoted 3 lines

Since we're talking about v4, can you please make sure that for v4 it:
- Passes CI https://docs.u-boot.org/en/latest/develop/ci_testing.html as that will cover some non-Linux host builds.

I don't have resources available to set up a Gitlab runner. Based on the documentation you provided it seems like this wouldn't be effective for me as a non-custodian.

Yes, correct, today using Azure is the easy option.

Quoted 4 lines

I did use GitHub to trigger an Azure pipeline. There was one failure and several errors in the binman Command Line test.

    https://github.com/u-boot/u-boot/pull/875/checks?check_run_id=65015204887

And the full log is:
https://dev.azure.com/u-boot/u-boot/_build/results?buildId=12893&view=logs&j=c59aff74-743b-5f08-f408-4a608a489153&t=f2ea3536-b291-5a39-ad92-0220c9b8101a

and so yes, it's from your changes.

Quoted 3 lines

These are PKCS11 errors, so of course I thought my patch was to blame. But I'm seeing the same errors on Debian 13 running 'binman test' manually on the master branch.

Some of the tests are indeed more frustrating than others to run either outside of CI, or outside of the containers, or both. I would recommend looking at the portion of .azure-pipelines.yml for that job for the steps to replicate, and if it doesn't work inside of your host (and
https://docs.u-boot.org/en/latest/build/gcc.html is still missing things) it's easiest to just pull and run the CI container.

Quoted 7 lines
Quoted 6 lines

- See if you can get access to a FreeBSD or OpenBSD host and make sure the tools build still works there too? I was hoping Mark would have commented / tested-by v3 because I do want to make sure the libressl case still builds. At worst case, I have a freebie Oracle VM that's FreeBSD based, so you can maybe spin one of those up as well?

Quoted 9 lines
Quoted 4 lines

I spent some time again setting up OpenBSD and FreeBSD virtual machines, but I was unable to reproduce the build environment for U-Boot. But thanks to Enric and Mark's work it looks like we have the LibreSSL use case covered now.

Yes, thanks.

Signature · 1 line
Tom

I finally got to the bottom of this. Debian/Ubuntu ship OpenSSL backends separately. The CI environment is missing the 'pkcs11-provider' package, which is causing the binman tests to fail.

    $ apt show pkcs11-provider
    Package: pkcs11-provider
    Version: 1.0-3
    Priority: optional
    Section: libs
    Maintainer: Luca Boccassi <[email protected]>
    Installed-Size: 410 kB
    Depends: libc6 (>= 2.34), libssl3t64 (>= 3.0.7~)
    Homepage: https://github.com/latchset/pkcs11-provider
    Download-Size: 125 kB
    APT-Manual-Installed: yes
    APT-Sources: http://ftp.debian.org/debian stable/main amd64 Packages
    Description: OpenSSL 3 provider for PKCS11
    With this provider for OpenSSL you can use the OpenSSL library
    (version 3) and command line tools with any PKCS11 implementation as
    backend for the crypto operations.

With this package installed the SSL errors logged on Azure are no longer reproducible.

Quoted 7 lines

The results from the first pipeline expired while I was investigating this. I reran the CI job so you can see the error messages.

    https://dev.azure.com/u-boot/u-boot/_build/results?buildId=13035&view=logs&j=c59aff74-743b-5f08-f408-4a608a489153&t=f2ea3536-b291-5a39-ad92-0220c9b8101a

I have looked into the .azure-pipelines.yml file, but it's not clear to me how to configure the CI to install extra packages.

Ah, OK. So the package needs to be added to tools/docker/Dockerfile (and doc/build/gcc.rst). For testing changes out, you can then modify .azure-pipelines.yml to point at your image, rather than the default image. Or hack in a "sudo apt-get update && sudo apt-get install ..." to the job.

Signature · 1 line
Tom
#11 lore raw

--->8

Quoted 28 lines
Quoted 28 lines

I finally got to the bottom of this. Debian/Ubuntu ship OpenSSL backends separately. The CI environment is missing the 'pkcs11-provider' package, which is causing the binman tests to fail.

    $ apt show pkcs11-provider
    Package: pkcs11-provider
    Version: 1.0-3
    Priority: optional
    Section: libs
    Maintainer: Luca Boccassi <[email protected]>
    Installed-Size: 410 kB
    Depends: libc6 (>= 2.34), libssl3t64 (>= 3.0.7~)
    Homepage: https://github.com/latchset/pkcs11-provider
    Download-Size: 125 kB
    APT-Manual-Installed: yes
    APT-Sources: http://ftp.debian.org/debian stable/main amd64 Packages
    Description: OpenSSL 3 provider for PKCS11
    With this provider for OpenSSL you can use the OpenSSL library
    (version 3) and command line tools with any PKCS11 implementation as
    backend for the crypto operations.

With this package installed the SSL errors logged on Azure are no longer reproducible.

The results from the first pipeline expired while I was investigating this. I reran the CI job so you can see the error messages.

    https://dev.azure.com/u-boot/u-boot/_build/results?buildId=13035&view=logs&j=c59aff74-743b-5f08-f408-4a608a489153&t=f2ea3536-b291-5a39-ad92-0220c9b8101a
Quoted 11 lines
Quoted 2 lines

I have looked into the .azure-pipelines.yml file, but it's not clear to me how to configure the CI to install extra packages.

Ah, OK. So the package needs to be added to tools/docker/Dockerfile (and doc/build/gcc.rst). For testing changes out, you can then modify .azure-pipelines.yml to point at your image, rather than the default image. Or hack in a "sudo apt-get update && sudo apt-get install ..." to the job.

Signature · 1 line
Tom

Hi Tom

Updating the dockerfile and documentation was easy enough, but I was still seeing the Azure pipeline fail with the same errors. It seems to be ignoring the updated dockerfile.

After digging through the pipeline logs I noticed that Azure is using the Windows Subsystem for Linux with Arch Linux to set up the test environment. The package name 'pkcs11-provider' is even the same on Arch, so I added that to .azure-pipelines.yml.

    https://archlinux.org/packages/extra/x86_64/pkcs11-provider/

And the Azure pipeline now fails because it reports the package doesn't exist.

    https://dev.azure.com/u-boot/u-boot/_build/results?buildId=13066&view=logs&j=8222cf02-b5ce-5040-5def-6173bf341f71&t=5f6e674b-07e4-5ce5-77ac-ecaae7331dd8

I am not an expert in these CI systems, so I'm not sure what else can be done to change the test environment.

Eddie

#12 lore raw
Quoted 54 lines · Eddie Kovsky

--->8

Quoted 28 lines
Quoted 28 lines

I finally got to the bottom of this. Debian/Ubuntu ship OpenSSL backends separately. The CI environment is missing the 'pkcs11-provider' package, which is causing the binman tests to fail.

    $ apt show pkcs11-provider
    Package: pkcs11-provider
    Version: 1.0-3
    Priority: optional
    Section: libs
    Maintainer: Luca Boccassi <[email protected]>
    Installed-Size: 410 kB
    Depends: libc6 (>= 2.34), libssl3t64 (>= 3.0.7~)
    Homepage: https://github.com/latchset/pkcs11-provider
    Download-Size: 125 kB
    APT-Manual-Installed: yes
    APT-Sources: http://ftp.debian.org/debian stable/main amd64 Packages
    Description: OpenSSL 3 provider for PKCS11
    With this provider for OpenSSL you can use the OpenSSL library
    (version 3) and command line tools with any PKCS11 implementation as
    backend for the crypto operations.

With this package installed the SSL errors logged on Azure are no longer reproducible.

The results from the first pipeline expired while I was investigating this. I reran the CI job so you can see the error messages.

    https://dev.azure.com/u-boot/u-boot/_build/results?buildId=13035&view=logs&j=c59aff74-743b-5f08-f408-4a608a489153&t=f2ea3536-b291-5a39-ad92-0220c9b8101a
Quoted 11 lines
Quoted 2 lines

I have looked into the .azure-pipelines.yml file, but it's not clear to me how to configure the CI to install extra packages.

Ah, OK. So the package needs to be added to tools/docker/Dockerfile (and doc/build/gcc.rst). For testing changes out, you can then modify .azure-pipelines.yml to point at your image, rather than the default image. Or hack in a "sudo apt-get update && sudo apt-get install ..." to the job.

Signature · 1 line
Tom

Hi Tom

Updating the dockerfile and documentation was easy enough, but I was still seeing the Azure pipeline fail with the same errors. It seems to be ignoring the updated dockerfile.

After digging through the pipeline logs I noticed that Azure is using the Windows Subsystem for Linux with Arch Linux to set up the test environment. The package name 'pkcs11-provider' is even the same on Arch, so I added that to .azure-pipelines.yml.

    https://archlinux.org/packages/extra/x86_64/pkcs11-provider/
Quoted 7 lines

And the Azure pipeline now fails because it reports the package doesn't exist.

    https://dev.azure.com/u-boot/u-boot/_build/results?buildId=13066&view=logs&j=8222cf02-b5ce-5040-5def-6173bf341f71&t=5f6e674b-07e4-5ce5-77ac-ecaae7331dd8

I am not an expert in these CI systems, so I'm not sure what else can be done to change the test environment.

So, I see two problems. One is the failure on Windows hosts. Perhaps
https://www.msys2.org/docs/package-management/ has some hints on how to find out where it's looking for packages and if that's packaged in turn? The other is that the binman test suites are still failing, on Linux.

Signature · 1 line
Tom
#13 lore raw
Quoted 60 lines · Tom Rini
Quoted 59 lines · Eddie Kovsky

--->8

Quoted 28 lines
Quoted 28 lines

I finally got to the bottom of this. Debian/Ubuntu ship OpenSSL backends separately. The CI environment is missing the 'pkcs11-provider' package, which is causing the binman tests to fail.

    $ apt show pkcs11-provider
    Package: pkcs11-provider
    Version: 1.0-3
    Priority: optional
    Section: libs
    Maintainer: Luca Boccassi <[email protected]>
    Installed-Size: 410 kB
    Depends: libc6 (>= 2.34), libssl3t64 (>= 3.0.7~)
    Homepage: https://github.com/latchset/pkcs11-provider
    Download-Size: 125 kB
    APT-Manual-Installed: yes
    APT-Sources: http://ftp.debian.org/debian stable/main amd64 Packages
    Description: OpenSSL 3 provider for PKCS11
    With this provider for OpenSSL you can use the OpenSSL library
    (version 3) and command line tools with any PKCS11 implementation as
    backend for the crypto operations.

With this package installed the SSL errors logged on Azure are no longer reproducible.

The results from the first pipeline expired while I was investigating this. I reran the CI job so you can see the error messages.

    https://dev.azure.com/u-boot/u-boot/_build/results?buildId=13035&view=logs&j=c59aff74-743b-5f08-f408-4a608a489153&t=f2ea3536-b291-5a39-ad92-0220c9b8101a
Quoted 11 lines
Quoted 2 lines

I have looked into the .azure-pipelines.yml file, but it's not clear to me how to configure the CI to install extra packages.

Ah, OK. So the package needs to be added to tools/docker/Dockerfile (and doc/build/gcc.rst). For testing changes out, you can then modify .azure-pipelines.yml to point at your image, rather than the default image. Or hack in a "sudo apt-get update && sudo apt-get install ..." to the job.

Signature · 1 line
Tom

Hi Tom

Updating the dockerfile and documentation was easy enough, but I was still seeing the Azure pipeline fail with the same errors. It seems to be ignoring the updated dockerfile.

After digging through the pipeline logs I noticed that Azure is using the Windows Subsystem for Linux with Arch Linux to set up the test environment. The package name 'pkcs11-provider' is even the same on Arch, so I added that to .azure-pipelines.yml.

    https://archlinux.org/packages/extra/x86_64/pkcs11-provider/

And the Azure pipeline now fails because it reports the package doesn't exist.

    https://dev.azure.com/u-boot/u-boot/_build/results?buildId=13066&view=logs&j=8222cf02-b5ce-5040-5def-6173bf341f71&t=5f6e674b-07e4-5ce5-77ac-ecaae7331dd8
Quoted 10 lines
Quoted 2 lines

I am not an expert in these CI systems, so I'm not sure what else can be done to change the test environment.

So, I see two problems. One is the failure on Windows hosts. Perhaps
https://www.msys2.org/docs/package-management/ has some hints on how to find out where it's looking for packages and if that's packaged in turn? The other is that the binman test suites are still failing, on Linux.

Signature · 1 line
Tom

Okay, I see now that MSYS2 is really a package management tool for Windows that happens to reuse some of the tools from Arch Linux. But it doesn't package pkcs11-provider. The only pkcs11 package available is pkcs11-helper, which is a different upstream and does not resolve the binman failures on Azure.

    https://packages.msys2.org/base/mingw-w64-pkcs11-helper

I will include the Dockerfile update adding pkcs11-provider when I send v4, which should resolve the errors on Linux. But at this point I've done all I can to resolve the issues with CI.

Eddie