Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

aiocoap-client with DTLS is broken #167

Closed
pokgak opened this issue Aug 26, 2019 · 11 comments
Closed

aiocoap-client with DTLS is broken #167

pokgak opened this issue Aug 26, 2019 · 11 comments

Comments

@pokgak
Copy link
Contributor

pokgak commented Aug 26, 2019

Using aiocoap-client to connect with a libcoap server as described in the documentation (plus a small modification on how to run the libcoap server instructions #168), the client keeps on sending ClientHello, even though the server already responded with a HelloVerifyRequest.

Wireshark also shows that DTLS 1.0 is used instead of DTLS 1.2.

aiocoap-dtls-log

With --verbose flag I got this output on the client:

pi@coaptest:~/aiocoap $ ./aiocoap-client --verbose coaps://localhost --credentials testserver.json
INFO:coap:Retransmission, Message ID: 33070.
INFO:coap:Retransmission, Message ID: 33070.
INFO:coap:Retransmission, Message ID: 33070.
INFO:coap:Retransmission, Message ID: 33070.
INFO:coap:Exchange timed out

I'm using aiocoap-version: aiocoap-client 0.4a1.post0 and latest libcoap from develop branch built with --with-tinydtls flag set.

@chrysn chrysn closed this as completed in d9cbf49 Aug 26, 2019
@chrysn
Copy link
Owner

chrysn commented Aug 26, 2019

The DTLS version thing I've also seen in previous tests, but that appears to be harmless (or an artifact of DTLS's version negotiation). Thanks for pointing this out and providing a patch (ref #168) faster than I could respond! :-)

@pokgak
Copy link
Contributor Author

pokgak commented Aug 26, 2019

This issue is not solved yet because #168 is not a fix for this issue. I forgot to mention that I already made the change before testing. Sorry for the inconvenience.

@pokgak
Copy link
Contributor Author

pokgak commented Aug 27, 2019

The DTLS version thing I've also seen in previous tests, but that appears to be harmless (or an artifact of DTLS's version negotiation)

Apparently, this is not the case. I found out that the aiocoap-client does not respond to the HelloVerifyRequest from the server because it failed in the minimum DTLS version check done by tinydtls. This causes it to stop processing the handshake packets. Commenting out the check, the handshake is successful and weirdly, Wireshark now also shows the correct DTLS version number.

This check is done in the function is_record() in dtls.c of tinydtls repo if you want to look at it.

@pokgak
Copy link
Contributor Author

pokgak commented Aug 27, 2019

Found the fix :)

It is caused by a bug in older version of tinydtls which is fixed in eclipse/tinydtls@3beeca9. I confirmed this by rebuilding DTLSSocket locally using that commit for the tinydtls repo. With it the handshake is successful and aiocoap-client can send and receive correctly using the example provided in the documentation.

That said, this issue can stay closed but we'll need to contact DTLSSocket upstream to update their tinydls repo to fix the problem.

Edit: Tested using commit eclipse/tinydtls@3beeca9.

@chrysn
Copy link
Owner

chrysn commented Aug 28, 2019

Reopening as a reminder to bump the dependency. (Given the wrapper's distribution, it's fair to assume that users of latest aiocoap can upgrade tinydtls, and without a dependency on a fixed version I anticipate this will wind up here again.)

Thanks for tracking this down!

@chrysn chrysn reopened this Aug 28, 2019
@pokgak
Copy link
Contributor Author

pokgak commented Aug 28, 2019

Just a side note: I tried with tinydtls develop branch (eclipse/tinydtls@494a40d) too and aiocoap-client fails with error:

Traceback (most recent call last):
  File "./aiocoap-client", line 9, in <module>
    aiocoap.cli.client.sync_main()
  File "/home/pi/aiocoap/aiocoap/cli/client.py", line 348, in sync_main
    asyncio.get_event_loop().run_until_complete(single_request(args))
  File "/usr/lib/python3.7/asyncio/base_events.py", line 584, in run_until_complete
    return future.result()
  File "/home/pi/aiocoap/aiocoap/cli/client.py", line 269, in single_request
    response_data = await requester.response
  File "/home/pi/aiocoap/aiocoap/protocol.py", line 718, in _run_outer
    await cls._run(app_request, response, weak_observation, protocol, log)
  File "/home/pi/aiocoap/aiocoap/protocol.py", line 743, in _run
    await protocol.find_remote_and_interface(app_request)
  File "/home/pi/aiocoap/aiocoap/protocol.py", line 295, in find_remote_and_interface
    raise RuntimeError("No request interface could route message")
RuntimeError: No request interface could route message

@chrysn
Copy link
Owner

chrysn commented Sep 2, 2019

@kabel42, it seems I still can't create an account with https://git.fslab.de/jkonra2m/tinydtls-cython -- could you release an updateded DTLSSocket version that uses a recent tinydtls version?

@kabel42
Copy link

kabel42 commented Sep 2, 2019

sorry, didn't notice there were new commits in the repo.
0.1.10 should now be on PiPy with newest upstream

@chrysn
Copy link
Owner

chrysn commented Sep 3, 2019

That did not help, and I just checked the versions involved. The fixing commit eclipse/tinydtls@3beeca9 is not in tinydtls' master yet -- sorry, my "a recent tinydtls version" statement was wrong.

@kabel42, would you consider publishing a version based on their develop branch? I'm just tracking down the "No request interface could route message" error, it basically is a consequence of errors during module import (there was some restructuring in the tinydtls library, and the wrapper doesn't build all symbols yet), and is fixed by

diff --git a/DTLSSocket/tinydtls b/DTLSSocket/tinydtls
index 8414f8a..9a34961 160000
--- a/DTLSSocket/tinydtls
+++ b/DTLSSocket/tinydtls
@@ -1 +1 @@
-Subproject commit 8414f8ace98bab1f835b494c85e3a6d8144341c9
+Subproject commit 9a3496119688047b6d8b79826f13425397d92e10
diff --git a/setup.py b/setup.py
index 7eafd21..d1e4062 100644
--- a/setup.py
+++ b/setup.py
@@ -45,7 +45,8 @@ setup(
                  "DTLSSocket/tinydtls/peer.c",
                  "DTLSSocket/tinydtls/session.c",
                  "DTLSSocket/tinydtls/aes/rijndael.c",
-                 "DTLSSocket/tinydtls/sha2/sha2.c"
+                 "DTLSSocket/tinydtls/sha2/sha2.c",
+                 "DTLSSocket/tinydtls/platform-specific/dtls_prng_posix.c",
                  ],
                 include_dirs=['DTLSSocket/tinydtls'],
                 define_macros=[('DTLSv12', '1'),

@chrysn
Copy link
Owner

chrysn commented Sep 3, 2019

Current aiocoap master now depends on a new version and works with libcoap's example server.

Thank you both for your valuable inputs and quick response times.

@pokgak, out of curiousity, does that mean aiocoap can be used straightforward with RIOT-OS/RIOT#12104?

@chrysn
Copy link
Owner

chrysn commented Sep 5, 2019

… and confirmed working with current RIOT-OS/RIOT#12104 :-D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants