Cryptography · Study deck

E2: Device-to-Gateway Encryption

Picture a sealed sensor message reaching a local controller that must read it before switching a fan.

Shield Shelly is your guide for this deck.

encryptiondevicegateway
Shield Shelly, the module guide, in a scene from this chapter.
iotclass.org

After studying this chapter

Learning objectives

You will be able to:

  • Explain exactly where E2 encryption terminates and which component owns plaintext.
  • Design an E2 packet envelope with per-device identity, nonce or counter, authenticated metadata, ciphertext, and tag.
  • Define replay protection that survives reset, sleep, loss, and gateway restart.
  • Decide when a trusted gateway justifies E2 and when an untrusted gateway requires E3.
iotclass.org

Major section

In 60 Seconds

A gateway means the trusted device or service that joins systems and, in this design, ends the protected device link.

  • E2 protects messages from a device to a trusted gateway.
  • Each device has its own credential, the gateway checks replay state and accepts plaintext only after authentication succeeds, and intermediate routers only forward ciphertext.
  • E2 is the right fit when the gateway is allowed to read payloads for local control or filtering.
iotclass.org

Major section

Choose E2 Only When the Gateway May Read · Plaintext Owner

E2 is not the same thing as end-to-end device-to-cloud encryption.

  • In E2, the gateway is trusted to authenticate and decrypt device payloads.
  • That final plaintext boundary is what enables local action and creates the gateway-compromise risk.
  • In E2, the gateway is an approved plaintext owner.

Key terms

If the gateway
If the gateway is third-party, semi-public, or outside your control, route sensitive payloads to E3.

Why it matters

Trusted gateway The gateway may read payloads The gateway can validate, decrypt, filter, aggregate, and act locally because it is a plaintext owner.

E2 protects the full device-to-gateway path, then intentionally terminates at the trusted gateway.
E2 protects the full device-to-gateway path, then intentionally terminates at the trusted gateway.
iotclass.org

Major section

Build the Packet So the Gateway Can Prove It

An E2 packet should let the receiver check three facts before it releases plaintext: which enrolled credential authenticated it, whether the message has already been accepted, and whether the protected bytes were modified.

  • Unknown device IDs, disabled devices, and swapped device IDs are rejected.
  • Separates old and new keys during rotation and recovery.
  • This packet structure turns the E2 trust boundary into a reviewable receive procedure rather than a claim that encryption is present.
  • Tampering with any authenticated header causes verification failure.

Why it matters

A unique nonce avoids reuse under one key; authenticated counter or sequence state enables replay rejection.

The gateway should authenticate metadata and freshness before accepting device plaintext.
The gateway should authenticate metadata and freshness before accepting device plaintext.
iotclass.org

Major section

Build the Packet So the Gateway Can Prove It (continued)

Identity selects the expected device and key scope; freshness state rejects an old envelope; authenticated metadata binds visible routing context to the protected message; and the tag detects modification before plaintext is accepted.

  • Old, retired, and future key epochs fail according to policy.
  • Replayed, rolled-back, duplicated, and out-of-window packets are rejected.
  • Authenticates headers that must remain readable for routing or policy decisions.
iotclass.org

Major section

Prefer a Reviewed AEAD Envelope · Make Freshness Survive Reboots and Loss

Replay protection is not just a sequence number field.

  • The device, gateway, and recovery process must agree what happens after sleep, reset, packet loss, clock drift, key rotation, and gateway failover.
  • Device stores send state Persist enough counter, epoch, or nonce state so reboot does not reuse values under the same key.
  • Loss is expected Use a bounded acceptance window only when the protocol can tolerate out-of-order delivery.
iotclass.org

Major section

Use DTLS When the Gateway Link Is Datagram-Based

Ordinary TLS expects reliable, ordered bytes, so it is the wrong transport shape for lossy datagram links.

  • DTLS is the TLS family protocol adapted for datagrams: it protects records that may be lost, reordered, or retransmitted while still requiring authentication, confidentiality, integrity, and replay handling.
  • DTLS can secure the device-to-gateway session, but the gateway is still a plaintext owner once the session terminates there.
  • Authenticated session endpoint that receives ordered bytes.

