Skip to contentSkip to conversation

net: lwip: root certificates

PATCH Superseded Jerome Forissier 5 participants 30 messages Feb 27, 2025 – Jul 18, 2025 Networking

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover net: lwip: root certificates

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(-)
Signature · 1 line
2.43.0
#1 lore raw

PATCH 1/5 net: lwip: extend wget to support CA (root) certificates

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

---
 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(-)
cmd/Kconfig +15 -0
index 8dd42571abc..a188a2ef24b 100644
@@ -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
cmd/net-lwip.c +12 -3
index 0fd446ecb20..0672f48a7a8 100644
@@ -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
lib/mbedtls/Makefile +3 -0
index e66c2018d97..8a0a984e149 100644
@@ -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
lib/mbedtls/mbedtls_def_config.h +5 -0
index fd440c392f9..7b6a7f482f0 100644
@@ -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 */
net/lwip/wget.c +54 -1

73 lines not on this page · raw message

Signature · 1 line
2.43.0
#2 lore raw

Re: [PATCH 1/5] net: lwip: extend wget to support CA (root) certificates

Hi Jerome

Quoted 7 lines
cmd/Kconfig +6 -0
+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

cmd/Kconfig config WGET_HTTPS · line 2195

Quoted 10 lines
cmd/Kconfig +9 -0
+         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?

[...]

Quoted 3 lines

}

+#if defined CONFIG_WGET_HTTPS

you can do #if IS_ENABLED() here

Quoted 10 lines
net/lwip/wget.c +10 -0
+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;

net/lwip/wget.c static err_t httpc_headers_done_cb(httpc_state_t *connection, void *arg, struct · line 308

Quoted 10 lines
net/lwip/wget.c +10 -0
+
+       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?

Quoted 13 lines
net/lwip/wget.c +13 -0
+               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);

net/lwip/wget.c static err_t httpc_headers_done_cb(httpc_state_t *connection, void *arg, struct · line 331

Quoted 10 lines
net/lwip/wget.c +10 -0
+       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

#3 lore raw

Re: [PATCH 1/5] net: lwip: extend wget to support CA (root) certificates

Hi Ilias,

Quoted 13 lines · Ilias Apalodimas

Hi Jerome

Quoted 11 lines
cmd/Kconfig +10 -0
+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
Quoted 8 lines

cmd/Kconfig config WGET_HTTPS · line 2195

Quoted 6 lines
cmd/Kconfig +5 -0
+       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.

Quoted 8 lines

[...]

Quoted 3 lines

}

+#if defined CONFIG_WGET_HTTPS

you can do #if IS_ENABLED() here

Better yet: #if CONFIG_IS_ENABLED(WGET_HTTPS) I suppose.

Quoted 16 lines
Quoted 16 lines
net/lwip/wget.c +16 -0
+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);
Quoted 8 lines

net/lwip/wget.c static err_t httpc_headers_done_cb(httpc_state_t *connection, void *arg, struct · line 308

Quoted 4 lines
net/lwip/wget.c +4 -0
+       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,

Signature · 1 line
Jerome
#4 lore raw

PATCH 2/5 lwip: tls: enforce checking of server certificates based on CA availability

In reply to Jerome Forissier

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.

---
 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(-)
lib/lwip/lwip/src/apps/altcp_tls/altcp_tls_mbedtls.c +2 -1
index 46421588fef..fa3d1d74fed 100644
@@ -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
lib/lwip/lwip/src/include/lwip/apps/altcp_tls_mbedtls_opts.h +0 -6
index e41301c061c..71aa5993935 100644
@@ -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 */
Signature · 1 line
2.43.0
Reviewed-by on v1 2/5
#5 lore raw

Re: [PATCH 2/5] lwip: tls: enforce checking of server certificates based on CA availability

Hi Jerome

++CC Simon for lwIP

Quoted 8 lines · Jerome Forissier

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

Quoted 48 lines
---
 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(-)
lib/lwip/lwip/src/apps/altcp_tls/altcp_tls_mbedtls.c +2 -1
index 46421588fef..fa3d1d74fed 100644
@@ -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
lib/lwip/lwip/src/include/lwip/apps/altcp_tls_mbedtls_opts.h +0 -7
index e41301c061c..71aa5993935 100644
@@ -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

#6 lore raw

Re: [PATCH 2/5] lwip: tls: enforce checking of server certificates based on CA availability

Hi Ilias,

Quoted 15 lines · Ilias Apalodimas

Hi Jerome

++CC Simon for lwIP

Quoted 8 lines · Jerome Forissier

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

Quoted 2 lines

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

Quoted 2 lines

Thanks!

Signature · 1 line
Jerome
Quoted 49 lines
Quoted 49 lines
---
 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(-)
lib/lwip/lwip/src/apps/altcp_tls/altcp_tls_mbedtls.c +2 -1
index 46421588fef..fa3d1d74fed 100644
@@ -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
lib/lwip/lwip/src/include/lwip/apps/altcp_tls_mbedtls_opts.h +0 -7
index e41301c061c..71aa5993935 100644
@@ -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

#7 lore raw

PATCH 3/5 lwip: tls: warn when no CA exists amd log certificate validation errors

In reply to Jerome Forissier

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).

---
 lib/lwip/lwip/src/apps/altcp_tls/altcp_tls_mbedtls.c | 6 ++++++
 1 file changed, 6 insertions(+)
lib/lwip/lwip/src/apps/altcp_tls/altcp_tls_mbedtls.c +6 -0
index fa3d1d74fed..ef51a5ac168 100644
@@ -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);
Signature · 1 line
2.43.0
Reviewed-by on v1 3/5
#8 lore raw

Re: [PATCH 3/5] lwip: tls: warn when no CA exists amd log certificate validation errors

+CC Simon again

Same comments. The patch is nice we should somehow get it in lwIP

Quoted 7 lines · Jerome Forissier

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).

Quoted 31 lines
---
 lib/lwip/lwip/src/apps/altcp_tls/altcp_tls_mbedtls.c | 6 ++++++
 1 file changed, 6 insertions(+)
lib/lwip/lwip/src/apps/altcp_tls/altcp_tls_mbedtls.c +6 -1
index fa3d1d74fed..ef51a5ac168 100644
@@ -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

#9 lore raw

PATCH 4/5 net: lwip: add support for built-in root certificates

In reply to Jerome Forissier

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)

---
 cmd/Kconfig       | 16 +++++++++++++-
 cmd/net-lwip.c    |  4 ++++
 net/lwip/Makefile |  6 ++++++
 net/lwip/wget.c   | 53 +++++++++++++++++++++++++++++++++++++++--------
 4 files changed, 69 insertions(+), 10 deletions(-)
cmd/Kconfig +15 -1
index a188a2ef24b..cb3cc859616 100644
@@ -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
cmd/net-lwip.c +4 -0
index 0672f48a7a8..a848d0b1dcf 100644
@@ -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
net/lwip/Makefile +6 -0
index 79dd6b3fb50..950c5316bb9 100644
@@ -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
net/lwip/wget.c +44 -9

97 lines not on this page · raw message

Signature · 1 line
2.43.0
#10 lore raw

Re: [PATCH 4/5] net: lwip: add support for built-in root certificates

Sorry for replying to myself, I spotted a small mistake.

Quoted 123 lines · Jerome Forissier

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)

---
 cmd/Kconfig       | 16 +++++++++++++-
 cmd/net-lwip.c    |  4 ++++
 net/lwip/Makefile |  6 ++++++
 net/lwip/wget.c   | 53 +++++++++++++++++++++++++++++++++++++++--------
 4 files changed, 69 insertions(+), 10 deletions(-)
cmd/Kconfig +15 -1
index a188a2ef24b..cb3cc859616 100644
@@ -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
cmd/net-lwip.c +4 -0
index 0672f48a7a8..a848d0b1dcf 100644
@@ -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
net/lwip/Makefile +6 -0
index 79dd6b3fb50..950c5316bb9 100644
@@ -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
net/lwip/wget.c +9 -5
index 14466598d7c..f24aa9c2380 100644
@@ -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);

net/lwip/wget.c static err_t httpc_headers_done_cb(httpc_state_t *connection, void *arg, struct · line 314

Quoted 10 lines
net/lwip/wget.c +0 -4
-	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...

Quoted 22 lines
net/lwip/wget.c +12 -0
+	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);
+}

net/lwip/wget.c static int set_cacert(char * const saddr, char * const ssz) · line 354

Quoted 10 lines
net/lwip/wget.c +8 -0
 #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.

Quoted 32 lines
net/lwip/wget.c +15 -0
+
+	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)
#11 lore raw

Re: [PATCH 4/5] net: lwip: add support for built-in root certificates

Hi Jerome,

Quoted 8 lines · Jerome Forissier

Sorry for replying to myself, I spotted a small mistake.

Quoted 4 lines · Jerome Forissier

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?

[...]

Quoted 30 lines
Quoted 30 lines
cmd/net-lwip.c +4 -0
@@ -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
net/lwip/Makefile +6 -0
index 79dd6b3fb50..950c5316bb9 100644
@@ -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
net/lwip/wget.c +0 -1
index 14466598d7c..f24aa9c2380 100644
--- a/net/lwip/wget.c
Quoted 8 lines

