eclipse-leshan / leshan

Java Library for LWM2M
https://www.eclipse.org/leshan/
BSD 3-Clause "New" or "Revised" License
642 stars 405 forks source link

Issue with running Contiki-NG with latest release of Leshan (2.0.0-M15) #1627

Open joakimeriksson opened 5 days ago

joakimeriksson commented 5 days ago

Version(s)

v2.0.0-M15

Which components

leshan-server-demo

Tested With

Contiki-NG LwM2M IPSO Objects example

What happened

When the client tries to join the server using DTLS there is an issue at the client hello stage:

2024-06-26 15:44:40,517 DTLSConnector        [WARN] Processing new CLIENT_HELLO from peer [[fd00:0:0:0:302:304:506:708]:5684] failed! PEER=[fd00:0:0:0:302:304:506:708]:5684 
java.lang.IllegalArgumentException: Bad arguments
    at java.base/javax.crypto.Mac.update(Mac.java:528)
    at org.eclipse.californium.scandium.dtls.ClientHello.updateForCookie(ClientHello.java:371)
    at org.eclipse.californium.scandium.CookieGenerator.generateCookie(CookieGenerator.java:175)
    at org.eclipse.californium.scandium.CookieGenerator.generateCookie(CookieGenerator.java:196)
    at org.eclipse.californium.scandium.DTLSConnector.processNewClientHello(DTLSConnector.java:2677)
    at org.eclipse.californium.scandium.DTLSConnector.access$1500(DTLSConnector.java:262)
    at org.eclipse.californium.scandium.DTLSConnector$16.run(DTLSConnector.java:2087)
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1144)
    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:642)
    at java.base/java.lang.Thread.run(Thread.java:1589)

It might be related to an update in the Scandium DTLS implementation that seems to have a change in the implementation of the client hello (including that specific line).

How to reproduce

Likely possible to reproduce with any client using PSK and DTLS with our settings in contiki-ng's lwm2m example. Run the leshan demo server locally then do the following in contiki-ng.

>contiki-ng/examples/lwm2m-ipso-objects
make MAKE_WITH_DTLS=1 MAKE_COAP_DTLS_WITH_PSK=1 MAKE_COAP_DTLS_WITH_CLIENT=1 MAKE_COAP_DTLS_KEYSTORE=MAKE_COAP_DTLS_KEYSTORE_SIMPLE
sudo ./build/native/example-ipso-objects.native
...

This will cause the problem.

Relevant Output

No response

sbernard31 commented 5 days ago

I'm busy on another task for now. I could try to look at this just after. But at first sight it seems this is relative to scanidum, so maybe better to open an issue directly there ?

joakimeriksson commented 4 days ago

I can do a copy of this there also. It should work well there also. I did not check the commit log for Leshan so I am not sure if there are any changes w.r.t to this in Leshan. https://github.com/eclipse-californium/californium/issues/2255