Beryl::TLS::RecordLayer
The record layer over an IO (RFC 9846 §5): writes and reads records, protects them once keys are installed, reassembles handshake messages and applies the plan's limits.
It does not decide what a message means; the handshake state machines
and Socket do. What it refuses on its own, with the alert RFC 9846
names: records over the size limits (record_overflow), records that
fail authentication (bad_record_mac), plaintext application data or
a protected record with an outer type other than application_data
(unexpected_message), zero-length handshake or alert fragments, a
handshake message interleaved with another content type, an alert that
is not two bytes (decode_error), and the floods the limits bound.
Every buffer it keeps starts at the size of the first record that needs
it (the read-ahead buffer at a record header, then the first record)
and grows, doubling, up to the record limits only when a larger
record arrives, so an idle connection with small requests holds a few
kilobytes. It reads ahead into its own buffer, so it turns off read
buffering on an IO::Buffered under it, for good: the bytes would
otherwise be buffered twice.
Constants
A handshake message header: type and a 24-bit length.
The largest plaintext fragment (§5.1).
The largest protected record this end writes: its header, the largest inner plaintext (content and type, no padding) and the tag.
The largest record on the wire: its header and the largest TLSCiphertext fragment.
Constructors
Instance methods
Bytes of records that fail to open which a server still skips, while it refuses the 0-RTT data a client offered (RFC 9846 §4.2.10).
Bytes of records that fail to open which a server still skips, while it refuses the 0-RTT data a client offered (RFC 9846 §4.2.10).
Returns whether no part of a handshake message is waiting. A key change must not split a message (§5.1).
Whether a plaintext alert is read while protection is installed: a server sets it while it waits for the client's flight, since a client that refuses the ServerHello has no keys to protect its alert with.
Whether a plaintext alert is read while protection is installed: a server sets it while it waits for the client's flight, since a client that refuses the ServerHello has no keys to protect its alert with.
Whether one compatibility change_cipher_spec is still accepted (RFC 9846 §5, Appendix D.4). A server turns it off until the first ClientHello is read; both ends turn it off once the handshake ends.
Whether one compatibility change_cipher_spec is still accepted (RFC 9846 §5, Appendix D.4). A server turns it off until the first ClientHello is read; both ends turn it off once the handshake ends.
Whether plaintext application_data records are skipped (within the same budget): a client that offered 0-RTT and got a HelloRetryRequest may still send them (§4.2.10).
Whether plaintext application_data records are skipped (within the same budget): a client that offered 0-RTT and got a HelloRetryRequest may still send them (§4.2.10).
The largest inner plaintext (content, type and padding) a protected record may carry: this end's record_size_limit once both ends sent one (RFC 8449 §4), 2^14 + 1 bytes until then.
The largest inner plaintext (content, type and padding) a protected record may carry: this end's record_size_limit once both ends sent one (RFC 8449 §4), 2^14 + 1 bytes until then.
The most content bytes per record written (the peer's record_size_limit less one, RFC 8449 §4).
The most content bytes per record written (the peer's record_size_limit less one, RFC 8449 §4).
Reads the next record after the handshake. Returns application data
as {ApplicationData, bytes}, a whole post-handshake message as
{Handshake, message}, or nil once the peer sent close_notify.
Reads the next whole handshake message, header included. Raises when anything but handshake records arrives, or the peer closes.
Keys for reading, or nil before the ServerHello.
Writes an alert. Errors from the IO are swallowed: an alert is the last thing sent on a failing connection.
Writes the one-byte compatibility change_cipher_spec record (Appendix D.4), always in plaintext.
Writes message (a whole handshake message) in as many handshake records as it takes. The first ClientHello goes out with the legacy record version 0x0301 (§5.1).
Keys for writing, or nil before the ServerHello.