net/lwip/wget.c static err_t httpc_headers_done_cb(httpc_state_t *connection, void *arg, struct · line 293

Quoted 8 lines

+++ b/net/lwip/wget.c

net/lwip/wget.c +3 -0
@@ -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

Quoted 69 lines
Quoted 20 lines
net/lwip/wget.c +6 -5
+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);

net/lwip/wget.c static err_t httpc_headers_done_cb(httpc_state_t *connection, void *arg, struct · line 314

Quoted 10 lines
net/lwip/wget.c +0 -4
-     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...

Quoted 22 lines
net/lwip/wget.c +12 -0
+     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);
+}

net/lwip/wget.c static int set_cacert(char * const saddr, char * const ssz) · line 354

Quoted 10 lines
net/lwip/wget.c +8 -0
 #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.

Quoted 5 lines

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

#12 lore raw

Re: [PATCH 4/5] net: lwip: add support for built-in root certificates

Hi Ilias,

Quoted 8 lines · Ilias Apalodimas

Hi Jerome,

Quoted 4 lines · Jerome Forissier

Sorry for replying to myself, I spotted a small mistake.

On 2/27/25 17:09, Jerome Forissier wrote:

Quoted 8 lines
Quoted 4 lines
Quoted 4 lines

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.

Quoted 36 lines

[...]

Quoted 32 lines
Quoted 32 lines
cmd/net-lwip.c +4 -0
@@ -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
net/lwip/Makefile +6 -0
index 79dd6b3fb50..950c5316bb9 100644
@@ -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
net/lwip/wget.c +0 -0
index 14466598d7c..f24aa9c2380 100644
@@ -288,31 +288,34 @@ static err_t httpc_headers_done_cb(httpc_state_t *connection, void *arg, struct
Quoted 8 lines
Quoted 6 lines

net/lwip/wget.c static err_t httpc_headers_done_cb(httpc_state_t *connection, void *arg, struct · line 293

Quoted 6 lines
net/lwip/wget.c +3 -0
 #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.

Quoted 70 lines
Quoted 70 lines
Quoted 21 lines
net/lwip/wget.c +6 -5
+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);

net/lwip/wget.c static err_t httpc_headers_done_cb(httpc_state_t *connection, void *arg, struct · line 314

Quoted 10 lines
net/lwip/wget.c +0 -4
-     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...

Quoted 22 lines
net/lwip/wget.c +12 -0
+     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);
+}

net/lwip/wget.c static int set_cacert(char * const saddr, char * const ssz) · line 354

Quoted 10 lines
net/lwip/wget.c +8 -0
 #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.

Quoted 7 lines
Quoted 5 lines

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,

Signature · 1 line
Jerome
Quoted 3 lines

Thanks
/Ilias

#13 lore raw

PATCH 5/5 configs: qemu_arm64_lwip_defconfig: enable WGET_CACERT and MBEDTLS_LIB_X509_PEM

In reply to Jerome Forissier

Enable the "wget cacert" command as well as support for parsing X509 certificates in PEM format.

---
 configs/qemu_arm64_lwip_defconfig | 2 ++
 1 file changed, 2 insertions(+)
configs/qemu_arm64_lwip_defconfig +2 -0
index 754c770c33f..f48c132743c 100644
@@ -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
Signature · 1 line
2.43.0
Reviewed-by on v1 5/5
#14 lore raw

Re: [PATCH 5/5] configs: qemu_arm64_lwip_defconfig: enable WGET_CACERT and MBEDTLS_LIB_X509_PEM

Quoted 20 lines · Jerome Forissier

Enable the "wget cacert" command as well as support for parsing X509 certificates in PEM format.

---
 configs/qemu_arm64_lwip_defconfig | 2 ++
 1 file changed, 2 insertions(+)
configs/qemu_arm64_lwip_defconfig +2 -1
index 754c770c33f..f48c132743c 100644
@@ -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
--
Quoted 2 lines

2.43.0

#15 lore raw
In reply to Jerome Forissier

Hi Jerome,

Quoted 69 lines · 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
Quoted 10 lines
 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

#16 lore raw
Quoted 84 lines · Simon Glass

Hi Jerome,

Quoted 69 lines · 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
Quoted 10 lines
 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(-)
Quoted 1 line

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,

Signature · 1 line
Jerome
#17 lore raw

Hi Jerome,

Quoted 88 lines · Jerome Forissier
Quoted 84 lines · Simon Glass

Hi Jerome,

Quoted 79 lines · 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(-)
Quoted 4 lines
Quoted 1 line

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/

#18 lore raw

Hi Simon,

Quoted 92 lines · Simon Glass

