abla/tls/pure/client

Generated from source.

Import with import "abla/tls/pure/client".

Source: abla/tls/pure/client/entry.ab

TLS_CLIENT_START (val)

val TLS_CLIENT_START

Client state before the handshake begins.

TLS_CLIENT_WAIT_SERVER_HELLO (val)

val TLS_CLIENT_WAIT_SERVER_HELLO

Client state awaiting the server's hello or retry.

TLS_CLIENT_WAIT_ENCRYPTED_EXTENSIONS (val)

val TLS_CLIENT_WAIT_ENCRYPTED_EXTENSIONS

TLS 1.3 state awaiting the server's encrypted extensions.

TLS_CLIENT_WAIT_CERTIFICATE (val)

val TLS_CLIENT_WAIT_CERTIFICATE

Client state awaiting the peer's certificate chain.

TLS_CLIENT_WAIT_CERTIFICATE_VERIFY (val)

val TLS_CLIENT_WAIT_CERTIFICATE_VERIFY

TLS 1.3 state awaiting the peer's transcript signature.

TLS_CLIENT_WAIT_FINISHED (val)

val TLS_CLIENT_WAIT_FINISHED

TLS 1.3 state awaiting the peer's Finished authenticator.

TLS_CLIENT_CONNECTED (val)

val TLS_CLIENT_CONNECTED

Client state after an authenticated handshake.

TLS_CLIENT_CLOSED (val)

val TLS_CLIENT_CLOSED

Client state after the TLS stream closes.

TLS_CLIENT_FAILED (val)

val TLS_CLIENT_FAILED

Terminal client state after a TLS error.

TLS_ALERT_CLOSE_NOTIFY (val)

val TLS_ALERT_CLOSE_NOTIFY

Alert indicating a clean end to the TLS stream.

TLS_ALERT_UNEXPECTED_MESSAGE (val)

val TLS_ALERT_UNEXPECTED_MESSAGE

Alert for a message that is invalid in the current protocol state.

TLS_ALERT_BAD_RECORD_MAC (val)

val TLS_ALERT_BAD_RECORD_MAC

Alert for an encrypted record that fails authentication.

TLS_ALERT_RECORD_OVERFLOW (val)

val TLS_ALERT_RECORD_OVERFLOW

Alert for a record beyond the negotiated size limit.

TLS_ALERT_HANDSHAKE_FAILURE (val)

val TLS_ALERT_HANDSHAKE_FAILURE

Alert for a handshake that cannot negotiate acceptable parameters.

TLS_ALERT_BAD_CERTIFICATE (val)

val TLS_ALERT_BAD_CERTIFICATE

Alert for a certificate the verifier rejects as bad.

TLS_ALERT_ILLEGAL_PARAMETER (val)

val TLS_ALERT_ILLEGAL_PARAMETER

Alert for a parameter with a disallowed value.

TLS_ALERT_DECODE_ERROR (val)

val TLS_ALERT_DECODE_ERROR

Alert for a message that cannot be parsed.

TLS_ALERT_DECRYPT_ERROR (val)

val TLS_ALERT_DECRYPT_ERROR

Alert for a failed handshake cryptographic check.

TLS_ALERT_PROTOCOL_VERSION (val)

val TLS_ALERT_PROTOCOL_VERSION

Alert for an unsupported TLS version.

TLS_ALERT_INTERNAL_ERROR (val)

val TLS_ALERT_INTERNAL_ERROR

Alert for a local failure that prevents completing the protocol.

TLS_ALERT_MISSING_EXTENSION (val)

val TLS_ALERT_MISSING_EXTENSION

Alert for a required extension missing from the handshake.

TLS_ALERT_UNSUPPORTED_EXTENSION (val)

val TLS_ALERT_UNSUPPORTED_EXTENSION

Alert for an extension that cannot be used in the current handshake.

TLS_ALERT_INAPPROPRIATE_FALLBACK (val)

val TLS_ALERT_INAPPROPRIATE_FALLBACK

Alert for an inappropriate fallback to an older protocol version.

TlsClientConfig (class)

