Chapters

15 TLS and DTLS for IoT

security
cryptography
iot

In 60 Seconds

Protect One Reading Across the Real Path

Picture a water meter that sends a usage reading through a building bridge. Encryption matters only if the right service receives the right reading and a copied message cannot be accepted as new.

Transmission Control Protocol (TCP) means a stream that checks order and delivery. Transport layer security means protection for that stream; it is called TLS. User Datagram Protocol (UDP) means sending separate messages without a lasting connection. Datagram Transport Layer Security (DTLS) protects those separate messages. Constrained Application Protocol (CoAP) means a compact request method for small devices. A gateway means the bridge between local devices and a wider network.

Send one reading, copy it, change one byte, use an expired identity, and restart the gateway. The receiver should accept only the valid current message. Every refusal should leave enough evidence to explain the boundary that held.

This runway does not prove the safety of a library or key store. The deeper sections explain handshakes, records, identities, cipher choices, and the checks needed before release.

TLS and DTLS protect one transport connection hop. TLS fits reliable byte streams such as TCP; DTLS fits unreliable datagrams such as UDP for CoAP. Both only become a security claim when the peer identity is validated, strong record protection is negotiated, failure stops closed, and the plaintext boundary is named.

Start with the everyday picture: a device is not trying to encrypt “the Internet”; it is trying to reach one named peer without a stranger in the middle. TLS or DTLS earns trust only when that peer is verified, the records are protected, and failure does not fall back to plaintext.

15.1 Secure One Verified Connection

This section: Secure One Verified Connection — TLS and DTLS turn an untrusted network path into a protected connection.

TLS and DTLS turn an untrusted network path into a protected connection. On one connection they do three jobs at once: they confirm who the other end is (authentication), hide the bytes while they travel (confidentiality), and detect any change in transit (integrity). Almost every IoT device that talks to a cloud, a gateway, or a service relies on one of them.

The split between the two is about the transport underneath. TLS runs over a reliable, ordered byte stream (TCP). DTLS is the datagram variant for unreliable transports (UDP), and it is the one used with constrained IoT protocols such as CoAP. The important limit is the size of the claim: TLS and DTLS protect a connection hop, from the device to whatever terminates the session, not the whole journey.

If you only need the intuition, this layer is enough: pick TLS for reliable streams and DTLS for datagrams, then make sure the device actually checks who it is talking to. Encryption to an unverified peer is not security, and a handshake that fails must stop, not silently drop to plaintext.

Think of a sealed, tamper-evident courier pouch carried between two named offices. TLS is the pouch sent down a single reliable conveyor belt, where every item arrives once and in order. DTLS is the same pouch broken into separate parcels that may arrive late, out of order, or duplicated, so the receiving office stamps each parcel with a number and refuses repeats. In both cases the clerk checks the courier’s ID badge before opening anything. Encrypting the pouch but skipping the badge check just means you handed your secrets neatly to the wrong office. Compare those transport assumptions in Figure 15.1 before choosing a protocol.

Inspect Figure 15.1 across the connection and delivery assumptions before selecting a protected transport profile.

Comparison of IoT transport protocols TCP, UDP, DTLS, and QUIC by connection model, reliability, overhead, and typical IoT use cases.
Figure 15.1: IoT transport comparison of TCP, UDP, DTLS, and QUIC by connection behavior, reliability, overhead, and typical applications.

Read Figure 15.1 across the connection model, reliability behavior, overhead, and intended use rather than choosing from the protocol name alone. TCP gives TLS an ordered reliable byte stream; UDP leaves DTLS to tolerate loss, reordering, and duplication while still protecting records. QUIC has a different integrated transport and security model and must be evaluated as its own profile. Whichever path fits the application, the running narrative remains peer identity, fresh keys, protected records, replay handling, and no silent plaintext fallback.

15.1.1 The One-Minute View

It secures a connection hop

Authentication, confidentiality, and integrity for one transport session, between the device and whatever terminates it.

Match it to the transport

TLS over a reliable ordered stream (TCP); DTLS over datagrams (UDP), the variant used with constrained protocols such as CoAP.

Identity is the catch

Encrypting to an unverified peer, or falling back to plaintext on failure, breaks the claim even when the bytes are encrypted.

