Skip to content

examples/dtls-echo: handle handshake_failure alert#12478

Merged
benpicco merged 2 commits intoRIOT-OS:masterfrom
pokgak:pr/dtls_echo/handle_handshake_failure
Oct 21, 2019
Merged

examples/dtls-echo: handle handshake_failure alert#12478
benpicco merged 2 commits intoRIOT-OS:masterfrom
pokgak:pr/dtls_echo/handle_handshake_failure

Conversation

@pokgak
Copy link
Copy Markdown
Contributor

@pokgak pokgak commented Oct 17, 2019

Contribution description

This PR adds handling of handshake_failure alert in the dtls-echo example application and bumps tinydtls pkg to include fixes from the tinydtls repo. With this PR, the client should be able to react to handshake_failure alert sent from the server when e.g. no matching cipher suites are supported.

Testing procedure

I wrote a test script using pexpect that starts two native instances and sends a packet from the client to the server. Link to the script. If anybody is using the script, set BUILD_IN_DOCKER=0 because there is problem passing environment variable set to docker.

Steps to use this script
  1. Create tap interfaces with RIOT/dist/tools/tapsetup/tapsetup -c
  2. Change directory to dtls-echo example: cd RIOT/dtls-echo
  3. Run a native instance with PORT=tap0 and get the IP with ifconfig:
$ PORT=tap0 make all term
> ifconfig
  1. Change <SERVER_IP> in the script to the one found in step 3.
  2. Run script from the dtls-echo example application: ./test-send.py

Issues/PRs references

Fixes #12351

@benpicco benpicco added Area: examples Area: Example Applications CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Type: bug The issue reports a bug / The PR fixes a bug (including spelling errors) labels Oct 17, 2019
&remote);

if (res <= 0) {
if (res < 0) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it make sense to continue if res == 0, that is

no received data is available, but everything is in order. sock_udp_recv()

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case yes, because DTLS alerts have payload size 0 but are important for the client/server to know if they received any alerts.

Copy link
Copy Markdown
Contributor

@benpicco benpicco Oct 18, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So just to be clear, that is UDP payload size? The signalling happens by sending an empty message to the DTLS port?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So just to be clear, that is UDP payload size?

Yepp, like with normal udp sockets;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wait. now that you mention it, I might be wrong here. I'll check again.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, I somehow had the wrong idea in mind that a DTLS alert has payload size 0 eventhough I already saw many times in wireshark that it isn't.

In this case yes, because DTLS alerts have payload size 0 but are important for the client/server to know if they received any alerts.

This statement is wrong.

The signalling happens by sending an empty message to the DTLS port?

No, the signalling happens by sending a DTLS message with type alert in a DTLS record header, which means the received payload size cannot be 0.

Receiving a UDP payload size 0 is technically not an error but it doesn't make sense to continue if res == 0 because we are expecting a DTLS packet and not just UDP. So I'll revert this change and check if I made the same mistake at other places.

Sorry for the confusion :)

@benpicco
Copy link
Copy Markdown
Contributor

Murdock found some issues.

@pokgak
Copy link
Copy Markdown
Contributor Author

pokgak commented Oct 18, 2019

Travis is all green except for commit message length and squash check. Should I squash?

@benpicco
Copy link
Copy Markdown
Contributor

Yes please squash.

@pokgak pokgak force-pushed the pr/dtls_echo/handle_handshake_failure branch 2 times, most recently from e9e5863 to b770e85 Compare October 18, 2019 12:33
@pokgak
Copy link
Copy Markdown
Contributor Author

pokgak commented Oct 18, 2019

Fixed #12478 (comment). Tests all green :)

@pokgak
Copy link
Copy Markdown
Contributor Author

pokgak commented Oct 21, 2019

ping @benpicco

It would be nice if you could review and ACK this PR. It contains fixes that is needed so that the tests I did in #11943 (comment) all passes :)


return;
memcpy(&session.addr, &remote_peer->remote->addr.ipv6,
sizeof(session.addr));
Copy link
Copy Markdown
Contributor

@benpicco benpicco Oct 21, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor nit: keep this on one line, the line below is just as long.

Copy link
Copy Markdown
Contributor

@benpicco benpicco left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code looks good, adds error handling that wasn't there before.

There is a minor style issue, just squash directly.

Aiman Ismail added 2 commits October 21, 2019 13:24
This pulls in commit 865ca387cd9d05e52943e5641ad0eefafef218a3 which
fixes RIOT-OS#12351.
@pokgak pokgak force-pushed the pr/dtls_echo/handle_handshake_failure branch from b770e85 to 1900563 Compare October 21, 2019 11:27
@pokgak
Copy link
Copy Markdown
Contributor Author

pokgak commented Oct 21, 2019

Squashed and rebased to latest master.

@benpicco benpicco merged commit a653f9f into RIOT-OS:master Oct 21, 2019
@fjmolinas fjmolinas added this to the Release 2020.01 milestone Dec 13, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area: examples Area: Example Applications CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Type: bug The issue reports a bug / The PR fixes a bug (including spelling errors)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

examples/dtls-echo: server does not returns handshake failure when no supported cipher suite

4 participants