Config
#struct ConfigThe client configuration.
| Name | Type | Description |
|---|---|---|
server_name | str = "" | The hostname for SNI and for certificate verification. |
ca_file | str = "" | The file of root certificates; empty means the system roots. |
insecure_skip_verify | bool = false | Do not verify the certificate; for testing only, since it leaves the connection open to eavesdropping. |
skip_hostname_check | bool = false | Do not match the certificate against the server name. The chain is still verified against the CA; use it for a mode that checks the CA only. |
alpn | str = "" | The protocol for ALPN, such as h2. |
aes_only | bool = false | Offer AES ciphers only. |
frag_tls | bool = false | Split the first handshake message (the ClientHello) into several TLS records, so that a middlebox that reads only the first record never sees the whole hello. Off by default. |
frag_tcp | bool = false | Send the first flight as several small TCP writes, with frag_delay_ms between them, so that it does not travel in one packet. Off by default. |
frag_sni | bool = false | Make one cut in the middle of the server name, so no single record or packet holds the whole name. Used with frag_tls or frag_tcp. |
frag_min | int = 5 | The smallest piece in bytes when the hello is cut up. The default is 5. |
frag_max | int = 20 | The largest piece in bytes when the hello is cut up. The default is 20; a random size between frag_min and this is taken for each piece. |
frag_delay_ms | int = 0 | The pause in milliseconds between TCP pieces. The default is 0. |
frag_writes | int = 1 | How many of the first handshake writes are cut up. The default is 1, which is the ClientHello. |
import tls
func main:
mut cfg := tls.NewConfig("example.com")
cfg.alpn = "http/1.1"
mut conn := tls.Dial("example.com", 443, cfg)
if not tls.ConnOk(conn):
println "error:", tls.ConnError(conn)
ret
end
println tls.Version(conn), tls.CipherName(conn), tls.PeerCertCount(conn)
_ := tls.Write(conn, "GET / HTTP/1.1\r\nHost: example.com\r\nConnection: close\r\n\r\n")
mut body := ""
until tls.ConnOk(conn):
chunk := tls.Read(conn, 4096)
if chunk.Len() == 0:
break
end
body += chunk
end
println body.Len() > 0
tls.Close(conn)
end