15.1.2 Beginner Examples

  • A sensor that opens a TLS connection but accepts any certificate has encryption without authentication. It may be talking privately to an impostor.
  • A device using DTLS over UDP for CoAP still has to cope with lost, reordered, and duplicated datagrams. The security layer does not make a repeated command safe on its own.
  • “We use TLS” is not a claim a reviewer can accept. It does not say which peer is verified, which version and cipher suite, or where the session terminates and who sees plaintext after that.

15.1.3 Overview Knowledge Check

If you can say what TLS and DTLS protect, why the transport choice matters, and why encryption is not identity, you can stop here. Continue to Practitioner to configure and review a real deployment.

15.2 Build Evidence for a TLS or DTLS Deployment

This section: Build Evidence for a TLS or DTLS Deployment — A transport-security review should produce concrete evidence rather than an “encrypted” label.

A transport-security review should produce concrete evidence rather than an “encrypted” label. The strongest record names the transport and termination point, the authentication model, the version and cipher policy, the certificate or key validation behavior, the failure behavior, and the DTLS replay handling where it applies. Each item is a separate decision, and the common failure is asking the protocol to prove something it was never configured to prove.

15.2.1 Walkthrough: From Transport to Accepted Connection

  1. Name the transport and termination point. Decide TLS (reliable stream over TCP) or DTLS (datagrams over UDP, for example CoAP), and identify exactly which component terminates the session and sees plaintext after it.
  2. Choose the authentication model. Server certificate (X.509) validation; mutual TLS with a client certificate to authenticate the device; or, for constrained devices, pre-shared keys (PSK) or raw public keys. Record how the device’s own identity is proven, not only the server’s.
  3. Set the version and cipher policy. Require a modern version, restrict to AEAD cipher suites with ephemeral ECDHE for forward secrecy, and disable legacy options such as static RSA key exchange, RC4, and known CBC-padding-prone suites. Read the policy back from the deployed firmware, not just a design document.
  4. Validate the peer correctly. For certificates, check the trust chain, validity period, revocation or status, and the identity (name) match. Skipping the name check breaks authentication even when encryption works. For PSK, check the identity, scope, and rotation.
  5. Make failure fail closed. A failed or blocked handshake must stop protected data. It must never silently downgrade to cleartext or to a weaker version. Confirm there is no plaintext fallback path.
  6. Add DTLS handling where used. Confirm the anti-replay window, the per-record sequence number, the cookie or return-routability exchange against spoofed-source denial of service, and that the application deduplicates state-changing commands.
  7. Record redacted evidence and retest triggers. Keep negotiated parameters and both success and failure captures with no raw secrets, and note which changes (new trust anchor, cipher policy, certificate rotation) reopen the review.

15.2.2 The Authentication Options

Authentication Option
Useful When
Good Evidence
Review Warning
Server certificate (X.509)
Devices authenticate a cloud, gateway, or local service.
Expected name match, scoped trust anchor, chain plus validity plus revocation check, and a wrong-name rejection test.
Accepting any valid-looking certificate, or skipping the name check, removes the identity claim.
Mutual TLS (client certificate)
The service must authenticate each device with asymmetric credentials.
Per-device key in protected storage, plus issuance, renewal, and revocation records.
A fleet-shared client certificate destroys per-device accountability.
Pre-shared key (PSK)
Provisioning can distribute scoped secrets to constrained devices.
Per-device or scoped PSK, identity label, rotation, old-secret rejection, and a profile that adds ephemeral ECDHE for forward secrecy.
One fleet-wide PSK means a single extraction compromises every device, and a PSK-only profile may lack forward secrecy.
Raw public key
Constrained devices avoid certificate parsing but still need a bound identity.
A trusted out-of-band mapping of public key to device identity, plus a rotation path.
A raw key with no trusted identity binding authenticates nothing.

15.2.4 Practitioner Knowledge Check

If you can choose the transport and authentication model, set a safe version and cipher policy, and scope a deployment claim to its evidence, you can stop here. Continue to Under the Hood for the handshake mechanics, record protection, and failure modes.

15.3 How the Handshake and Records Earn Trust

This section: How the Handshake and Records Earn Trust — The deeper layer explains how each guarantee is built and why each is separate.

The deeper layer explains how each guarantee is built and why each is separate. A connection is only as trustworthy as its handshake, its key agreement, its record protection, and its plaintext boundary.

15.3.1 The Handshake Establishes a Verified Transcript

