std

module std::tlssource

TLS 1.2 and 1.3 over a TCP connection (std::net), client or server: Mbed TLS behind the compiler's src/support/tls.c, which a native program links only when it reaches this module (lib/<target>/tls.a; Mbed TLS is Apache-2.0, its notice in lib/<target>/mbedtls-LICENSE). ECDHE over X25519, P-256 and P-384, AES-GCM and ChaCha20-Poly1305, RSA and ECDSA certificates.

A client trusts the certificate authorities in the PEM file ALLOY_CA_FILE names, when it is set; else the system's: on Linux its bundle (SSL_CERT_FILE, else the distributions' usual places), on Windows its chain engine and SSL policy, which fetch roots not yet needed and check revocation, on macOS its trust evaluation, which follows the Keychain. WebAssembly has none: on WASI every connect fails with Unsupported, and the web's requests go through the browser.

type Tlssource

exp type Tls : Disposable = struct

A session over a connection, which it owns: disposing it ends the session (telling the peer) and closes the connection.

Functions

type TlsErrorsource

exp type TlsError = enum

Why a session did not start.

Variants

Certificate: String

the server's certificate is not trusted for the host: why

Handshake: String

the handshake failed otherwise: why, when known

Unsupported

no TLS here: WebAssembly

type Certificatesource

exp type Certificate = struct

A server's certificate chain, its own certificate first, and its private key, as PEM text.

Fields

exp chain: Vector<u8>
exp key: Vector<u8>

Functions

fn Certificate::from_pemsource

exp fn Certificate::from_pem(chain: &[u8], key: &[u8]) -> Certificate

fn Tls::connectsource

exp fn Tls::connect(connection: Connection, host: &[u8]) -> Result<Tls, TlsError>

The handshake over the connection as its client, the server's certificate checked for the host.

fn Tls::acceptsource

exp fn Tls::accept(connection: Connection, certificate: &Certificate) -> Result<Tls, TlsError>

The handshake over the connection as its server, with the certificate: for tests and services. The client's certificate is not asked for.

fn readsource

exp fn read(self tls: &var Tls, buffer: &var [u8]) -> u64

Reads what has arrived into the buffer, waiting for some; how many bytes, 0 when the peer ended the session or closed the connection, or after an error or a timeout.

fn writesource

exp fn write(self tls: &var Tls, bytes: &[u8]) -> bool

Writes all the bytes; false when the session failed.

fn connectionsource

exp fn connection(self tls: &Tls) -> &Connection

The connection under the session: for its handle, or to shut it down from another task.

fn set_timeoutsource

exp fn set_timeout(self tls: &var Tls, limit: Duration)

Makes reads and writes waiting longer than the limit fail, as the connection's set_timeout does.

fn disposesource

exp fn dispose(self tls: &var Tls)