quic_cert (quic v3.2.0)

View Source

Summary

Functions

Read trust anchors from a PEM file as DER.

Check, where a server starts, that a listener asking for client certificates has trust anchors to check them against. Without cacerts or cacertfile every client certificate would be checked against the OS store, so any publicly issued one would authenticate.

A host name as matched against certificates and sent as SNI: without a trailing dot, internationalized labels as A-labels (UTS 46 mapping, STD3 rules). error when the result is not a host name (labels of 1 to 63 letters, digits, - or _, at most 253 octets) or is an IP address.

The address a host or server name gives as an IP literal, bare or in brackets ([::1]), with or without an IPv6 zone ID; error for a hostname.

Whether a server with these options asks the client for a certificate: verify (true or verify_peer) asks and accepts a client without one; require_client_cert asks and refuses one without.

Turn a cacertfile option into the DER cacerts the rest of the library takes.

Validate a client's certificate chain (mutual TLS, RFC 9846 §4.5.1.3).

Validate a server's certificate chain and identity.

Functions

cacerts_from_file(File)

-spec cacerts_from_file(file:name_all()) ->
                           {ok, [public_key:der_encoded()]} |
                           {error, {cacertfile, file:name_all(), term()}}.

Read trust anchors from a PEM file as DER.

A bundle yields every certificate in it. A file that cannot be read, or that holds no certificate, is an error rather than an empty list: empty anchors mean trust nothing, which fails every later handshake with a reason that says nothing about the file.

check_client_auth(Opts)

-spec check_client_auth(map()) -> ok | {error, term()}.

Check, where a server starts, that a listener asking for client certificates has trust anchors to check them against. Without cacerts or cacertfile every client certificate would be checked against the OS store, so any publicly issued one would authenticate.

dns_name(ServerName)

-spec dns_name(binary()) -> {ok, binary()} | error.

A host name as matched against certificates and sent as SNI: without a trailing dot, internationalized labels as A-labels (UTS 46 mapping, STD3 rules). error when the result is not a host name (labels of 1 to 63 letters, digits, - or _, at most 253 octets) or is an IP address.

host_address(Host)

-spec host_address(binary() | string()) -> {ok, inet:ip_address()} | error.

The address a host or server name gives as an IP literal, bare or in brackets ([::1]), with or without an IPv6 zone ID; error for a hostname.

requests_client_cert(Opts)

-spec requests_client_cert(map()) -> boolean().

Whether a server with these options asks the client for a certificate: verify (true or verify_peer) asks and accepts a client without one; require_client_cert asks and refuses one without.

resolve_cacerts(Opts)

-spec resolve_cacerts(map()) -> {ok, map()} | {error, term()}.

Turn a cacertfile option into the DER cacerts the rest of the library takes.

Called once where a connection or server starts, so the file is read once and a bad path fails the call that named it. An explicit cacerts is what the caller already resolved, so it wins.

validate_client(Leaf, Intermediates, CaCerts)

-spec validate_client(binary() | undefined, [binary()], [binary()] | undefined) -> ok | {error, term()}.

Validate a client's certificate chain (mutual TLS, RFC 9846 §4.5.1.3).

Same trust-anchor chain validation as validate_server/4, but with no identity/hostname check: a client certificate is not bound to a server name, and the peer's application identity is established separately (e.g. from the certificate subject plus an out-of-band token). Leaf is the client's end-entity certificate (DER), Intermediates the rest of the chain in wire (leaf-to-root) order, and CaCerts the trust anchors (DER list, or undefined for the OS trust store).

validate_server(Leaf, Intermediates, CaCerts, ServerName)

-spec validate_server(binary() | undefined, [binary()], [binary()] | undefined, binary() | undefined) ->
                         ok | {error, term()}.

Validate a server's certificate chain and identity.

Leaf is the server's end-entity certificate (DER). Intermediates are the remaining certificates sent by the peer (DER), in the leaf-to-root order they arrive on the wire. CaCerts are the trust anchors as a DER list, or undefined to use the OS trust store. ServerName is the expected identity (binary hostname or IP literal), or undefined to skip the hostname check.