@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.
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.
der BytesCertificateInfo.dns_names#
DNS subject alternative names in certificate order; empty when the certificate has none.
dns_names List[String]CertificateInfo.issuer#
The issuing authority as a distinguished-name string, in the same format as
subject.
issuer StringCertificateInfo.not_after#
End of the validity period as a UTC Timestamp.
not_after TimestampCertificateInfo.not_before#
Start of the validity period as a UTC Timestamp.
not_before TimestampCertificateInfo.subject#
The certificate subject as a distinguished-name string, such as
CN=example.com,O=Example.
subject StringTlsInfo Type#
Negotiated TLS version, cipher, protocol, and peer certificate information.
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.
alpn StringTlsInfo.cipher_suite#
Negotiated cipher suite as its numeric IANA identifier, such as 4865 (0x1301) for TLS_AES_128_GCM_SHA256.
cipher_suite IntTlsInfo.peer_certificates#
The peer’s presented certificates as DER bytes, leaf first; empty when the peer sent none.
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.
verified BoolTlsInfo.version#
Negotiated protocol version as its numeric wire code, such as 771 (0x0303) for TLS 1.2 or 772 (0x0304) for TLS 1.3.
version IntTlsOptions Type#
Client or server TLS settings, including roots, certificates, and ALPN protocols.
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.
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.
certificate_pem String = ""TlsOptions.private_key_pem#
PEM private key matching certificate_pem. Both must be set together and match,
or setup fails.
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.
require_client_certificate Bool = falseTlsOptions.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.
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.
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.
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.
fn verify_certificates(chain_pem String, roots_pem String, server_name String, now Timestamp) Result[Void, Error] { ... }