Key terms

If that plaintext ownership
If that plaintext ownership is not acceptable, the payload needs E3 object protection even if the local hop also uses DTLS.
iotclass.org

Major section

Use DTLS When the Gateway Link Is Datagram-Based (continued)

If that plaintext ownership is not acceptable, the payload needs E3 object protection even if the local hop also uses DTLS.

  • TCP profile, certificate or PSK policy, version policy, and identity validation tests.
  • DTLS version, cipher suite, replay window, retransmission behavior, and cookie behavior are tested.
  • Payload fields that must survive gateway forwarding without gateway plaintext access.
  • Forwarder only, unless the payload is explicitly assigned to E2 plaintext ownership.
iotclass.org

Major section

DTLS on Datagram Links · Choose Credentials the Device Can Protect

Certificate-based DTLS can be appropriate when devices can store and validate certificates and the deployment needs PKI-style identity management.

  • Very small sensors may instead use raw public keys or a pre-shared key profile.
  • The PSK must identify one device or a tightly bounded derivation path, not the whole fleet.
  • A good E2 review therefore pairs the authentication mode with key ownership, storage, rotation, and revocation evidence.
iotclass.org

Major section

Prove DTLS Survives Spoofing, Sleep, and Rotation · DTLS Cookie Exchange

Sleepy devices should not repeat full handshakes every time they wake if the protocol and risk model allow resumption.

  • UDP lets an attacker spoof source addresses more easily than TCP.
  • Battery life is the other deployment issue.
  • Spoofed-source handshakes fail without creating persistent gateway state or amplification.
iotclass.org

Major section

Choose E2, E3, or E4 by Plaintext Ownership

The right answer depends on who may see plaintext, not on which name sounds stronger.

  • That comparison connects the layer labels to a concrete review question: name every permitted reader first, then require keys and negative tests for that boundary.
  • Payloads that must remain opaque through gateways, brokers, queues, or proxies.
  • The E2 path ends at a trusted gateway that verifies and decrypts device data; the E3 path keeps the selected payload opaque until the cloud or application endpoint; and E4 protects an authenticated transport session, which may begin at the gateway after it has already seen plaintext.
Choose E2 only when gateway plaintext is part of the approved design.
Choose E2 only when gateway plaintext is part of the approved design.
iotclass.org

Major section

Choose E2, E3, or E4 by Plaintext Ownership (continued)

Gateway key store controls, per-device keys, replay rejection, tag failure tests, and local action policy.

  • Forwarder only; it should not have payload keys.
  • Gateway cannot decrypt test payloads; cloud rejects tampered objects and wrong device identity.
  • Certificate identity validation, version policy, expired/revoked credential behavior, and downgrade tests.
iotclass.org

Major section

E2 Is Appropriate When · Treat the Gateway Key Store as the Boundary

The E2 gateway is both a verifier and a key holder.

  • Its key store is therefore part of the security boundary, not a normal configuration file.
  • Provision Enroll unique device credentials Manufacturing, commissioning, or onboarding should create one device identity and one active E2 key record per device.
  • Rotate Support overlap and retry Rotation needs key epochs, rollback-safe activation, and recovery from devices that miss an update window.
iotclass.org

Major section

Scenario · Avoid the E2 Mistakes That Expose Plaintext

Gateways run local HVAC safety logic during cloud outages, so they are approved to read operational payloads.

  • Visitor-count payloads are sensitive and should remain opaque to the gateway.
  • Per-device E2 keys, replay rejection, tag failure tests, and gateway action logs.
  • Gateway policy limits storage, logging, and forwarding of decrypted fields.

Key terms

If gateway compromise
If gateway compromise is in scope, use E3 for sensitive fields or remove plaintext duties from the gateway.
iotclass.org

Major section

Summary · Key Takeaway

Device-to-gateway encryption protects data as it moves from constrained devices into local gateways.

  • It must account for local attackers, shared network media, gateway trust, credential storage, and what happens when gateways relay data onward.
  • Device-to-gateway security should define both ends of trust.
  • Encrypt the link, authenticate the device and gateway, and decide whether the gateway is allowed to see plaintext or only forward protected payloads.
