JFLib

netio/trust.rs#

Source: lib/netio/trust.rs

trust -- https to a server with its own private CA (Ed25519): the client either has the CA
(a PEM file), has pinned the CA's fingerprint, or learns it on the first connection and lets
the user decide (trust on first use, like SSH host keys)

  presented_ca(&chain, name, now)  the CA at the end of a server's chain that issued the
                                   server certificate, valid now and for `name`
  connector(ServerTrust, identity, seen)   for Client::with_connector; a CA that is unknown
                                   (Ask) or not the pinned one ends the handshake with
                                   HttpError::Tls(UNTRUSTED) and lands in `seen`
  fingerprint_text(&digest)        "AB:CD:..." for people to compare
  system_connector(extra_cas)      https to public servers: the system's CAs (and these),
                                   TLS 1.3 or 1.2 (mail servers, update servers, web hooks)

The connectors of a CA (system_connector, ServerTrust::Ca) keep the session tickets of the
servers they reach (tls::Sessions), so the next request to a server resumes its session
(TLS 1.3, no 0-RTT).
/// the text of HttpError::Tls when the server's CA needs the user's decision
UNTRUSTED: &str = "untrusted-ca"
  • enum ServerTrust

    • Ca(Cert) -- certificates of this CA only
    • Pin([u8; 32]) -- the CA with this SHA-256 (of its DER)
    • Ask -- learn the CA: every connection stops with UNTRUSTED after the handshake
  • struct Presented a CA a server presented that is not (yet) trusted

    • fingerprint: [u8; 32]
    • name: String -- the CA's common name
    • changed: bool -- a different CA than the pinned one (a reinstalled server, or someone in between)
    • pem: String -- the CA itself (PEM), to keep instead of the fingerprint
  • fn presented_ca(chain: &[Cert], name: &str, now: i64) -> Result<Cert, String>

  • fn fingerprint_text(d: &[u8]) -> String "AB:CD:EF:..." of a digest

  • fn parse_fingerprint(s: &str) -> Option<[u8; 32]> "AB:CD:.." / "abcd.." / with spaces -> the 32 bytes

  • fn system_connector(extra: Vec<Cert>) -> Connector https to public servers (the system's certificate authorities and extra); resumes the sessions of servers it reached before

  • fn connector(trust: ServerTrust, identity: Option<Identity>, seen: Arc<Mutex<Option<Presented>>>) -> Connector

Source: docs/API.md in the JFLib repository.