class TlsClientConfig(
    val host: string,
    val suites: array<int>,
    val signatureAlgorithms: array<int>,
    val alpn: array<string>,
    val verifier: (array<string>, string, int, string, string) -> TlsVerdict,
    val random: (int) -> string,
    /** Builds the ClientHello that answers a HelloRetryRequest from the first one, the new key share and
     *  the cookie ("" for none); tlsPatchClientHello is the standard answer. */
    val secondHello: (string, TlsKeyShare, string) -> string,
    /** The TLS 1.2 suites (the modern subset) offered besides TLS 1.3's: [] makes a TLS 1.3-only client. */
    val suites12: array<int> = [TLS12_ECDHE_ECDSA_AES_128_GCM_SHA256, TLS12_ECDHE_RSA_AES_128_GCM_SHA256,
        TLS12_ECDHE_ECDSA_AES_256_GCM_SHA384, TLS12_ECDHE_RSA_AES_256_GCM_SHA384,
        TLS12_ECDHE_ECDSA_CHACHA20_POLY1305_SHA256, TLS12_ECDHE_RSA_CHACHA20_POLY1305_SHA256],
    /** True for a client that retries after a failed handshake with a lower version than it supports: the ClientHello
     *  then carries TLS_FALLBACK_SCSV (RFC 7507), so a server that could have done better refuses it. */
    val fallback: bool = false,
    /** The groups offered, in the client's order ([] for tlsDefaultGroups: the hybrid, X25519, P-256, P-384). The first gets a key
     *  share (with X25519's too when the first is the hybrid, as browsers do), the others are answered with a HelloRetryRequest. */
    val groups: array<int> = [],
    /** Where to find (and put) session tickets: a connection to a host that has a ticket in it offers to resume, and a ticket the server sends is kept in it
     *  (TLS 1.3, psk_dhe_ke, no 0-RTT). The caller owns the cache and shares it among connections; null: no resumption. */
    val sessions: TlsSessionCache? = null,
    /** What authenticated the server, as a name: tickets are kept and offered only under the same scope, because a resumption skips the Certificate (RFC 8446 section 4.6.1): "" (the default) keeps and offers none.
     *  tlsClientConfigWithSessions sets it; abla/tls/pure derives it from the verify mode and trust file; for tlsX509Verifier use tlsX509Scope(store). */
    val sessionScope: string = "",
    /** Revocation checking by OCSP stapling (abla/crypto/ocsp), on by default since v0.2.70: 0 asks for nothing and refuses what was not asked for (v0.2.69 and before); above 0 (1 = OCSP_POLICY_STAPLE, 2 = OCSP_POLICY_REQUIRE)
     *  the ClientHello offers status_request, a staple the server sends is read (TLS 1.3 in the Certificate entry, TLS 1.2 in a CertificateStatus message) and `stapleVerifier` judges the chain and its staples after the
     *  certificate check. It takes effect only with a `stapleVerifier`: the stock clients of abla/tls/pure (tlsConnect and its relatives, tlsSessionClient with TLS_VERIFY_HOST) set it from their trust store; a
     *  configuration made by hand with its own `verifier` has none, and then offers and checks nothing, as with 0 (tlsClientConfigWithRevocation sets both). */
    val revocation: int = 1,
    /** Called, when `revocation` is above 0, with the chain and the stapled response of each of its certificates ("" for none) once the chain and signature have verified; an answer that is not accepted ends the handshake. */
    val stapleVerifier: ((array<string>, array<string>) -> TlsVerdict)? = null
)

The certificate check: the chain (DER, end entity first), the host name, the signature scheme of the CertificateVerify, the content that was signed and the signature. Returns "" when the chain is trusted for the host and the signature is valid, else the reason.

TlsClientConfig.checksStaples (extension fun)

fun TlsClientConfig.checksStaples(): bool

Whether this configuration offers status_request and has the staples judged: revocation above 0 and a staple verifier to judge them.

TlsKeyPair (class)

class TlsKeyPair(val group: int, val publicKey: string, val privateKey: string)

An ephemeral key pair offered in the key_share extension.

TlsIdentity (class)

