For the complete documentation index, see llms.txt. This page is also available as Markdown.

DTLS Pre-Shared Keys

Authenticate CoAP devices over DTLS with a per-device pre-shared key

With DTLS pre-shared keys (PSK), each device shares a symmetric key with akenza. The device proves that it knows the key during the DTLS handshake, and the connection is encrypted with keys derived from it. No certificates are needed, which keeps the handshake small for constrained devices.

  • PSK identity: the device ID of the device in akenza. The device sends it in the DTLS handshake.

  • Key: one key per device, stored encrypted in akenza. akenza generates a 32-byte key, or you supply your own key of 16 to 64 bytes.

Setup

1. Create the device connector

Create a CoAP device connector and select DTLS with Pre-Shared Keys as device authentication (Create Data Flow > Start with empty Data Flow > + Device Connector > CoAP > New CoAP Device Connector).

2. Create the device and its key

Create a device on a data flow with this device connector. The device ID is the PSK identity, so set it to the identifier the device sends in the handshake (e.g. its serial number or IMEI).

Add the key in the Device Credentials section, either in the device creation wizard or later on the device details tab:

  • Generate key (default): akenza generates a random 32-byte key.

  • Use my own key: enter a key of 16 to 64 bytes, as hex or base64. Use this for keys that were provisioned on the device at the factory. A value with hex digits only is read as hex.

Optionally set a validity date. The device can no longer connect with the key after this date.

3. Provision the device

Configure the device with:

Setting
Value

Endpoint

coaps://coap.akenza.io:5684

PSK identity

The device ID

PSK

The key from step 2

Cipher suite

Store the key securely on the device, e.g. in a secure element or a hardware-backed keystore, not in plain-text application files.

POST coaps://coap.akenza.io:5684/v3/capture

The device is identified by the PSK identity, so the secret and deviceId query parameters are not needed. If deviceId is passed, it must match the PSK identity. Content formats, the timestamp and topic query parameters and the responses are the same as for plain CoAP (see CoAP).

Downlinks work the same way as with client certificates: the device pulls commands with GET /v3/commands over the DTLS connection, or receives them piggy-backed on an uplink.

Cipher suites

akenza offers the recommended PSK and ECDHE_PSK cipher suites, including:

Cipher suite
Notes

TLS_PSK_WITH_AES_128_CCM_8

Mandatory to implement for CoAP (RFC 7252 §9.1.3.1), smallest handshake

TLS_ECDHE_PSK_WITH_AES_128_CCM_8_SHA256

Adds forward secrecy: a leaked key does not decrypt previously recorded traffic

Use TLS_ECDHE_PSK_WITH_AES_128_CCM_8_SHA256 if the device can afford the additional elliptic curve computation.

With PSK cipher suites, akenza does not present a server certificate. The device knows it talks to akenza because only akenza knows the key.

DTLS Connection IDs are supported as for certificates, see DTLS with Connection ID (CID).

Key rotation and revocation

A device has only one active key. To rotate it, delete the credential on the device details tab, create a new one and provision the device with the new key. The device can't connect between the deletion and the re-provisioning.

Deleting the credential also revokes existing DTLS sessions: the next request of the device is answered with 4.01 Unauthorized, and new handshakes fail.

Troubleshooting

Symptom
Cause

The DTLS handshake fails

Unknown PSK identity, wrong key, no active key (deleted or expired), or the device's connector does not use DTLS with Pre-Shared Keys

4.01 Unauthorized after a handshake

The key was deleted or expired after the session was established, the connector's auth type was changed, or deviceId does not match the PSK identity

The server never answers the handshake

The device's first handshake message (ClientHello) is larger than one UDP datagram and is split in two. akenza drops split ClientHello messages. Offer fewer cipher suites and extensions, e.g. only the PSK cipher suites

Test the connection

With OpenSSL

The following script checks the key and sends one uplink with openssl s_client. It offers only TLS_PSK_WITH_AES_128_CCM_8, which keeps the handshake small:

A successful uplink returns a response starting with the bytes 61 41 (ACK, 2.01 Created), followed by a payload like {"id":"<uuid>","message":"ok"}.

To check only the handshake, run the openssl s_client command without -quiet and without input. A working handshake prints Cipher is PSK-AES128-CCM8.

With libcoap

You can also use coap-client from libcoap. Prefix a hex key with 0x:

A successful uplink returns 2.01 Created with a payload like {"message":"ok","id":"<uuid>"}.

Last updated

Was this helpful?