Hi Jerome,

Quoted 88 lines · Jerome Forissier
Quoted 84 lines · Simon Glass

Hi Jerome,

Quoted 79 lines · 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(-)
Quoted 7 lines
Quoted 4 lines
Quoted 1 line

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,

Signature · 1 line
Jerome
Quoted 5 lines

Regards,
SImon

[1] https://lore.kernel.org/u-boot/CAC_iWjKMo7=RE3=1=y3MpgC95itO170ruJYk6omh-4NuAJ8SRA@mail.gmail.com/

#19 lore raw

Hi Jerome,

Quoted 98 lines · Jerome Forissier

Hi Simon,

Quoted 94 lines · Simon Glass

Hi Jerome,

Quoted 90 lines · Jerome Forissier
Quoted 85 lines · Simon Glass

Hi Jerome,

Quoted 69 lines · 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
Quoted 10 lines
 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?

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

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

#20 lore raw
Quoted 105 lines · Simon Glass

Hi Jerome,

Quoted 101 lines · Jerome Forissier

Hi Simon,

Quoted 97 lines · Simon Glass

Hi Jerome,

Quoted 92 lines · Jerome Forissier
Quoted 84 lines · Simon Glass

Hi Jerome,

Quoted 69 lines · 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
Quoted 10 lines
 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(-)
Quoted 1 line

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.

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

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...

Quoted 2 lines

It should not
take long to add a basic test, e.g. for ping.

...I'm on it.

Quoted 2 lines

Regards,
Simon

Thanks,

Signature · 1 line
Jerome
#21 lore raw

Hi Simon,

Quoted 117 lines · Jerome Forissier
Quoted 105 lines · Simon Glass

Hi Jerome,

Quoted 101 lines · Jerome Forissier

Hi Simon,

Quoted 97 lines · Simon Glass

Hi Jerome,

Quoted 92 lines · Jerome Forissier
Quoted 84 lines · Simon Glass

Hi Jerome,

Quoted 69 lines · 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
Quoted 10 lines
 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(-)
Quoted 1 line

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.

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

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.

Quoted 6 lines

I don't see how exactly it would make things harder, but...

Quoted 2 lines

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,

Signature · 1 line
Jerome
Quoted 5 lines
Quoted 3 lines

Regards,
Simon

Thanks,

#22 lore raw

Hi Jerome,

Quoted 121 lines · Jerome Forissier

Hi Simon,

Quoted 117 lines · Jerome Forissier
Quoted 113 lines · Simon Glass

Hi Jerome,

Quoted 98 lines · Jerome Forissier

Hi Simon,

Quoted 94 lines · Simon Glass

Hi Jerome,

Quoted 90 lines · Jerome Forissier
Quoted 85 lines · Simon Glass

Hi Jerome,

Quoted 69 lines · 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
Quoted 10 lines
 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?

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

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.

Quoted 8 lines
Quoted 6 lines

I don't see how exactly it would make things harder, but...

Quoted 2 lines

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

#23 lore raw
In reply to Jerome Forissier
Quoted 49 lines · 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

Quoted 8 lines

# 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!

Signature · 1 line
Tom
#24 lore raw
Quoted 60 lines · Tom Rini
Quoted 49 lines · 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

Quoted 8 lines

# 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)

Quoted 2 lines

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,

Signature · 1 line
Jerome
#25 lore raw

Hi Jerome,

Quoted 16 lines · Jerome Forissier
Quoted 12 lines · Tom Rini
Quoted 10 lines · 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.

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

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

#26 lore raw

Hi Ilias,

Quoted 26 lines · Ilias Apalodimas

Hi Jerome,

Quoted 16 lines · Jerome Forissier
Quoted 12 lines · Tom Rini
Quoted 10 lines · 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.

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

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).

Quoted 8 lines

[...]

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,

Signature · 1 line
Jerome
#27 lore raw
In reply to Jerome Forissier

Hi Jerome,

Quoted 39 lines

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

Quoted 8 lines

# 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

#28 lore raw

Hi Da,

Quoted 50 lines · Da Xue

Hi Jerome,

Quoted 39 lines

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

Quoted 8 lines

# 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)

Quoted 3 lines

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,

Signature · 1 line
Jerome
Quoted 3 lines

Best Regards,
Da

#29 lore raw
Quoted 58 lines · Jerome Forissier

Hi Da,

Quoted 50 lines · Da Xue

Hi Jerome,

Quoted 39 lines

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

Quoted 8 lines

# 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)

Quoted 3 lines

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)"

Quoted 5 lines

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.

Quoted 9 lines

Thanks,
--
Jerome

Quoted 3 lines

Best Regards,
Da

Best Regards,
Da