Manuscript Documentation
v2026.12.0

@std/net/tls.ms#

Import each required symbol with import Name from "@std/net/tls.ms".

CertificateInfo Type#

Parsed certificate identity, validity range, and original DER bytes.

Manuscript
type CertificateInfo {
    subject String
    issuer String
    dns_names List[String]
    not_before Timestamp
    not_after Timestamp
    der Bytes
}

CertificateInfo.der#

The certificate’s binary DER encoding, as a copy independent of the PEM text.

Manuscript
der Bytes

CertificateInfo.dns_names#

DNS subject alternative names in certificate order; empty when the certificate has none.

Manuscript
dns_names List[String]

CertificateInfo.issuer#

The issuing authority as a distinguished-name string, in the same format as subject.

Manuscript
issuer String

CertificateInfo.not_after#

End of the validity period as a UTC Timestamp.

Manuscript
not_after Timestamp

CertificateInfo.not_before#

Start of the validity period as a UTC Timestamp.

Manuscript
not_before Timestamp

CertificateInfo.subject#

The certificate subject as a distinguished-name string, such as CN=example.com,O=Example.

Manuscript
subject String

TlsInfo Type#

Negotiated TLS version, cipher, protocol, and peer certificate information.

Manuscript
type TlsInfo {
    version Int
    cipher_suite Int
    alpn String
    peer_certificates List[Bytes]
    verified Bool
}

TlsInfo.alpn#

The application protocol both sides agreed on, or an empty string when none was negotiated.

Manuscript
alpn String

TlsInfo.cipher_suite#

Negotiated cipher suite as its numeric IANA identifier, such as 4865 (0x1301) for TLS_AES_128_GCM_SHA256.

Manuscript
cipher_suite Int

TlsInfo.peer_certificates#

The peer’s presented certificates as DER bytes, leaf first; empty when the peer sent none.

Manuscript
peer_certificates List[Bytes]

TlsInfo.verified#

True when the peer’s certificate chain was verified against the configured roots; False when no peer chain was verified.

Manuscript
verified Bool

TlsInfo.version#

Negotiated protocol version as its numeric wire code, such as 771 (0x0303) for TLS 1.2 or 772 (0x0304) for TLS 1.3.

Manuscript
version Int

TlsOptions Type#

Client or server TLS settings, including roots, certificates, and ALPN protocols.

Manuscript
type TlsOptions {
    server_name String = ""
    roots_pem String = ""
    certificate_pem String = ""
    private_key_pem String = ""
    alpn List[String] = []
    require_client_certificate Bool = false
}

TlsOptions.alpn#

Application-layer protocols to offer or accept, in preference order, such as h2 or http/1.1. Each must be 1 through 255 bytes; empty disables negotiation.

Manuscript
alpn List[String] = []

TlsOptions.certificate_pem#

PEM certificate chain this side presents, paired with private_key_pem. Servers must supply it; clients supply it only for mutual TLS.

Manuscript
certificate_pem String = ""

TlsOptions.private_key_pem#

PEM private key matching certificate_pem. Both must be set together and match, or setup fails.

Manuscript
private_key_pem String = ""

TlsOptions.require_client_certificate#

Servers only: when True, a client must present a certificate that verifies against roots_pem. Setting it on a client configuration is rejected.

Manuscript
require_client_certificate Bool = false

TlsOptions.roots_pem#

PEM certificates to trust. Clients use them instead of the system roots; servers use them to verify client certificates. An empty string selects the system roots; invalid PEM is rejected.

Manuscript
roots_pem String = ""

TlsOptions.server_name#

Host name a TLS client sends for server name indication and matches against the server certificate; it must be non-empty for connect_tls_config. HTTP and WebSocket clients take the name from the URL host and ignore this field, and servers do not use it.

Manuscript
server_name String = ""

parse_certificates Function#

Parses PEM certificates. When max_certificates is given and the text holds more, the call returns EOVERFLOW rather than a truncated list; a negative limit returns EINVAL, and text that is not a PEM certificate returns EBADMSG.

Manuscript
fn parse_certificates(pem String, max_certificates Int? = null) Result[List[CertificateInfo], Error] { ... }

verify_certificates Function#

Verifies a PEM certificate chain for server_name against the roots and name constraints, as of now. An empty roots_pem reads the system roots. An empty server_name returns EINVAL, and invalid PEM returns EBADMSG.

Manuscript
fn verify_certificates(chain_pem String, roots_pem String, server_name String, now Timestamp) Result[Void, Error] { ... }