class TlsIdentity(val chain: array<string>, val schemes: array<int>, val sign: (int, string) -> string,
    val error: string = "", val secrets: array<string> = [])

A certificate and its key, a client's for mutual TLS or a server's: the chain (DER, end entity first), the signature schemes its key can make, and the signing function (scheme and the content to sign give the signature, "" on failure). secrets are the key bytes the signing function holds, which wipe clears (the loaders, tlsIdentityFromPem and tlsIdentityFromPkcs12, fill them in).

TlsIdentity.ok (method)

fun ok(): bool

True for an identity with a certificate and a key that signs.

TlsIdentity.wipe (extension fun)

fun TlsIdentity.wipe(): void

Clears the key bytes the identity holds: it signs nothing after this. For when it is done with (a connection's identity after its handshake, a listener's when it closes).

TlsClient (class)

class TlsClient(
    val config: TlsClientConfig,
    var state: int,
    var error: string,
    var inbox: string,
    var handshakeBuffer: TlsHandshakeBuffer,
    var outbox: string,
    var applicationData: string,
    val transcript: TlsTranscript,
    var hash: int,
    var suite: int,
    var keyLength: int,
    var aead: int,
    val helloRandom: string,
    val sessionId: string,
    var firstHello: string,
    var keyPairs: array<TlsKeyPair>,
    var retried: bool,
    var retrySuite: int,
    var readEncrypted: bool,
    var writeEncrypted: bool,
    var read: TlsRecordProtection,
    var write: TlsRecordProtection,
    var handshakeSecret: string,
    var clientHandshakeSecret: string,
    var serverHandshakeSecret: string,
    var clientApplicationSecret: string,
    var serverApplicationSecret: string,
    var masterSecret: string,
    var chain: array<string>,
    var negotiatedAlpn: string,
    var sentCompatibilityChangeCipherSpec: bool,
    var peerClosed: bool,
    var sentClose: bool,
    /** True when the handshake failed in the certificate check (the verifier's answer). */
    var certificateRejected: bool,
    /** The identity to present when the server asks for a certificate; null presents none. */
    var identity: TlsIdentity?,
    /** The certificate request's context and schemes, once the server has sent one. */
    var requested: bool,
    var requestContext: string,
    var requestSchemes: array<int>,
    /** TLS 1.2 (set when the server's hello chooses it): the suite code, the protections, the keys, the server random,
     *  the server's key-exchange group and point. */
    var v12: bool,
    var v12Suite: int,
    var v12Read: Tls12Protection,
    var v12Write: Tls12Protection,
    var v12Keys: Tls12Keys,
    var serverRandom: string,
    var v12Group: int,
    var v12Point: string,
    /** Records in a row that carried nothing (empty application data, ChangeCipherSpec), KeyUpdates in a row, and a
     *  KeyUpdate the peer asked for that is still to be answered (once per batch of input). */
    var emptyRun: int = 0,
    var keyUpdateRun: int = 0,
    var keyUpdateOwed: bool = false,
    /** Warning alerts in a row (ignored up to four, as BoringSSL does). */
    var warningRun: int = 0,
    /** The key exchange group that was negotiated (0 until the ServerHello is processed): the group of the key share, or of the
     *  TLS 1.2 ServerKeyExchange. */
    var negotiatedGroup: int = 0,
    /** Resumption: the ticket this connection offered (null if none), whether the server accepted it, and the resumption master secret kept to make the PSKs of
     *  the tickets the server sends (a buffer of its own, wiped with the connection). */
    var offeredPsk: TlsStoredTicket? = null,
    var didResume: bool = false,
    var resumptionMaster: string = "",
    /** The tls-exporter channel binding (RFC 9266), made when the TLS 1.3 handshake completes; "" before, and on TLS 1.2. */
    var channelExporter: string = "",
    /** Revocation: the OCSP response stapled to each certificate of the chain ("" for none), whether a TLS 1.2 CertificateStatus came, and whether the TLS 1.2 ServerHello promised one. */
    var statuses: array<string> = [],
    var statusSeen: bool = false,
    var statusPromised: bool = false,
    /** A ChangeCipherSpec arrived before the ServerHello (TLS 1.3 compatibility mode allows it): a ServerHello that then chooses TLS 1.2 makes it out of order. */
    var ccsBeforeHello: bool = false
)

