1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

tests/nanocoap_cli: add DTLS support

This commit is contained in:
Benjamin Valentin 2022-10-11 12:20:50 +02:00 committed by Benjamin Valentin
parent d660e3ebbd
commit 8379bb7d4a
3 changed files with 77 additions and 3 deletions

View File

@ -22,22 +22,27 @@ LOW_MEMORY_BOARDS := \
blackpill-stm32f103c8 \
bluepill-stm32f103c8 \
derfmega128 \
im880b \
nucleo-f302r8 \
saml10-xpro \
saml11-xpro \
spark-core \
stm32f7508-dk \
stm32mp157c-dk2 \
#
# Don't enable VFS functions on small boards
# Don't enable VFS, DTLS functions on small boards
ifeq (,$(filter $(BOARD),$(LOW_MEMORY_BOARDS)))
USEMODULE += nanocoap_dtls
USEMODULE += prng_sha256prng
USEMODULE += nanocoap_vfs
USEMODULE += vfs_default
# USEMODULE += vfs_auto_format
USEMODULE += shell_cmds_default
# VFS operations require more stack on the main thread
CFLAGS += -DTHREAD_STACKSIZE_MAIN=THREAD_STACKSIZE_LARGE
# DTLS and VFS operations require more stack on the main thread
CFLAGS += -DTHREAD_STACKSIZE_MAIN=\(3*THREAD_STACKSIZE_DEFAULT\)
# always enable auto-format for native
ifeq ($(BOARD),native)

View File

@ -21,6 +21,7 @@
#include <stdio.h>
#include "msg.h"
#include "net/nanocoap_sock.h"
#include "net/gnrc/netif.h"
#include "net/ipv6/addr.h"
#include "shell.h"
@ -28,6 +29,25 @@
#define MAIN_QUEUE_SIZE (4)
static msg_t _main_msg_queue[MAIN_QUEUE_SIZE];
#if IS_USED(MODULE_NANOCOAP_DTLS)
#include "net/credman.h"
#include "net/dsm.h"
#include "tinydtls_keys.h"
static const uint8_t psk_id_0[] = PSK_DEFAULT_IDENTITY;
static const uint8_t psk_key_0[] = PSK_DEFAULT_KEY;
static const credman_credential_t credential = {
.type = CREDMAN_TYPE_PSK,
.tag = CONFIG_NANOCOAP_SOCK_DTLS_TAG,
.params = {
.psk = {
.key = { .s = psk_key_0, .len = sizeof(psk_key_0) - 1, },
.id = { .s = psk_id_0, .len = sizeof(psk_id_0) - 1, },
}
},
};
#endif
extern int nanotest_client_cmd(int argc, char **argv);
extern int nanotest_client_url_cmd(int argc, char **argv);
extern int nanotest_server_cmd(int argc, char **argv);
@ -121,6 +141,14 @@ int main(void)
msg_init_queue(_main_msg_queue, MAIN_QUEUE_SIZE);
puts("nanocoap test app");
#if IS_USED(MODULE_NANOCOAP_DTLS)
int res = credman_add(&credential);
if (res < 0 && res != CREDMAN_EXIST) {
printf("nanocoap: cannot add credential to system: %d\n", res);
return res;
}
#endif
/* start shell */
puts("All up, running the shell now");
char line_buf[SHELL_DEFAULT_BUFSIZE];

View File

@ -0,0 +1,41 @@
/*
* Copyright (C) 2018 Inria
*
* This file is subject to the terms and conditions of the GNU Lesser
* General Public License v2.1. See the file LICENSE in the top level
* directory for more details.
*/
/**
* @ingroup examples
* @{
*
* @file
* @brief PSK and RPK keys for the dtls-sock example.
*
* @author Raul Fuentes <raul.fuentes-samaniego@inria.fr>
*
* @}
*/
#ifndef TINYDTLS_KEYS_H
#define TINYDTLS_KEYS_H
#ifdef __cplusplus
extern "C" {
#endif
/*
* Default keys examples for tinyDTLS (for RIOT, Linux and Contiki)
*/
#define PSK_DEFAULT_IDENTITY "Client_identity"
#define PSK_DEFAULT_KEY "secretPSK"
#define PSK_OPTIONS "i:k:"
#define PSK_ID_MAXLEN 32
#define PSK_MAXLEN 32
#ifdef __cplusplus
}
#endif
#endif /* TINYDTLS_KEYS_H */