netio/tls/conn.rs#
Source: lib/netio/tls/conn.rs
conn -- the TLS handshake and the record stream, without I/O
Conn::client(cfg) / Conn::server(cfg)
feed(bytes) bytes from the peer (any split)
take_out() -> bytes to send to the peer
read_plain / write_plain / close
established(), peer_cert(), version(), suite()
TLS 1.3 on both sides: the suites ChaCha20-Poly1305, AES-128-GCM (SHA-256) and AES-256-GCM
(SHA-384); the groups X25519MLKEM768 (post-quantum hybrid), X25519, P-256 and P-384, and on
the server also SecP256r1MLKEM768 and SecP384r1MLKEM1024 (kx.rs); certificates and handshake
signatures with Ed25519, ECDSA (P-256 / P-384), RSA-PSS (RSA PKCS #1 v1.5 for certificates);
mutual authentication with any of these keys. A client sends key shares for
X25519MLKEM768 and X25519 and takes a HelloRetryRequest for P-256 or P-384; a server sends one
for the first group of the client it has when no share fits, and a dummy change_cipher_spec
for middleboxes (D.4).
A client that trusts the system's certificate authorities (Trust::System: mail servers,
update servers, web hooks) or a check of its own (Trust::Custom) falls back to TLS 1.2 with
ECDHE (X25519, P-256, P-384) and AEAD suites (AES-GCM, ChaCha20-Poly1305), the extended
master secret when the server has it and the TLS 1.3 downgrade check. Other connections
never fall back.
Resumption (TLS 1.3, RFC 8446 2.2, 4.6.1): a server with ServerConfig::tickets sends session
tickets after the client's Finished and takes them back with psk_dhe_ke (the PSK and a fresh
key exchange); a client with ClientConfig::sessions keeps the tickets it gets and offers one.
0-RTT (2.3, 4.2.10) when the server allows it (ServerConfig::early_data): the client sends
data right after its ClientHello, the server takes it only from a fresh ClientHello it has
not seen (8.2, 8.3) and hands it apart from the rest (read_early). No external PSKs, no
psk_ke, no TLS 1.2 resumption, no renegotiation; post-handshake KeyUpdate is supported.
Every protocol error ends the connection with the matching alert.
AL_CLOSE_NOTIFY: u8 = 0
AL_UNEXPECTED_MESSAGE: u8 = 10
AL_BAD_RECORD_MAC: u8 = 20
AL_RECORD_OVERFLOW: u8 = 22
AL_HANDSHAKE_FAILURE: u8 = 40
AL_BAD_CERTIFICATE: u8 = 42
AL_UNSUPPORTED_CERTIFICATE: u8 = 43
AL_CERTIFICATE_REVOKED: u8 = 44
AL_CERTIFICATE_EXPIRED: u8 = 45
AL_ILLEGAL_PARAMETER: u8 = 47
AL_UNKNOWN_CA: u8 = 48
AL_DECODE_ERROR: u8 = 50
AL_DECRYPT_ERROR: u8 = 51
AL_PROTOCOL_VERSION: u8 = 70
AL_INTERNAL_ERROR: u8 = 80
AL_NO_RENEGOTIATION: u8 = 100
AL_MISSING_EXTENSION: u8 = 109
AL_UNSUPPORTED_EXTENSION: u8 = 110
AL_BAD_CERTIFICATE_STATUS_RESPONSE: u8 = 113
AL_CERTIFICATE_REQUIRED: u8 = 116
AL_NO_APPLICATION_PROTOCOL: u8 = 120
struct Conn
impl Conn
fn group(&self) -> u16the key exchange groupfn alpn(&self) -> Option<&str>the application protocol agreed on (ALPN; one that is not UTF-8 gives None)fn server_name(&self) -> &stra server: the name of the client's server_name (lower case)fn client(cfg: ClientConfig) -> Connfn client_early(cfg: ClientConfig, early: &[u8]) -> Conna client that sendsearlyas 0-RTT data right after its ClientHello when a session of cfg.sessions allows it (as much as the session takes); early_taken() says after the handshake what the server took. Empty: Conn::clientfn server(cfg: ServerConfig) -> Connfn established(&self) -> boolfn ready(&self) -> boolthe connection carries data: established, or a server that took 0-RTT and sent its flight (it may read the early data and answer before the client's Finished, RFC 8446 4.2.10; read_plain gives data only once the handshake is done)fn resumed(&self) -> boolthe handshake took a ticket (a PSK) instead of certificatesfn early_taken(&self) -> usizea client: the bytes of its 0-RTT data the server took (0: none sent, the server refused them, or it has not answered yet)fn in_early(&self) -> boola server: 0-RTT data may still come (it took 0-RTT and the client's EndOfEarlyData has not come)fn has_early(&self) -> boola server: 0-RTT data received and not read yetfn read_early(&mut self, buf: &mut [u8]) -> usizea server: read 0-RTT data (data an attacker may have replayed, RFC 8446 8: for requests that do no harm twice); what is not read here comes first from read_plain once the handshake is donefn closed(&self) -> boolfn peer_closed(&self) -> boolthe peer sent close_notify (an orderly end, not a cut connection)fn test_force_status(&mut self)(tests) a server staples what it keeps even to a client that did not askfn ocsp_response(&self) -> Option<&[u8]>a client: the OCSP response the server stapled for its certificate (DER)fn peer_certs(&self) -> &[Cert]the peer's certificate chain (leaf first)fn version(&self) -> &'static str"TLS 1.3" / "TLS 1.2"fn suite(&self) -> u16the negotiated cipher suitefn take_out(&mut self) -> Vec<u8>fn has_plain(&self) -> boolfn read_plain(&mut self, buf: &mut [u8]) -> usizefn write_plain(&mut self, data: &[u8]) -> Result<(), TlsError>fn test_cr_sig_algs(&mut self, algs: Vec<u16>)(tests) the signature schemes a server's CertificateRequest lists (empty: all it takes)fn test_server_prefs(&mut self, suites: Vec<u16>, groups: Vec<u16>)(tests) a server that prefers these suites, in this order, and has only these groups (empty: its own): HelloRetryRequests and suites of SHA-384 between two JFLib programsfn test_key_update(&mut self, request: bool) -> Result<(), TlsError>(tests) a KeyUpdate of our own (TLS 1.3, established),request: the peer is asked to update its keys toofn write_empty(&mut self) -> Result<(), TlsError>(tests) an application data record without datafn close(&mut self)send close_notifyfn feed(&mut self, data: &[u8]) -> Result<(), TlsError>bytes from the peer