Holds the TLS client state, transcript, key material, and record buffers for a socket-independent handshake.

tlsAeadFor (fun)

fun tlsAeadFor(suite: int): int

Returns the record protection algorithm for the TLS 1.3 suite, or zero for an unsupported suite.

tlsSuiteHash (fun)

fun tlsSuiteHash(suite: int): int

Returns SHA-384 for the AES-256-GCM TLS 1.3 suite and SHA-256 for the remaining suites.

TLS_MLKEM768_CLIENT_SHARE_SIZE (val)

val TLS_MLKEM768_CLIENT_SHARE_SIZE

---- Key exchange groups ---- (A slice, and a string built with +, may share their memory with the string they come from, so what is made of a secret and outlives its wiping is copied into a buffer of its own, tlsOwnedCopy, first: the secret made of two parts, the public key sliced out of a decapsulation key.) X25519MLKEM768 (draft-ietf-tls-ecdhe-mlkem, section 4): the client's key_exchange value is the ML-KEM-768 encapsulation key (1184 bytes) followed by an X25519 public key (32): 1216 bytes (section 4.1, which notes the order is the reverse of the naming convention of the hybrid design draft: "for historical reasons"); the server's is the ML-KEM ciphertext (1088) followed by its X25519 public key (32): 1120 bytes (section 4.2); the shared secret is the ML-KEM secret followed by the X25519 one, 64 bytes (section 4.3). The server checks the encapsulation key (FIPS 203 section 7.2) and aborts with illegal_parameter when it fails, the client checks the ciphertext length (illegal_parameter), and the X25519 part has its all-zero check (section 4.3 and RFC 8446 section 7.4.2). The private key of a hybrid pair is the 2400-byte decapsulation key followed by the 32-byte X25519 scalar.

TLS_MLKEM768_SERVER_SHARE_SIZE (val)

val TLS_MLKEM768_SERVER_SHARE_SIZE

Byte length of the server's hybrid share, including the ML-KEM-768 ciphertext and X25519 public share.

tlsDefaultGroups (fun)

fun tlsDefaultGroups(): array<int>

The groups a ClientHello lists when the configuration names none: the hybrid first, then the classic curves.

tlsGroupIsHybrid (fun)

fun tlsGroupIsHybrid(group: int): bool

Returns true for the combined X25519 and ML-KEM-768 exchange group.

tlsGroupIsClassic (fun)

fun tlsGroupIsClassic(group: int): bool

The groups TLS 1.2's ECDHE can use (named curves): the hybrid is a TLS 1.3 group only.

tlsGenerateKeyPair (fun)

fun tlsGenerateKeyPair(group: int, random: (int) -> string): TlsKeyPair?

A key pair for group from the bytes of random (32 for X25519 and P-256, 48 for P-384, 64 and 32 for the hybrid's seeds and its X25519 key): null for another group. The private key is made of the random source's bytes, which the machine that uses the pair clears when it is done (tlsWipe): random returns fresh bytes, as tlsPureRandom does.

tlsAgree (fun)

fun tlsAgree(pair: TlsKeyPair, peerShare: string): CryptoResult

The shared secret of our key pair and the peer's share; ok false for an invalid share (for the hybrid: a share that is not the 1120 bytes of a server's, or whose X25519 part gives an all-zero secret).

TlsServerExchange (class)

class TlsServerExchange(val ok: bool, val alert: int, val error: string, val publicKey: string, val secret: string)

What a server does with a client's key share: the share to send back and the shared secret, or the alert to send.

tlsServerExchange (fun)

fun tlsServerExchange(group: int, clientShare: string, random: (int) -> string): TlsServerExchange

The server's half of the key exchange for group against the client's share. A DH group makes its ephemeral key and agrees; the hybrid encapsulates to the client's ML-KEM key (which must pass FIPS 203 section 7.2) and makes an X25519 key.

TlsClientShares (class)

class TlsClientShares(val ok: bool, val groups: array<int>, val pairs: array<TlsKeyPair>, val shares: array<TlsKeyShare>)

