contiki-ng / tinydtls

A version of tinyDTLS that is refactored to be more easy to use "standalone" (e.g. without bindings to a specific IP-stack).
Other
8 stars 25 forks source link

Invalid decrypt_error response connected to unreliability of the Handshake protocol #19

Open pfg666 opened 3 years ago

pfg666 commented 3 years ago

Non-conformance Bug affecting usability of the library

A similar issue was reported for eclipse's TinyDTLS implementation.

Contiki-NG TinyDTLS client generates an unwarranted decrypt_error alert upon receiving an unencrypted HelloVerifyRequest with epoch 1. Similarly, the server generates a decrypt_error upon receiving a CKE with epoch 1. Below captures for the two behaviors are shown.

ctinydtls_decrypt

ctinydtls_decrypt_server

Upon investigating this matter, we found that by terminating the initial handshake on receiving messages with epoch 1, TinyDTLS no longer ensures reliability of the handshake protocol. If the client/server receive Finished (epoch 1) before ChangeCipherSpec (epoch 0), Contik-NG TinyDTLS will abort the handshake. Such an event can happen due to reordering. This problem is exposed in the below capture for a TinyDTLS client. Notice that the server ChangeCipherSpec is received after an encrypted record which is the Finished message. This leads to unwarranted handshake termination.

ctinydtls_reorder

Steps to Reproduce I attached files necessary for reproduction using DTLS-Fuzzer, a Java-based tool for testing DTLS libraries. Also included in the archive the captures of the interaction show above. DTLS-Fuzzer requires the JDK for Java 8. On Ubuntu, this can be installed by running: sudo apt-get install openjdk-8-jdk

Unpack the archive, cd to resulting folder and run bash reproduce.sh test_sequence_decrypt or bash reproduce.sh test_sequence_reorder, while running an instance of Wireshark on the side. The reproduction script will:

I also added the test sequence 'test_sequence_handshake'. This is similar to the reordering sequence, but without the reordering. By executing this sequence via bash reproduce.sh test_sequence_handshake, you should complete the handshake with the client.

Note that the problems affect both clients and servers. On request, I can provide reproduction scripts also for servers. I am guessing fixing the problem for clients will also do it for servers.

Thanks!

reproduction.tar.gz