webrtc_dtls13_record (webrtc v0.1.0)
View SourceDTLS 1.3 record layer (RFC 9147 §4): demultiplexing of DTLSPlaintext and DTLSCiphertext records (§4.1), the unified header, AEAD protection with the TLS 1.3 nonce and inner plaintext (RFC 8446 §5.2, §5.3), record number encryption (§4.2.3), record number reconstruction (§4.2.2) and the ACK message (§7).
Nothing here raises on peer input: malformed records are skipped (§4.5.2).
Summary
Functions
Decrypt the record number, reconstruct it from Next (one plus the highest sequence number deprotected in the epoch) and open the record. Returns the full sequence number, the inner content type and the content.
Bytes added to a protected record: 5 byte header, content type and the 16 byte AEAD tag.
The same with the peer's connection ID in the header.
Protect one record with the full header (16-bit sequence number and length), encrypting the sequence number.
The same with the peer's connection ID in the header (C bit, RFC 9147 §4, §9), part of the AEAD additional data. No CID for undefined or an empty one.
The sequence number closest to Next whose low Bits bits are Low.
The most recent epoch among Epochs whose low two bits are Bits.
Split a datagram into records. Parsing stops at a record whose boundary cannot be found; records with a connection ID (not negotiated) stop parsing too, as the CID length is unknown.
The same, with records carrying a connection ID of CidLen bytes (the one we offered, RFC 9147 §9); undefined when we offered none, and a record with a CID then ends parsing (§9: rejected).
Types
-type rec() :: #{format := plain, type := webrtc_dtls_record:content_type(), version := 0..65535, epoch := 0..65535, seq := 0..281474976710655, fragment := binary()} | #{format := unified, epoch_bits := 0..3, cid => binary(), seq_len := 1 | 2, enc_seq := non_neg_integer(), first := byte(), length := undefined | non_neg_integer(), body := binary()}.
Functions
-spec decode_ack(binary()) -> {ok, [{non_neg_integer(), non_neg_integer()}]} | error.
-spec encode_ack([{non_neg_integer(), non_neg_integer()}]) -> binary().
-spec open(rec(), webrtc_dtls13_keys:keys(), non_neg_integer()) -> {ok, non_neg_integer(), webrtc_dtls_record:content_type(), binary()} | record_overflow | error.
Decrypt the record number, reconstruct it from Next (one plus the highest sequence number deprotected in the epoch) and open the record. Returns the full sequence number, the inner content type and the content.
-spec overhead() -> pos_integer().
Bytes added to a protected record: 5 byte header, content type and the 16 byte AEAD tag.
-spec overhead(undefined | binary()) -> pos_integer().
The same with the peer's connection ID in the header.
-spec protect(webrtc_dtls_record:content_type(), non_neg_integer(), non_neg_integer(), iodata(), webrtc_dtls13_keys:keys()) -> binary().
Protect one record with the full header (16-bit sequence number and length), encrypting the sequence number.
-spec protect(webrtc_dtls_record:content_type(), non_neg_integer(), non_neg_integer(), iodata(), webrtc_dtls13_keys:keys(), undefined | binary()) -> binary().
The same with the peer's connection ID in the header (C bit, RFC 9147 §4, §9), part of the AEAD additional data. No CID for undefined or an empty one.
-spec reconstruct(non_neg_integer(), 8 | 16, non_neg_integer()) -> non_neg_integer().
The sequence number closest to Next whose low Bits bits are Low.
-spec select_epoch(0..3, [non_neg_integer()]) -> {ok, non_neg_integer()} | error.
The most recent epoch among Epochs whose low two bits are Bits.
Split a datagram into records. Parsing stops at a record whose boundary cannot be found; records with a connection ID (not negotiated) stop parsing too, as the CID length is unknown.
-spec split(binary(), undefined | pos_integer()) -> [rec()].
The same, with records carrying a connection ID of CidLen bytes (the one we offered, RFC 9147 §9); undefined when we offered none, and a record with a CID then ends parsing (§9: rejected).