Skip to content

Commit 625d048

Browse files
simensrostadrlubos
authored andcommitted
net: samples: http_server: Store TLS credentials to PSA storage
Store TLS credentials to PSA storage. Signed-off-by: Simen S. Røstad <[email protected]>
1 parent c8c8c73 commit 625d048

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

samples/net/http_server/boards/nrf7002dk_nrf5340_cpuapp_ns.conf

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ CONFIG_MBEDTLS_HEAP_SIZE=16384
4646
# DHCPv4
4747
CONFIG_NET_DHCPV4=y
4848

49+
# TLS credentials
50+
CONFIG_TLS_CREDENTIALS_BACKEND_PROTECTED_STORAGE=y
51+
4952
# Shell and Wi-fi Credentials
5053
CONFIG_SHELL=y
5154
CONFIG_NET_SHELL=y

samples/net/http_server/src/credentials_provision.c

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,11 @@ int credentials_provision(void)
2525
TLS_CREDENTIAL_CA_CERTIFICATE,
2626
server_certificate,
2727
sizeof(server_certificate));
28-
if (ret < 0) {
28+
29+
if (ret == -EEXIST) {
30+
LOG_DBG("CA certificate already exists, sec tag: %d",
31+
CONFIG_HTTP_SERVER_SAMPLE_SERVER_CERTIFICATE_SEC_TAG);
32+
} else if (ret < 0) {
2933
LOG_ERR("Failed to register CA certificate: %d", ret);
3034
return ret;
3135
}
@@ -34,15 +38,22 @@ int credentials_provision(void)
3438
TLS_CREDENTIAL_SERVER_CERTIFICATE,
3539
server_certificate,
3640
sizeof(server_certificate));
37-
if (ret < 0) {
41+
if (ret == -EEXIST) {
42+
LOG_DBG("Public certificate already exists, sec tag: %d",
43+
CONFIG_HTTP_SERVER_SAMPLE_SERVER_CERTIFICATE_SEC_TAG);
44+
} else if (ret < 0) {
3845
LOG_ERR("Failed to register public certificate: %d", ret);
3946
return ret;
4047
}
4148

4249
ret = tls_credential_add(CONFIG_HTTP_SERVER_SAMPLE_SERVER_CERTIFICATE_SEC_TAG,
4350
TLS_CREDENTIAL_PRIVATE_KEY,
4451
server_private_key, sizeof(server_private_key));
45-
if (ret < 0) {
52+
53+
if (ret == -EEXIST) {
54+
LOG_DBG("Private key already exists, sec tag: %d",
55+
CONFIG_HTTP_SERVER_SAMPLE_SERVER_CERTIFICATE_SEC_TAG);
56+
} else if (ret < 0) {
4657
LOG_ERR("Failed to register private key: %d", ret);
4758
return ret;
4859
}

0 commit comments

Comments
 (0)