What a ClientHello offers for key exchange: the groups listed, the key shares sent and the key pairs behind them.

tlsClientShares (fun)

fun tlsClientShares(requested: array<int>, tls13: bool, random: (int) -> string): TlsClientShares

The groups and key shares of a ClientHello for the groups requested (in the client's order). With TLS 1.3 the shares are for the first classical group (X25519, P-256 or P-384) and the first hybrid, as BoringSSL's and browsers' clients do, so a server that has either answers with no extra round trip, and anything else costs a HelloRetryRequest; a group that cannot be offered here is skipped for the shares. A client without TLS 1.3 (tls13 false) lists the classical groups only (the hybrid is a TLS 1.3 group) and has a share for the first of them. ok is false if a key pair cannot be made.

tlsClientConfig (fun)

fun tlsClientConfig(host: string, verifier: (array<string>, string, int, string, string) -> TlsVerdict,
    random: (int) -> string): TlsClientConfig

The usual configuration: AES-GCM suites, the signature schemes the stack can verify, no ALPN.

tlsClientStartWith (fun)

fun tlsClientStartWith(config: TlsClientConfig, clientHello: string, helloRandom: string, sessionId: string,
    keyPairs: array<TlsKeyPair>, recordVersion: int, offeredPsk: TlsStoredTicket? = null): TlsClient

Starts a client from a ClientHello message that is already built (its 4-byte header included), with the random, session id and key pairs it was built from. The RFC 8448 traces use this; tlsClientNew builds its own. The ClientHello is queued as the first record. The client keeps copies of the private keys, which it clears when it is done with them; keyPairs stay as they are.

tlsClientNew (fun)

fun tlsClientNew(config: TlsClientConfig): TlsClient

Starts a client: builds a ClientHello with a fresh random, a 32-byte compatibility session id and the key shares for the configuration's groups (the hybrid and X25519 by default) from its random source.

TlsClient.failed (extension fun)

fun TlsClient.failed(): bool

Returns true when the TLS client is in its failure state.

TlsClient.connected (extension fun)

fun TlsClient.connected(): bool

Returns true when the TLS client has completed its handshake.

TlsClient.closed (extension fun)

fun TlsClient.closed(): bool

True once the peer sent close_notify (every byte it sent was delivered).

TlsClient.takeOutput (extension fun)

fun TlsClient.takeOutput(): string

The bytes to send to the peer; empties the queue.

TlsClient.takeApplicationData (extension fun)

fun TlsClient.takeApplicationData(): string

The application data received so far; empties the buffer.

TlsClient.useIdentity (extension fun)

fun TlsClient.useIdentity(identity: TlsIdentity): void

Sets the certificate to present if the server asks for one (before the first feed).

TlsClient.alpn (extension fun)

fun TlsClient.alpn(): string

The ALPN protocol the server chose ("" for none).

TlsClient.feed (extension fun)

fun TlsClient.feed(data: string): void

Feeds bytes received from the peer: every complete record in them is processed.

TlsClient.send (extension fun)

fun TlsClient.send(data: string): bool

Queues application data (any length) as records. False when the connection is not open.

TlsClient.close (extension fun)

fun TlsClient.close(): void

Queues close_notify; the connection takes no more application data.

TLS_CLIENT12_WAIT_CERTIFICATE (val)

val TLS_CLIENT12_WAIT_CERTIFICATE

---- TLS 1.2 (the modern subset, RFC 5246 with RFC 7627's extended master secret) ---- The server's ServerHello without supported_versions switches the client to this path: Certificate, ServerKeyExchange (ECDHE, signed under the certificate's key with the client's and server's randoms), [CertificateRequest], ServerHelloDone; then the client's [Certificate], ClientKeyExchange, [CertificateVerify], ChangeCipherSpec, Finished; then the server's ChangeCipherSpec and Finished.

TLS_CLIENT12_WAIT_KEY_EXCHANGE (val)

val TLS_CLIENT12_WAIT_KEY_EXCHANGE

TLS 1.2 state awaiting the server's signed key exchange.

TLS_CLIENT12_WAIT_HELLO_DONE (val)

val TLS_CLIENT12_WAIT_HELLO_DONE

TLS 1.2 state awaiting the end of the server's initial messages.

TLS_CLIENT12_WAIT_CHANGE_CIPHER_SPEC (val)

val TLS_CLIENT12_WAIT_CHANGE_CIPHER_SPEC

TLS 1.2 state awaiting the switch to negotiated record protection.

TLS_CLIENT12_WAIT_FINISHED (val)

val TLS_CLIENT12_WAIT_FINISHED

TLS 1.2 state awaiting the server's Finished authenticator.

tlsCertificateEcGroup (fun)

fun tlsCertificateEcGroup(certificate: string): int

The TLS group (secp256r1 23, secp384r1 24, secp521r1 25) of the EC key in the DER certificate certificate, or 0 for another or no EC key (RFC 8422 section 5.1.1: in TLS 1.2 the client's list of groups also names the curves of the certificates it accepts).

TlsClient.resumed (extension fun)

fun TlsClient.resumed(): bool

Whether this connection resumed a session: the server accepted a ticket from the cache (so no certificate was sent).

TlsClient.channelBinding (extension fun)

fun TlsClient.channelBinding(kind: string): string

The channel binding of kind ("tls-exporter" or "tls-server-end-point", abla/tls/pure/binding), raw bytes, "" when it is not available (see there). Valid once connected.

tlsClientConfigWithSessions (fun)

fun tlsClientConfigWithSessions(config: TlsClientConfig, sessions: TlsSessionCache?, scope: string): TlsClientConfig

config with its ticket cache set (the other fields as they were): a connection made from it offers the tickets in sessions that were obtained under the same scope and keeps the ones the server sends under it. scope names what authenticates the server for this configuration (the verify mode and trust anchors, for abla/tls/pure's own configurations; tlsX509Scope(store) for tlsX509Verifier(store, now)): a ticket resumes without a Certificate, so a ticket must never cross to a configuration that verifies differently. "" keeps and offers none.

tlsClientConfigWithAlpn (fun)

fun tlsClientConfigWithAlpn(config: TlsClientConfig, alpn: array<string>): TlsClientConfig

config offering the application protocols alpn (in the client's order, for example ["h2", "http/1.1"]); the server's choice is TlsClient.alpn() once connected ("" when it chose none). Names are checked when the client starts.

TlsBuiltHello (class)

class TlsBuiltHello(val message: string, val ticket: TlsStoredTicket?)

A ClientHello and the ticket it offers (null when it offers none).

tlsClientBuildHello (fun)

fun tlsClientBuildHello(config: TlsClientConfig, helloRandom: string, sessionId: string, offer: TlsClientShares): TlsBuiltHello

The ClientHello for config and the key shares in offer: with a ticket cache, a ticket for the host and ALPN protocols (taken out of the cache) goes in as a PSK (psk_dhe_ke) with its binder over the partial ClientHello (RFC 8446 section 4.2.11). The caller starts the client with the message (tlsClientStartWith) and sets offeredPsk to the ticket, or uses tlsClientNew, which does all this.

tlsClientConfigWithRevocation (fun)

fun tlsClientConfigWithRevocation(config: TlsClientConfig, policy: int, stapleVerifier: (array<string>, array<string>) -> TlsVerdict,
    verifier: ((array<string>, string, int, string, string) -> TlsVerdict)? = null): TlsClientConfig

config with revocation checking by OCSP stapling (abla/crypto/ocsp): policy is OCSP_POLICY_STAPLE (use a staple when the server sends one, refuse a revoked or invalid one, accept the lack of one unless the certificate is must-staple) or OCSP_POLICY_REQUIRE (a good staple is required); 0 is as before. The ClientHello then offers status_request, and after the chain and the signature have verified stapleVerifier (tlsOcspVerifier of abla/tls/pure/verify) judges the stapled responses. verifier, when given, replaces the config's chain verifier (the one tlsX509RevocationVerifiers makes with the staple verifier, which then does not verify the chain again). Nothing is fetched.

Built from Abla v0.2.79 source ba5d6b7d. Examples and generated signatures follow that source revision.