Course contentsShow
← Security
Lesson 2784 of 3,05252. Embedded and IoT SecurityFree lesson

CoAP Security with DTLS

Datagram Transport Layer Security for CoAP, pre-shared keys, certificate modes, and handling packet loss in secure channels.

CoAP Security with DTLS

What you'll learn: How Datagram Transport Layer Security (DTLS) protects CoAP communications in constrained IoT environments.

The Challenge of Securing UDP-Based Protocols

CoAP runs over UDP (not TCP), which means traditional TLS won't work—TLS requires TCP's reliable connection. DTLS is TLS adapted for datagram protocols, providing encryption, authentication, and integrity checking while tolerating packet loss and reordering that's common with UDP.

Think of DTLS as adding secure envelopes to postcards (UDP packets) rather than creating a secure tunnel (like TLS does for TCP streams). Each envelope is self-contained and can arrive out of order or get lost without breaking the entire conversation.

Authentication Modes

Pre-Shared Keys (PSK): Both CoAP client and server hold the same secret key beforehand. When connecting, they prove they know the key without transmitting it. This is lightweight and perfect for resource-constrained devices, but requires manual key provisioning and management across all devices.

Certificate Mode: Uses X.509 certificates for authentication, similar to HTTPS. The device and server exchange certificates during the DTLS handshake. This scales better but requires more memory, processing power, and a Public Key Infrastructure (PKI)—challenging for tiny IoT devices.

Raw Public Keys (RPK): A middle ground using just the public key without the full certificate overhead.

Handling Packet Loss

DTLS implements its own handshake reliability through timers and retransmissions. If a handshake packet is lost, DTLS waits, then retransmits. Once the secure session is established, application-level CoAP handles any message loss with its own confirmable/non-confirmable message types—security doesn't break because of missing packets.

Key Takeaway: DTLS adapts TLS security to UDP's unreliable nature, enabling encrypted CoAP communications using either lightweight pre-shared keys or certificate-based authentication while gracefully handling the packet loss inherent in constrained IoT networks.