JFLib

netio/dane.rs#

Source: lib/netio/dane.rs

dane -- TLS servers authenticated by TLSA records that DNSSEC vouches for (RFC 6698, 7671)

  Tlsa { usage, selector, matching, data }   Tlsa::from_rr(&Rr)   usable()
  lookup(&Resolver, host, port) -> NetResult<Option<Vec<Tlsa>>>   the TLSA RRset of
                    _PORT._tcp.HOST when DNSSEC says it is secure; None when there is none
                    (NODATA, NXDOMAIN) or it is insecure; bogus is an error (RFC 6698 4.1:
                    the client must not connect)
  trust(&Resolver, host, port) -> NetResult<Trust>   Trust::Dane with the usable records, or
                    Trust::System without them (RFC 7671 4.1: then PKIX as usual)
  check(&[Tlsa], chain, name, ocsp, now) -> Result<Match, String>   what Trust::Dane does in
                    the handshake; Match says what decided (Match::pkix: the system's check,
                    so the client's Revocation holds as for Trust::System)

Usages (RFC 7671): DANE-EE (3) the server's certificate or key itself: neither its name nor
its validity is checked (5.1); DANE-TA (2) a certificate of the chain the server sent (or the
record's own, for 2 0 0) is the trust anchor: the chain up to it must hold, the server's name
included (5.2); PKIX-TA (0) and PKIX-EE (1) as well as the system's check of the chain
(crate::roots::verify_system_chain), the record then matching a CA of the PKIX path or the
server's certificate: PKIX-TA a CA of the path the system built and trusts (the root the
server left out included, from Windows' and Apple's own store as from the bundle: RFC 6698
2.1.1, RFC 7671 5.4), or one the server sent or of the bundle that the chain leads to.
Selectors: 0 the whole certificate, 1 its SubjectPublicKeyInfo; matching: 0 exact, 1
SHA-256, 2 SHA-512.  A record of an unknown usage, selector or matching type, or of a digest
of the wrong length, is not usable and is passed over (RFC 7671 4.1); one usable record that
matches is enough.  The resolver must validate (Config::dnssec): without it
lookup finds no secure records.  A host name with a final dot is looked up as it is, without
the search domains.  Revocation (tls::Revocation, a stapled OCSP response) counts where the
system's check decides (PKIX-TA, PKIX-EE, no usable record), not for DANE-EE and DANE-TA,
whose record is the trust (RFC 7671 5.1, 5.2).
/// certificate usage: a CA of the chain, with the system's check (RFC 7218 names)
USAGE_PKIX_TA: u8 = 0
/// the server's certificate, with the system's check
USAGE_PKIX_EE: u8 = 1
/// a CA of the chain as the trust anchor
USAGE_DANE_TA: u8 = 2
/// the server's certificate or key itself
USAGE_DANE_EE: u8 = 3
/// selector: the whole certificate (DER)
SELECTOR_CERT: u8 = 0
/// selector: its SubjectPublicKeyInfo (DER)
SELECTOR_SPKI: u8 = 1
/// matching type: the selected bytes themselves
MATCH_EXACT: u8 = 0
/// matching type: their SHA-256
MATCH_SHA256: u8 = 1
/// matching type: their SHA-512
MATCH_SHA512: u8 = 2
  • struct Tlsa a TLSA record's data (RFC 6698 2.1)
    • usage: u8
    • selector: u8
    • matching: u8
    • data: Vec<u8>

impl Tlsa

  • fn from_rr(r: &Rr) -> Option<Tlsa> the data of a TLSA record (None for another type)

  • fn usable(&self) -> bool whether this side can use the record: a known usage, selector and matching type, a digest of its length

  • fn matches(&self, c: &Cert) -> bool whether a certificate is the one the record names

  • fn lookup(r: &Resolver, host: &str, port: u16) -> NetResult<Option<Vec<Tlsa>>> the TLSA records of _port._tcp.host when DNSSEC says they are secure

  • fn trust(r: &Resolver, host: &str, port: u16) -> NetResult<Trust> the trust for a TLS connection to host:port: DANE with the usable secure TLSA records, the system's CAs without them

  • enum Match what decided a chain in check

    • Record(u8) -- a record of this usage (USAGE_*) matched
    • System -- no usable record: the system's check (RFC 7671 4.1)

impl Match

  • fn pkix(self) -> bool the system's check decided (PKIX-TA, PKIX-EE, no usable record): revocation counts as for Trust::System

  • fn may_use_pkix(tlsa: &[Tlsa]) -> bool whether records may let the system's check decide (a PKIX usage, or none usable): a client then asks for a stapled OCSP response as with Trust::System

  • fn check(tlsa: &[Tlsa], chain: &[Cert], name: &str, ocsp: Option<&[u8]>, now: i64) -> Result<Match, String> a server's chain (leaf first) against TLSA records; name is the server's name (DANE-TA and the PKIX usages check it), ocsp the response the server stapled (for the system's check), now Unix seconds. Without a usable record the system's check decides (RFC 7671 4.1)

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