Nimony

The road to Nim 3

tls

nimony/lib/std/tls.nim

A TLS 1.3 client (RFC 8446) as a streamio.TlsEngine: a state machine that takes records in and gives records out and does no I/O of its own. The stream core moves the bytes (connect(address, tls = newTlsEngine())).

What it speaks, deliberately few:

  • TLS 1.3 only. Every server worth trusting has spoken it for years, and

1.2's surface is most of what has gone wrong with TLS.

  • Key exchange X25519; cipher suite TLS_CHACHA20_POLY1305_SHA256.
  • Server authentication by std/crypto/x509 against a TrustStore:

ECDSA P-256/P-384 and RSA-PSS CertificateVerify, a chain to a root, the host name. There is no "insecure" switch; a caller who must talk to a self-signed server puts that certificate into the store.

No session resumption, no 0-RTT, no client certificates (a request for one is answered with an empty certificate, which the server may refuse).

.. code-block:: nim let e = newTlsEngine() let (r, w) = connect("example.com:443", "GET / HTTP/1.1\r\n...", tls = e) # on a failure, e.failure / e.certError / e.alert say what went wrong