eclipse-leshan / leshan

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

Fix serialization issue in demo server #1600

Closed sconvent closed 7 months ago

sconvent commented 7 months ago

When using the leshan-server-demo with DTLS (and a Raw Public Key), serialization of RegistrationUpdate events throw exceptions.

Here is the full error message:

java.lang.RuntimeException: com.fasterxml.jackson.databind.exc.InvalidDefinitionException:
 Invalid type definition for type `sun.security.ec.ECPublicKeyImpl`:
 Failed to construct BeanSerializer for [simple type, class sun.security.ec.ECPublicKeyImpl]:
  (java.lang.IllegalArgumentException) Failed to call `setAccess()` on Method 'getW' (of class `sun.security.ec.ECPublicKeyImpl`) due to `java.lang.reflect.InaccessibleObjectException`,
  problem:
    Unable to make public java.security.spec.ECPoint sun.security.ec.ECPublicKeyImpl.getW() accessible:
    module jdk.crypto.ec does not "exports sun.security.ec" to unnamed module @5a6d67c3 
    (through reference chain: 
       org.eclipse.leshan.server.demo.servlet.EventServlet$RegUpdate["update"]
       ->org.eclipse.leshan.server.registration.RegistrationUpdate["clientTransportData"]
       ->org.eclipse.leshan.core.peer.IpPeer["identity"]
       ->org.eclipse.leshan.core.peer.RpkIdentity["publicKey"])

The public key should not be part of this message anyways I assume. The proposed solution implements a custom Serializer similar to the already existing JacksonRegistrationSerializer.

sconvent commented 7 months ago

I just signed the ECA, please re-run the check 🙂

sbernard31 commented 7 months ago

Thx for your contribution. :pray:

I will probably look at this next week :slightly_smiling_face:

I just signed the ECA, please re-run the check 🙂

Yep I just checked it sounds good. :+1:

github-actions[bot] commented 7 months ago

:x: Checkstyle Validation Failed ! (more details)

Ensure your code build locally using:

mvn clean install

Or just validate checkstyle rules with :

mvn checkstyle:checkstyle

See also How configure your IDE.

github-actions[bot] commented 7 months ago

:information_source: Some tips :

If documentation or those automatic comments are not clear enough, please create a new issue to discus about how to enhance it.

sbernard31 commented 7 months ago

I just tested that and I am able to reproduce :heavy_check_mark:.
I also test your fix and it seems to work. :+1:
I also checked the serialization and it sounds OK.

I will fix the header issue and integrate this in master.

Thx again for you contribution :pray:

sbernard31 commented 7 months ago

This is now integrated in master (commit ae49f5352a14180cec9c1d287486f1d59ef2c71a) This should be deployed in few minutes on Leshan sandbox.