iotclass.org

Deck summary

Key takeaways

A gateway means the trusted device or service that joins systems and, in this design, ends the protected device link.

  • E2 is not the same thing as end-to-end device-to-cloud encryption.
  • An E2 packet should let the receiver check three facts before it releases plaintext: which enrolled credential authenticated it, whether the message has already been accepted, and whether the protected bytes were modified.
  • Identity selects the expected device and key scope; freshness state rejects an old envelope; authenticated metadata binds visible routing context to the protected message; and the tag detects modification before plaintext is accepted.
iotclass.org

Retrieval practice

Recall check 1 of 4

Shield Shelly says: answer from memory, then check your reasoning.

Q1In E2 device-to-gateway encryption, where does protected payload become plaintext?

AInside any nearby device using the same fleet key
BAt every intermediate mesh router en route.
CAt the trusted gateway after authentication
DOnly at the cloud even when the gateway acts locally
Show answer

Answer: C The gateway is the approved plaintext owner in E2.

Q2A sleeping device reboots and its gateway also restarts; what must replay protection define?

ACiphertext length alone after both sides restart.
BBoth device and gateway need persistent or rebuilt freshness state.
CRadio transmit power with no per-device counter after restart.
DA rule accepting every old counter after restart
Show answer

Answer: B Counters alone fail if reset lets old packets appear fresh.

iotclass.org

Retrieval practice

Recall check 2 of 4

Shield Shelly says: answer from memory, then check your reasoning.

Q3Why is DTLS pre-shared-key mode often chosen for very constrained IoT devices?

AIt lets every device safely reuse one factory secret forever
BIt uses a provisioned symmetric key instead of certificates
CIt disables encryption so the handshake is cheaper
DIt avoids all key rotation and revocation requirements
Show answer

Answer: B PSK mode lowers device storage and computation needs, but the keys still need careful provisioning.

iotclass.org

Retrieval practice

Recall check 3 of 4

Shield Shelly says: answer from memory, then check your reasoning.

Q4What problem does the DTLS stateless cookie exchange solve for a UDP gateway?

AIt replaces all per-device credentials with anonymous access
BIt compresses telemetry payloads before local routing
CIt checks return-routability before allocating gateway handshake state
DIt proves the gateway may read every application payload
Show answer

Answer: C The client must echo a gateway-issued cookie before the gateway commits resources.

Q5What rejects duplicate device packets outside the permitted replay window at the gateway?

ADevice Credential
BAuthenticated Envelope
CGateway Key Store
DReplay State
Show answer

Answer: D It rejects duplicates and packets outside the allowed replay window, while permitted out-of-order packets may still pass.

iotclass.org

Retrieval practice

Recall check 4 of 4

Shield Shelly says: answer from memory, then check your reasoning.

Q6Complete the E2 gateway design review gate:

Areturn 'REQUIRE_PER_DEVICE_KEY'
Breturn 'ALLOW_SHARED_GATEWAY_SECRET'
Creturn 'SKIP_DEVICE_IDENTITY'
Dreturn 'ACCEPT_FACTORY_TEST_KEY'
Show answer

Answer: A The gate rejects shared fleet keys, missing replay rejection, missing tag-failure rejection, and sensitive payloads sent to an untrusted gateway.

iotclass.org

Print reference

Answers 1 of 2

Answer key.

  1. C · The gateway is the approved plaintext owner in E2.
  2. B · Counters alone fail if reset lets old packets appear fresh.
  3. B · PSK mode lowers device storage and computation needs, but the keys still need careful provisioning.
  4. C · The client must echo a gateway-issued cookie before the gateway commits resources.
  5. D · It rejects duplicates and packets outside the allowed replay window, while permitted out-of-order packets may still pass.
iotclass.org

Print reference

Answers 2 of 2

Answer key.

  1. A · The gate rejects shared fleet keys, missing replay rejection, missing tag-failure rejection, and sensitive payloads sent to an untrusted gateway.
iotclass.org