Before any application data flows, the handshake authenticates the peer, agrees on fresh key material, and negotiates parameters such as version, cipher suite, and key-exchange group. Crucially, it authenticates a transcript of that negotiation: when both sides verify the Finished messages, any attacker tampering with or downgrading the offered parameters is detected. This is why a downgrade to a weak version or cipher does not pass silently when the configuration enforces a minimum.

TLS 1.3 (RFC 8446) modernized this: its standard cipher suites use AEAD, ephemeral (EC)DHE provides forward secrecy, and static RSA key transport was removed. PSK-only handshakes do not provide forward secrecy. Most of the handshake after the server’s first message is itself encrypted, and the normal handshake completes in a single round trip. An optional 0-RTT “early data” mode sends data before that round trip completes, with replay risk. TLS 1.2 (RFC 5246) can be safe when configured with AEAD cipher suites and ephemeral ECDHE for forward secrecy, avoiding legacy options such as static RSA key exchange, RC4, and the known CBC-padding pitfalls.

TLS and DTLS handshake narrated tour

Play silently with captions on provisional storyboard timing; narration audio is pending. Production pacing is not protocol time. Choose Reduced motion for a complete still at each beat.

Play the tour to open the workbench. Pause, replay a beat, or read the full transcript below. Situations marked CANNOT SHOW keep the existing frame and provide captions only.

Full transcript — TLS and DTLS handshake (8 beats)

B1 — Meter identity question
You are the engineer connecting a building's water meter to its service. A usage reading needs to reach the intended service without being exposed to an impostor. Before sending that reading, how does the meter establish who will receive it?

Model caption: Your water meter must reach its intended service.

B2 — TLS 1.3 scope
Transport Layer Security, or TLS, protects a connection over a reliable, ordered stream. Its handshake negotiates protection, sets up fresh keys, and checks the other endpoint's identity. Follow the certificate handshake for TLS version one point three. The normal handshake completes in one round trip.

Model caption: TLS version one point three: a normal full handshake takes one round trip.

B3 — Certificate handshake
The meter's Client Hello offers security options. The service's Server Hello selects compatible options and supplies information for calculating handshake keys. The following handshake messages are encrypted. The meter validates the server certificate, including its expected name. A signature ties the server's identity to the handshake. Finished messages check that both sides derived the right secrets and saw the same handshake messages. Then protected application data can flow.

Model caption: Options, fresh keys, identity validation, and Finished verification lead to protected application data.

B4 — DTLS loss and MTU
Now give your meter a datagram connection: separate messages that can be lost. Datagram Transport Layer Security, or DTLS, protects that kind of transport. The loss example uses DTLS version one point three. Use a certificate chain: linked digital identity documents. Set a budget of one hundred sixty bytes per datagram. These are teaching estimates, rather than measured traffic sizes.

Model caption: DTLS version one point three; certificate chain; one hundred sixty bytes per datagram. Sizes are teaching estimates.

B5 — Fragment budget arithmetic
Start with seven hundred sixty bytes. Add two thousand six hundred for the certificate choice, giving three thousand three hundred sixty. Add two hundred twenty for datagram handling, giving three thousand five hundred eighty; the TLS version one point two addition is zero. Compare the datagram budget with the model's minimum of sixty-four bytes; one hundred sixty is larger. Divide three thousand five hundred eighty by one hundred sixty: twenty-two, with sixty bytes remaining. Round up to twenty-three. The model requires at least one fragment, so the result stays twenty-three message pieces, called fragments.

Model caption: Seven hundred sixty plus two thousand six hundred plus two hundred twenty plus zero gives three thousand five hundred eighty bytes. The larger of sixty-four and one hundred sixty is one hundred sixty. Division gives twenty-two with sixty bytes remaining; rounding up gives twenty-three, already greater than the minimum of one.

B6 — Conditional retransmission
The group of certificate messages can be split into fragments and put back together before verification. If that group is missing, the loss path includes acknowledgments and retransmission when a timer expires. Recovery gets handshake messages delivered so verification can continue.

Model caption: A missing group of certificate messages can trigger retransmission when a timer expires.

B7 — Encryption before trust
One misconception is that encrypted handshake messages already mean the intended server is trusted. After Server Hello, encryption is active while identity is still being checked. Accepting any certificate could leave your meter talking privately to an impostor. Certificate validation and Finished verification establish the authenticated connection.

