Skip to content

Commit bd83c19

Browse files
mrodgers-witekionashif
authored andcommitted
samples: http_server: update cipher suites and certificates
Existing cipher suites and certificates used by HTTP server sample are included in RFC9113 Appendix A: Prohibited TLS 1.2 Cipher Suites. The RFC specifies that when using HTTP/2, these cipher suites may be treated as an error of type INADEQUATE_SECURITY, and in practice it seems that Chrome and Firefox do implement this. The certificates have been updated to use ECDSA-P265 signatures, and supported cipher suites updated to include ECDH key exchange and AES GCM and CCM modes. Some scripts are included to allow users to generate their own certificates if desired. Signed-off-by: Matt Rodgers <[email protected]>
1 parent 45c6553 commit bd83c19

File tree

8 files changed

+103
-0
lines changed

8 files changed

+103
-0
lines changed

samples/net/sockets/http_server/CMakeLists.txt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,20 @@ if(CONFIG_NET_SOCKETS_SOCKOPT_TLS AND
2020
add_dependencies(app development_psk)
2121
endif()
2222

23+
set(CERTS_DIR ${CMAKE_CURRENT_SOURCE_DIR}/src/certs)
24+
25+
add_custom_target(sample_ca_cert
26+
WORKING_DIRECTORY ${CERTS_DIR}
27+
COMMAND sh gen_ca_cert.sh
28+
COMMENT "Generating sample CA certificate"
29+
)
30+
31+
add_custom_target(sample_server_cert
32+
WORKING_DIRECTORY ${CERTS_DIR}
33+
COMMAND sh gen_server_cert.sh
34+
COMMENT "Generating sample server certificate"
35+
)
36+
2337
option(INCLUDE_HTML_CONTENT "Include the HTML content" ON)
2438

2539
target_sources(app PRIVATE src/main.c)

samples/net/sockets/http_server/prj.conf

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,14 @@ CONFIG_NET_SOCKETS_SOCKOPT_TLS=y
6969
CONFIG_NET_SOCKETS_TLS_MAX_CONTEXTS=6
7070
CONFIG_TLS_CREDENTIALS=y
7171
CONFIG_TLS_MAX_CREDENTIALS_NUMBER=5
72+
CONFIG_MBEDTLS_ECDH_C=y
73+
CONFIG_MBEDTLS_ECDSA_C=y
74+
CONFIG_MBEDTLS_ECP_C=y
75+
CONFIG_MBEDTLS_ECP_DP_SECP256R1_ENABLED=y
76+
CONFIG_MBEDTLS_KEY_EXCHANGE_RSA_ENABLED=n
77+
CONFIG_MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED=y
78+
CONFIG_MBEDTLS_CIPHER_CCM_ENABLED=y
79+
CONFIG_MBEDTLS_CIPHER_GCM_ENABLED=y
7280

7381
# Networking tweaks
7482
# Required to handle large number of consecutive connections,
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
*.pem
2+
!ca_cert.pem
3+
*.ext
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
-----BEGIN CERTIFICATE-----
2+
MIIB5DCCAYmgAwIBAgIUXHpFEmhwtzDyteoz+ZSOhyQ6xzUwCgYIKoZIzj0EAwIw
3+
RjEWMBQGA1UECgwNWmVwaHlycHJvamVjdDEsMCoGA1UEAwwjWmVwaHlycHJvamVj
4+
dCBTYW1wbGUgRGV2ZWxvcG1lbnQgQ0EwIBcNMjQxMTI3MTE1ODUwWhgPMjEyNDEx
5+
MDMxMTU4NTBaMEYxFjAUBgNVBAoMDVplcGh5cnByb2plY3QxLDAqBgNVBAMMI1pl
6+
cGh5cnByb2plY3QgU2FtcGxlIERldmVsb3BtZW50IENBMFkwEwYHKoZIzj0CAQYI
7+
KoZIzj0DAQcDQgAEvCX35MoLVdt4STWeomwFjuLV8nAz+K1IIc5PrfD9nVhLZfOS
8+
Z35O9dTEMvn1dP2MqUqjL6wWA3oSnvItU81qD6NTMFEwHQYDVR0OBBYEFNFC9qd/
9+
SSYq7aDvLGsc4Fu7Fn5cMB8GA1UdIwQYMBaAFNFC9qd/SSYq7aDvLGsc4Fu7Fn5c
10+
MA8GA1UdEwEB/wQFMAMBAf8wCgYIKoZIzj0EAwIDSQAwRgIhALWzu1PtNJYu9sWb
11+
A2iBixJuoK7y8EqCkGDp0e66mA+qAiEAyz7YdO7zhcHWgaUXqLwlVqe5cstVMsLv
12+
4TbLwQi+wfI=
13+
-----END CERTIFICATE-----
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Copyright (c) 2024, Witekio
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
# Generate a root CA private key
5+
openssl ecparam \
6+
-name prime256v1 \
7+
-genkey \
8+
-out ca_privkey.pem
9+
10+
# Generate a root CA certificate using private key
11+
openssl req \
12+
-new \
13+
-x509 \
14+
-days 36500 \
15+
-key ca_privkey.pem \
16+
-out ca_cert.pem \
17+
-subj "/O=Zephyrproject/CN=Zephyrproject Sample Development CA"
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# Copyright (c) 2024, Witekio
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
# Generate a server private key
5+
openssl ecparam \
6+
-name prime256v1 \
7+
-genkey \
8+
-out server_privkey.pem
9+
10+
# Generate a certificate signing request using server key
11+
openssl req \
12+
-new \
13+
-sha256 \
14+
-key server_privkey.pem \
15+
-out server_csr.pem \
16+
-subj "/O=Zephyrproject/CN=zephyr"
17+
18+
# Create a file containing server CSR extensions
19+
echo "subjectKeyIdentifier=hash" > server_csr.ext
20+
echo "authorityKeyIdentifier=keyid,issuer" >> server_csr.ext
21+
echo "basicConstraints=critical,CA:FALSE" >> server_csr.ext
22+
echo "keyUsage=critical,digitalSignature" >> server_csr.ext
23+
echo "extendedKeyUsage=serverAuth" >> server_csr.ext
24+
echo "subjectAltName=DNS:zephyr.local,IP.1:192.0.2.1,IP.2:2001:db8::1" >> server_csr.ext
25+
26+
# Create a server certificate by signing the server CSR using the CA cert/key
27+
openssl x509 \
28+
-req \
29+
-sha256 \
30+
-CA ca_cert.pem \
31+
-CAkey ca_privkey.pem \
32+
-days 36500 \
33+
-CAcreateserial \
34+
-CAserial ca.srl \
35+
-in server_csr.pem \
36+
-out server_cert.pem \
37+
-extfile server_csr.ext
38+
39+
# Create DER encoded versions of server certificate and private key
40+
openssl ec \
41+
-outform der \
42+
-in server_privkey.pem \
43+
-out server_privkey.der
44+
45+
openssl x509 \
46+
-outform der \
47+
-in server_cert.pem \
48+
-out server_cert.der
-150 Bytes
Binary file not shown.
-1.07 KB
Binary file not shown.

0 commit comments

Comments
 (0)