Browse Source
Update the CoAP server sample to demonstrate using DTLS for secure sockets. Signed-off-by: Pieter De Gendt <pieter.degendt@basalte.be>pull/88358/head
14 changed files with 279 additions and 21 deletions
@ -0,0 +1,36 @@ |
|||||||
|
# Copyright (c) 2023, Emna Rekik |
||||||
|
# Copyright (c) 2025, Basalte bv |
||||||
|
# SPDX-License-Identifier: Apache-2.0 |
||||||
|
|
||||||
|
# Config options for CoAP server sample application |
||||||
|
|
||||||
|
mainmenu "CoAP server sample application" |
||||||
|
|
||||||
|
config NET_SAMPLE_COAPS_SERVICE |
||||||
|
bool "Enable CoAP secure service" |
||||||
|
depends on NET_SOCKETS_ENABLE_DTLS || TLS_CREDENTIALS |
||||||
|
|
||||||
|
config NET_SAMPLE_COAP_SERVER_SERVICE_PORT |
||||||
|
int "Port number for CoAP service" |
||||||
|
default 5684 if NET_SAMPLE_COAPS_SERVICE |
||||||
|
default 5683 |
||||||
|
|
||||||
|
if NET_SAMPLE_COAPS_SERVICE |
||||||
|
|
||||||
|
config NET_SAMPLE_PSK_HEADER_FILE |
||||||
|
string "Header file containing PSK" |
||||||
|
default "dummy_psk.h" |
||||||
|
depends on MBEDTLS_KEY_EXCHANGE_PSK_ENABLED |
||||||
|
help |
||||||
|
Name of a header file containing a pre-shared key. |
||||||
|
|
||||||
|
config NET_SAMPLE_CERTS_WITH_SC |
||||||
|
bool "Signed Certificates" |
||||||
|
depends on NET_SOCKETS_SOCKOPT_TLS |
||||||
|
help |
||||||
|
Enable this flag, if you are interested to run this |
||||||
|
application with certificates. |
||||||
|
|
||||||
|
endif |
||||||
|
|
||||||
|
source "Kconfig.zephyr" |
@ -0,0 +1,18 @@ |
|||||||
|
CONFIG_NET_SAMPLE_COAPS_SERVICE=y |
||||||
|
|
||||||
|
# Secure Socket |
||||||
|
CONFIG_NET_SOCKETS_SOCKOPT_TLS=y |
||||||
|
CONFIG_NET_SOCKETS_ENABLE_DTLS=y |
||||||
|
CONFIG_NET_SOCKETS_TLS_MAX_CLIENT_SESSION_COUNT=6 |
||||||
|
CONFIG_NET_SOCKETS_TLS_MAX_CONTEXTS=6 |
||||||
|
CONFIG_NET_SOCKETS_DTLS_TIMEOUT=30000 |
||||||
|
|
||||||
|
# TLS configuration |
||||||
|
CONFIG_MBEDTLS_DEBUG=y |
||||||
|
CONFIG_MBEDTLS=y |
||||||
|
CONFIG_MBEDTLS_BUILTIN=y |
||||||
|
CONFIG_MBEDTLS_ENABLE_HEAP=y |
||||||
|
CONFIG_MBEDTLS_HEAP_SIZE=60000 |
||||||
|
CONFIG_MBEDTLS_SSL_DTLS_CONNECTION_ID=y |
||||||
|
CONFIG_MBEDTLS_SSL_MAX_CONTENT_LEN=2048 |
||||||
|
CONFIG_MBEDTLS_KEY_EXCHANGE_PSK_ENABLED=y |
@ -0,0 +1,43 @@ |
|||||||
|
/*
|
||||||
|
* Copyright (c) 2018 Nordic Semiconductor ASA |
||||||
|
* |
||||||
|
* SPDX-License-Identifier: Apache-2.0 |
||||||
|
*/ |
||||||
|
|
||||||
|
#ifndef __CERTIFICATE_H__ |
||||||
|
#define __CERTIFICATE_H__ |
||||||
|
|
||||||
|
#define SERVER_CERTIFICATE_TAG 1 |
||||||
|
#define PSK_TAG 2 |
||||||
|
|
||||||
|
#if !defined(CONFIG_NET_SAMPLE_CERTS_WITH_SC) |
||||||
|
static const unsigned char server_certificate[] = { |
||||||
|
#include "coaps-server-cert.der.inc" |
||||||
|
}; |
||||||
|
|
||||||
|
/* This is the private key in pkcs#8 format. */ |
||||||
|
static const unsigned char private_key[] = { |
||||||
|
#include "coaps-server-key.der.inc" |
||||||
|
}; |
||||||
|
|
||||||
|
#else |
||||||
|
|
||||||
|
static const unsigned char ca_certificate[] = { |
||||||
|
#include "ca.der.inc" |
||||||
|
}; |
||||||
|
|
||||||
|
static const unsigned char server_certificate[] = { |
||||||
|
#include "server.der.inc" |
||||||
|
}; |
||||||
|
|
||||||
|
/* This is the private key in pkcs#8 format. */ |
||||||
|
static const unsigned char private_key[] = { |
||||||
|
#include "server_privkey.der.inc" |
||||||
|
}; |
||||||
|
#endif |
||||||
|
|
||||||
|
#if defined(CONFIG_MBEDTLS_KEY_EXCHANGE_PSK_ENABLED) |
||||||
|
#include CONFIG_NET_SAMPLE_PSK_HEADER_FILE |
||||||
|
#endif |
||||||
|
|
||||||
|
#endif /* __CERTIFICATE_H__ */ |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -0,0 +1,14 @@ |
|||||||
|
/*
|
||||||
|
* Copyright (c) 2019 Nordic Semiconductor ASA |
||||||
|
* |
||||||
|
* SPDX-License-Identifier: Apache-2.0 |
||||||
|
*/ |
||||||
|
|
||||||
|
#ifndef __DUMMY_PSK_H__ |
||||||
|
#define __DUMMY_PSK_H__ |
||||||
|
|
||||||
|
static const unsigned char psk[] = {0x01, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, |
||||||
|
0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}; |
||||||
|
static const char psk_id[] = "PSK_identity"; |
||||||
|
|
||||||
|
#endif /* __DUMMY_PSK_H__ */ |
Loading…
Reference in new issue