Model caption: Encryption is active before server identity validation and Finished checks are complete.

B8 — Authenticated data
Establish who shares the keys before trusting the protected reading.

Model caption: Establish who shares the keys before trusting the protected reading.

15.3.2 A Cipher Suite Is a Bundle

A cipher suite is not one algorithm. In TLS 1.3 it selects an AEAD cipher (such as AES-GCM, AES-CCM, or ChaCha20-Poly1305) and a hash for key derivation and transcript binding; key exchange and authentication are negotiated separately. TLS 1.2 suite names also include key exchange and authentication. Naming “AES” says nothing about how keys are agreed or how the peer is authenticated, so a review records the version, suite, key-exchange mode, and authentication method.

15.3.3 Record Protection and Replay

After the handshake, application data is split into records, each protected with the negotiated AEAD: the record is encrypted and carries an authentication tag, and the receiver must reject a record whose tag fails before using any plaintext. TLS detects replayed or reordered records through implicit sequence numbers bound to record protection (RFC 8446 §5.3; RFC 5246 §6.2.3); TCP also provides ordered delivery. DTLS datagrams may be lost, reordered, or duplicated, so the receiver uses per-record sequence numbers to detect duplicates; a sliding anti-replay window can also reject records that fall outside its acceptance range.

15.3.4 DTLS, Datagrams, and Denial of Service

DTLS adds handling a stream does not need: retransmission and reordering of handshake messages and per-record sequence numbers. DTLS 1.3 record processing rejects duplicate sequence numbers (RFC 9147 §4.5.1), while §3.4 describes replay detection as optional; a sliding anti-replay window is a common implementation. When enabled, a cookie or return-routability exchange makes a client prove it can receive at its claimed source address before the server commits substantial state or sends large responses. This resists denial of service and amplification from spoofed source addresses. Verify replay handling and the deployment’s cookie policy. None of this makes a state-changing datagram idempotent: if a repeated command would be unsafe, the application still needs command identifiers or a deduplication policy of its own.

15.3.5 0-RTT Early Data and Resumption

Session resumption reduces handshake cost, and TLS 1.3 can carry 0-RTT early data in the client’s first flight, before the handshake finishes. The trade-off is concrete: early data is replayable by an attacker who captured it, and it is not forward-secret. Applications must restrict early data to safe, idempotent operations and keep state-changing actions such as unlocks, configuration changes, firmware actions, and payments out of it.

15.3.6 Where the Protection Ends

TLS and DTLS protect a single connection hop, between the two endpoints of the transport session. If a broker, proxy, gateway, or load balancer terminates the session, that component sees plaintext, and protection beyond it is a separate decision (for example, end-to-end object or payload protection). Confidentiality on the wire is not the same as confidentiality in the terminating service’s memory or logs, so a review names the component that terminates the session and who reads the data after it.

Mechanism
What It Guarantees
Evidence to Request
Failure Mode If Weak
Authenticated handshake
The peer is who the credentials claim, and negotiated parameters are not tampered or downgraded.
Certificate or PSK validation logs, Finished transcript verification, and a downgrade-rejection test.
An impostor is accepted, or parameters are silently downgraded to weak ones.
Forward secrecy (ephemeral ECDHE)
A later key compromise does not expose past recorded sessions.
ECDHE negotiated, no static RSA key transport, and a fresh ephemeral key per session.
A stolen long-term key decrypts traffic captured earlier.
AEAD record protection
Each record is confidential and tamper-evident, rejected before use on tag failure.
AEAD suite negotiated, a modified-record rejection test, and a unique nonce per key.
Tampered or unauthenticated records are parsed and acted on.
Anti-replay (sequence and window)
Duplicated or out-of-window records are rejected, so old messages cannot be replayed.
DTLS replay window enabled, a duplicate-datagram test, and application deduplication for commands.
A replayed datagram is executed as if it were a new command.
0-RTT early data
Optional faster reconnect, but it is replayable and not forward-secret.
Early data limited to idempotent operations, with a replay-harmless or replay-rejected test.
A replayed early-data request triggers a state change.

