3

I'm trying to figure out the most data-use efficient way to secure our CoAP API. DTLS seems to be the right way to do it, but looking at how much data the handshake requires (and making some uninformed assumptions about how often that needs to happen) it seems that DTLS with X.509 certificates dwarfs the actual data use of CoAP itself.

The most obvious solution would be to just use symmetric keys that are programmed in at the factory, but I don't think I like the security risks that imposes. As far as I understand there is no way to recover from a server-side intrusion other than manually installing new keys on all the devices.

The solution that I'm thinking of proposing is basically a hybrid of the two, distribute the devices with a secured CA that lets the devices do a standard handshake and establish a "temporary" symmetric key. Then to save bandwidth to the device I'd store that key (session?) in a database for the device to continue for months or years at a time, but still have the ability to expire the keys if we discover any have gotten out.

I know I could just use the standard session resumption handshake to resume a session, but I'm not sure that is required since DTLS is connection-less and I can pretend the "connection" is always open. And if I can avoid having to repeat the handshake that would lower data consumption and probably lower server load somewhat too.

The things that I don't know are: Does DTLS define a limit on how long a session can remain open? Or is there a timeout where a session must be removed after some period of inactivity? If not, do the implementations of DTLS define one themselves?

Is there any thing else that I may be overlooking as to why this wouldn't work? Or is there something more straightforward that I'm not thinking of?

Azdle
  • 1,763
  • 1
  • 14
  • 21
  • I have used session pings. Clients would send “heartbeat ping” to the sever at periodic intervals and if server did not hear after some n number of pings, it would close the session. Also, as long as the factory installed symmetric keys are usually stored in the HSM storage (and so they cannot be retrieved), there wouldn’t be an issue with losing keys. – John Mar 26 '19 at 11:07

2 Answers2

2

Timeouts are application specific, and you can set them as high as you need, or just keep the connections around as long as you can (eg. with a fixed number of usable connections, timing out the least recently used when a new one is opened).

Session resumption data can be held for as long as both parties agree the resumption data is still good (eg. no underlying certificates have expired). Session resumption should be at least as cheap as manually installed symmetric keys.

So a sensible approach seems to be to just try continuing the session if the sending party still has it open, fall back to session resumption on error, and if that doesn't work go through the full handshake again. There don't necessarily need to be agreed-on times for any of that.

chrysn
  • 683
  • 4
  • 16
1

(and making some uninformed assumptions about how often that needs to happen)

My feeling is, an ip-address change after a quiet periode is assumed. If that is assumed, the "DTLS session timeout" is the timeout of "NAT(like)s" on your ip-route. And that NAT timeout is still (too frequently) 30s. If there are no "NAT(like)" on your ip-route, and so the peers are able to exchange ip-messages by their static (not changing) ip-address and port, then there is no such DTLS timeout. Except, as already answered, your application requires that. There are also some discussions in the IETF when the exchange the connection keys for some security reasons. But the number are rather high (except you want to use AES128_CCM8).

since DTLS is connection-less

DTLS requires a context with a master-key and the "association keys" (TLS "connection keys"). That master-key is assigned to the DTLS session id, and the "association keys" are usually assigned to the ip-address and port. The DTLS session resumption is then used in scenarios, where the addresses may change (e.g. because of "NAT(like)s", or, because the peers are entering a sleeping mode and gets a new ip-address on wake-up). With such ip-address changes, the DTLS session resumption is used to refresh the assignment of the "association keys" with the new address. A DTLS resumption is more, it uses also new "association keys", but it's mainly done to overcome the address change.

The most obvious solution would be to just use symmetric keys

Between PSK and x509, there is also RPK, which offers similiar security as x509 with less data used. Also PSK_ECDHE cipher suites may be a choice.

And hopefully DTLS CID will make CoAP/DTLS more efficient. At least for my tests, experiments and usage over the last 2 years, that was the technique, which brought back CoAP into "must be considered"!

Achim Kraus
  • 567
  • 1
  • 5
  • 8