Skip to content

Commit 45c6553

Browse files
mrodgers-witekionashif
authored andcommitted
samples: http_server: consolidate certificate options
Remove the CONFIG_NET_SAMPLE_CERTS_WITH_SC option and make the CA-signed certificate the only option - there is no real downside to this over using the unsigned certificate. Remove adding of CA certificate as a TLS credential on the server, since this credential is not used by the server. It may be useful to include in any client code used to communicate with the server, so the certificate itself is retained. After this, some TLS tag enumerations are unused so have been removed. Signed-off-by: Matt Rodgers <[email protected]>
1 parent 2d60d24 commit 45c6553

File tree

9 files changed

+4
-44
lines changed

9 files changed

+4
-44
lines changed

samples/net/sockets/http_server/CMakeLists.txt

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,15 +54,12 @@ foreach(web_resource
5454
endforeach()
5555

5656
foreach(inc_file
57-
ca.der
58-
server.der
57+
server_cert.der
5958
server_privkey.der
60-
https-server-cert.der
61-
https-server-key.der
6259
)
6360
generate_inc_file_for_target(
6461
app
65-
src/${inc_file}
62+
src/certs/${inc_file}
6663
${gen_dir}/${inc_file}.inc
6764
)
6865
endforeach()

samples/net/sockets/http_server/Kconfig

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,6 @@ config NET_SAMPLE_PSK_HEADER_FILE
3131
Name of a header file containing a
3232
pre-shared key.
3333

34-
config NET_SAMPLE_CERTS_WITH_SC
35-
bool "Signed certificates"
36-
depends on NET_SOCKETS_SOCKOPT_TLS
37-
help
38-
Enable this flag, if you are interested to run this
39-
application with signed certificates and keys.
40-
4134
config NET_SAMPLE_WEBSOCKET_SERVICE
4235
bool "Enable websocket service"
4336
default y if HTTP_SERVER_WEBSOCKET

samples/net/sockets/http_server/src/certificate.h

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,40 +8,20 @@
88
#define __CERTIFICATE_H__
99

1010
enum tls_tag {
11-
/** The Certificate Authority public key */
12-
HTTP_SERVER_CA_CERTIFICATE_TAG,
1311
/** Used for both the public and private server keys */
1412
HTTP_SERVER_CERTIFICATE_TAG,
15-
/** Used for both the public and private client keys */
16-
HTTP_SERVER_CLIENT_CERTIFICATE_TAG,
13+
/* Used for pre-shared key */
1714
PSK_TAG,
1815
};
1916

20-
#if !defined(CONFIG_NET_SAMPLE_CERTS_WITH_SC)
2117
static const unsigned char server_certificate[] = {
22-
#include "https-server-cert.der.inc"
23-
};
24-
25-
/* This is the private key in pkcs#8 format. */
26-
static const unsigned char private_key[] = {
27-
#include "https-server-key.der.inc"
28-
};
29-
30-
#else
31-
32-
static const unsigned char ca_certificate[] = {
33-
#include "ca.der.inc"
34-
};
35-
36-
static const unsigned char server_certificate[] = {
37-
#include "server.der.inc"
18+
#include "server_cert.der.inc"
3819
};
3920

4021
/* This is the private key in pkcs#8 format. */
4122
static const unsigned char private_key[] = {
4223
#include "server_privkey.der.inc"
4324
};
44-
#endif
4525

4626
#if defined(CONFIG_MBEDTLS_KEY_EXCHANGE_PSK_ENABLED)
4727
#include CONFIG_NET_SAMPLE_PSK_HEADER_FILE
File renamed without changes.
File renamed without changes.

samples/net/sockets/http_server/src/server_privkey.der renamed to samples/net/sockets/http_server/src/certs/server_privkey.der

File renamed without changes.
-767 Bytes
Binary file not shown.
-1.19 KB
Binary file not shown.

samples/net/sockets/http_server/src/main.c

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -311,16 +311,6 @@ static void setup_tls(void)
311311
#if defined(CONFIG_NET_SOCKETS_SOCKOPT_TLS)
312312
int err;
313313

314-
#if defined(CONFIG_NET_SAMPLE_CERTS_WITH_SC)
315-
err = tls_credential_add(HTTP_SERVER_CERTIFICATE_TAG,
316-
TLS_CREDENTIAL_CA_CERTIFICATE,
317-
ca_certificate,
318-
sizeof(ca_certificate));
319-
if (err < 0) {
320-
LOG_ERR("Failed to register CA certificate: %d", err);
321-
}
322-
#endif /* defined(CONFIG_NET_SAMPLE_CERTS_WITH_SC) */
323-
324314
err = tls_credential_add(HTTP_SERVER_CERTIFICATE_TAG,
325315
TLS_CREDENTIAL_SERVER_CERTIFICATE,
326316
server_certificate,

0 commit comments

Comments
 (0)