Skip to content

Commit 92b54c5

Browse files
committed
Fix review comments
1 parent d8c310d commit 92b54c5

File tree

3 files changed

+26
-22
lines changed

3 files changed

+26
-22
lines changed

pico_w/wifi/dtls/README.md

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Setup
22

33
These examples demonstrate how to use dtls via mbedtls on a Pico W device.
4-
You need to define DTLS_SERVER and run the makecerts.sh script to generate the certificates and keys needed for the server and client.
4+
You need to define DTLS_SERVER and run the `makecerts.sh` script to generate the certificates and keys needed for the server and client.
55
```
66
export DTLS_SERVER=myserver
77
cd dtls/certs
@@ -12,36 +12,34 @@ The examples should now build.
1212
# Running the dtls examples
1313

1414
The client connects to a server and sends it a few lines of text which it expects to be sent back.
15-
16-
You can build and run the client and server examples on two Pico W devices. To make testing easier to test with just one Pico W device, you can run the server or client on a Linux host.
17-
The client.sh and server.sh scripts show how to run the client or server with openssl. The host folder contains source code for a version of the client and server using mbedtls.
15+
You can build and run the client and server examples on two Pico W devices, or to test with just one Pico W device, you can run the server or client on a Linux host.
1816

1917
## Using openssl
2018

21-
The host/server.sh and host/client/sh scripts demonstrate how to use DTLS with openssl, although you will have to echo text manually.
22-
For example, run dtls_echo_client on a Pico W device and the server.sh on a linux PC.
19+
The `host/server.sh` and `host/client.sh` scripts demonstrate how to use DTLS with openssl, although you will have to echo text manually.
20+
For example, run dtls_echo_client on a Pico W device and the `server.sh` on a linux host.
2321
```
2422
export DTLS_SERVER=myserver
2523
cd host
2624
./server.sh
2725
```
2826
The scripts use the keys in certs/myserver
2927

30-
Or run dtls_echo_server on a Pico W device and client.sh on a linux PC. The host name for the server on Pico W is set to `pico_dtls_example`"`. Make sure you build the code for the Pico W and run the client with the right DTLS_SERVER name (and matching keys in the client and server) or else the SSL handshake will fail.
28+
Or run dtls_echo_server on a Pico W device and `client.sh` on a linux host. The host name for the server on Pico W is set to `pico_dtls_example`. Make sure you build the code for the Pico W and run the client with the right DTLS_SERVER name (and matching keys in the client and server) or else the SSL handshake will fail.
3129
```
3230
export DTLS_SERVER=pico_dtls_example
3331
ping pico_dtls_example # make sure you can reach it!
3432
cd host
3533
./client.sh
3634
```
37-
The scripts use the keys in certs/pico_dtls_example. Type a sentence into the client.sh console and the server should send it back as a reply.
35+
The scripts use the keys in certs/pico_dtls_example. Type a sentence into the `client.sh` console and the server should send it back as a reply.
3836

3937
## Using mbedtls
4038

4139
The host folder contains C versions of the examples that can be compiled natively for the host. They are modified versions of mbedtls examples.
42-
You can build these on a rpi linux device to act as the server or client. The mbedtls library in PICO_SDK_PATH will be used to build the host code.
40+
If you are building the server or client on a linux host, the mbedtls library in PICO_SDK_PATH will be used to build the code.
4341

44-
For example, run dtls_echo_client on a Pico W device and the dtls_host_echo_server on a linux PC.
42+
For example, run dtls_echo_client on a Pico W device and the dtls_host_echo_server on a linux host.
4543
```
4644
export DTLS_SERVER=myserver
4745
cd host
@@ -52,7 +50,7 @@ make -j8
5250
./dtls_host_echo_server
5351
5452
```
55-
Or run dtls_echo_server on a Pico W device and dtls_host_echo_client on a linux PC.
53+
Or run dtls_echo_server on a Pico W device and dtls_host_echo_client on a linux host.
5654
```
5755
export DTLS_SERVER=pico_dtls_example
5856
cd host
@@ -62,4 +60,4 @@ cmake ..
6260
make -j8
6361
./dtls_host_echo_client
6462
```
65-
Remember to build the client and server for the host and Pico W with the correct value of DTLS_SERVER or else the handshake will fail.
63+
Remember to build the client and server for the linux host and Pico W with the correct value of DTLS_SERVER or else the handshake will fail.

pico_w/wifi/dtls/certs/makecerts.sh

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#!/usr/bin/bash
2+
set -e
23

