* [PATCH 0/5] net: lwip: root certificates
@ 2025-02-27 16:09 Jerome Forissier
2025-02-27 16:09 ` [PATCH 1/5] net: lwip: extend wget to support CA (root) certificates Jerome Forissier
` (7 more replies)
0 siblings, 8 replies; 30+ messages in thread
From: Jerome Forissier @ 2025-02-27 16:09 UTC (permalink / raw)
To: u-boot; +Cc: Ilias Apalodimas, Jerome Forissier
This series adds support for HTTP server authentication using root (CA)
certificates.
As a first step, the wget command is extended to support a sub-command:
cacert <addr> <size>. The memory region shall contain the CA
certificates. With this, it is possible to load the certificates from
storage or get them from the network for example, which is convenient
for testing at least. The Kconfig symbol for this feature is
WGET_CACERT=y.
Then new Kconfig symbols are added to support providing the certificates
at build time, as a DER or PEM encoded X509 collection:
WGET_BUILTIN_CACERT=y and WGET_BUILTIN_CACERT_PATH=<some path>.
Note that PEM support requires MBEDTLS_LIB_X509_PEM=y (for the cacert
command as well as for the builtin way).
Here is a complete example (showing only the relevant output from the
various commands):
make qemu_arm64_lwip_defconfig
wget https://curl.se/ca/cacert.pem
echo CONFIG_WGET_BUILTIN_CACERT=y >>.config
echo CONFIG_WGET_BUILTIN_CACERT_PATH=cacert.pem >>.config
make olddefconfig
make -j$(nproc) CROSS_COMPILE="ccache aarch64-linux-gnu-"
qemu-system-aarch64 -M virt -nographic -cpu max \
-object rng-random,id=rng0,filename=/dev/urandom \
-device virtio-rng-pci,rng=rng0 -bios u-boot.bin
=> dhcp
# HTTPS transfer using the builtin CA certificates
=> wget https://www.google.com/
18724 bytes transferred in 15 ms (1.2 MiB/s)
# Disable certificate validation
=> wget cacert 0 0
# Unsafe HTTPS transfer
=> wget https://www.google.com/
WARNING: no CA certificates, HTTPS connections not authenticated
16570 bytes transferred in 15 ms (1.1 MiB/s)
# Dowload and apply CA certificates from the net
=> wget https://curl.se/ca/cacert.pem
WARNING: no CA certificates, HTTPS connections not authenticated
##
233263 bytes transferred in 61 ms (3.6 MiB/s)
=> wget cacert $fileaddr $filesize
# Now HTTPS is authenticated against the new CA
=> wget https://www.google.com/
18743 bytes transferred in 14 ms (1.3 MiB/s)
# Drop the certificates again...
=> wget cacert 0 0
# Check that transfer is not secure
=> wget https://www.google.com/
WARNING: no CA certificates, HTTPS connections not authenticated
# Restore the builtin CA
=> wget cacert builtin
# No more WARNING
=> wget https://www.google.com/
18738 bytes transferred in 15 ms (1.2 MiB/s)
Jerome Forissier (5):
net: lwip: extend wget to support CA (root) certificates
lwip: tls: enforce checking of server certificates based on CA
availability
lwip: tls: warn when no CA exists amd log certificate validation
errors
net: lwip: add support for built-in root certificates
configs: qemu_arm64_lwip_defconfig: enable WGET_CACERT and
MBEDTLS_LIB_X509_PEM
cmd/Kconfig | 29 ++++++
cmd/net-lwip.c | 19 +++-
configs/qemu_arm64_lwip_defconfig | 2 +
.../src/apps/altcp_tls/altcp_tls_mbedtls.c | 9 +-
.../lwip/apps/altcp_tls_mbedtls_opts.h | 6 --
lib/mbedtls/Makefile | 3 +
lib/mbedtls/mbedtls_def_config.h | 5 ++
net/lwip/Makefile | 6 ++
net/lwip/wget.c | 90 ++++++++++++++++++-
9 files changed, 158 insertions(+), 11 deletions(-)
--
2.43.0
^ permalink raw reply [flat|nested] 30+ messages in thread
* [PATCH 1/5] net: lwip: extend wget to support CA (root) certificates
2025-02-27 16:09 [PATCH 0/5] net: lwip: root certificates Jerome Forissier
@ 2025-02-27 16:09 ` Jerome Forissier
2025-02-28 21:24 ` Ilias Apalodimas
2025-02-27 16:09 ` [PATCH 2/5] lwip: tls: enforce checking of server certificates based on CA availability Jerome Forissier
` (6 subsequent siblings)
7 siblings, 1 reply; 30+ messages in thread
From: Jerome Forissier @ 2025-02-27 16:09 UTC (permalink / raw)
To: u-boot
Cc: Ilias Apalodimas, Jerome Forissier, Tom Rini, Joe Hershberger,
Ramon Fried, Simon Glass, Heinrich Schuchardt,
Mattijs Korpershoek, Ibai Erkiaga, Michal Simek, Raymond Mao,
Philippe Reynes, Adriano Cordova
Add the "cacert" (Certification Authority certificates) subcommand to
wget to pass root certificates to the code handling the HTTPS protocol.
The subcommand is enabled by the WGET_CACERT Kconfig symbol.
Usage example:
=> dhcp
# Download some root certificates (note: not authenticated!)
=> wget https://curl.se/ca/cacert.pem
# Enable certificate verification
=> wget cacert $loadaddr $filesize
# Disable certificate verification
=> wget cacert 0 0
Signed-off-by: Jerome Forissier <jerome.forissier@linaro.org>
---
cmd/Kconfig | 15 +++++++++
cmd/net-lwip.c | 15 +++++++--
lib/mbedtls/Makefile | 3 ++
lib/mbedtls/mbedtls_def_config.h | 5 +++
net/lwip/wget.c | 55 +++++++++++++++++++++++++++++++-
5 files changed, 89 insertions(+), 4 deletions(-)
diff --git a/cmd/Kconfig b/cmd/Kconfig
index 8dd42571abc..a188a2ef24b 100644
--- a/cmd/Kconfig
+++ b/cmd/Kconfig
@@ -2177,6 +2177,21 @@ config WGET_HTTPS
help
Enable TLS over http for wget.
+config WGET_CACERT
+ bool "wget cacert"
+ depends on CMD_WGET
+ depends on WGET_HTTPS
+ help
+ Adds the "cacert" sub-command to wget to provide root certificates
+ to the HTTPS engine.
+
+config MBEDTLS_LIB_X509_PEM
+ depends on WGET_CACERT
+ bool "Support for PEM-encoded X509 certificates"
+ help
+ This option enables MbedTLS to parse PEM-encoded X509 certificates.
+ When disabled, only DER format is accepted.
+
endif # if CMD_NET
config CMD_PXE
diff --git a/cmd/net-lwip.c b/cmd/net-lwip.c
index 0fd446ecb20..0672f48a7a8 100644
--- a/cmd/net-lwip.c
+++ b/cmd/net-lwip.c
@@ -27,9 +27,18 @@ U_BOOT_CMD(dns, 3, 1, do_dns, "lookup the IP of a hostname",
#endif
#if defined(CONFIG_CMD_WGET)
-U_BOOT_CMD(wget, 3, 1, do_wget,
- "boot image via network using HTTP/HTTPS protocol",
+U_BOOT_CMD(wget, 4, 1, do_wget,
+ "boot image via network using HTTP/HTTPS protocol"
+#if defined(CONFIG_WGET_CACERT)
+ "\nwget cacert - configure wget root certificates"
+#endif
+ ,
"[loadAddress] url\n"
- "wget [loadAddress] [host:]path"
+ "wget [loadAddress] [host:]path\n"
+ " - load file"
+#if defined(CONFIG_WGET_CACERT)
+ "\nwget cacert <address> <length>\n"
+ " - provide CA certificates (0 0 to disable verification)"
+#endif
);
#endif
diff --git a/lib/mbedtls/Makefile b/lib/mbedtls/Makefile
index e66c2018d97..8a0a984e149 100644
--- a/lib/mbedtls/Makefile
+++ b/lib/mbedtls/Makefile
@@ -57,6 +57,9 @@ mbedtls_lib_x509-$(CONFIG_$(SPL_)X509_CERTIFICATE_PARSER_MBEDTLS) += \
$(MBEDTLS_LIB_DIR)/x509_crt.o
mbedtls_lib_x509-$(CONFIG_$(SPL_)PKCS7_MESSAGE_PARSER_MBEDTLS) += \
$(MBEDTLS_LIB_DIR)/pkcs7.o
+mbedtls_lib_x509-$(CONFIG_MBEDTLS_LIB_X509_PEM) += \
+ $(MBEDTLS_LIB_DIR)/base64.o \
+ $(MBEDTLS_LIB_DIR)/pem.o
#mbedTLS TLS support
obj-$(CONFIG_MBEDTLS_LIB_TLS) += mbedtls_lib_tls.o
diff --git a/lib/mbedtls/mbedtls_def_config.h b/lib/mbedtls/mbedtls_def_config.h
index fd440c392f9..7b6a7f482f0 100644
--- a/lib/mbedtls/mbedtls_def_config.h
+++ b/lib/mbedtls/mbedtls_def_config.h
@@ -138,6 +138,11 @@
#define MBEDTLS_ECP_DP_BP384R1_ENABLED
#define MBEDTLS_ECP_DP_BP512R1_ENABLED
+/* CA certificates parsing */
+#if CONFIG_IS_ENABLED(MBEDTLS_LIB_X509_PEM)
+#define MBEDTLS_PEM_PARSE_C
+#define MBEDTLS_BASE64_C
+#endif
#endif /* #if defined CONFIG_MBEDTLS_LIB_TLS */
#endif /* #if defined CONFIG_MBEDTLS_LIB */
diff --git a/net/lwip/wget.c b/net/lwip/wget.c
index 14f27d42998..14466598d7c 100644
--- a/net/lwip/wget.c
+++ b/net/lwip/wget.c
@@ -285,6 +285,53 @@ static err_t httpc_headers_done_cb(httpc_state_t *connection, void *arg, struct
return ERR_OK;
}
+#if defined CONFIG_WGET_HTTPS
+static char *cacert;
+size_t cacert_size;
+#endif
+
+#if defined CONFIG_WGET_CACERT
+static int set_cacert(char * const saddr, char * const ssz)
+{
+ mbedtls_x509_crt crt;
+ ulong addr, sz;
+ int ret;
+
+ if (cacert)
+ free(cacert);
+
+ addr = hextoul(saddr, NULL);
+ sz = hextoul(ssz, NULL);
+ sz++; /* For the trailing '\0' in case of a text (PEM) file */
+
+ if (!addr) {
+ cacert = NULL;
+ cacert_size = 0;
+ return CMD_RET_SUCCESS;
+ }
+
+ cacert = malloc(sz);
+ if (!cacert)
+ return CMD_RET_FAILURE;
+ cacert_size = sz;
+
+ memcpy(cacert, (void *)addr, sz - 1);
+ cacert[sz] = '\0';
+
+ mbedtls_x509_crt_init(&crt);
+ ret = mbedtls_x509_crt_parse(&crt, cacert, cacert_size);
+ if (ret) {
+ printf("Could not parse certificates (%d)\n", ret);
+ free(cacert);
+ cacert = NULL;
+ cacert_size = 0;
+ return CMD_RET_FAILURE;
+ }
+
+ return CMD_RET_SUCCESS;
+}
+#endif
+
static int wget_loop(struct udevice *udev, ulong dst_addr, char *uri)
{
#if defined CONFIG_WGET_HTTPS
@@ -316,7 +363,8 @@ static int wget_loop(struct udevice *udev, ulong dst_addr, char *uri)
if (is_https) {
tls_allocator.alloc = &altcp_tls_alloc;
tls_allocator.arg =
- altcp_tls_create_config_client(NULL, 0, ctx.server_name);
+ altcp_tls_create_config_client(cacert, cacert_size,
+ ctx.server_name);
if (!tls_allocator.arg) {
log_err("error: Cannot create a TLS connection\n");
@@ -369,6 +417,11 @@ int do_wget(struct cmd_tbl *cmdtp, int flag, int argc, char * const argv[])
ulong dst_addr;
char nurl[1024];
+#if defined CONFIG_WGET_CACERT
+ if (argc == 4 && !strncmp(argv[1], "cacert", strlen("cacert")))
+ return set_cacert(argv[2], argv[3]);
+#endif
+
if (argc < 2 || argc > 3)
return CMD_RET_USAGE;
--
2.43.0
^ permalink raw reply related [flat|nested] 30+ messages in thread
* [PATCH 2/5] lwip: tls: enforce checking of server certificates based on CA availability
2025-02-27 16:09 [PATCH 0/5] net: lwip: root certificates Jerome Forissier
2025-02-27 16:09 ` [PATCH 1/5] net: lwip: extend wget to support CA (root) certificates Jerome Forissier
@ 2025-02-27 16:09 ` Jerome Forissier
2025-02-28 21:26 ` Ilias Apalodimas
2025-02-27 16:09 ` [PATCH 3/5] lwip: tls: warn when no CA exists amd log certificate validation errors Jerome Forissier
` (5 subsequent siblings)
7 siblings, 1 reply; 30+ messages in thread
From: Jerome Forissier @ 2025-02-27 16:09 UTC (permalink / raw)
To: u-boot
Cc: Ilias Apalodimas, Jerome Forissier, Tom Rini, Javier Tia,
Heinrich Schuchardt
Instead of relying on some build time configuration to determine if
server certificates need to be checked against CA certificates, do it
based on the availability of such certificates. If no CA is configured
then no check can succeed; on the other hand if we have CA certs then
we should not ignore them. It is always possible to remove the CA certs
(via 'wget cacert 0 0') to force an HTTPS download that would fail
certificate validation.
Signed-off-by: Jerome Forissier <jerome.forissier@linaro.org>
---
lib/lwip/lwip/src/apps/altcp_tls/altcp_tls_mbedtls.c | 3 ++-
.../lwip/src/include/lwip/apps/altcp_tls_mbedtls_opts.h | 6 ------
2 files changed, 2 insertions(+), 7 deletions(-)
diff --git a/lib/lwip/lwip/src/apps/altcp_tls/altcp_tls_mbedtls.c b/lib/lwip/lwip/src/apps/altcp_tls/altcp_tls_mbedtls.c
index 46421588fef..fa3d1d74fed 100644
--- a/lib/lwip/lwip/src/apps/altcp_tls/altcp_tls_mbedtls.c
+++ b/lib/lwip/lwip/src/apps/altcp_tls/altcp_tls_mbedtls.c
@@ -786,6 +786,7 @@ altcp_tls_create_config(int is_server, u8_t cert_count, u8_t pkey_count, int hav
int ret;
struct altcp_tls_config *conf;
mbedtls_x509_crt *mem;
+ int authmode = have_ca ? MBEDTLS_SSL_VERIFY_REQUIRED : MBEDTLS_SSL_VERIFY_NONE;
if (TCP_WND < MBEDTLS_SSL_IN_CONTENT_LEN || TCP_WND < MBEDTLS_SSL_OUT_CONTENT_LEN) {
LWIP_DEBUGF(ALTCP_MBEDTLS_DEBUG|LWIP_DBG_LEVEL_SERIOUS,
@@ -840,7 +841,7 @@ altcp_tls_create_config(int is_server, u8_t cert_count, u8_t pkey_count, int hav
altcp_mbedtls_free_config(conf);
return NULL;
}
- mbedtls_ssl_conf_authmode(&conf->conf, ALTCP_MBEDTLS_AUTHMODE);
+ mbedtls_ssl_conf_authmode(&conf->conf, authmode);
mbedtls_ssl_conf_rng(&conf->conf, mbedtls_ctr_drbg_random, &altcp_tls_entropy_rng->ctr_drbg);
#if ALTCP_MBEDTLS_LIB_DEBUG != LWIP_DBG_OFF
diff --git a/lib/lwip/lwip/src/include/lwip/apps/altcp_tls_mbedtls_opts.h b/lib/lwip/lwip/src/include/lwip/apps/altcp_tls_mbedtls_opts.h
index e41301c061c..71aa5993935 100644
--- a/lib/lwip/lwip/src/include/lwip/apps/altcp_tls_mbedtls_opts.h
+++ b/lib/lwip/lwip/src/include/lwip/apps/altcp_tls_mbedtls_opts.h
@@ -100,12 +100,6 @@
#define ALTCP_MBEDTLS_SESSION_TICKET_TIMEOUT_SECONDS (60 * 60 * 24)
#endif
-/** Certificate verification mode: MBEDTLS_SSL_VERIFY_NONE, MBEDTLS_SSL_VERIFY_OPTIONAL (default),
- * MBEDTLS_SSL_VERIFY_REQUIRED (recommended)*/
-#ifndef ALTCP_MBEDTLS_AUTHMODE
-#define ALTCP_MBEDTLS_AUTHMODE MBEDTLS_SSL_VERIFY_OPTIONAL
-#endif
-
#endif /* LWIP_ALTCP */
#endif /* LWIP_HDR_ALTCP_TLS_OPTS_H */
--
2.43.0
^ permalink raw reply related [flat|nested] 30+ messages in thread
* [PATCH 3/5] lwip: tls: warn when no CA exists amd log certificate validation errors
2025-02-27 16:09 [PATCH 0/5] net: lwip: root certificates Jerome Forissier
2025-02-27 16:09 ` [PATCH 1/5] net: lwip: extend wget to support CA (root) certificates Jerome Forissier
2025-02-27 16:09 ` [PATCH 2/5] lwip: tls: enforce checking of server certificates based on CA availability Jerome Forissier
@ 2025-02-27 16:09 ` Jerome Forissier
2025-02-28 21:28 ` Ilias Apalodimas
2025-02-27 16:09 ` [PATCH 4/5] net: lwip: add support for built-in root certificates Jerome Forissier
` (4 subsequent siblings)
7 siblings, 1 reply; 30+ messages in thread
From: Jerome Forissier @ 2025-02-27 16:09 UTC (permalink / raw)
To: u-boot
Cc: Ilias Apalodimas, Jerome Forissier, Tom Rini, Javier Tia,
Heinrich Schuchardt
Using HTTPS without root (CA) certificates is a security issue. Print a
warning in this case. Also, when certificate verification fail, print
an additional message because "HTTP client error 4" is not very
informative (4 is HTTPC_RESULT_ERR_CLOSED).
Signed-off-by: Jerome Forissier <jerome.forissier@linaro.org>
---
lib/lwip/lwip/src/apps/altcp_tls/altcp_tls_mbedtls.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/lib/lwip/lwip/src/apps/altcp_tls/altcp_tls_mbedtls.c b/lib/lwip/lwip/src/apps/altcp_tls/altcp_tls_mbedtls.c
index fa3d1d74fed..ef51a5ac168 100644
--- a/lib/lwip/lwip/src/apps/altcp_tls/altcp_tls_mbedtls.c
+++ b/lib/lwip/lwip/src/apps/altcp_tls/altcp_tls_mbedtls.c
@@ -298,6 +298,9 @@ altcp_mbedtls_lower_recv_process(struct altcp_pcb *conn, altcp_mbedtls_state_t *
if (ret != 0) {
LWIP_DEBUGF(ALTCP_MBEDTLS_DEBUG, ("mbedtls_ssl_handshake failed: %d\n", ret));
/* handshake failed, connection has to be closed */
+ if (ret == MBEDTLS_ERR_X509_CERT_VERIFY_FAILED) {
+ printf("Certificate verification failed\n");
+ }
if (conn->err) {
conn->err(conn->arg, ERR_CLSD);
}
@@ -841,6 +844,9 @@ altcp_tls_create_config(int is_server, u8_t cert_count, u8_t pkey_count, int hav
altcp_mbedtls_free_config(conf);
return NULL;
}
+ if (authmode == MBEDTLS_SSL_VERIFY_NONE) {
+ printf("WARNING: no CA certificates, HTTPS connections not authenticated\n");
+ }
mbedtls_ssl_conf_authmode(&conf->conf, authmode);
mbedtls_ssl_conf_rng(&conf->conf, mbedtls_ctr_drbg_random, &altcp_tls_entropy_rng->ctr_drbg);
--
2.43.0
^ permalink raw reply related [flat|nested] 30+ messages in thread
* [PATCH 4/5] net: lwip: add support for built-in root certificates
2025-02-27 16:09 [PATCH 0/5] net: lwip: root certificates Jerome Forissier
` (2 preceding siblings ...)
2025-02-27 16:09 ` [PATCH 3/5] lwip: tls: warn when no CA exists amd log certificate validation errors Jerome Forissier
@ 2025-02-27 16:09 ` Jerome Forissier
2025-02-27 16:38 ` Jerome Forissier
2025-02-27 16:09 ` [PATCH 5/5] configs: qemu_arm64_lwip_defconfig: enable WGET_CACERT and MBEDTLS_LIB_X509_PEM Jerome Forissier
` (3 subsequent siblings)
7 siblings, 1 reply; 30+ messages in thread
From: Jerome Forissier @ 2025-02-27 16:09 UTC (permalink / raw)
To: u-boot
Cc: Ilias Apalodimas, Jerome Forissier, Tom Rini, Joe Hershberger,
Ramon Fried, Simon Glass, Heinrich Schuchardt,
Mattijs Korpershoek, Ibai Erkiaga, Michal Simek, Adriano Cordova
Introduce Kconfig symbols WGET_BUILTIN_CACERT and
WGET_BUILTIN_CACERT_PATH to provide root certificates at build time. The
file may be a DER-encoded (.crt) or PEM-encoded (.pem) X509 collection
of one or more certificates. PEM encoding needs MBEDTLS_LIB_X509_PEM.
Usage example:
wget https://curl.se/ca/cacert.pem
make qemu_arm64_lwip_defconfig
echo CONFIG_WGET_BUILTIN_CACERT=y >>.config
echo CONFIG_WGET_BUILTIN_CACERT_PATH=cacert.pem >>.config
echo CONFIG_MBEDTLS_LIB_X509_PEM=y >>.config
make olddefconfig
make -j$(nproc) CROSS_COMPILE="ccache aarch64-linux-gnu-"
qemu-system-aarch64 -M virt -nographic -cpu max \
-object rng-random,id=rng0,filename=/dev/urandom \
-device virtio-rng-pci,rng=rng0 -bios u-boot.bin
=> dhcp
# HTTPS transfer using the builtin CA certificates
=> wget https://www.google.com/
18724 bytes transferred in 15 ms (1.2 MiB/s)
Bytes transferred = 18724 (4924 hex)
Signed-off-by: Jerome Forissier <jerome.forissier@linaro.org>
---
cmd/Kconfig | 16 +++++++++++++-
cmd/net-lwip.c | 4 ++++
net/lwip/Makefile | 6 ++++++
net/lwip/wget.c | 53 +++++++++++++++++++++++++++++++++++++++--------
4 files changed, 69 insertions(+), 10 deletions(-)
diff --git a/cmd/Kconfig b/cmd/Kconfig
index a188a2ef24b..cb3cc859616 100644
--- a/cmd/Kconfig
+++ b/cmd/Kconfig
@@ -2186,12 +2186,26 @@ config WGET_CACERT
to the HTTPS engine.
config MBEDTLS_LIB_X509_PEM
- depends on WGET_CACERT
+ depends on WGET_HTTPS
bool "Support for PEM-encoded X509 certificates"
help
This option enables MbedTLS to parse PEM-encoded X509 certificates.
When disabled, only DER format is accepted.
+config WGET_BUILTIN_CACERT
+ bool "Built-in CA certificates"
+ depends on WGET_HTTPS
+
+config WGET_BUILTIN_CACERT_PATH
+ string "Path to root certificates"
+ depends on WGET_BUILTIN_CACERT
+ default "cacert.crt"
+ help
+ Set this to the path to a DER- or PEM-encoded X509 file containing
+ Certification Authority certificates, a.k.a. root certificates, for
+ the purpose of authenticating HTTPS connections. Do not forget to
+ enable MBEDTLS_LIB_X509_PEM if the file is PEM.
+
endif # if CMD_NET
config CMD_PXE
diff --git a/cmd/net-lwip.c b/cmd/net-lwip.c
index 0672f48a7a8..a848d0b1dcf 100644
--- a/cmd/net-lwip.c
+++ b/cmd/net-lwip.c
@@ -39,6 +39,10 @@ U_BOOT_CMD(wget, 4, 1, do_wget,
#if defined(CONFIG_WGET_CACERT)
"\nwget cacert <address> <length>\n"
" - provide CA certificates (0 0 to disable verification)"
+#if defined(CONFIG_WGET_BUILTIN_CACERT)
+ "\nwget cacert builtin\n"
+ " - use the builtin CA certificates"
+#endif
#endif
);
#endif
diff --git a/net/lwip/Makefile b/net/lwip/Makefile
index 79dd6b3fb50..950c5316bb9 100644
--- a/net/lwip/Makefile
+++ b/net/lwip/Makefile
@@ -6,3 +6,9 @@ obj-$(CONFIG_CMD_DNS) += dns.o
obj-$(CONFIG_CMD_PING) += ping.o
obj-$(CONFIG_CMD_TFTPBOOT) += tftp.o
obj-$(CONFIG_WGET) += wget.o
+
+ifeq (y,$(CONFIG_WGET_BUILTIN_CACERT))
+$(obj)/builtin_cacert.c: $(CONFIG_WGET_BUILTIN_CACERT_PATH:"%"=%) FORCE
+ $(call if_changed,bin2c,builtin_cacert)
+obj-y += builtin_cacert.o
+endif
diff --git a/net/lwip/wget.c b/net/lwip/wget.c
index 14466598d7c..f24aa9c2380 100644
--- a/net/lwip/wget.c
+++ b/net/lwip/wget.c
@@ -288,31 +288,34 @@ static err_t httpc_headers_done_cb(httpc_state_t *connection, void *arg, struct
#if defined CONFIG_WGET_HTTPS
static char *cacert;
size_t cacert_size;
+
+#if defined CONFIG_WGET_BUILTIN_CACERT
+extern char builtin_cacert[];
+extern const size_t builtin_cacert_size;
+static bool cacert_initialized;
+#endif
#endif
-#if defined CONFIG_WGET_CACERT
-static int set_cacert(char * const saddr, char * const ssz)
+#if defined CONFIG_WGET_CACERT || defined CONFIG_WGET_BUILTIN_CACERT
+static int _set_cacert(void *addr, size_t sz)
{
mbedtls_x509_crt crt;
- ulong addr, sz;
+ void *p;
int ret;
if (cacert)
free(cacert);
- addr = hextoul(saddr, NULL);
- sz = hextoul(ssz, NULL);
- sz++; /* For the trailing '\0' in case of a text (PEM) file */
-
if (!addr) {
cacert = NULL;
cacert_size = 0;
return CMD_RET_SUCCESS;
}
- cacert = malloc(sz);
- if (!cacert)
+ p = malloc(sz);
+ if (!p)
return CMD_RET_FAILURE;
+ cacert = p;
cacert_size = sz;
memcpy(cacert, (void *)addr, sz - 1);
@@ -328,10 +331,33 @@ static int set_cacert(char * const saddr, char * const ssz)
return CMD_RET_FAILURE;
}
+#if defined CONFIG_WGET_BUILTIN_CACERT
+ cacert_initialized = true;
+#endif
return CMD_RET_SUCCESS;
}
+
+#if defined CONFIG_WGET_BUILTIN_CACERT
+static int set_cacert_builtin(void)
+{
+ return _set_cacert(builtin_cacert, builtin_cacert_size);
+}
#endif
+#if defined CONFIG_WGET_CACERT
+static int set_cacert(char * const saddr, char * const ssz)
+{
+ ulong addr, sz;
+
+ addr = hextoul(saddr, NULL);
+ sz = hextoul(ssz, NULL);
+ sz++; /* For the trailing '\0' in case of a text (PEM) file */
+
+ return _set_cacert((void *)addr, sz);
+}
+#endif
+#endif /* CONFIG_WGET_CACERT || CONFIG_WGET_BUILTIN_CACERT */
+
static int wget_loop(struct udevice *udev, ulong dst_addr, char *uri)
{
#if defined CONFIG_WGET_HTTPS
@@ -361,6 +387,10 @@ static int wget_loop(struct udevice *udev, ulong dst_addr, char *uri)
memset(&conn, 0, sizeof(conn));
#if defined CONFIG_WGET_HTTPS
if (is_https) {
+#if defined CONFIG_WGET_BUILTIN_CACERT
+ if (!cacert_initialized)
+ set_cacert_builtin();
+#endif
tls_allocator.alloc = &altcp_tls_alloc;
tls_allocator.arg =
altcp_tls_create_config_client(cacert, cacert_size,
@@ -420,6 +450,11 @@ int do_wget(struct cmd_tbl *cmdtp, int flag, int argc, char * const argv[])
#if defined CONFIG_WGET_CACERT
if (argc == 4 && !strncmp(argv[1], "cacert", strlen("cacert")))
return set_cacert(argv[2], argv[3]);
+#if defined CONFIG_WGET_BUILTIN_CACERT
+ if (argc == 3 && !strncmp(argv[1], "cacert", strlen("cacert")) &&
+ !strncmp(argv[2], "builtin", strlen("builtin")))
+ return set_cacert_builtin();
+#endif
#endif
if (argc < 2 || argc > 3)
--
2.43.0
^ permalink raw reply related [flat|nested] 30+ messages in thread
* [PATCH 5/5] configs: qemu_arm64_lwip_defconfig: enable WGET_CACERT and MBEDTLS_LIB_X509_PEM
2025-02-27 16:09 [PATCH 0/5] net: lwip: root certificates Jerome Forissier
` (3 preceding siblings ...)
2025-02-27 16:09 ` [PATCH 4/5] net: lwip: add support for built-in root certificates Jerome Forissier
@ 2025-02-27 16:09 ` Jerome Forissier
2025-02-28 21:28 ` Ilias Apalodimas
2025-02-27 16:27 ` [PATCH 0/5] net: lwip: root certificates Simon Glass
` (2 subsequent siblings)
7 siblings, 1 reply; 30+ messages in thread
From: Jerome Forissier @ 2025-02-27 16:09 UTC (permalink / raw)
To: u-boot
Cc: Ilias Apalodimas, Jerome Forissier, Tom Rini, Peter Robinson,
Simon Glass
Enable the "wget cacert" command as well as support for parsing X509
certificates in PEM format.
Signed-off-by: Jerome Forissier <jerome.forissier@linaro.org>
---
configs/qemu_arm64_lwip_defconfig | 2 ++
1 file changed, 2 insertions(+)
diff --git a/configs/qemu_arm64_lwip_defconfig b/configs/qemu_arm64_lwip_defconfig
index 754c770c33f..f48c132743c 100644
--- a/configs/qemu_arm64_lwip_defconfig
+++ b/configs/qemu_arm64_lwip_defconfig
@@ -8,3 +8,5 @@ CONFIG_CMD_DNS=y
CONFIG_CMD_WGET=y
CONFIG_EFI_HTTP_BOOT=y
CONFIG_WGET_HTTPS=y
+CONFIG_WGET_CACERT=y
+CONFIG_MBEDTLS_LIB_X509_PEM=y
--
2.43.0
^ permalink raw reply related [flat|nested] 30+ messages in thread
* Re: [PATCH 0/5] net: lwip: root certificates
2025-02-27 16:09 [PATCH 0/5] net: lwip: root certificates Jerome Forissier
` (4 preceding siblings ...)
2025-02-27 16:09 ` [PATCH 5/5] configs: qemu_arm64_lwip_defconfig: enable WGET_CACERT and MBEDTLS_LIB_X509_PEM Jerome Forissier
@ 2025-02-27 16:27 ` Simon Glass
2025-02-27 16:43 ` Jerome Forissier
2025-02-27 18:06 ` Tom Rini
2025-07-15 4:45 ` Da Xue
7 siblings, 1 reply; 30+ messages in thread
From: Simon Glass @ 2025-02-27 16:27 UTC (permalink / raw)
To: Jerome Forissier; +Cc: u-boot, Ilias Apalodimas
Hi Jerome,
On Thu, 27 Feb 2025 at 09:09, Jerome Forissier
<jerome.forissier@linaro.org> wrote:
>
> This series adds support for HTTP server authentication using root (CA)
> certificates.
>
> As a first step, the wget command is extended to support a sub-command:
> cacert <addr> <size>. The memory region shall contain the CA
> certificates. With this, it is possible to load the certificates from
> storage or get them from the network for example, which is convenient
> for testing at least. The Kconfig symbol for this feature is
> WGET_CACERT=y.
>
> Then new Kconfig symbols are added to support providing the certificates
> at build time, as a DER or PEM encoded X509 collection:
> WGET_BUILTIN_CACERT=y and WGET_BUILTIN_CACERT_PATH=<some path>.
> Note that PEM support requires MBEDTLS_LIB_X509_PEM=y (for the cacert
> command as well as for the builtin way).
>
> Here is a complete example (showing only the relevant output from the
> various commands):
>
> make qemu_arm64_lwip_defconfig
> wget https://curl.se/ca/cacert.pem
> echo CONFIG_WGET_BUILTIN_CACERT=y >>.config
> echo CONFIG_WGET_BUILTIN_CACERT_PATH=cacert.pem >>.config
> make olddefconfig
> make -j$(nproc) CROSS_COMPILE="ccache aarch64-linux-gnu-"
> qemu-system-aarch64 -M virt -nographic -cpu max \
> -object rng-random,id=rng0,filename=/dev/urandom \
> -device virtio-rng-pci,rng=rng0 -bios u-boot.bin
> => dhcp
> # HTTPS transfer using the builtin CA certificates
> => wget https://www.google.com/
> 18724 bytes transferred in 15 ms (1.2 MiB/s)
> # Disable certificate validation
> => wget cacert 0 0
> # Unsafe HTTPS transfer
> => wget https://www.google.com/
> WARNING: no CA certificates, HTTPS connections not authenticated
> 16570 bytes transferred in 15 ms (1.1 MiB/s)
> # Dowload and apply CA certificates from the net
> => wget https://curl.se/ca/cacert.pem
> WARNING: no CA certificates, HTTPS connections not authenticated
> ##
> 233263 bytes transferred in 61 ms (3.6 MiB/s)
> => wget cacert $fileaddr $filesize
> # Now HTTPS is authenticated against the new CA
> => wget https://www.google.com/
> 18743 bytes transferred in 14 ms (1.3 MiB/s)
> # Drop the certificates again...
> => wget cacert 0 0
> # Check that transfer is not secure
> => wget https://www.google.com/
> WARNING: no CA certificates, HTTPS connections not authenticated
> # Restore the builtin CA
> => wget cacert builtin
> # No more WARNING
> => wget https://www.google.com/
> 18738 bytes transferred in 15 ms (1.2 MiB/s)
>
> Jerome Forissier (5):
> net: lwip: extend wget to support CA (root) certificates
> lwip: tls: enforce checking of server certificates based on CA
> availability
> lwip: tls: warn when no CA exists amd log certificate validation
> errors
> net: lwip: add support for built-in root certificates
> configs: qemu_arm64_lwip_defconfig: enable WGET_CACERT and
> MBEDTLS_LIB_X509_PEM
>
> cmd/Kconfig | 29 ++++++
> cmd/net-lwip.c | 19 +++-
> configs/qemu_arm64_lwip_defconfig | 2 +
> .../src/apps/altcp_tls/altcp_tls_mbedtls.c | 9 +-
> .../lwip/apps/altcp_tls_mbedtls_opts.h | 6 --
> lib/mbedtls/Makefile | 3 +
> lib/mbedtls/mbedtls_def_config.h | 5 ++
> net/lwip/Makefile | 6 ++
> net/lwip/wget.c | 90 ++++++++++++++++++-
> 9 files changed, 158 insertions(+), 11 deletions(-)
Did you manage to add some sandbox tests for lwip?
Regards,
Simon
^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: [PATCH 4/5] net: lwip: add support for built-in root certificates
2025-02-27 16:09 ` [PATCH 4/5] net: lwip: add support for built-in root certificates Jerome Forissier
@ 2025-02-27 16:38 ` Jerome Forissier
2025-03-01 6:59 ` Ilias Apalodimas
0 siblings, 1 reply; 30+ messages in thread
From: Jerome Forissier @ 2025-02-27 16:38 UTC (permalink / raw)
To: u-boot
Cc: Ilias Apalodimas, Tom Rini, Joe Hershberger, Ramon Fried,
Simon Glass, Heinrich Schuchardt, Mattijs Korpershoek,
Ibai Erkiaga, Michal Simek, Adriano Cordova
Sorry for replying to myself, I spotted a small mistake.
On 2/27/25 17:09, Jerome Forissier wrote:
> Introduce Kconfig symbols WGET_BUILTIN_CACERT and
> WGET_BUILTIN_CACERT_PATH to provide root certificates at build time. The
> file may be a DER-encoded (.crt) or PEM-encoded (.pem) X509 collection
> of one or more certificates. PEM encoding needs MBEDTLS_LIB_X509_PEM.
>
> Usage example:
>
> wget https://curl.se/ca/cacert.pem
> make qemu_arm64_lwip_defconfig
> echo CONFIG_WGET_BUILTIN_CACERT=y >>.config
> echo CONFIG_WGET_BUILTIN_CACERT_PATH=cacert.pem >>.config
> echo CONFIG_MBEDTLS_LIB_X509_PEM=y >>.config
> make olddefconfig
> make -j$(nproc) CROSS_COMPILE="ccache aarch64-linux-gnu-"
> qemu-system-aarch64 -M virt -nographic -cpu max \
> -object rng-random,id=rng0,filename=/dev/urandom \
> -device virtio-rng-pci,rng=rng0 -bios u-boot.bin
> => dhcp
> # HTTPS transfer using the builtin CA certificates
> => wget https://www.google.com/
> 18724 bytes transferred in 15 ms (1.2 MiB/s)
> Bytes transferred = 18724 (4924 hex)
>
> Signed-off-by: Jerome Forissier <jerome.forissier@linaro.org>
> ---
> cmd/Kconfig | 16 +++++++++++++-
> cmd/net-lwip.c | 4 ++++
> net/lwip/Makefile | 6 ++++++
> net/lwip/wget.c | 53 +++++++++++++++++++++++++++++++++++++++--------
> 4 files changed, 69 insertions(+), 10 deletions(-)
>
> diff --git a/cmd/Kconfig b/cmd/Kconfig
> index a188a2ef24b..cb3cc859616 100644
> --- a/cmd/Kconfig
> +++ b/cmd/Kconfig
> @@ -2186,12 +2186,26 @@ config WGET_CACERT
> to the HTTPS engine.
>
> config MBEDTLS_LIB_X509_PEM
> - depends on WGET_CACERT
> + depends on WGET_HTTPS
> bool "Support for PEM-encoded X509 certificates"
> help
> This option enables MbedTLS to parse PEM-encoded X509 certificates.
> When disabled, only DER format is accepted.
>
> +config WGET_BUILTIN_CACERT
> + bool "Built-in CA certificates"
> + depends on WGET_HTTPS
> +
> +config WGET_BUILTIN_CACERT_PATH
> + string "Path to root certificates"
> + depends on WGET_BUILTIN_CACERT
> + default "cacert.crt"
> + help
> + Set this to the path to a DER- or PEM-encoded X509 file containing
> + Certification Authority certificates, a.k.a. root certificates, for
> + the purpose of authenticating HTTPS connections. Do not forget to
> + enable MBEDTLS_LIB_X509_PEM if the file is PEM.
> +
> endif # if CMD_NET
>
> config CMD_PXE
> diff --git a/cmd/net-lwip.c b/cmd/net-lwip.c
> index 0672f48a7a8..a848d0b1dcf 100644
> --- a/cmd/net-lwip.c
> +++ b/cmd/net-lwip.c
> @@ -39,6 +39,10 @@ U_BOOT_CMD(wget, 4, 1, do_wget,
> #if defined(CONFIG_WGET_CACERT)
> "\nwget cacert <address> <length>\n"
> " - provide CA certificates (0 0 to disable verification)"
> +#if defined(CONFIG_WGET_BUILTIN_CACERT)
> + "\nwget cacert builtin\n"
> + " - use the builtin CA certificates"
> +#endif
> #endif
> );
> #endif
> diff --git a/net/lwip/Makefile b/net/lwip/Makefile
> index 79dd6b3fb50..950c5316bb9 100644
> --- a/net/lwip/Makefile
> +++ b/net/lwip/Makefile
> @@ -6,3 +6,9 @@ obj-$(CONFIG_CMD_DNS) += dns.o
> obj-$(CONFIG_CMD_PING) += ping.o
> obj-$(CONFIG_CMD_TFTPBOOT) += tftp.o
> obj-$(CONFIG_WGET) += wget.o
> +
> +ifeq (y,$(CONFIG_WGET_BUILTIN_CACERT))
> +$(obj)/builtin_cacert.c: $(CONFIG_WGET_BUILTIN_CACERT_PATH:"%"=%) FORCE
> + $(call if_changed,bin2c,builtin_cacert)
> +obj-y += builtin_cacert.o
> +endif
> diff --git a/net/lwip/wget.c b/net/lwip/wget.c
> index 14466598d7c..f24aa9c2380 100644
> --- a/net/lwip/wget.c
> +++ b/net/lwip/wget.c
> @@ -288,31 +288,34 @@ static err_t httpc_headers_done_cb(httpc_state_t *connection, void *arg, struct
> #if defined CONFIG_WGET_HTTPS
> static char *cacert;
> size_t cacert_size;
> +
> +#if defined CONFIG_WGET_BUILTIN_CACERT
> +extern char builtin_cacert[];
> +extern const size_t builtin_cacert_size;
> +static bool cacert_initialized;
> +#endif
> #endif
>
> -#if defined CONFIG_WGET_CACERT
> -static int set_cacert(char * const saddr, char * const ssz)
> +#if defined CONFIG_WGET_CACERT || defined CONFIG_WGET_BUILTIN_CACERT
> +static int _set_cacert(void *addr, size_t sz)
> {
> mbedtls_x509_crt crt;
> - ulong addr, sz;
> + void *p;
> int ret;
>
> if (cacert)
> free(cacert);
>
> - addr = hextoul(saddr, NULL);
> - sz = hextoul(ssz, NULL);
> - sz++; /* For the trailing '\0' in case of a text (PEM) file */
> -
> if (!addr) {
> cacert = NULL;
> cacert_size = 0;
> return CMD_RET_SUCCESS;
> }
>
> - cacert = malloc(sz);
> - if (!cacert)
HERE...
> + p = malloc(sz);
> + if (!p)
> return CMD_RET_FAILURE;
> + cacert = p;
> cacert_size = sz;
>
> memcpy(cacert, (void *)addr, sz - 1);
> @@ -328,10 +331,33 @@ static int set_cacert(char * const saddr, char * const ssz)
> return CMD_RET_FAILURE;
> }
>
> +#if defined CONFIG_WGET_BUILTIN_CACERT
> + cacert_initialized = true;
> +#endif
> return CMD_RET_SUCCESS;
> }
> +
> +#if defined CONFIG_WGET_BUILTIN_CACERT
> +static int set_cacert_builtin(void)
> +{
> + return _set_cacert(builtin_cacert, builtin_cacert_size);
> +}
> #endif
>
> +#if defined CONFIG_WGET_CACERT
> +static int set_cacert(char * const saddr, char * const ssz)
> +{
> + ulong addr, sz;
> +
> + addr = hextoul(saddr, NULL);
> + sz = hextoul(ssz, NULL);
> + sz++; /* For the trailing '\0' in case of a text (PEM) file */
This line should have been moved to _set_cacert() at the place I marked
"HERE" above.
The reason for this hack is, before even attempting to parse a file as
PEM format (which is text-based), mbedtls_x509_crt_parse() checks that
buf[buflen - 1] == '\0'. When a text file is obtained via wget there is
no null terminator. Same when using bin2c. So adding the '\0' is
necessary.
I decided to always add a null byte because it appears to not cause any
problem with binary (DER) files anyways.
> +
> + return _set_cacert((void *)addr, sz);
> +}
> +#endif
> +#endif /* CONFIG_WGET_CACERT || CONFIG_WGET_BUILTIN_CACERT */
> +
> static int wget_loop(struct udevice *udev, ulong dst_addr, char *uri)
> {
> #if defined CONFIG_WGET_HTTPS
> @@ -361,6 +387,10 @@ static int wget_loop(struct udevice *udev, ulong dst_addr, char *uri)
> memset(&conn, 0, sizeof(conn));
> #if defined CONFIG_WGET_HTTPS
> if (is_https) {
> +#if defined CONFIG_WGET_BUILTIN_CACERT
> + if (!cacert_initialized)
> + set_cacert_builtin();
> +#endif
> tls_allocator.alloc = &altcp_tls_alloc;
> tls_allocator.arg =
> altcp_tls_create_config_client(cacert, cacert_size,
> @@ -420,6 +450,11 @@ int do_wget(struct cmd_tbl *cmdtp, int flag, int argc, char * const argv[])
> #if defined CONFIG_WGET_CACERT
> if (argc == 4 && !strncmp(argv[1], "cacert", strlen("cacert")))
> return set_cacert(argv[2], argv[3]);
> +#if defined CONFIG_WGET_BUILTIN_CACERT
> + if (argc == 3 && !strncmp(argv[1], "cacert", strlen("cacert")) &&
> + !strncmp(argv[2], "builtin", strlen("builtin")))
> + return set_cacert_builtin();
> +#endif
> #endif
>
> if (argc < 2 || argc > 3)
^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: [PATCH 0/5] net: lwip: root certificates
2025-02-27 16:27 ` [PATCH 0/5] net: lwip: root certificates Simon Glass
@ 2025-02-27 16:43 ` Jerome Forissier
2025-03-04 15:46 ` Simon Glass
0 siblings, 1 reply; 30+ messages in thread
From: Jerome Forissier @ 2025-02-27 16:43 UTC (permalink / raw)
To: Simon Glass; +Cc: u-boot, Ilias Apalodimas
On 2/27/25 17:27, Simon Glass wrote:
> Hi Jerome,
>
> On Thu, 27 Feb 2025 at 09:09, Jerome Forissier
> <jerome.forissier@linaro.org> wrote:
>>
>> This series adds support for HTTP server authentication using root (CA)
>> certificates.
>>
>> As a first step, the wget command is extended to support a sub-command:
>> cacert <addr> <size>. The memory region shall contain the CA
>> certificates. With this, it is possible to load the certificates from
>> storage or get them from the network for example, which is convenient
>> for testing at least. The Kconfig symbol for this feature is
>> WGET_CACERT=y.
>>
>> Then new Kconfig symbols are added to support providing the certificates
>> at build time, as a DER or PEM encoded X509 collection:
>> WGET_BUILTIN_CACERT=y and WGET_BUILTIN_CACERT_PATH=<some path>.
>> Note that PEM support requires MBEDTLS_LIB_X509_PEM=y (for the cacert
>> command as well as for the builtin way).
>>
>> Here is a complete example (showing only the relevant output from the
>> various commands):
>>
>> make qemu_arm64_lwip_defconfig
>> wget https://curl.se/ca/cacert.pem
>> echo CONFIG_WGET_BUILTIN_CACERT=y >>.config
>> echo CONFIG_WGET_BUILTIN_CACERT_PATH=cacert.pem >>.config
>> make olddefconfig
>> make -j$(nproc) CROSS_COMPILE="ccache aarch64-linux-gnu-"
>> qemu-system-aarch64 -M virt -nographic -cpu max \
>> -object rng-random,id=rng0,filename=/dev/urandom \
>> -device virtio-rng-pci,rng=rng0 -bios u-boot.bin
>> => dhcp
>> # HTTPS transfer using the builtin CA certificates
>> => wget https://www.google.com/
>> 18724 bytes transferred in 15 ms (1.2 MiB/s)
>> # Disable certificate validation
>> => wget cacert 0 0
>> # Unsafe HTTPS transfer
>> => wget https://www.google.com/
>> WARNING: no CA certificates, HTTPS connections not authenticated
>> 16570 bytes transferred in 15 ms (1.1 MiB/s)
>> # Dowload and apply CA certificates from the net
>> => wget https://curl.se/ca/cacert.pem
>> WARNING: no CA certificates, HTTPS connections not authenticated
>> ##
>> 233263 bytes transferred in 61 ms (3.6 MiB/s)
>> => wget cacert $fileaddr $filesize
>> # Now HTTPS is authenticated against the new CA
>> => wget https://www.google.com/
>> 18743 bytes transferred in 14 ms (1.3 MiB/s)
>> # Drop the certificates again...
>> => wget cacert 0 0
>> # Check that transfer is not secure
>> => wget https://www.google.com/
>> WARNING: no CA certificates, HTTPS connections not authenticated
>> # Restore the builtin CA
>> => wget cacert builtin
>> # No more WARNING
>> => wget https://www.google.com/
>> 18738 bytes transferred in 15 ms (1.2 MiB/s)
>>
>> Jerome Forissier (5):
>> net: lwip: extend wget to support CA (root) certificates
>> lwip: tls: enforce checking of server certificates based on CA
>> availability
>> lwip: tls: warn when no CA exists amd log certificate validation
>> errors
>> net: lwip: add support for built-in root certificates
>> configs: qemu_arm64_lwip_defconfig: enable WGET_CACERT and
>> MBEDTLS_LIB_X509_PEM
>>
>> cmd/Kconfig | 29 ++++++
>> cmd/net-lwip.c | 19 +++-
>> configs/qemu_arm64_lwip_defconfig | 2 +
>> .../src/apps/altcp_tls/altcp_tls_mbedtls.c | 9 +-
>> .../lwip/apps/altcp_tls_mbedtls_opts.h | 6 --
>> lib/mbedtls/Makefile | 3 +
>> lib/mbedtls/mbedtls_def_config.h | 5 ++
>> net/lwip/Makefile | 6 ++
>> net/lwip/wget.c | 90 ++++++++++++++++++-
>> 9 files changed, 158 insertions(+), 11 deletions(-)
>
> Did you manage to add some sandbox tests for lwip?
Unfortunately not. I am testing mostly with QEMU (qemu_arm64_lwip_defconfig)
and sometimes with KV260 and i.MX93.
Regards,
--
Jerome
^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: [PATCH 0/5] net: lwip: root certificates
2025-02-27 16:09 [PATCH 0/5] net: lwip: root certificates Jerome Forissier
` (5 preceding siblings ...)
2025-02-27 16:27 ` [PATCH 0/5] net: lwip: root certificates Simon Glass
@ 2025-02-27 18:06 ` Tom Rini
2025-02-27 18:31 ` Jerome Forissier
2025-07-15 4:45 ` Da Xue
7 siblings, 1 reply; 30+ messages in thread
From: Tom Rini @ 2025-02-27 18:06 UTC (permalink / raw)
To: Jerome Forissier; +Cc: u-boot, Ilias Apalodimas
[-- Attachment #1: Type: text/plain, Size: 2721 bytes --]
On Thu, Feb 27, 2025 at 05:09:00PM +0100, Jerome Forissier wrote:
> This series adds support for HTTP server authentication using root (CA)
> certificates.
>
> As a first step, the wget command is extended to support a sub-command:
> cacert <addr> <size>. The memory region shall contain the CA
> certificates. With this, it is possible to load the certificates from
> storage or get them from the network for example, which is convenient
> for testing at least. The Kconfig symbol for this feature is
> WGET_CACERT=y.
>
> Then new Kconfig symbols are added to support providing the certificates
> at build time, as a DER or PEM encoded X509 collection:
> WGET_BUILTIN_CACERT=y and WGET_BUILTIN_CACERT_PATH=<some path>.
> Note that PEM support requires MBEDTLS_LIB_X509_PEM=y (for the cacert
> command as well as for the builtin way).
>
> Here is a complete example (showing only the relevant output from the
> various commands):
>
> make qemu_arm64_lwip_defconfig
> wget https://curl.se/ca/cacert.pem
> echo CONFIG_WGET_BUILTIN_CACERT=y >>.config
> echo CONFIG_WGET_BUILTIN_CACERT_PATH=cacert.pem >>.config
> make olddefconfig
> make -j$(nproc) CROSS_COMPILE="ccache aarch64-linux-gnu-"
> qemu-system-aarch64 -M virt -nographic -cpu max \
> -object rng-random,id=rng0,filename=/dev/urandom \
> -device virtio-rng-pci,rng=rng0 -bios u-boot.bin
> => dhcp
> # HTTPS transfer using the builtin CA certificates
> => wget https://www.google.com/
> 18724 bytes transferred in 15 ms (1.2 MiB/s)
> # Disable certificate validation
> => wget cacert 0 0
> # Unsafe HTTPS transfer
> => wget https://www.google.com/
> WARNING: no CA certificates, HTTPS connections not authenticated
> 16570 bytes transferred in 15 ms (1.1 MiB/s)
> # Dowload and apply CA certificates from the net
> => wget https://curl.se/ca/cacert.pem
> WARNING: no CA certificates, HTTPS connections not authenticated
> ##
> 233263 bytes transferred in 61 ms (3.6 MiB/s)
> => wget cacert $fileaddr $filesize
> # Now HTTPS is authenticated against the new CA
> => wget https://www.google.com/
> 18743 bytes transferred in 14 ms (1.3 MiB/s)
> # Drop the certificates again...
> => wget cacert 0 0
> # Check that transfer is not secure
> => wget https://www.google.com/
> WARNING: no CA certificates, HTTPS connections not authenticated
> # Restore the builtin CA
> => wget cacert builtin
> # No more WARNING
> => wget https://www.google.com/
> 18738 bytes transferred in 15 ms (1.2 MiB/s)
As part of v2, please update the documentation as well with some example
like the above (perhaps as enable X/Y/Z then at run time ...), thanks!
--
Tom
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 659 bytes --]
^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: [PATCH 0/5] net: lwip: root certificates
2025-02-27 18:06 ` Tom Rini
@ 2025-02-27 18:31 ` Jerome Forissier
2025-02-28 7:40 ` Ilias Apalodimas
0 siblings, 1 reply; 30+ messages in thread
From: Jerome Forissier @ 2025-02-27 18:31 UTC (permalink / raw)
To: Tom Rini; +Cc: u-boot, Ilias Apalodimas
On 2/27/25 19:06, Tom Rini wrote:
> On Thu, Feb 27, 2025 at 05:09:00PM +0100, Jerome Forissier wrote:
>
>> This series adds support for HTTP server authentication using root (CA)
>> certificates.
>>
>> As a first step, the wget command is extended to support a sub-command:
>> cacert <addr> <size>. The memory region shall contain the CA
>> certificates. With this, it is possible to load the certificates from
>> storage or get them from the network for example, which is convenient
>> for testing at least. The Kconfig symbol for this feature is
>> WGET_CACERT=y.
>>
>> Then new Kconfig symbols are added to support providing the certificates
>> at build time, as a DER or PEM encoded X509 collection:
>> WGET_BUILTIN_CACERT=y and WGET_BUILTIN_CACERT_PATH=<some path>.
>> Note that PEM support requires MBEDTLS_LIB_X509_PEM=y (for the cacert
>> command as well as for the builtin way).
>>
>> Here is a complete example (showing only the relevant output from the
>> various commands):
>>
>> make qemu_arm64_lwip_defconfig
>> wget https://curl.se/ca/cacert.pem
>> echo CONFIG_WGET_BUILTIN_CACERT=y >>.config
>> echo CONFIG_WGET_BUILTIN_CACERT_PATH=cacert.pem >>.config
>> make olddefconfig
>> make -j$(nproc) CROSS_COMPILE="ccache aarch64-linux-gnu-"
>> qemu-system-aarch64 -M virt -nographic -cpu max \
>> -object rng-random,id=rng0,filename=/dev/urandom \
>> -device virtio-rng-pci,rng=rng0 -bios u-boot.bin
>> => dhcp
>> # HTTPS transfer using the builtin CA certificates
>> => wget https://www.google.com/
>> 18724 bytes transferred in 15 ms (1.2 MiB/s)
>> # Disable certificate validation
>> => wget cacert 0 0
>> # Unsafe HTTPS transfer
>> => wget https://www.google.com/
>> WARNING: no CA certificates, HTTPS connections not authenticated
>> 16570 bytes transferred in 15 ms (1.1 MiB/s)
>> # Dowload and apply CA certificates from the net
>> => wget https://curl.se/ca/cacert.pem
>> WARNING: no CA certificates, HTTPS connections not authenticated
>> ##
>> 233263 bytes transferred in 61 ms (3.6 MiB/s)
>> => wget cacert $fileaddr $filesize
>> # Now HTTPS is authenticated against the new CA
>> => wget https://www.google.com/
>> 18743 bytes transferred in 14 ms (1.3 MiB/s)
>> # Drop the certificates again...
>> => wget cacert 0 0
>> # Check that transfer is not secure
>> => wget https://www.google.com/
>> WARNING: no CA certificates, HTTPS connections not authenticated
>> # Restore the builtin CA
>> => wget cacert builtin
>> # No more WARNING
>> => wget https://www.google.com/
>> 18738 bytes transferred in 15 ms (1.2 MiB/s)
>
> As part of v2, please update the documentation as well with some example
> like the above (perhaps as enable X/Y/Z then at run time ...), thanks!
Will do.
Thanks,
--
Jerome
^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: [PATCH 0/5] net: lwip: root certificates
2025-02-27 18:31 ` Jerome Forissier
@ 2025-02-28 7:40 ` Ilias Apalodimas
2025-02-28 11:42 ` Jerome Forissier
0 siblings, 1 reply; 30+ messages in thread
From: Ilias Apalodimas @ 2025-02-28 7:40 UTC (permalink / raw)
To: Jerome Forissier; +Cc: Tom Rini, u-boot
Hi Jerome,
On Thu, 27 Feb 2025 at 20:31, Jerome Forissier
<jerome.forissier@linaro.org> wrote:
>
>
>
> On 2/27/25 19:06, Tom Rini wrote:
> > On Thu, Feb 27, 2025 at 05:09:00PM +0100, Jerome Forissier wrote:
> >
> >> This series adds support for HTTP server authentication using root (CA)
> >> certificates.
> >>
> >> As a first step, the wget command is extended to support a sub-command:
> >> cacert <addr> <size>. The memory region shall contain the CA
> >> certificates. With this, it is possible to load the certificates from
> >> storage or get them from the network for example, which is convenient
> >> for testing at least. The Kconfig symbol for this feature is
> >> WGET_CACERT=y.
> >>
> >> Then new Kconfig symbols are added to support providing the certificates
> >> at build time, as a DER or PEM encoded X509 collection:
> >> WGET_BUILTIN_CACERT=y and WGET_BUILTIN_CACERT_PATH=<some path>.
> >> Note that PEM support requires MBEDTLS_LIB_X509_PEM=y (for the cacert
> >> command as well as for the builtin way).
[...]
I don't know if we can do it in this patchset, but in the future, we
could store the sha256 and the CA certificate path in a U-Boot elf
section.
Since we will soon have .rodata section with proper memory
permissions, we could automatically download the cert in mem and make
sure it's valid.
Cheers
/Ilias
^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: [PATCH 0/5] net: lwip: root certificates
2025-02-28 7:40 ` Ilias Apalodimas
@ 2025-02-28 11:42 ` Jerome Forissier
0 siblings, 0 replies; 30+ messages in thread
From: Jerome Forissier @ 2025-02-28 11:42 UTC (permalink / raw)
To: Ilias Apalodimas; +Cc: Tom Rini, u-boot
Hi Ilias,
On 2/28/25 08:40, Ilias Apalodimas wrote:
> Hi Jerome,
>
> On Thu, 27 Feb 2025 at 20:31, Jerome Forissier
> <jerome.forissier@linaro.org> wrote:
>>
>>
>>
>> On 2/27/25 19:06, Tom Rini wrote:
>>> On Thu, Feb 27, 2025 at 05:09:00PM +0100, Jerome Forissier wrote:
>>>
>>>> This series adds support for HTTP server authentication using root (CA)
>>>> certificates.
>>>>
>>>> As a first step, the wget command is extended to support a sub-command:
>>>> cacert <addr> <size>. The memory region shall contain the CA
>>>> certificates. With this, it is possible to load the certificates from
>>>> storage or get them from the network for example, which is convenient
>>>> for testing at least. The Kconfig symbol for this feature is
>>>> WGET_CACERT=y.
>>>>
>>>> Then new Kconfig symbols are added to support providing the certificates
>>>> at build time, as a DER or PEM encoded X509 collection:
>>>> WGET_BUILTIN_CACERT=y and WGET_BUILTIN_CACERT_PATH=<some path>.
>>>> Note that PEM support requires MBEDTLS_LIB_X509_PEM=y (for the cacert
>>>> command as well as for the builtin way).
>
> [...]
>
> I don't know if we can do it in this patchset, but in the future, we
> could store the sha256 and the CA certificate path in a U-Boot elf
> section.
> Since we will soon have .rodata section with proper memory
> permissions, we could automatically download the cert in mem and make
> sure it's valid.
That's a good idea and I think we have (almost) enough to do that
already via scripting:
=> wget https://curl.se/ca/cacert.pem
WARNING: no CA certificates, HTTPS connections not authenticated
##
233263 bytes transferred in 96 ms (2.3 MiB/s)
Bytes transferred = 233263 (38f2f hex)
=> hash sha256 $fileaddr $filesize cacert_sha256
sha256 for 40200000 ... 40238f2e ==> 50a6277ec69113f00c5fd45f09e8b97a4b3e32daa35d3a95ab30137a55386cef
=> if test "$cacert_sha256" = 50a6277ec69113f00c5fd45f09e8b97a4b3e32daa35d3a95ab30137a55386cef; then wget cacert $fileaddr $filesize; fi
=> wget cacert required
The last step is currently missing but trivial to implement. It tells
wget that it must not do HTTPS without CA certificates. So if the hash
doesn't match the cacert will remain unset and wget will error out on
https://. I can add it in v2.
I still think it may be a good idea to be able to embed the
certificates themselves, because for some reason the CA server might
not be always available or we may want to avoid an extra download.
Perhaps gzip support would be nice, too?
Cheers,
--
Jerome
^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: [PATCH 1/5] net: lwip: extend wget to support CA (root) certificates
2025-02-27 16:09 ` [PATCH 1/5] net: lwip: extend wget to support CA (root) certificates Jerome Forissier
@ 2025-02-28 21:24 ` Ilias Apalodimas
2025-03-05 12:09 ` Jerome Forissier
0 siblings, 1 reply; 30+ messages in thread
From: Ilias Apalodimas @ 2025-02-28 21:24 UTC (permalink / raw)
To: Jerome Forissier
Cc: u-boot, Tom Rini, Joe Hershberger, Ramon Fried, Simon Glass,
Heinrich Schuchardt, Mattijs Korpershoek, Ibai Erkiaga,
Michal Simek, Raymond Mao, Philippe Reynes, Adriano Cordova
Hi Jerome
>
> +config WGET_CACERT
> + bool "wget cacert"
> + depends on CMD_WGET
> + depends on WGET_HTTPS
> + help
> + Adds the "cacert" sub-command to wget to provide root certificates
> + to the HTTPS engine.
> +
> +config MBEDTLS_LIB_X509_PEM
> + depends on WGET_CACERT
> + bool "Support for PEM-encoded X509 certificates"
> + help
> + This option enables MbedTLS to parse PEM-encoded X509 certificates.
> + When disabled, only DER format is accepted.
> +
> endif # if CMD_NET
I guess that's needed because most of the RootCAs you can download are in PEM?
[...]
> }
>
> +#if defined CONFIG_WGET_HTTPS
you can do #if IS_ENABLED() here
> +static char *cacert;
> +size_t cacert_size;
> +#endif
> +
> +#if defined CONFIG_WGET_CACERT
> +static int set_cacert(char * const saddr, char * const ssz)
> +{
> + mbedtls_x509_crt crt;
> + ulong addr, sz;
> + int ret;
> +
> + if (cacert)
> + free(cacert);
> +
> + addr = hextoul(saddr, NULL);
> + sz = hextoul(ssz, NULL);
> + sz++; /* For the trailing '\0' in case of a text (PEM) file */
> +
> + if (!addr) {
> + cacert = NULL;
cacert is already allocated. Can't we just free it here if it's
supposed to be removed and reuse the memory otherwise, instead of
doing free/alloc on every command?
> + cacert_size = 0;
> + return CMD_RET_SUCCESS;
> + }
> +
> + cacert = malloc(sz);
> + if (!cacert)
> + return CMD_RET_FAILURE;
> + cacert_size = sz;
> +
> + memcpy(cacert, (void *)addr, sz - 1);
> + cacert[sz] = '\0';
> +
> + mbedtls_x509_crt_init(&crt);
> + ret = mbedtls_x509_crt_parse(&crt, cacert, cacert_size);
> + if (ret) {
> + printf("Could not parse certificates (%d)\n", ret);
> + free(cacert);
> + cacert = NULL;
> + cacert_size = 0;
> + return CMD_RET_FAILURE;
> + }
> +
> + return CMD_RET_SUCCESS;
[...]
Thanks
/Ilias
^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: [PATCH 2/5] lwip: tls: enforce checking of server certificates based on CA availability
2025-02-27 16:09 ` [PATCH 2/5] lwip: tls: enforce checking of server certificates based on CA availability Jerome Forissier
@ 2025-02-28 21:26 ` Ilias Apalodimas
2025-03-05 12:27 ` Jerome Forissier
0 siblings, 1 reply; 30+ messages in thread
From: Ilias Apalodimas @ 2025-02-28 21:26 UTC (permalink / raw)
To: Jerome Forissier
Cc: u-boot, Tom Rini, Javier Tia, Heinrich Schuchardt,
Simon Goldschmidt
Hi Jerome
++CC Simon for lwIP
On Thu, 27 Feb 2025 at 18:09, Jerome Forissier
<jerome.forissier@linaro.org> wrote:
>
> Instead of relying on some build time configuration to determine if
> server certificates need to be checked against CA certificates, do it
> based on the availability of such certificates. If no CA is configured
> then no check can succeed; on the other hand if we have CA certs then
> we should not ignore them. It is always possible to remove the CA certs
> (via 'wget cacert 0 0') to force an HTTPS download that would fail
> certificate validation
This looks correct, but we should at some point send those to lwIP as
well instead of keeping them locally
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
>
> Signed-off-by: Jerome Forissier <jerome.forissier@linaro.org>
> ---
> lib/lwip/lwip/src/apps/altcp_tls/altcp_tls_mbedtls.c | 3 ++-
> .../lwip/src/include/lwip/apps/altcp_tls_mbedtls_opts.h | 6 ------
> 2 files changed, 2 insertions(+), 7 deletions(-)
>
> diff --git a/lib/lwip/lwip/src/apps/altcp_tls/altcp_tls_mbedtls.c b/lib/lwip/lwip/src/apps/altcp_tls/altcp_tls_mbedtls.c
> index 46421588fef..fa3d1d74fed 100644
> --- a/lib/lwip/lwip/src/apps/altcp_tls/altcp_tls_mbedtls.c
> +++ b/lib/lwip/lwip/src/apps/altcp_tls/altcp_tls_mbedtls.c
> @@ -786,6 +786,7 @@ altcp_tls_create_config(int is_server, u8_t cert_count, u8_t pkey_count, int hav
> int ret;
> struct altcp_tls_config *conf;
> mbedtls_x509_crt *mem;
> + int authmode = have_ca ? MBEDTLS_SSL_VERIFY_REQUIRED : MBEDTLS_SSL_VERIFY_NONE;
>
> if (TCP_WND < MBEDTLS_SSL_IN_CONTENT_LEN || TCP_WND < MBEDTLS_SSL_OUT_CONTENT_LEN) {
> LWIP_DEBUGF(ALTCP_MBEDTLS_DEBUG|LWIP_DBG_LEVEL_SERIOUS,
> @@ -840,7 +841,7 @@ altcp_tls_create_config(int is_server, u8_t cert_count, u8_t pkey_count, int hav
> altcp_mbedtls_free_config(conf);
> return NULL;
> }
> - mbedtls_ssl_conf_authmode(&conf->conf, ALTCP_MBEDTLS_AUTHMODE);
> + mbedtls_ssl_conf_authmode(&conf->conf, authmode);
>
> mbedtls_ssl_conf_rng(&conf->conf, mbedtls_ctr_drbg_random, &altcp_tls_entropy_rng->ctr_drbg);
> #if ALTCP_MBEDTLS_LIB_DEBUG != LWIP_DBG_OFF
> diff --git a/lib/lwip/lwip/src/include/lwip/apps/altcp_tls_mbedtls_opts.h b/lib/lwip/lwip/src/include/lwip/apps/altcp_tls_mbedtls_opts.h
> index e41301c061c..71aa5993935 100644
> --- a/lib/lwip/lwip/src/include/lwip/apps/altcp_tls_mbedtls_opts.h
> +++ b/lib/lwip/lwip/src/include/lwip/apps/altcp_tls_mbedtls_opts.h
> @@ -100,12 +100,6 @@
> #define ALTCP_MBEDTLS_SESSION_TICKET_TIMEOUT_SECONDS (60 * 60 * 24)
> #endif
>
> -/** Certificate verification mode: MBEDTLS_SSL_VERIFY_NONE, MBEDTLS_SSL_VERIFY_OPTIONAL (default),
> - * MBEDTLS_SSL_VERIFY_REQUIRED (recommended)*/
> -#ifndef ALTCP_MBEDTLS_AUTHMODE
> -#define ALTCP_MBEDTLS_AUTHMODE MBEDTLS_SSL_VERIFY_OPTIONAL
> -#endif
> -
> #endif /* LWIP_ALTCP */
>
> #endif /* LWIP_HDR_ALTCP_TLS_OPTS_H */
> --
> 2.43.0
>
^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: [PATCH 3/5] lwip: tls: warn when no CA exists amd log certificate validation errors
2025-02-27 16:09 ` [PATCH 3/5] lwip: tls: warn when no CA exists amd log certificate validation errors Jerome Forissier
@ 2025-02-28 21:28 ` Ilias Apalodimas
0 siblings, 0 replies; 30+ messages in thread
From: Ilias Apalodimas @ 2025-02-28 21:28 UTC (permalink / raw)
To: Jerome Forissier, Simon Goldschmidt
Cc: u-boot, Tom Rini, Javier Tia, Heinrich Schuchardt
+CC Simon again
Same comments. The patch is nice we should somehow get it in lwIP
On Thu, 27 Feb 2025 at 18:09, Jerome Forissier
<jerome.forissier@linaro.org> wrote:
>
> Using HTTPS without root (CA) certificates is a security issue. Print a
> warning in this case. Also, when certificate verification fail, print
> an additional message because "HTTP client error 4" is not very
> informative (4 is HTTPC_RESULT_ERR_CLOSED).
>
> Signed-off-by: Jerome Forissier <jerome.forissier@linaro.org>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
> ---
> lib/lwip/lwip/src/apps/altcp_tls/altcp_tls_mbedtls.c | 6 ++++++
> 1 file changed, 6 insertions(+)
>
> diff --git a/lib/lwip/lwip/src/apps/altcp_tls/altcp_tls_mbedtls.c b/lib/lwip/lwip/src/apps/altcp_tls/altcp_tls_mbedtls.c
> index fa3d1d74fed..ef51a5ac168 100644
> --- a/lib/lwip/lwip/src/apps/altcp_tls/altcp_tls_mbedtls.c
> +++ b/lib/lwip/lwip/src/apps/altcp_tls/altcp_tls_mbedtls.c
> @@ -298,6 +298,9 @@ altcp_mbedtls_lower_recv_process(struct altcp_pcb *conn, altcp_mbedtls_state_t *
> if (ret != 0) {
> LWIP_DEBUGF(ALTCP_MBEDTLS_DEBUG, ("mbedtls_ssl_handshake failed: %d\n", ret));
> /* handshake failed, connection has to be closed */
> + if (ret == MBEDTLS_ERR_X509_CERT_VERIFY_FAILED) {
> + printf("Certificate verification failed\n");
> + }
> if (conn->err) {
> conn->err(conn->arg, ERR_CLSD);
> }
> @@ -841,6 +844,9 @@ altcp_tls_create_config(int is_server, u8_t cert_count, u8_t pkey_count, int hav
> altcp_mbedtls_free_config(conf);
> return NULL;
> }
> + if (authmode == MBEDTLS_SSL_VERIFY_NONE) {
> + printf("WARNING: no CA certificates, HTTPS connections not authenticated\n");
> + }
> mbedtls_ssl_conf_authmode(&conf->conf, authmode);
>
> mbedtls_ssl_conf_rng(&conf->conf, mbedtls_ctr_drbg_random, &altcp_tls_entropy_rng->ctr_drbg);
> --
> 2.43.0
>
^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: [PATCH 5/5] configs: qemu_arm64_lwip_defconfig: enable WGET_CACERT and MBEDTLS_LIB_X509_PEM
2025-02-27 16:09 ` [PATCH 5/5] configs: qemu_arm64_lwip_defconfig: enable WGET_CACERT and MBEDTLS_LIB_X509_PEM Jerome Forissier
@ 2025-02-28 21:28 ` Ilias Apalodimas
0 siblings, 0 replies; 30+ messages in thread
From: Ilias Apalodimas @ 2025-02-28 21:28 UTC (permalink / raw)
To: Jerome Forissier; +Cc: u-boot, Tom Rini, Peter Robinson, Simon Glass
On Thu, 27 Feb 2025 at 18:09, Jerome Forissier
<jerome.forissier@linaro.org> wrote:
>
> Enable the "wget cacert" command as well as support for parsing X509
> certificates in PEM format.
>
> Signed-off-by: Jerome Forissier <jerome.forissier@linaro.org>
> ---
> configs/qemu_arm64_lwip_defconfig | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/configs/qemu_arm64_lwip_defconfig b/configs/qemu_arm64_lwip_defconfig
> index 754c770c33f..f48c132743c 100644
> --- a/configs/qemu_arm64_lwip_defconfig
> +++ b/configs/qemu_arm64_lwip_defconfig
> @@ -8,3 +8,5 @@ CONFIG_CMD_DNS=y
> CONFIG_CMD_WGET=y
> CONFIG_EFI_HTTP_BOOT=y
> CONFIG_WGET_HTTPS=y
> +CONFIG_WGET_CACERT=y
> +CONFIG_MBEDTLS_LIB_X509_PEM=y
> --
> 2.43.0
>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: [PATCH 4/5] net: lwip: add support for built-in root certificates
2025-02-27 16:38 ` Jerome Forissier
@ 2025-03-01 6:59 ` Ilias Apalodimas
2025-03-05 12:34 ` Jerome Forissier
0 siblings, 1 reply; 30+ messages in thread
From: Ilias Apalodimas @ 2025-03-01 6:59 UTC (permalink / raw)
To: Jerome Forissier
Cc: u-boot, Tom Rini, Joe Hershberger, Ramon Fried, Simon Glass,
Heinrich Schuchardt, Mattijs Korpershoek, Ibai Erkiaga,
Michal Simek, Adriano Cordova
Hi Jerome,
On Thu, 27 Feb 2025 at 18:38, Jerome Forissier
<jerome.forissier@linaro.org> wrote:
>
> Sorry for replying to myself, I spotted a small mistake.
>
> On 2/27/25 17:09, Jerome Forissier wrote:
> > Introduce Kconfig symbols WGET_BUILTIN_CACERT and
> > WGET_BUILTIN_CACERT_PATH to provide root certificates at build time. The
> > file may be a DER-encoded (.crt) or PEM-encoded (.pem) X509 collection
> > of one or more certificates. PEM encoding needs MBEDTLS_LIB_X509_PEM.
I understand that for downloaded certificates supporting both is
convenient since DER might not be available. But why don't we limit
our built-in options to DER only, which is smaller anyway?
[...]
> > --- a/cmd/net-lwip.c
> > +++ b/cmd/net-lwip.c
> > @@ -39,6 +39,10 @@ U_BOOT_CMD(wget, 4, 1, do_wget,
> > #if defined(CONFIG_WGET_CACERT)
> > "\nwget cacert <address> <length>\n"
> > " - provide CA certificates (0 0 to disable verification)"
> > +#if defined(CONFIG_WGET_BUILTIN_CACERT)
> > + "\nwget cacert builtin\n"
> > + " - use the builtin CA certificates"
> > +#endif
> > #endif
> > );
> > #endif
> > diff --git a/net/lwip/Makefile b/net/lwip/Makefile
> > index 79dd6b3fb50..950c5316bb9 100644
> > --- a/net/lwip/Makefile
> > +++ b/net/lwip/Makefile
> > @@ -6,3 +6,9 @@ obj-$(CONFIG_CMD_DNS) += dns.o
> > obj-$(CONFIG_CMD_PING) += ping.o
> > obj-$(CONFIG_CMD_TFTPBOOT) += tftp.o
> > obj-$(CONFIG_WGET) += wget.o
> > +
> > +ifeq (y,$(CONFIG_WGET_BUILTIN_CACERT))
> > +$(obj)/builtin_cacert.c: $(CONFIG_WGET_BUILTIN_CACERT_PATH:"%"=%) FORCE
> > + $(call if_changed,bin2c,builtin_cacert)
> > +obj-y += builtin_cacert.o
> > +endif
> > diff --git a/net/lwip/wget.c b/net/lwip/wget.c
> > index 14466598d7c..f24aa9c2380 100644
> > --- a/net/lwip/wget.c
> > +++ b/net/lwip/wget.c
> > @@ -288,31 +288,34 @@ static err_t httpc_headers_done_cb(httpc_state_t *connection, void *arg, struct
> > #if defined CONFIG_WGET_HTTPS
> > static char *cacert;
> > size_t cacert_size;
> > +
> > +#if defined CONFIG_WGET_BUILTIN_CACERT
> > +extern char builtin_cacert[];
const as well? IIRC all the bin2 generated variables end up in .rodata
> > +extern const size_t builtin_cacert_size;
> > +static bool cacert_initialized;
> > +#endif
> > #endif
> >
> > -#if defined CONFIG_WGET_CACERT
> > -static int set_cacert(char * const saddr, char * const ssz)
> > +#if defined CONFIG_WGET_CACERT || defined CONFIG_WGET_BUILTIN_CACERT
> > +static int _set_cacert(void *addr, size_t sz)
> > {
> > mbedtls_x509_crt crt;
> > - ulong addr, sz;
> > + void *p;
> > int ret;
> >
> > if (cacert)
> > free(cacert);
> >
> > - addr = hextoul(saddr, NULL);
> > - sz = hextoul(ssz, NULL);
> > - sz++; /* For the trailing '\0' in case of a text (PEM) file */
> > -
> > if (!addr) {
> > cacert = NULL;
> > cacert_size = 0;
> > return CMD_RET_SUCCESS;
> > }
> >
> > - cacert = malloc(sz);
> > - if (!cacert)
>
> HERE...
>
> > + p = malloc(sz);
> > + if (!p)
> > return CMD_RET_FAILURE;
> > + cacert = p;
> > cacert_size = sz;
> >
> > memcpy(cacert, (void *)addr, sz - 1);
> > @@ -328,10 +331,33 @@ static int set_cacert(char * const saddr, char * const ssz)
> > return CMD_RET_FAILURE;
> > }
> >
> > +#if defined CONFIG_WGET_BUILTIN_CACERT
> > + cacert_initialized = true;
> > +#endif
> > return CMD_RET_SUCCESS;
> > }
> > +
> > +#if defined CONFIG_WGET_BUILTIN_CACERT
> > +static int set_cacert_builtin(void)
> > +{
> > + return _set_cacert(builtin_cacert, builtin_cacert_size);
> > +}
> > #endif
> >
> > +#if defined CONFIG_WGET_CACERT
> > +static int set_cacert(char * const saddr, char * const ssz)
> > +{
> > + ulong addr, sz;
> > +
> > + addr = hextoul(saddr, NULL);
> > + sz = hextoul(ssz, NULL);
> > + sz++; /* For the trailing '\0' in case of a text (PEM) file */
>
> This line should have been moved to _set_cacert() at the place I marked
> "HERE" above.
>
> The reason for this hack is, before even attempting to parse a file as
> PEM format (which is text-based), mbedtls_x509_crt_parse() checks that
> buf[buflen - 1] == '\0'. When a text file is obtained via wget there is
> no null terminator. Same when using bin2c. So adding the '\0' is
> necessary.
and if we do DER only for built-in this goes away as well
Thanks
/Ilias
^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: [PATCH 0/5] net: lwip: root certificates
2025-02-27 16:43 ` Jerome Forissier
@ 2025-03-04 15:46 ` Simon Glass
2025-03-07 10:49 ` Jerome Forissier
0 siblings, 1 reply; 30+ messages in thread
From: Simon Glass @ 2025-03-04 15:46 UTC (permalink / raw)
To: Jerome Forissier; +Cc: u-boot, Ilias Apalodimas
Hi Jerome,
On Thu, 27 Feb 2025 at 09:43, Jerome Forissier
<jerome.forissier@linaro.org> wrote:
>
>
>
> On 2/27/25 17:27, Simon Glass wrote:
> > Hi Jerome,
> >
> > On Thu, 27 Feb 2025 at 09:09, Jerome Forissier
> > <jerome.forissier@linaro.org> wrote:
> >>
> >> This series adds support for HTTP server authentication using root (CA)
> >> certificates.
> >>
> >> As a first step, the wget command is extended to support a sub-command:
> >> cacert <addr> <size>. The memory region shall contain the CA
> >> certificates. With this, it is possible to load the certificates from
> >> storage or get them from the network for example, which is convenient
> >> for testing at least. The Kconfig symbol for this feature is
> >> WGET_CACERT=y.
> >>
> >> Then new Kconfig symbols are added to support providing the certificates
> >> at build time, as a DER or PEM encoded X509 collection:
> >> WGET_BUILTIN_CACERT=y and WGET_BUILTIN_CACERT_PATH=<some path>.
> >> Note that PEM support requires MBEDTLS_LIB_X509_PEM=y (for the cacert
> >> command as well as for the builtin way).
> >>
> >> Here is a complete example (showing only the relevant output from the
> >> various commands):
> >>
> >> make qemu_arm64_lwip_defconfig
> >> wget https://curl.se/ca/cacert.pem
> >> echo CONFIG_WGET_BUILTIN_CACERT=y >>.config
> >> echo CONFIG_WGET_BUILTIN_CACERT_PATH=cacert.pem >>.config
> >> make olddefconfig
> >> make -j$(nproc) CROSS_COMPILE="ccache aarch64-linux-gnu-"
> >> qemu-system-aarch64 -M virt -nographic -cpu max \
> >> -object rng-random,id=rng0,filename=/dev/urandom \
> >> -device virtio-rng-pci,rng=rng0 -bios u-boot.bin
> >> => dhcp
> >> # HTTPS transfer using the builtin CA certificates
> >> => wget https://www.google.com/
> >> 18724 bytes transferred in 15 ms (1.2 MiB/s)
> >> # Disable certificate validation
> >> => wget cacert 0 0
> >> # Unsafe HTTPS transfer
> >> => wget https://www.google.com/
> >> WARNING: no CA certificates, HTTPS connections not authenticated
> >> 16570 bytes transferred in 15 ms (1.1 MiB/s)
> >> # Dowload and apply CA certificates from the net
> >> => wget https://curl.se/ca/cacert.pem
> >> WARNING: no CA certificates, HTTPS connections not authenticated
> >> ##
> >> 233263 bytes transferred in 61 ms (3.6 MiB/s)
> >> => wget cacert $fileaddr $filesize
> >> # Now HTTPS is authenticated against the new CA
> >> => wget https://www.google.com/
> >> 18743 bytes transferred in 14 ms (1.3 MiB/s)
> >> # Drop the certificates again...
> >> => wget cacert 0 0
> >> # Check that transfer is not secure
> >> => wget https://www.google.com/
> >> WARNING: no CA certificates, HTTPS connections not authenticated
> >> # Restore the builtin CA
> >> => wget cacert builtin
> >> # No more WARNING
> >> => wget https://www.google.com/
> >> 18738 bytes transferred in 15 ms (1.2 MiB/s)
> >>
> >> Jerome Forissier (5):
> >> net: lwip: extend wget to support CA (root) certificates
> >> lwip: tls: enforce checking of server certificates based on CA
> >> availability
> >> lwip: tls: warn when no CA exists amd log certificate validation
> >> errors
> >> net: lwip: add support for built-in root certificates
> >> configs: qemu_arm64_lwip_defconfig: enable WGET_CACERT and
> >> MBEDTLS_LIB_X509_PEM
> >>
> >> cmd/Kconfig | 29 ++++++
> >> cmd/net-lwip.c | 19 +++-
> >> configs/qemu_arm64_lwip_defconfig | 2 +
> >> .../src/apps/altcp_tls/altcp_tls_mbedtls.c | 9 +-
> >> .../lwip/apps/altcp_tls_mbedtls_opts.h | 6 --
> >> lib/mbedtls/Makefile | 3 +
> >> lib/mbedtls/mbedtls_def_config.h | 5 ++
> >> net/lwip/Makefile | 6 ++
> >> net/lwip/wget.c | 90 ++++++++++++++++++-
> >> 9 files changed, 158 insertions(+), 11 deletions(-)
> >
> > Did you manage to add some sandbox tests for lwip?
>
> Unfortunately not. I am testing mostly with QEMU (qemu_arm64_lwip_defconfig)
> and sometimes with KV260 and i.MX93.
My understanding was that someone was working on it [1] and I had
assumed it was you?
Regards,
SImon
[1] https://lore.kernel.org/u-boot/CAC_iWjKMo7=RE3=1=y3MpgC95itO170ruJYk6omh-4NuAJ8SRA@mail.gmail.com/
^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: [PATCH 1/5] net: lwip: extend wget to support CA (root) certificates
2025-02-28 21:24 ` Ilias Apalodimas
@ 2025-03-05 12:09 ` Jerome Forissier
0 siblings, 0 replies; 30+ messages in thread
From: Jerome Forissier @ 2025-03-05 12:09 UTC (permalink / raw)
To: Ilias Apalodimas
Cc: u-boot, Tom Rini, Joe Hershberger, Ramon Fried, Simon Glass,
Heinrich Schuchardt, Mattijs Korpershoek, Ibai Erkiaga,
Michal Simek, Raymond Mao, Philippe Reynes, Adriano Cordova
Hi Ilias,
On 2/28/25 22:24, Ilias Apalodimas wrote:
> Hi Jerome
>
>>
>> +config WGET_CACERT
>> + bool "wget cacert"
>> + depends on CMD_WGET
>> + depends on WGET_HTTPS
>> + help
>> + Adds the "cacert" sub-command to wget to provide root certificates
>> + to the HTTPS engine.
>> +
>> +config MBEDTLS_LIB_X509_PEM
>> + depends on WGET_CACERT
>> + bool "Support for PEM-encoded X509 certificates"
>> + help
>> + This option enables MbedTLS to parse PEM-encoded X509 certificates.
>> + When disabled, only DER format is accepted.
>> +
>> endif # if CMD_NET
>
> I guess that's needed because most of the RootCAs you can download are in PEM?
Yes, but thinking about it I'll just drop the PEM support for now as it makes
things a bit more complex (the `\0` issue) for no good reason.
>
> [...]
>
>> }
>>
>> +#if defined CONFIG_WGET_HTTPS
>
> you can do #if IS_ENABLED() here
Better yet: #if CONFIG_IS_ENABLED(WGET_HTTPS) I suppose.
>> +static char *cacert;
>> +size_t cacert_size;
>> +#endif
>> +
>> +#if defined CONFIG_WGET_CACERT
>> +static int set_cacert(char * const saddr, char * const ssz)
>> +{
>> + mbedtls_x509_crt crt;
>> + ulong addr, sz;
>> + int ret;
>> +
>> + if (cacert)
>> + free(cacert);
>> +
>> + addr = hextoul(saddr, NULL);
>> + sz = hextoul(ssz, NULL);
>> + sz++; /* For the trailing '\0' in case of a text (PEM) file */
>> +
>> + if (!addr) {
>> + cacert = NULL;
>
> cacert is already allocated. Can't we just free it here if it's
> supposed to be removed and reuse the memory otherwise, instead of
> doing free/alloc on every command?
The size of the certificates may change so it's easier to free/malloc
every time.
Thanks,
--
Jerome
^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: [PATCH 2/5] lwip: tls: enforce checking of server certificates based on CA availability
2025-02-28 21:26 ` Ilias Apalodimas
@ 2025-03-05 12:27 ` Jerome Forissier
0 siblings, 0 replies; 30+ messages in thread
From: Jerome Forissier @ 2025-03-05 12:27 UTC (permalink / raw)
To: Ilias Apalodimas
Cc: u-boot, Tom Rini, Javier Tia, Heinrich Schuchardt,
Simon Goldschmidt
Hi Ilias,
On 2/28/25 22:26, Ilias Apalodimas wrote:
> Hi Jerome
>
> ++CC Simon for lwIP
>
> On Thu, 27 Feb 2025 at 18:09, Jerome Forissier
> <jerome.forissier@linaro.org> wrote:
>>
>> Instead of relying on some build time configuration to determine if
>> server certificates need to be checked against CA certificates, do it
>> based on the availability of such certificates. If no CA is configured
>> then no check can succeed; on the other hand if we have CA certs then
>> we should not ignore them. It is always possible to remove the CA certs
>> (via 'wget cacert 0 0') to force an HTTPS download that would fail
>> certificate validation
>
> This looks correct, but we should at some point send those to lwIP as
> well instead of keeping them locally
I agree, but it seems upstream doesn't care much about contributions,
unfortunately. The patches I submitted got zero consideration until now
[1][2]. And the list of unacknowledged/unassigne patch is quite large
[3]. So I would not bother for now.
[1] https://savannah.nongnu.org/patch/?10462 (TFTP blocksize)
[2] https://savannah.nongnu.org/patch/?10480 (TFTP port binding)
[3] https://savannah.nongnu.org/patch/?group=lwip
>
> Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Thanks!
--
Jerome
>
>>
>> Signed-off-by: Jerome Forissier <jerome.forissier@linaro.org>
>> ---
>> lib/lwip/lwip/src/apps/altcp_tls/altcp_tls_mbedtls.c | 3 ++-
>> .../lwip/src/include/lwip/apps/altcp_tls_mbedtls_opts.h | 6 ------
>> 2 files changed, 2 insertions(+), 7 deletions(-)
>>
>> diff --git a/lib/lwip/lwip/src/apps/altcp_tls/altcp_tls_mbedtls.c b/lib/lwip/lwip/src/apps/altcp_tls/altcp_tls_mbedtls.c
>> index 46421588fef..fa3d1d74fed 100644
>> --- a/lib/lwip/lwip/src/apps/altcp_tls/altcp_tls_mbedtls.c
>> +++ b/lib/lwip/lwip/src/apps/altcp_tls/altcp_tls_mbedtls.c
>> @@ -786,6 +786,7 @@ altcp_tls_create_config(int is_server, u8_t cert_count, u8_t pkey_count, int hav
>> int ret;
>> struct altcp_tls_config *conf;
>> mbedtls_x509_crt *mem;
>> + int authmode = have_ca ? MBEDTLS_SSL_VERIFY_REQUIRED : MBEDTLS_SSL_VERIFY_NONE;
>>
>> if (TCP_WND < MBEDTLS_SSL_IN_CONTENT_LEN || TCP_WND < MBEDTLS_SSL_OUT_CONTENT_LEN) {
>> LWIP_DEBUGF(ALTCP_MBEDTLS_DEBUG|LWIP_DBG_LEVEL_SERIOUS,
>> @@ -840,7 +841,7 @@ altcp_tls_create_config(int is_server, u8_t cert_count, u8_t pkey_count, int hav
>> altcp_mbedtls_free_config(conf);
>> return NULL;
>> }
>> - mbedtls_ssl_conf_authmode(&conf->conf, ALTCP_MBEDTLS_AUTHMODE);
>> + mbedtls_ssl_conf_authmode(&conf->conf, authmode);
>>
>> mbedtls_ssl_conf_rng(&conf->conf, mbedtls_ctr_drbg_random, &altcp_tls_entropy_rng->ctr_drbg);
>> #if ALTCP_MBEDTLS_LIB_DEBUG != LWIP_DBG_OFF
>> diff --git a/lib/lwip/lwip/src/include/lwip/apps/altcp_tls_mbedtls_opts.h b/lib/lwip/lwip/src/include/lwip/apps/altcp_tls_mbedtls_opts.h
>> index e41301c061c..71aa5993935 100644
>> --- a/lib/lwip/lwip/src/include/lwip/apps/altcp_tls_mbedtls_opts.h
>> +++ b/lib/lwip/lwip/src/include/lwip/apps/altcp_tls_mbedtls_opts.h
>> @@ -100,12 +100,6 @@
>> #define ALTCP_MBEDTLS_SESSION_TICKET_TIMEOUT_SECONDS (60 * 60 * 24)
>> #endif
>>
>> -/** Certificate verification mode: MBEDTLS_SSL_VERIFY_NONE, MBEDTLS_SSL_VERIFY_OPTIONAL (default),
>> - * MBEDTLS_SSL_VERIFY_REQUIRED (recommended)*/
>> -#ifndef ALTCP_MBEDTLS_AUTHMODE
>> -#define ALTCP_MBEDTLS_AUTHMODE MBEDTLS_SSL_VERIFY_OPTIONAL
>> -#endif
>> -
>> #endif /* LWIP_ALTCP */
>>
>> #endif /* LWIP_HDR_ALTCP_TLS_OPTS_H */
>> --
>> 2.43.0
>>
^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: [PATCH 4/5] net: lwip: add support for built-in root certificates
2025-03-01 6:59 ` Ilias Apalodimas
@ 2025-03-05 12:34 ` Jerome Forissier
0 siblings, 0 replies; 30+ messages in thread
From: Jerome Forissier @ 2025-03-05 12:34 UTC (permalink / raw)
To: Ilias Apalodimas
Cc: u-boot, Tom Rini, Joe Hershberger, Ramon Fried, Simon Glass,
Heinrich Schuchardt, Mattijs Korpershoek, Ibai Erkiaga,
Michal Simek, Adriano Cordova
Hi Ilias,
On 3/1/25 07:59, Ilias Apalodimas wrote:
> Hi Jerome,
>
> On Thu, 27 Feb 2025 at 18:38, Jerome Forissier
> <jerome.forissier@linaro.org> wrote:
>>
>> Sorry for replying to myself, I spotted a small mistake.
>>
>> On 2/27/25 17:09, Jerome Forissier wrote:
>>> Introduce Kconfig symbols WGET_BUILTIN_CACERT and
>>> WGET_BUILTIN_CACERT_PATH to provide root certificates at build time. The
>>> file may be a DER-encoded (.crt) or PEM-encoded (.pem) X509 collection
>>> of one or more certificates. PEM encoding needs MBEDTLS_LIB_X509_PEM.
>
> I understand that for downloaded certificates supporting both is
> convenient since DER might not be available. But why don't we limit
> our built-in options to DER only, which is smaller anyway?
Yeah v2 will be DER-only.
>
> [...]
>
>
>>> --- a/cmd/net-lwip.c
>>> +++ b/cmd/net-lwip.c
>>> @@ -39,6 +39,10 @@ U_BOOT_CMD(wget, 4, 1, do_wget,
>>> #if defined(CONFIG_WGET_CACERT)
>>> "\nwget cacert <address> <length>\n"
>>> " - provide CA certificates (0 0 to disable verification)"
>>> +#if defined(CONFIG_WGET_BUILTIN_CACERT)
>>> + "\nwget cacert builtin\n"
>>> + " - use the builtin CA certificates"
>>> +#endif
>>> #endif
>>> );
>>> #endif
>>> diff --git a/net/lwip/Makefile b/net/lwip/Makefile
>>> index 79dd6b3fb50..950c5316bb9 100644
>>> --- a/net/lwip/Makefile
>>> +++ b/net/lwip/Makefile
>>> @@ -6,3 +6,9 @@ obj-$(CONFIG_CMD_DNS) += dns.o
>>> obj-$(CONFIG_CMD_PING) += ping.o
>>> obj-$(CONFIG_CMD_TFTPBOOT) += tftp.o
>>> obj-$(CONFIG_WGET) += wget.o
>>> +
>>> +ifeq (y,$(CONFIG_WGET_BUILTIN_CACERT))
>>> +$(obj)/builtin_cacert.c: $(CONFIG_WGET_BUILTIN_CACERT_PATH:"%"=%) FORCE
>>> + $(call if_changed,bin2c,builtin_cacert)
>>> +obj-y += builtin_cacert.o
>>> +endif
>>> diff --git a/net/lwip/wget.c b/net/lwip/wget.c
>>> index 14466598d7c..f24aa9c2380 100644
>>> --- a/net/lwip/wget.c
>>> +++ b/net/lwip/wget.c
>>> @@ -288,31 +288,34 @@ static err_t httpc_headers_done_cb(httpc_state_t *connection, void *arg, struct
>>> #if defined CONFIG_WGET_HTTPS
>>> static char *cacert;
>>> size_t cacert_size;
>>> +
>>> +#if defined CONFIG_WGET_BUILTIN_CACERT
>>> +extern char builtin_cacert[];
>
> const as well? IIRC all the bin2 generated variables end up in .rodata
Yep. Will fix.
>
>>> +extern const size_t builtin_cacert_size;
>>> +static bool cacert_initialized;
>>> +#endif
>>> #endif
>>>
>>> -#if defined CONFIG_WGET_CACERT
>>> -static int set_cacert(char * const saddr, char * const ssz)
>>> +#if defined CONFIG_WGET_CACERT || defined CONFIG_WGET_BUILTIN_CACERT
>>> +static int _set_cacert(void *addr, size_t sz)
>>> {
>>> mbedtls_x509_crt crt;
>>> - ulong addr, sz;
>>> + void *p;
>>> int ret;
>>>
>>> if (cacert)
>>> free(cacert);
>>>
>>> - addr = hextoul(saddr, NULL);
>>> - sz = hextoul(ssz, NULL);
>>> - sz++; /* For the trailing '\0' in case of a text (PEM) file */
>>> -
>>> if (!addr) {
>>> cacert = NULL;
>>> cacert_size = 0;
>>> return CMD_RET_SUCCESS;
>>> }
>>>
>>> - cacert = malloc(sz);
>>> - if (!cacert)
>>
>> HERE...
>>
>>> + p = malloc(sz);
>>> + if (!p)
>>> return CMD_RET_FAILURE;
>>> + cacert = p;
>>> cacert_size = sz;
>>>
>>> memcpy(cacert, (void *)addr, sz - 1);
>>> @@ -328,10 +331,33 @@ static int set_cacert(char * const saddr, char * const ssz)
>>> return CMD_RET_FAILURE;
>>> }
>>>
>>> +#if defined CONFIG_WGET_BUILTIN_CACERT
>>> + cacert_initialized = true;
>>> +#endif
>>> return CMD_RET_SUCCESS;
>>> }
>>> +
>>> +#if defined CONFIG_WGET_BUILTIN_CACERT
>>> +static int set_cacert_builtin(void)
>>> +{
>>> + return _set_cacert(builtin_cacert, builtin_cacert_size);
>>> +}
>>> #endif
>>>
>>> +#if defined CONFIG_WGET_CACERT
>>> +static int set_cacert(char * const saddr, char * const ssz)
>>> +{
>>> + ulong addr, sz;
>>> +
>>> + addr = hextoul(saddr, NULL);
>>> + sz = hextoul(ssz, NULL);
>>> + sz++; /* For the trailing '\0' in case of a text (PEM) file */
>>
>> This line should have been moved to _set_cacert() at the place I marked
>> "HERE" above.
>>
>> The reason for this hack is, before even attempting to parse a file as
>> PEM format (which is text-based), mbedtls_x509_crt_parse() checks that
>> buf[buflen - 1] == '\0'. When a text file is obtained via wget there is
>> no null terminator. Same when using bin2c. So adding the '\0' is
>> necessary.
>
> and if we do DER only for built-in this goes away as well
Indeed.
Thanks,
--
Jerome
>
> Thanks
> /Ilias
^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: [PATCH 0/5] net: lwip: root certificates
2025-03-04 15:46 ` Simon Glass
@ 2025-03-07 10:49 ` Jerome Forissier
2025-03-13 12:51 ` Simon Glass
0 siblings, 1 reply; 30+ messages in thread
From: Jerome Forissier @ 2025-03-07 10:49 UTC (permalink / raw)
To: Simon Glass; +Cc: u-boot, Ilias Apalodimas
Hi Simon,
On 3/4/25 16:46, Simon Glass wrote:
> Hi Jerome,
>
> On Thu, 27 Feb 2025 at 09:43, Jerome Forissier
> <jerome.forissier@linaro.org> wrote:
>>
>>
>>
>> On 2/27/25 17:27, Simon Glass wrote:
>>> Hi Jerome,
>>>
>>> On Thu, 27 Feb 2025 at 09:09, Jerome Forissier
>>> <jerome.forissier@linaro.org> wrote:
>>>>
>>>> This series adds support for HTTP server authentication using root (CA)
>>>> certificates.
>>>>
>>>> As a first step, the wget command is extended to support a sub-command:
>>>> cacert <addr> <size>. The memory region shall contain the CA
>>>> certificates. With this, it is possible to load the certificates from
>>>> storage or get them from the network for example, which is convenient
>>>> for testing at least. The Kconfig symbol for this feature is
>>>> WGET_CACERT=y.
>>>>
>>>> Then new Kconfig symbols are added to support providing the certificates
>>>> at build time, as a DER or PEM encoded X509 collection:
>>>> WGET_BUILTIN_CACERT=y and WGET_BUILTIN_CACERT_PATH=<some path>.
>>>> Note that PEM support requires MBEDTLS_LIB_X509_PEM=y (for the cacert
>>>> command as well as for the builtin way).
>>>>
>>>> Here is a complete example (showing only the relevant output from the
>>>> various commands):
>>>>
>>>> make qemu_arm64_lwip_defconfig
>>>> wget https://curl.se/ca/cacert.pem
>>>> echo CONFIG_WGET_BUILTIN_CACERT=y >>.config
>>>> echo CONFIG_WGET_BUILTIN_CACERT_PATH=cacert.pem >>.config
>>>> make olddefconfig
>>>> make -j$(nproc) CROSS_COMPILE="ccache aarch64-linux-gnu-"
>>>> qemu-system-aarch64 -M virt -nographic -cpu max \
>>>> -object rng-random,id=rng0,filename=/dev/urandom \
>>>> -device virtio-rng-pci,rng=rng0 -bios u-boot.bin
>>>> => dhcp
>>>> # HTTPS transfer using the builtin CA certificates
>>>> => wget https://www.google.com/
>>>> 18724 bytes transferred in 15 ms (1.2 MiB/s)
>>>> # Disable certificate validation
>>>> => wget cacert 0 0
>>>> # Unsafe HTTPS transfer
>>>> => wget https://www.google.com/
>>>> WARNING: no CA certificates, HTTPS connections not authenticated
>>>> 16570 bytes transferred in 15 ms (1.1 MiB/s)
>>>> # Dowload and apply CA certificates from the net
>>>> => wget https://curl.se/ca/cacert.pem
>>>> WARNING: no CA certificates, HTTPS connections not authenticated
>>>> ##
>>>> 233263 bytes transferred in 61 ms (3.6 MiB/s)
>>>> => wget cacert $fileaddr $filesize
>>>> # Now HTTPS is authenticated against the new CA
>>>> => wget https://www.google.com/
>>>> 18743 bytes transferred in 14 ms (1.3 MiB/s)
>>>> # Drop the certificates again...
>>>> => wget cacert 0 0
>>>> # Check that transfer is not secure
>>>> => wget https://www.google.com/
>>>> WARNING: no CA certificates, HTTPS connections not authenticated
>>>> # Restore the builtin CA
>>>> => wget cacert builtin
>>>> # No more WARNING
>>>> => wget https://www.google.com/
>>>> 18738 bytes transferred in 15 ms (1.2 MiB/s)
>>>>
>>>> Jerome Forissier (5):
>>>> net: lwip: extend wget to support CA (root) certificates
>>>> lwip: tls: enforce checking of server certificates based on CA
>>>> availability
>>>> lwip: tls: warn when no CA exists amd log certificate validation
>>>> errors
>>>> net: lwip: add support for built-in root certificates
>>>> configs: qemu_arm64_lwip_defconfig: enable WGET_CACERT and
>>>> MBEDTLS_LIB_X509_PEM
>>>>
>>>> cmd/Kconfig | 29 ++++++
>>>> cmd/net-lwip.c | 19 +++-
>>>> configs/qemu_arm64_lwip_defconfig | 2 +
>>>> .../src/apps/altcp_tls/altcp_tls_mbedtls.c | 9 +-
>>>> .../lwip/apps/altcp_tls_mbedtls_opts.h | 6 --
>>>> lib/mbedtls/Makefile | 3 +
>>>> lib/mbedtls/mbedtls_def_config.h | 5 ++
>>>> net/lwip/Makefile | 6 ++
>>>> net/lwip/wget.c | 90 ++++++++++++++++++-
>>>> 9 files changed, 158 insertions(+), 11 deletions(-)
>>>
>>> Did you manage to add some sandbox tests for lwip?
>>
>> Unfortunately not. I am testing mostly with QEMU (qemu_arm64_lwip_defconfig)
>> and sometimes with KV260 and i.MX93.
>
> My understanding was that someone was working on it [1] and I had
> assumed it was you?
Yes, it is on my TODO list. Higher priority things have kept coming in, but
hopefully I can resume this work soon.
Regards,
--
Jerome
>
> Regards,
> SImon
>
> [1] https://lore.kernel.org/u-boot/CAC_iWjKMo7=RE3=1=y3MpgC95itO170ruJYk6omh-4NuAJ8SRA@mail.gmail.com/
^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: [PATCH 0/5] net: lwip: root certificates
2025-03-07 10:49 ` Jerome Forissier
@ 2025-03-13 12:51 ` Simon Glass
2025-03-13 13:23 ` Jerome Forissier
0 siblings, 1 reply; 30+ messages in thread
From: Simon Glass @ 2025-03-13 12:51 UTC (permalink / raw)
To: Jerome Forissier; +Cc: u-boot, Ilias Apalodimas
Hi Jerome,
On Fri, 7 Mar 2025 at 10:49, Jerome Forissier
<jerome.forissier@linaro.org> wrote:
>
> Hi Simon,
>
> On 3/4/25 16:46, Simon Glass wrote:
> > Hi Jerome,
> >
> > On Thu, 27 Feb 2025 at 09:43, Jerome Forissier
> > <jerome.forissier@linaro.org> wrote:
> >>
> >>
> >>
> >> On 2/27/25 17:27, Simon Glass wrote:
> >>> Hi Jerome,
> >>>
> >>> On Thu, 27 Feb 2025 at 09:09, Jerome Forissier
> >>> <jerome.forissier@linaro.org> wrote:
> >>>>
> >>>> This series adds support for HTTP server authentication using root (CA)
> >>>> certificates.
> >>>>
> >>>> As a first step, the wget command is extended to support a sub-command:
> >>>> cacert <addr> <size>. The memory region shall contain the CA
> >>>> certificates. With this, it is possible to load the certificates from
> >>>> storage or get them from the network for example, which is convenient
> >>>> for testing at least. The Kconfig symbol for this feature is
> >>>> WGET_CACERT=y.
> >>>>
> >>>> Then new Kconfig symbols are added to support providing the certificates
> >>>> at build time, as a DER or PEM encoded X509 collection:
> >>>> WGET_BUILTIN_CACERT=y and WGET_BUILTIN_CACERT_PATH=<some path>.
> >>>> Note that PEM support requires MBEDTLS_LIB_X509_PEM=y (for the cacert
> >>>> command as well as for the builtin way).
> >>>>
> >>>> Here is a complete example (showing only the relevant output from the
> >>>> various commands):
> >>>>
> >>>> make qemu_arm64_lwip_defconfig
> >>>> wget https://curl.se/ca/cacert.pem
> >>>> echo CONFIG_WGET_BUILTIN_CACERT=y >>.config
> >>>> echo CONFIG_WGET_BUILTIN_CACERT_PATH=cacert.pem >>.config
> >>>> make olddefconfig
> >>>> make -j$(nproc) CROSS_COMPILE="ccache aarch64-linux-gnu-"
> >>>> qemu-system-aarch64 -M virt -nographic -cpu max \
> >>>> -object rng-random,id=rng0,filename=/dev/urandom \
> >>>> -device virtio-rng-pci,rng=rng0 -bios u-boot.bin
> >>>> => dhcp
> >>>> # HTTPS transfer using the builtin CA certificates
> >>>> => wget https://www.google.com/
> >>>> 18724 bytes transferred in 15 ms (1.2 MiB/s)
> >>>> # Disable certificate validation
> >>>> => wget cacert 0 0
> >>>> # Unsafe HTTPS transfer
> >>>> => wget https://www.google.com/
> >>>> WARNING: no CA certificates, HTTPS connections not authenticated
> >>>> 16570 bytes transferred in 15 ms (1.1 MiB/s)
> >>>> # Dowload and apply CA certificates from the net
> >>>> => wget https://curl.se/ca/cacert.pem
> >>>> WARNING: no CA certificates, HTTPS connections not authenticated
> >>>> ##
> >>>> 233263 bytes transferred in 61 ms (3.6 MiB/s)
> >>>> => wget cacert $fileaddr $filesize
> >>>> # Now HTTPS is authenticated against the new CA
> >>>> => wget https://www.google.com/
> >>>> 18743 bytes transferred in 14 ms (1.3 MiB/s)
> >>>> # Drop the certificates again...
> >>>> => wget cacert 0 0
> >>>> # Check that transfer is not secure
> >>>> => wget https://www.google.com/
> >>>> WARNING: no CA certificates, HTTPS connections not authenticated
> >>>> # Restore the builtin CA
> >>>> => wget cacert builtin
> >>>> # No more WARNING
> >>>> => wget https://www.google.com/
> >>>> 18738 bytes transferred in 15 ms (1.2 MiB/s)
> >>>>
> >>>> Jerome Forissier (5):
> >>>> net: lwip: extend wget to support CA (root) certificates
> >>>> lwip: tls: enforce checking of server certificates based on CA
> >>>> availability
> >>>> lwip: tls: warn when no CA exists amd log certificate validation
> >>>> errors
> >>>> net: lwip: add support for built-in root certificates
> >>>> configs: qemu_arm64_lwip_defconfig: enable WGET_CACERT and
> >>>> MBEDTLS_LIB_X509_PEM
> >>>>
> >>>> cmd/Kconfig | 29 ++++++
> >>>> cmd/net-lwip.c | 19 +++-
> >>>> configs/qemu_arm64_lwip_defconfig | 2 +
> >>>> .../src/apps/altcp_tls/altcp_tls_mbedtls.c | 9 +-
> >>>> .../lwip/apps/altcp_tls_mbedtls_opts.h | 6 --
> >>>> lib/mbedtls/Makefile | 3 +
> >>>> lib/mbedtls/mbedtls_def_config.h | 5 ++
> >>>> net/lwip/Makefile | 6 ++
> >>>> net/lwip/wget.c | 90 ++++++++++++++++++-
> >>>> 9 files changed, 158 insertions(+), 11 deletions(-)
> >>>
> >>> Did you manage to add some sandbox tests for lwip?
> >>
> >> Unfortunately not. I am testing mostly with QEMU (qemu_arm64_lwip_defconfig)
> >> and sometimes with KV260 and i.MX93.
> >
> > My understanding was that someone was working on it [1] and I had
> > assumed it was you?
>
> Yes, it is on my TODO list. Higher priority things have kept coming in, but
> hopefully I can resume this work soon.
Until the tests are added, please stop sending new series for lwip. It
is just going to make it harder to add the tests later. It should not
take long to add a basic test, e.g. for ping.
Regards,
Simon
^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: [PATCH 0/5] net: lwip: root certificates
2025-03-13 12:51 ` Simon Glass
@ 2025-03-13 13:23 ` Jerome Forissier
2025-03-14 22:01 ` Jerome Forissier
0 siblings, 1 reply; 30+ messages in thread
From: Jerome Forissier @ 2025-03-13 13:23 UTC (permalink / raw)
To: Simon Glass; +Cc: u-boot, Ilias Apalodimas
On 3/13/25 13:51, Simon Glass wrote:
> Hi Jerome,
>
> On Fri, 7 Mar 2025 at 10:49, Jerome Forissier
> <jerome.forissier@linaro.org> wrote:
>>
>> Hi Simon,
>>
>> On 3/4/25 16:46, Simon Glass wrote:
>>> Hi Jerome,
>>>
>>> On Thu, 27 Feb 2025 at 09:43, Jerome Forissier
>>> <jerome.forissier@linaro.org> wrote:
>>>>
>>>>
>>>>
>>>> On 2/27/25 17:27, Simon Glass wrote:
>>>>> Hi Jerome,
>>>>>
>>>>> On Thu, 27 Feb 2025 at 09:09, Jerome Forissier
>>>>> <jerome.forissier@linaro.org> wrote:
>>>>>>
>>>>>> This series adds support for HTTP server authentication using root (CA)
>>>>>> certificates.
>>>>>>
>>>>>> As a first step, the wget command is extended to support a sub-command:
>>>>>> cacert <addr> <size>. The memory region shall contain the CA
>>>>>> certificates. With this, it is possible to load the certificates from
>>>>>> storage or get them from the network for example, which is convenient
>>>>>> for testing at least. The Kconfig symbol for this feature is
>>>>>> WGET_CACERT=y.
>>>>>>
>>>>>> Then new Kconfig symbols are added to support providing the certificates
>>>>>> at build time, as a DER or PEM encoded X509 collection:
>>>>>> WGET_BUILTIN_CACERT=y and WGET_BUILTIN_CACERT_PATH=<some path>.
>>>>>> Note that PEM support requires MBEDTLS_LIB_X509_PEM=y (for the cacert
>>>>>> command as well as for the builtin way).
>>>>>>
>>>>>> Here is a complete example (showing only the relevant output from the
>>>>>> various commands):
>>>>>>
>>>>>> make qemu_arm64_lwip_defconfig
>>>>>> wget https://curl.se/ca/cacert.pem
>>>>>> echo CONFIG_WGET_BUILTIN_CACERT=y >>.config
>>>>>> echo CONFIG_WGET_BUILTIN_CACERT_PATH=cacert.pem >>.config
>>>>>> make olddefconfig
>>>>>> make -j$(nproc) CROSS_COMPILE="ccache aarch64-linux-gnu-"
>>>>>> qemu-system-aarch64 -M virt -nographic -cpu max \
>>>>>> -object rng-random,id=rng0,filename=/dev/urandom \
>>>>>> -device virtio-rng-pci,rng=rng0 -bios u-boot.bin
>>>>>> => dhcp
>>>>>> # HTTPS transfer using the builtin CA certificates
>>>>>> => wget https://www.google.com/
>>>>>> 18724 bytes transferred in 15 ms (1.2 MiB/s)
>>>>>> # Disable certificate validation
>>>>>> => wget cacert 0 0
>>>>>> # Unsafe HTTPS transfer
>>>>>> => wget https://www.google.com/
>>>>>> WARNING: no CA certificates, HTTPS connections not authenticated
>>>>>> 16570 bytes transferred in 15 ms (1.1 MiB/s)
>>>>>> # Dowload and apply CA certificates from the net
>>>>>> => wget https://curl.se/ca/cacert.pem
>>>>>> WARNING: no CA certificates, HTTPS connections not authenticated
>>>>>> ##
>>>>>> 233263 bytes transferred in 61 ms (3.6 MiB/s)
>>>>>> => wget cacert $fileaddr $filesize
>>>>>> # Now HTTPS is authenticated against the new CA
>>>>>> => wget https://www.google.com/
>>>>>> 18743 bytes transferred in 14 ms (1.3 MiB/s)
>>>>>> # Drop the certificates again...
>>>>>> => wget cacert 0 0
>>>>>> # Check that transfer is not secure
>>>>>> => wget https://www.google.com/
>>>>>> WARNING: no CA certificates, HTTPS connections not authenticated
>>>>>> # Restore the builtin CA
>>>>>> => wget cacert builtin
>>>>>> # No more WARNING
>>>>>> => wget https://www.google.com/
>>>>>> 18738 bytes transferred in 15 ms (1.2 MiB/s)
>>>>>>
>>>>>> Jerome Forissier (5):
>>>>>> net: lwip: extend wget to support CA (root) certificates
>>>>>> lwip: tls: enforce checking of server certificates based on CA
>>>>>> availability
>>>>>> lwip: tls: warn when no CA exists amd log certificate validation
>>>>>> errors
>>>>>> net: lwip: add support for built-in root certificates
>>>>>> configs: qemu_arm64_lwip_defconfig: enable WGET_CACERT and
>>>>>> MBEDTLS_LIB_X509_PEM
>>>>>>
>>>>>> cmd/Kconfig | 29 ++++++
>>>>>> cmd/net-lwip.c | 19 +++-
>>>>>> configs/qemu_arm64_lwip_defconfig | 2 +
>>>>>> .../src/apps/altcp_tls/altcp_tls_mbedtls.c | 9 +-
>>>>>> .../lwip/apps/altcp_tls_mbedtls_opts.h | 6 --
>>>>>> lib/mbedtls/Makefile | 3 +
>>>>>> lib/mbedtls/mbedtls_def_config.h | 5 ++
>>>>>> net/lwip/Makefile | 6 ++
>>>>>> net/lwip/wget.c | 90 ++++++++++++++++++-
>>>>>> 9 files changed, 158 insertions(+), 11 deletions(-)
>>>>>
>>>>> Did you manage to add some sandbox tests for lwip?
>>>>
>>>> Unfortunately not. I am testing mostly with QEMU (qemu_arm64_lwip_defconfig)
>>>> and sometimes with KV260 and i.MX93.
>>>
>>> My understanding was that someone was working on it [1] and I had
>>> assumed it was you?
>>
>> Yes, it is on my TODO list. Higher priority things have kept coming in, but
>> hopefully I can resume this work soon.
>
> Until the tests are added, please stop sending new series for lwip. It
> is just going to make it harder to add the tests later.
I don't see how exactly it would make things harder, but...
> It should not
> take long to add a basic test, e.g. for ping.
...I'm on it.
> Regards,
> Simon
Thanks,
--
Jerome
^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: [PATCH 0/5] net: lwip: root certificates
2025-03-13 13:23 ` Jerome Forissier
@ 2025-03-14 22:01 ` Jerome Forissier
2025-03-15 12:47 ` Simon Glass
0 siblings, 1 reply; 30+ messages in thread
From: Jerome Forissier @ 2025-03-14 22:01 UTC (permalink / raw)
To: Simon Glass; +Cc: u-boot, Ilias Apalodimas
Hi Simon,
On 3/13/25 14:23, Jerome Forissier wrote:
>
>
> On 3/13/25 13:51, Simon Glass wrote:
>> Hi Jerome,
>>
>> On Fri, 7 Mar 2025 at 10:49, Jerome Forissier
>> <jerome.forissier@linaro.org> wrote:
>>>
>>> Hi Simon,
>>>
>>> On 3/4/25 16:46, Simon Glass wrote:
>>>> Hi Jerome,
>>>>
>>>> On Thu, 27 Feb 2025 at 09:43, Jerome Forissier
>>>> <jerome.forissier@linaro.org> wrote:
>>>>>
>>>>>
>>>>>
>>>>> On 2/27/25 17:27, Simon Glass wrote:
>>>>>> Hi Jerome,
>>>>>>
>>>>>> On Thu, 27 Feb 2025 at 09:09, Jerome Forissier
>>>>>> <jerome.forissier@linaro.org> wrote:
>>>>>>>
>>>>>>> This series adds support for HTTP server authentication using root (CA)
>>>>>>> certificates.
>>>>>>>
>>>>>>> As a first step, the wget command is extended to support a sub-command:
>>>>>>> cacert <addr> <size>. The memory region shall contain the CA
>>>>>>> certificates. With this, it is possible to load the certificates from
>>>>>>> storage or get them from the network for example, which is convenient
>>>>>>> for testing at least. The Kconfig symbol for this feature is
>>>>>>> WGET_CACERT=y.
>>>>>>>
>>>>>>> Then new Kconfig symbols are added to support providing the certificates
>>>>>>> at build time, as a DER or PEM encoded X509 collection:
>>>>>>> WGET_BUILTIN_CACERT=y and WGET_BUILTIN_CACERT_PATH=<some path>.
>>>>>>> Note that PEM support requires MBEDTLS_LIB_X509_PEM=y (for the cacert
>>>>>>> command as well as for the builtin way).
>>>>>>>
>>>>>>> Here is a complete example (showing only the relevant output from the
>>>>>>> various commands):
>>>>>>>
>>>>>>> make qemu_arm64_lwip_defconfig
>>>>>>> wget https://curl.se/ca/cacert.pem
>>>>>>> echo CONFIG_WGET_BUILTIN_CACERT=y >>.config
>>>>>>> echo CONFIG_WGET_BUILTIN_CACERT_PATH=cacert.pem >>.config
>>>>>>> make olddefconfig
>>>>>>> make -j$(nproc) CROSS_COMPILE="ccache aarch64-linux-gnu-"
>>>>>>> qemu-system-aarch64 -M virt -nographic -cpu max \
>>>>>>> -object rng-random,id=rng0,filename=/dev/urandom \
>>>>>>> -device virtio-rng-pci,rng=rng0 -bios u-boot.bin
>>>>>>> => dhcp
>>>>>>> # HTTPS transfer using the builtin CA certificates
>>>>>>> => wget https://www.google.com/
>>>>>>> 18724 bytes transferred in 15 ms (1.2 MiB/s)
>>>>>>> # Disable certificate validation
>>>>>>> => wget cacert 0 0
>>>>>>> # Unsafe HTTPS transfer
>>>>>>> => wget https://www.google.com/
>>>>>>> WARNING: no CA certificates, HTTPS connections not authenticated
>>>>>>> 16570 bytes transferred in 15 ms (1.1 MiB/s)
>>>>>>> # Dowload and apply CA certificates from the net
>>>>>>> => wget https://curl.se/ca/cacert.pem
>>>>>>> WARNING: no CA certificates, HTTPS connections not authenticated
>>>>>>> ##
>>>>>>> 233263 bytes transferred in 61 ms (3.6 MiB/s)
>>>>>>> => wget cacert $fileaddr $filesize
>>>>>>> # Now HTTPS is authenticated against the new CA
>>>>>>> => wget https://www.google.com/
>>>>>>> 18743 bytes transferred in 14 ms (1.3 MiB/s)
>>>>>>> # Drop the certificates again...
>>>>>>> => wget cacert 0 0
>>>>>>> # Check that transfer is not secure
>>>>>>> => wget https://www.google.com/
>>>>>>> WARNING: no CA certificates, HTTPS connections not authenticated
>>>>>>> # Restore the builtin CA
>>>>>>> => wget cacert builtin
>>>>>>> # No more WARNING
>>>>>>> => wget https://www.google.com/
>>>>>>> 18738 bytes transferred in 15 ms (1.2 MiB/s)
>>>>>>>
>>>>>>> Jerome Forissier (5):
>>>>>>> net: lwip: extend wget to support CA (root) certificates
>>>>>>> lwip: tls: enforce checking of server certificates based on CA
>>>>>>> availability
>>>>>>> lwip: tls: warn when no CA exists amd log certificate validation
>>>>>>> errors
>>>>>>> net: lwip: add support for built-in root certificates
>>>>>>> configs: qemu_arm64_lwip_defconfig: enable WGET_CACERT and
>>>>>>> MBEDTLS_LIB_X509_PEM
>>>>>>>
>>>>>>> cmd/Kconfig | 29 ++++++
>>>>>>> cmd/net-lwip.c | 19 +++-
>>>>>>> configs/qemu_arm64_lwip_defconfig | 2 +
>>>>>>> .../src/apps/altcp_tls/altcp_tls_mbedtls.c | 9 +-
>>>>>>> .../lwip/apps/altcp_tls_mbedtls_opts.h | 6 --
>>>>>>> lib/mbedtls/Makefile | 3 +
>>>>>>> lib/mbedtls/mbedtls_def_config.h | 5 ++
>>>>>>> net/lwip/Makefile | 6 ++
>>>>>>> net/lwip/wget.c | 90 ++++++++++++++++++-
>>>>>>> 9 files changed, 158 insertions(+), 11 deletions(-)
>>>>>>
>>>>>> Did you manage to add some sandbox tests for lwip?
>>>>>
>>>>> Unfortunately not. I am testing mostly with QEMU (qemu_arm64_lwip_defconfig)
>>>>> and sometimes with KV260 and i.MX93.
>>>>
>>>> My understanding was that someone was working on it [1] and I had
>>>> assumed it was you?
>>>
>>> Yes, it is on my TODO list. Higher priority things have kept coming in, but
>>> hopefully I can resume this work soon.
>>
>> Until the tests are added, please stop sending new series for lwip. It
>> is just going to make it harder to add the tests later.
>
> I don't see how exactly it would make things harder, but...
>
>> It should not
>> take long to add a basic test, e.g. for ping.
>
> ...I'm on it.
Please see https://lists.denx.de/pipermail/u-boot/2025-March/583551.html.
Thanks,
--
Jerome
>
>> Regards,
>> Simon
>
> Thanks,
^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: [PATCH 0/5] net: lwip: root certificates
2025-03-14 22:01 ` Jerome Forissier
@ 2025-03-15 12:47 ` Simon Glass
0 siblings, 0 replies; 30+ messages in thread
From: Simon Glass @ 2025-03-15 12:47 UTC (permalink / raw)
To: Jerome Forissier; +Cc: u-boot, Ilias Apalodimas
Hi Jerome,
On Fri, 14 Mar 2025 at 22:01, Jerome Forissier
<jerome.forissier@linaro.org> wrote:
>
> Hi Simon,
>
> On 3/13/25 14:23, Jerome Forissier wrote:
> >
> >
> > On 3/13/25 13:51, Simon Glass wrote:
> >> Hi Jerome,
> >>
> >> On Fri, 7 Mar 2025 at 10:49, Jerome Forissier
> >> <jerome.forissier@linaro.org> wrote:
> >>>
> >>> Hi Simon,
> >>>
> >>> On 3/4/25 16:46, Simon Glass wrote:
> >>>> Hi Jerome,
> >>>>
> >>>> On Thu, 27 Feb 2025 at 09:43, Jerome Forissier
> >>>> <jerome.forissier@linaro.org> wrote:
> >>>>>
> >>>>>
> >>>>>
> >>>>> On 2/27/25 17:27, Simon Glass wrote:
> >>>>>> Hi Jerome,
> >>>>>>
> >>>>>> On Thu, 27 Feb 2025 at 09:09, Jerome Forissier
> >>>>>> <jerome.forissier@linaro.org> wrote:
> >>>>>>>
> >>>>>>> This series adds support for HTTP server authentication using root (CA)
> >>>>>>> certificates.
> >>>>>>>
> >>>>>>> As a first step, the wget command is extended to support a sub-command:
> >>>>>>> cacert <addr> <size>. The memory region shall contain the CA
> >>>>>>> certificates. With this, it is possible to load the certificates from
> >>>>>>> storage or get them from the network for example, which is convenient
> >>>>>>> for testing at least. The Kconfig symbol for this feature is
> >>>>>>> WGET_CACERT=y.
> >>>>>>>
> >>>>>>> Then new Kconfig symbols are added to support providing the certificates
> >>>>>>> at build time, as a DER or PEM encoded X509 collection:
> >>>>>>> WGET_BUILTIN_CACERT=y and WGET_BUILTIN_CACERT_PATH=<some path>.
> >>>>>>> Note that PEM support requires MBEDTLS_LIB_X509_PEM=y (for the cacert
> >>>>>>> command as well as for the builtin way).
> >>>>>>>
> >>>>>>> Here is a complete example (showing only the relevant output from the
> >>>>>>> various commands):
> >>>>>>>
> >>>>>>> make qemu_arm64_lwip_defconfig
> >>>>>>> wget https://curl.se/ca/cacert.pem
> >>>>>>> echo CONFIG_WGET_BUILTIN_CACERT=y >>.config
> >>>>>>> echo CONFIG_WGET_BUILTIN_CACERT_PATH=cacert.pem >>.config
> >>>>>>> make olddefconfig
> >>>>>>> make -j$(nproc) CROSS_COMPILE="ccache aarch64-linux-gnu-"
> >>>>>>> qemu-system-aarch64 -M virt -nographic -cpu max \
> >>>>>>> -object rng-random,id=rng0,filename=/dev/urandom \
> >>>>>>> -device virtio-rng-pci,rng=rng0 -bios u-boot.bin
> >>>>>>> => dhcp
> >>>>>>> # HTTPS transfer using the builtin CA certificates
> >>>>>>> => wget https://www.google.com/
> >>>>>>> 18724 bytes transferred in 15 ms (1.2 MiB/s)
> >>>>>>> # Disable certificate validation
> >>>>>>> => wget cacert 0 0
> >>>>>>> # Unsafe HTTPS transfer
> >>>>>>> => wget https://www.google.com/
> >>>>>>> WARNING: no CA certificates, HTTPS connections not authenticated
> >>>>>>> 16570 bytes transferred in 15 ms (1.1 MiB/s)
> >>>>>>> # Dowload and apply CA certificates from the net
> >>>>>>> => wget https://curl.se/ca/cacert.pem
> >>>>>>> WARNING: no CA certificates, HTTPS connections not authenticated
> >>>>>>> ##
> >>>>>>> 233263 bytes transferred in 61 ms (3.6 MiB/s)
> >>>>>>> => wget cacert $fileaddr $filesize
> >>>>>>> # Now HTTPS is authenticated against the new CA
> >>>>>>> => wget https://www.google.com/
> >>>>>>> 18743 bytes transferred in 14 ms (1.3 MiB/s)
> >>>>>>> # Drop the certificates again...
> >>>>>>> => wget cacert 0 0
> >>>>>>> # Check that transfer is not secure
> >>>>>>> => wget https://www.google.com/
> >>>>>>> WARNING: no CA certificates, HTTPS connections not authenticated
> >>>>>>> # Restore the builtin CA
> >>>>>>> => wget cacert builtin
> >>>>>>> # No more WARNING
> >>>>>>> => wget https://www.google.com/
> >>>>>>> 18738 bytes transferred in 15 ms (1.2 MiB/s)
> >>>>>>>
> >>>>>>> Jerome Forissier (5):
> >>>>>>> net: lwip: extend wget to support CA (root) certificates
> >>>>>>> lwip: tls: enforce checking of server certificates based on CA
> >>>>>>> availability
> >>>>>>> lwip: tls: warn when no CA exists amd log certificate validation
> >>>>>>> errors
> >>>>>>> net: lwip: add support for built-in root certificates
> >>>>>>> configs: qemu_arm64_lwip_defconfig: enable WGET_CACERT and
> >>>>>>> MBEDTLS_LIB_X509_PEM
> >>>>>>>
> >>>>>>> cmd/Kconfig | 29 ++++++
> >>>>>>> cmd/net-lwip.c | 19 +++-
> >>>>>>> configs/qemu_arm64_lwip_defconfig | 2 +
> >>>>>>> .../src/apps/altcp_tls/altcp_tls_mbedtls.c | 9 +-
> >>>>>>> .../lwip/apps/altcp_tls_mbedtls_opts.h | 6 --
> >>>>>>> lib/mbedtls/Makefile | 3 +
> >>>>>>> lib/mbedtls/mbedtls_def_config.h | 5 ++
> >>>>>>> net/lwip/Makefile | 6 ++
> >>>>>>> net/lwip/wget.c | 90 ++++++++++++++++++-
> >>>>>>> 9 files changed, 158 insertions(+), 11 deletions(-)
> >>>>>>
> >>>>>> Did you manage to add some sandbox tests for lwip?
> >>>>>
> >>>>> Unfortunately not. I am testing mostly with QEMU (qemu_arm64_lwip_defconfig)
> >>>>> and sometimes with KV260 and i.MX93.
> >>>>
> >>>> My understanding was that someone was working on it [1] and I had
> >>>> assumed it was you?
> >>>
> >>> Yes, it is on my TODO list. Higher priority things have kept coming in, but
> >>> hopefully I can resume this work soon.
> >>
> >> Until the tests are added, please stop sending new series for lwip. It
> >> is just going to make it harder to add the tests later.
> >
> > I don't see how exactly it would make things harder, but...
> >
> >> It should not
> >> take long to add a basic test, e.g. for ping.
> >
> > ...I'm on it.
>
> Please see https://lists.denx.de/pipermail/u-boot/2025-March/583551.html.
Thank you for doing that!
Regards,
Simon
^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: [PATCH 0/5] net: lwip: root certificates
2025-02-27 16:09 [PATCH 0/5] net: lwip: root certificates Jerome Forissier
` (6 preceding siblings ...)
2025-02-27 18:06 ` Tom Rini
@ 2025-07-15 4:45 ` Da Xue
2025-07-18 14:08 ` Jerome Forissier
7 siblings, 1 reply; 30+ messages in thread
From: Da Xue @ 2025-07-15 4:45 UTC (permalink / raw)
To: Jerome Forissier; +Cc: u-boot, Ilias Apalodimas
Hi Jerome,
> Then new Kconfig symbols are added to support providing the certificates
> at build time, as a DER or PEM encoded X509 collection:
> WGET_BUILTIN_CACERT=y and WGET_BUILTIN_CACERT_PATH=<some path>.
> Note that PEM support requires MBEDTLS_LIB_X509_PEM=y (for the cacert
> command as well as for the builtin way).
>
> Here is a complete example (showing only the relevant output from the
> various commands):
>
> make qemu_arm64_lwip_defconfig
> wget https://curl.se/ca/cacert.pem
> echo CONFIG_WGET_BUILTIN_CACERT=y >>.config
> echo CONFIG_WGET_BUILTIN_CACERT_PATH=cacert.pem >>.config
> make olddefconfig
> make -j$(nproc) CROSS_COMPILE="ccache aarch64-linux-gnu-"
> qemu-system-aarch64 -M virt -nographic -cpu max \
> -object rng-random,id=rng0,filename=/dev/urandom \
> -device virtio-rng-pci,rng=rng0 -bios u-boot.bin
> => dhcp
> # HTTPS transfer using the builtin CA certificates
> => wget https://www.google.com/
> 18724 bytes transferred in 15 ms (1.2 MiB/s)
> # Disable certificate validation
> => wget cacert 0 0
> # Unsafe HTTPS transfer
> => wget https://www.google.com/
> WARNING: no CA certificates, HTTPS connections not authenticated
> 16570 bytes transferred in 15 ms (1.1 MiB/s)
> # Dowload and apply CA certificates from the net
> => wget https://curl.se/ca/cacert.pem
> WARNING: no CA certificates, HTTPS connections not authenticated
> ##
> 233263 bytes transferred in 61 ms (3.6 MiB/s)
> => wget cacert $fileaddr $filesize
> # Now HTTPS is authenticated against the new CA
> => wget https://www.google.com/
> 18743 bytes transferred in 14 ms (1.3 MiB/s)
> # Drop the certificates again...
> => wget cacert 0 0
> # Check that transfer is not secure
> => wget https://www.google.com/
> WARNING: no CA certificates, HTTPS connections not authenticated
> # Restore the builtin CA
> => wget cacert builtin
> # No more WARNING
> => wget https://www.google.com/
> 18738 bytes transferred in 15 ms (1.2 MiB/s)
Is there a simple way to convert multi-certificate root trust pem to
der? I tried packing it as a PKCS#7 and got "Could not parse
certificates (-8576)"
Best Regards,
Da
^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: [PATCH 0/5] net: lwip: root certificates
2025-07-15 4:45 ` Da Xue
@ 2025-07-18 14:08 ` Jerome Forissier
2025-07-18 17:34 ` Da Xue
0 siblings, 1 reply; 30+ messages in thread
From: Jerome Forissier @ 2025-07-18 14:08 UTC (permalink / raw)
To: Da Xue; +Cc: u-boot, Ilias Apalodimas
Hi Da,
On 7/15/25 06:45, Da Xue wrote:
> Hi Jerome,
>
>> Then new Kconfig symbols are added to support providing the certificates
>> at build time, as a DER or PEM encoded X509 collection:
>> WGET_BUILTIN_CACERT=y and WGET_BUILTIN_CACERT_PATH=<some path>.
>> Note that PEM support requires MBEDTLS_LIB_X509_PEM=y (for the cacert
>> command as well as for the builtin way).
>>
>> Here is a complete example (showing only the relevant output from the
>> various commands):
>>
>> make qemu_arm64_lwip_defconfig
>> wget https://curl.se/ca/cacert.pem
>> echo CONFIG_WGET_BUILTIN_CACERT=y >>.config
>> echo CONFIG_WGET_BUILTIN_CACERT_PATH=cacert.pem >>.config
>> make olddefconfig
>> make -j$(nproc) CROSS_COMPILE="ccache aarch64-linux-gnu-"
>> qemu-system-aarch64 -M virt -nographic -cpu max \
>> -object rng-random,id=rng0,filename=/dev/urandom \
>> -device virtio-rng-pci,rng=rng0 -bios u-boot.bin
>> => dhcp
>> # HTTPS transfer using the builtin CA certificates
>> => wget https://www.google.com/
>> 18724 bytes transferred in 15 ms (1.2 MiB/s)
>> # Disable certificate validation
>> => wget cacert 0 0
>> # Unsafe HTTPS transfer
>> => wget https://www.google.com/
>> WARNING: no CA certificates, HTTPS connections not authenticated
>> 16570 bytes transferred in 15 ms (1.1 MiB/s)
>> # Dowload and apply CA certificates from the net
>> => wget https://curl.se/ca/cacert.pem
>> WARNING: no CA certificates, HTTPS connections not authenticated
>> ##
>> 233263 bytes transferred in 61 ms (3.6 MiB/s)
>> => wget cacert $fileaddr $filesize
>> # Now HTTPS is authenticated against the new CA
>> => wget https://www.google.com/
>> 18743 bytes transferred in 14 ms (1.3 MiB/s)
>> # Drop the certificates again...
>> => wget cacert 0 0
>> # Check that transfer is not secure
>> => wget https://www.google.com/
>> WARNING: no CA certificates, HTTPS connections not authenticated
>> # Restore the builtin CA
>> => wget cacert builtin
>> # No more WARNING
>> => wget https://www.google.com/
>> 18738 bytes transferred in 15 ms (1.2 MiB/s)
>
> Is there a simple way to convert multi-certificate root trust pem to
> der? I tried packing it as a PKCS#7 and got "Could not parse
> certificates (-8576)"
AFAICT MBed TLS should be able to parse multiple root certificates as
long as they are in DER form. U-Boot doesn't enable the PEM format at the
moment, it is less space-efficient. Please try:
openssl x509 -in cert.pem -outform DER -out cert.der
Thanks,
--
Jerome
>
> Best Regards,
> Da
^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: [PATCH 0/5] net: lwip: root certificates
2025-07-18 14:08 ` Jerome Forissier
@ 2025-07-18 17:34 ` Da Xue
0 siblings, 0 replies; 30+ messages in thread
From: Da Xue @ 2025-07-18 17:34 UTC (permalink / raw)
To: Jerome Forissier; +Cc: u-boot, Ilias Apalodimas
On Fri, Jul 18, 2025 at 10:08 AM Jerome Forissier
<jerome.forissier@linaro.org> wrote:
>
> Hi Da,
>
> On 7/15/25 06:45, Da Xue wrote:
> > Hi Jerome,
> >
> >> Then new Kconfig symbols are added to support providing the certificates
> >> at build time, as a DER or PEM encoded X509 collection:
> >> WGET_BUILTIN_CACERT=y and WGET_BUILTIN_CACERT_PATH=<some path>.
> >> Note that PEM support requires MBEDTLS_LIB_X509_PEM=y (for the cacert
> >> command as well as for the builtin way).
> >>
> >> Here is a complete example (showing only the relevant output from the
> >> various commands):
> >>
> >> make qemu_arm64_lwip_defconfig
> >> wget https://curl.se/ca/cacert.pem
> >> echo CONFIG_WGET_BUILTIN_CACERT=y >>.config
> >> echo CONFIG_WGET_BUILTIN_CACERT_PATH=cacert.pem >>.config
> >> make olddefconfig
> >> make -j$(nproc) CROSS_COMPILE="ccache aarch64-linux-gnu-"
> >> qemu-system-aarch64 -M virt -nographic -cpu max \
> >> -object rng-random,id=rng0,filename=/dev/urandom \
> >> -device virtio-rng-pci,rng=rng0 -bios u-boot.bin
> >> => dhcp
> >> # HTTPS transfer using the builtin CA certificates
> >> => wget https://www.google.com/
> >> 18724 bytes transferred in 15 ms (1.2 MiB/s)
> >> # Disable certificate validation
> >> => wget cacert 0 0
> >> # Unsafe HTTPS transfer
> >> => wget https://www.google.com/
> >> WARNING: no CA certificates, HTTPS connections not authenticated
> >> 16570 bytes transferred in 15 ms (1.1 MiB/s)
> >> # Dowload and apply CA certificates from the net
> >> => wget https://curl.se/ca/cacert.pem
> >> WARNING: no CA certificates, HTTPS connections not authenticated
> >> ##
> >> 233263 bytes transferred in 61 ms (3.6 MiB/s)
> >> => wget cacert $fileaddr $filesize
> >> # Now HTTPS is authenticated against the new CA
> >> => wget https://www.google.com/
> >> 18743 bytes transferred in 14 ms (1.3 MiB/s)
> >> # Drop the certificates again...
> >> => wget cacert 0 0
> >> # Check that transfer is not secure
> >> => wget https://www.google.com/
> >> WARNING: no CA certificates, HTTPS connections not authenticated
> >> # Restore the builtin CA
> >> => wget cacert builtin
> >> # No more WARNING
> >> => wget https://www.google.com/
> >> 18738 bytes transferred in 15 ms (1.2 MiB/s)
> >
> > Is there a simple way to convert multi-certificate root trust pem to
> > der? I tried packing it as a PKCS#7 and got "Could not parse
> > certificates (-8576)"
>
> AFAICT MBed TLS should be able to parse multiple root certificates as
> long as they are in DER form. U-Boot doesn't enable the PEM format at the
> moment, it is less space-efficient. Please try:
>
> openssl x509 -in cert.pem -outform DER -out cert.der
This only converts the first certificate to DER, not any of the other
certificates.
>
> Thanks,
> --
> Jerome
>
>
> >
> > Best Regards,
> > Da
Best Regards,
Da
^ permalink raw reply [flat|nested] 30+ messages in thread
end of thread, other threads:[~2025-07-18 17:34 UTC | newest]
Thread overview: 30+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-02-27 16:09 [PATCH 0/5] net: lwip: root certificates Jerome Forissier
2025-02-27 16:09 ` [PATCH 1/5] net: lwip: extend wget to support CA (root) certificates Jerome Forissier
2025-02-28 21:24 ` Ilias Apalodimas
2025-03-05 12:09 ` Jerome Forissier
2025-02-27 16:09 ` [PATCH 2/5] lwip: tls: enforce checking of server certificates based on CA availability Jerome Forissier
2025-02-28 21:26 ` Ilias Apalodimas
2025-03-05 12:27 ` Jerome Forissier
2025-02-27 16:09 ` [PATCH 3/5] lwip: tls: warn when no CA exists amd log certificate validation errors Jerome Forissier
2025-02-28 21:28 ` Ilias Apalodimas
2025-02-27 16:09 ` [PATCH 4/5] net: lwip: add support for built-in root certificates Jerome Forissier
2025-02-27 16:38 ` Jerome Forissier
2025-03-01 6:59 ` Ilias Apalodimas
2025-03-05 12:34 ` Jerome Forissier
2025-02-27 16:09 ` [PATCH 5/5] configs: qemu_arm64_lwip_defconfig: enable WGET_CACERT and MBEDTLS_LIB_X509_PEM Jerome Forissier
2025-02-28 21:28 ` Ilias Apalodimas
2025-02-27 16:27 ` [PATCH 0/5] net: lwip: root certificates Simon Glass
2025-02-27 16:43 ` Jerome Forissier
2025-03-04 15:46 ` Simon Glass
2025-03-07 10:49 ` Jerome Forissier
2025-03-13 12:51 ` Simon Glass
2025-03-13 13:23 ` Jerome Forissier
2025-03-14 22:01 ` Jerome Forissier
2025-03-15 12:47 ` Simon Glass
2025-02-27 18:06 ` Tom Rini
2025-02-27 18:31 ` Jerome Forissier
2025-02-28 7:40 ` Ilias Apalodimas
2025-02-28 11:42 ` Jerome Forissier
2025-07-15 4:45 ` Da Xue
2025-07-18 14:08 ` Jerome Forissier
2025-07-18 17:34 ` Da Xue
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox