Import std.net.tls
TlsClient
class
Public Class TlsClient
A client of TLS, which connects over a stream to a server whose certificate is for the host it connects to, which a root it trusts signed: the OS's, as it starts, or its own. It can offer application protocols, and give a certificate of its own to a server that asks for one.
Examples
Local tls = TlsClient()
tls.Offer(["http/1.1"])
Local tcp = Try TcpStream.Connect("example.com", 443)
Local secure = Try tls.Connect(tcp, "example.com")
Print(secure.Version, secure.PeerCertificate?.Subject ?? "no certificate")
Try secure.WriteText("GET / HTTP/1.1\r\nHost: example.com\r\nConnection: close\r\n\r\n")
Print(Try ReadAllText(secure))-
A new TlsClient, which trusts the OS's roots.
-
Trusts only
rootsfrom then on, instead of the OS'sroots, as for a server whose certificate a CA of a company's own signed. -
Trusts the OS's roots again, from then on.
-
Offers the application
protocols, like "h2" and "http/1.1", most wanted first, of which the server picks one, which the TlsStream's Protocol says. Panics for a name that isn't 1 to 255 bytes, or has a NUL, or names that come to more than 8192 bytes, each with 1 more. -
Gives a server that asks for a certificate
chain, its own certificate first, andkey, its private key. Panics when thechainis empty, or a certificate is one mbedTLS can't read, or thekeyisn't the first certificate's private key, of ECDSA P-256 or RSA, or the first certificate's usages aren't a TLS client's. -
@PanicsAtCaller Public Method Connect<S>(stream: S, host: String): TlsStream<S> Throws NetError, TimeoutErrormethod #TLS over
streamtohost, a name or an IP address, which the server's certificate has to be for, once the handshake is done. A name goes to the server as its server_name, and an address as none, as RFC 6066 has it. Panics for an emptyhost, one with a NUL, or one of more than 255 bytes. -
@PanicsAtCaller Public Async Method ConnectAsync<S>(stream: S, host: String): TlsStream<S> Throws NetError, TimeoutErrormethod #Connect's Async twin, which waits on the main thread.
Report an issue with this page or with FutureBlitz on GitHub.