15.3.7 Common Pitfalls

  • Confusing encryption with authentication: An encrypted connection can still reach the wrong peer. Check the certificate or PSK identity to establish the intended peer.
  • Claiming end-to-end security past a terminating proxy or broker: TLS and DTLS protect a hop; the session terminator reads plaintext.
  • Allowing plaintext or weak-version fallback: A failed or blocked handshake must fail closed rather than drop to cleartext or an obsolete version.
  • Using 0-RTT early data for state-changing commands: Early data is replayable and not forward-secret, making it unsafe for unlocks, configuration, firmware, or payments.
  • Forgetting DTLS replay and DoS handling: Datagrams can be lost, reordered, or duplicated. Without the anti-replay window and cookie exchange, duplicates and spoofed-source floods get through.

15.3.8 Under-the-Hood Knowledge Check

See why the tempting answer fails.
  1. A cartoon crosses out the wrong claim and shows the section evidence. Wrong idea: separate session keys give forward secrecy on their own. It fails because one stolen long-term key can reveal every recorded session key.

    Wrong idea: separate session keys give forward secrecy on their own. It fails because one stolen long-term key can reveal every recorded session key.

Recorded sessions remain exposed when one long-term key protects them all.

At this depth, TLS and DTLS are a set of independent guarantees layered on one connection: an authenticated, transcript-bound handshake; forward-secret key agreement; AEAD-protected records that are rejected before use on failure; anti-replay state that DTLS must maintain over lossy datagrams; and a clear plaintext boundary where the session terminates. A trustworthy review records each guarantee and its negative test, instead of accepting a single “it uses TLS” label.

15.4 Compare Stream and Datagram Handshakes Before You Choose

This section: Compare Stream and Datagram Handshakes Before You Choose

15.5 Summary

This section: Summary — TLS secures a reliable, ordered transport (TCP); DTLS is the datagram variant for unreliable transports (UDP), used with constrained protocols such as CoAP.

TLS secures a reliable, ordered transport (TCP); DTLS is the datagram variant for unreliable transports (UDP), used with constrained protocols such as CoAP. On one connection hop, TLS and DTLS authenticate the peer, keep the data confidential, and make it tamper-evident; encryption to an unverified peer is not security.

The handshake authenticates a negotiation transcript, so downgrade or tampering of the negotiated parameters is detected when both sides verify the Finished messages. TLS 1.3 (RFC 8446) standard suites use AEAD and no static RSA key transport; ephemeral (EC)DHE provides forward secrecy, but PSK-only mode does not. TLS 1.2 (RFC 5246) can be safe when configured with AEAD suites and ephemeral ECDHE.

A TLS 1.3 cipher suite selects an AEAD cipher and hash; key exchange and authentication are separate choices. Certificate validation must check the chain, validity, applicable revocation policy, and identity (name) match. DTLS adds per-record sequence numbers, an anti-replay window when enabled, and handshake retransmission; its configured cookie exchange resists spoofed-source denial of service and amplification. Verify the deployment’s replay and cookie policies.

0-RTT early data is replayable and not forward-secret, so it must be limited to safe, idempotent operations. TLS and DTLS protect only to the endpoint that terminates the session; a broker or proxy that terminates it reads plaintext.

Key Takeaway

TLS and DTLS protect a connection only when the transport choice, peer authentication, version and cipher policy, record protection, replay handling, and plaintext boundary are all chosen and evidenced, not when a single “it uses TLS” flag is set. Match TLS to streams and DTLS to datagrams, prove the peer’s identity, keep failure closed, and remember that the protection ends where the session terminates.

15.6 See Also

This section: See Also

Encryption Principles and Crypto Basics

Revisit confidentiality, integrity, authentication, and the AEAD discipline that TLS and DTLS records depend on.

Asymmetric Encryption

See the certificates, signatures, and ephemeral key agreement behind the handshake and forward secrecy.

E3 and E4 Transport Encryption

Place TLS and DTLS in the layered model and see where transport protection ends and payload protection begins.

Secure Communications

Apply transport security in firmware, provisioning, and day-to-day operations.

Find help

3 reviewed answers.

Where should I start in a module?

Open the module page from the sidebar to see its chapters in order. Use the module map to return to a topic you need.

Modules and paths

Reviewed

What can I try when a project does not work?

Check the symptom, then work through the diagnostic steps. Keep the error message and the smallest example that reproduces it.

When you are stuck

Reviewed

How do interactive examples work?

Use the interactive guide to check how examples and simulations work before changing your project.

Interactive examples guide

Reviewed