34
if [ "${PWD##*/}" != "certs" ]; then
45
echo Run this in the certs folder
@@ -8,6 +9,11 @@ if [ -z "$DTLS_SERVER" ]; then
89
echo Define DTLS_SERVER
910
exit 1
1011
fi
12+
if ! command -v openssl 2>&1 >/dev/null; then
13+
echo openssl could not be found
14+
exit 1
15+
fi
16+
1117
SERVER_NAME=$DTLS_SERVER
1218

1319
if [ -d "$SERVER_NAME" ]; then
@@ -30,27 +36,23 @@ openssl x509 -req -in $SERVER_NAME/client.csr -CA $SERVER_NAME/ca.crt -CAkey $SE
3036

3137
echo -n \#define DTLS_ROOT_CERT \" > $SERVER_NAME/dtls_client.inc
3238
cat $SERVER_NAME/ca.crt | awk '{printf "%s\\n\\\n", $0}' >> $SERVER_NAME/dtls_client.inc
33-
echo "\"" >> $SERVER_NAME/dtls_client.inc
34-
echo >> $SERVER_NAME/dtls_client.inc
39+
echo -e "\"\n" >> $SERVER_NAME/dtls_client.inc
3540

3641
echo -n \#define DTLS_KEY \" >> $SERVER_NAME/dtls_client.inc
3742
cat $SERVER_NAME/client.key | awk '{printf "%s\\n\\\n", $0}' >> $SERVER_NAME/dtls_client.inc
38-
echo "\"" >> $SERVER_NAME/dtls_client.inc
39-
echo >> $SERVER_NAME/dtls_client.inc
43+
echo -e "\"\n" >> $SERVER_NAME/dtls_client.inc
4044

4145
echo -n \#define DTLS_CERT \" >> $SERVER_NAME/dtls_client.inc
4246
cat $SERVER_NAME/client.crt | awk '{printf "%s\\n\\\n", $0}' >> $SERVER_NAME/dtls_client.inc
43-
echo "\"" >> $SERVER_NAME/dtls_client.inc
47+
echo -e "\"\n" >> $SERVER_NAME/dtls_client.inc
4448

4549
echo -n \#define DTLS_ROOT_CERT \" > $SERVER_NAME/dtls_server.inc
4650
cat $SERVER_NAME/ca.crt | awk '{printf "%s\\n\\\n", $0}' >> $SERVER_NAME/dtls_server.inc
47-
echo "\"" >> $SERVER_NAME/dtls_server.inc
48-
echo >> $SERVER_NAME/dtls_server.inc
51+
echo -e "\"\n" >> $SERVER_NAME/dtls_server.inc
4952

5053
echo -n \#define DTLS_KEY \" >> $SERVER_NAME/dtls_server.inc
5154
cat $SERVER_NAME/server.key | awk '{printf "%s\\n\\\n", $0}' >> $SERVER_NAME/dtls_server.inc
52-
echo "\"" >> $SERVER_NAME/dtls_server.inc
53-
echo >> $SERVER_NAME/dtls_server.inc
55+
echo -e "\"\n" >> $SERVER_NAME/dtls_server.inc
5456

5557
echo -n \#define DTLS_CERT \" >> $SERVER_NAME/dtls_server.inc
5658
cat $SERVER_NAME/server.crt | awk '{printf "%s\\n\\\n", $0}' >> $SERVER_NAME/dtls_server.inc

pico_w/wifi/dtls/dtls_common.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ static const uint8_t dtls_cert[] = DTLS_CERT;
3030
#endif
3131

3232
static void dtls_timer_callback(__unused async_context_t *context, async_at_time_worker_t *worker) {
33-
DTLS_DEBUG("pico_mbedtls_timing_worker_callback\n");
33+
DTLS_DEBUG("dtls_timer_callback\n");
3434
dtls_processing((dtls_session_t*)worker->user_data, true);
3535
}
3636

@@ -174,7 +174,11 @@ int dtls_base_init(dtls_base_t *base)
174174
}
175175
mbedtls_ssl_conf_ca_chain(&base->conf, base->cert.next, NULL);
176176
mbedtls_pk_init(&base->pkey);
177+
#if MBEDTLS_VERSION_MAJOR < 3
177178
ret = mbedtls_pk_parse_key(&base->pkey, dtls_key, sizeof(dtls_key), NULL, 0);
179+
#else
180+
ret = mbedtls_pk_parse_key(&base->pkey, dtls_key, sizeof(dtls_key), NULL, 0, NULL, NULL);
181+
#endif
178182
if (ret != 0) {
179183
DTLS_ERROR("Failed to parse key");
180184
return ret;

0 commit comments

Comments
 (0)