wakaama icon indicating copy to clipboard operation
wakaama copied to clipboard

Support for Mbed TLS?

Open hannestschofenig opened this issue 4 years ago • 18 comments

I was wondering whether there is interest in supporting Mbed TLS in Wakaama. Has someone been working on an integration already?

hannestschofenig avatar Sep 21 '21 09:09 hannestschofenig

I do not know Mbed TLS, but a quick glance make me think that is for tcp, is that correct? As far as I know there is only coap and udp support in wakaama andsupport for DTLS using tinyDTLS. Is there any specific features that you need in Mbed TLS that is missing in tinyDTLS?

tuve avatar Sep 22 '21 08:09 tuve

@tuve it's supporting DTLS too: https://tls.mbed.org/kb/how-to/dtls-tutorial

jvermillard avatar Sep 22 '21 08:09 jvermillard

I think the main problem with tinyDTLs is overall lack of maintenance and 1.3 and fullfledge PKI support. Also the lack of TLS support in TinyDTLs can be a problem, for example if you use HTTPS for your FOTA you will need an extra lib for TCP TLS.

jvermillard avatar Sep 22 '21 08:09 jvermillard

Maybe we should look into support that then. To my knowledge there isn't anybody currently looking into this.

tuve avatar Sep 22 '21 08:09 tuve

I already used mbedtls with wakaama. I think the question should be if tinydtls and/or mbedtls should be part of the wakaama core implementation in the future. tinydtls is currently only used in the examples and is not part of the core wakaama library.

LukasKarel avatar Sep 22 '21 09:09 LukasKarel

Good question. Even though I think you should never opt out of using dtls, I don't think it should be part of the core but rather referenced as a submodule as it is done now with tinydtls. But maybe this also should include the option of using mbed tls. Any thoughts on this?

tuve avatar Sep 22 '21 10:09 tuve

From a security point of view this is not ideal. Everyone who doesn't use the examples implements their own security layer. So these changes tend not to be pushed back directly. In addition, the implementations are copied and this leads to errors that could be avoided. If this is not taken into account, it is of course not a problem.

LukasKarel avatar Sep 22 '21 12:09 LukasKarel

Yes, that is a concern. Does anyone have any figures on the memory footprint of tinydtls and mbed tls, both compiled code and runtime?

tuve avatar Sep 22 '21 12:09 tuve

@LukasKarel You mentioned that you have used Wakaama with Mbed TLS. Is that code somewhere in a branch or so?

hannestschofenig avatar Sep 22 '21 12:09 hannestschofenig

@tuve Regarding a comparison between Mbed TLS and TinyDTLS. I don't have that data but the answer will heavily depend on the details of the comparison. The feature set is different between the two stacks. The biggest contributor to code size in TLS/DTLS stacks, in general, is the crypto itself -- not the TLS protocol. I have data to support this observation in https://arxiv.org/pdf/2011.12035.pdf (see Figure 8 and Figure 9).

hannestschofenig avatar Sep 22 '21 12:09 hannestschofenig

@LukasKarel You mentioned that you have used Wakaama with Mbed TLS. Is that code somewhere in a branch or so?

These repos are unfortunately not publicly available. But it should be pretty straight forward to implement a running prototype based on the current examples. Maybe I have some old files around and could create a working draft later this week.

@tuve I have never worked with tinydtls but mbedtls is highly configureable. Supported algorithms could be configured on compile time and therefore should reduce the footprint. Same is possible for buffer sizes to reduce heap usage for example.

LukasKarel avatar Sep 22 '21 14:09 LukasKarel

@hannestschofenig correct me if I'm wrong but It seems to me that mbedTLS also brings Connection ID which is a great feature for LWM2M, correct ?

These repos are unfortunately not publicly available. But it should be pretty straight forward to implement a running prototype based on the current examples. Maybe I have some old files around and could create a working draft later this week.

About integrating mbedTLS, I think providing an example could be a good start.

I think the question should be if tinydtls and/or mbedtls should be part of the wakaama core implementation in the future.

From a security point of view this is not ideal. Everyone who doesn't use the examples implements their own security layer. So these changes tend not to be pushed back directly. In addition, the implementations are copied and this leads to errors that could be avoided.

Very good question but not so easy to decide. I guess it depends on :

  • the scope wanted for the project
  • how much it is easy to make it part of core library but also to make it possible to use other TLS/DTLS library (if we still want to do that).
  • how much it is compatible with https://github.com/eclipse/wakaama/issues/494

Personally, I have no answer but I feel this are good questions for Wakaama Committers and Community.

sbernard31 avatar Sep 22 '21 14:09 sbernard31

@sbernard31 Yes, Mbed TLS provides CID support for DTLS 1.2.

hannestschofenig avatar Sep 23 '21 15:09 hannestschofenig

These repos are unfortunately not publicly available. But it should be pretty straight forward to implement a running prototype based on the current examples. Maybe I have some old files around and could create a working draft later this week.

About integrating mbedTLS, I think providing an example could be a good start.

I provided a sample but keep in mind, it is only a sample.

My opinion: Before thinking about integrating DTLS into wakaama (even multiple libraries), I would discuss the possibility to use wakaama with different CoAP libraries/or even a MQTT/HTTP library and try to seperate the layers.

LukasKarel avatar Sep 25 '21 10:09 LukasKarel

I think separation and layering in general is a better approach. Especially if we want to support anything other than CoAP, as it is right now I think that would be quite hard.

tuve avatar Sep 27 '21 06:09 tuve

Yes, Mbed TLS provides CID support for DTLS 1.2.

Be careful, if you use it! You must use the right IANA code-point for the extension, depending on which version of the DTLS 1.2 CID draft you are want to use, or you must use, because it's the only implemented in the mbedtls version you are using. At least, if you want to use it with Californium or Leshan.

mbedTLS - Update DTLS CID implementation to comply with the "final" draft

zephyr - DTLS connection ID

boaks avatar Sep 29 '21 06:09 boaks

I will submit a PR to the Mbed TLS repo to make this update.

hannestschofenig avatar Oct 01 '21 12:10 hannestschofenig

I have updated the Mbed TLS CID implementation: https://github.com/ARMmbed/mbedtls/pull/5061

hannestschofenig avatar Oct 12 '21 07:10 hannestschofenig