x509#
X.509 certificates: strict parsing, path validation with name constraints, a private Ed25519 CA's builder, the DER reader and writer (netio::x509 and netpkt::x509 are this crate) -- crate root lib/x509/lib.rs
x509 -- certificates (RFC 5280) for all of JFLib: netio's TLS and https, netpkt's TLS core and
simulators. A program's own private PKI (Ed25519, RFC 8410; built and signed here) and the
public web PKI (RSA and P-256 / P-384 keys; RSA PKCS #1 v1.5 / PSS and ECDSA signatures with
SHA-256 / 384 / 512), parsed strictly; no I/O, no clock (the caller passes the time)
der the DER reader and writer certificates need
IpAddr addresses in names (octets, parse, RFC 5952 text)
Cert::parse(der) -> Option<Cert> subject / issuer, validity, key, CA flag, names,
key and extended key usage, name constraints,
unknown critical extensions noticed
cert.fingerprint() -> SHA-256 (hex) fingerprint_bytes(), fingerprint_text() (colons)
cert.signed_by(&issuer) -> bool self_signed(), names(host), name_list(), bytes()
cert.verify(alg, data, sig) a signature made with the certificate's key
verify_chain(&[leaf, ...], &anchors, now, name, usage) -> Result<(), String> builds a
path through the given intermediates to an anchor;
verify_path: the same, and that path (to the anchor)
CertBuilder { .. }.sign(&issuer_cert_or_self, &issuer_key) -> DER (Ed25519)
CertBuilder { spki, .. }.sign_key(issuer, &PrivateKey, extra) -> DER any key, signed by any
PrivateKey: Ed25519, ECDSA (P-256 / P-384), RSA; PKCS #8 / SEC 1 / PKCS #1 (key.rs)
ocsp::check(der, &cert, &issuer, now) an OCSP response (RFC 6960); request, CertId,
ResponseBuilder for a private CA's responder (ocsp.rs)
CsrBuilder { dns, .. }.sign(&key), Csr::parse certificate requests (PKCS #10, csr.rs)
Not checked: CRLs, certificate policies (OCSP: the ocsp module; a certificate's responders,
caIssuers and TLS features are read). Name constraints are processed
for DNS names, IP addresses, e-mail addresses (rfc822Name), URIs (their host) and directory
names (a byte-wise prefix of the subject's RDNs); a CA that constrains another form refuses
every certificate below it that has a name of that form (RFC 5280 4.2.1.10). They apply to
the leaf and to the intermediates below the CA, self-issued ones excepted (6.1.3 (b)).
x509 crate root#
OID_ED25519: &[u64] = &[1, 3, 101, 112]
/// the TLS feature of a certificate that must come with a stapled OCSP response (RFC 7633:
/// status_request)
TLS_FEATURE_STATUS_REQUEST: u16 = 5
/// key usage bits as they appear in the first byte
KU_DIGITAL_SIGNATURE: u8 = 0x80
KU_KEY_CERT_SIGN: u8 = 0x04
KU_CRL_SIGN: u8 = 0x02
enum UsageServerClient
enum PubKeya public keyOther-- a key type this code does not useEd25519([u8; 32])Rsa { n: Vec<u8>, e: Vec<u8> }-- modulus and exponent, big-endian without leading zero bytesEc { curve: Curve, point: Vec<u8> }-- an uncompressed point (04 || x || y)
enum SigAlga signature algorithm (of certificates and of TLS handshakes)UnknownEd25519RsaPkcs1(HashAlg)RsaPss(HashAlg, Option<usize>)-- salt length None: any (TLS fixes it to the hash length)Ecdsa(HashAlg)
struct NameConstraintsthe name constraints of a CApermitted_dns: Vec<String>excluded_dns: Vec<String>permitted_ip: Vec<Vec<u8>>-- address and mask (4 + 4 or 16 + 16 bytes)excluded_ip: Vec<Vec<u8>>permitted_email: Vec<String>-- rfc822Name subtrees, lower case: a mailbox ("a@example.com"), all mailboxes of a host ("example.com") or of the subdomains of a domain (".example.com")excluded_email: Vec<String>permitted_uri: Vec<String>-- uniformResourceIdentifier subtrees, lower case: the URI's host ("example.com") or the subdomains of a domain (".example.com")excluded_uri: Vec<String>permitted_dn: Vec<Vec<u8>>-- directoryName subtrees (the DER of a Name): the subject begins with its RDNsexcluded_dn: Vec<Vec<u8>>other_forms: Vec<u8>-- the GeneralName tags of constrained forms not processed here (otherName 0xa0, x400Address 0xa3, ediPartyName 0xa5, registeredID 0x88)
struct Certder: Vec<u8>tbs: Vec<u8>serial: Vec<u8>issuer: Vec<u8>-- the raw DER of the issuer and subject names (compared byte for byte)subject: Vec<u8>subject_cn: Stringsubject_org: String-- the subject's organization, the issuer's common name and organization (for dialogs)issuer_cn: Stringissuer_org: Stringnot_before: i64not_after: i64public_key: Vec<u8>-- Ed25519 public key (empty for other key types)key: PubKeyed25519_signed: boolsig_alg: SigAlgsignature: Vec<u8>version: u8-- 1 or 3name_constraints: Option<NameConstraints>is_ca: boolpath_len: Option<u64>key_usage: Option<u8>eku: Vec<Vec<u8>>dns: Vec<String>ips: Vec<IpAddr>emails: Vec<String>-- rfc822Name entries of the subject alternative name and emailAddress attributes of the subject (lower case): what e-mail name constraints apply touris: Vec<String>-- uniformResourceIdentifier entries of the subject alternative namedirs: Vec<Vec<u8>>-- directoryName entries of the subject alternative name (the DER of each Name)other_names: Vec<u8>-- the tags of subject alternative names of other forms (otherName 0xa0, x400Address 0xa3, ediPartyName 0xa5, registeredID 0x88)ski: Vec<u8>aki: Vec<u8>-- the keyIdentifier of the authority key identifier (empty without one): which key of the issuer signed it (ACME's renewal information names a certificate by it)ocsp_urls: Vec<String>-- the OCSP responders of the authority information access (URIs, RFC 5280 4.2.2.1)ca_issuers: Vec<String>-- where the issuer's certificate is (caIssuers URIs of the authority information access)tls_features: Vec<u16>-- the TLS features the certificate demands (RFC 7633): TLS_FEATURE_STATUS_REQUEST is "must staple", a TLS client that asks for a stapled OCSP response refuses it without one (netio: Revocation::Stapled or Required with Trust::Anchors, System or Custom; with Revocation::Off, Trust::Pinned or Trust::Any it asks for none and does not look)ocsp_nocheck: bool-- id-pkix-ocsp-nocheck (RFC 6960 4.2.2.2.1): an OCSP responder's certificate that is not checked for revocation itselfunknown_critical: bool-- a critical extension this code does not understand (such a certificate is rejected)
impl Cert
fn parse(bytes: &[u8]) -> Option<Cert>fn spki(&self) -> Vec<u8>its SubjectPublicKeyInfo as it stands in the certificate (DER): what keys are pinned by and a certificate request carriesfn ocsp_signer(&self) -> boolwhether its extended key usage allows signing OCSP responses (id-kp-OCSPSigning: a responder its CA delegated to, RFC 6960 4.2.2.2)fn must_staple(&self) -> boolwhether it must come with a stapled OCSP response (RFC 7633)fn fingerprint_bytes(&self) -> [u8; 32]SHA-256 of the certificatefn fingerprint_text(&self) -> Stringthe fingerprint in hex with colons, as certificate dialogs write itfn self_signed(&self) -> boolit names itself as issuer and its own key made the signaturefn ed25519_key(&self) -> Option<[u8; 32]>its Ed25519 key (None for another kind)fn name_list(&self) -> Vec<String>what its names are, for a dialog: the DNS names, then the addressesfn bytes(&self) -> usizebytes it holds (an estimate for a memory budget)fn fingerprint(&self) -> StringSHA-256 of the certificate (hex)fn verify(&self, alg: SigAlg, data: &[u8], sig: &[u8]) -> boolwhether a signature overdatawas made with this certificate's keyfn signed_by(&self, issuer: &Cert) -> boolwhetherissuersigned this certificatefn eku_allows(&self, u: Usage) -> boolwhether the extended key usage allows this purpose (no extended key usage: every purpose)fn names(&self, host: &str) -> boolwhether the certificate names this host (DNS name, case-insensitive; IP address)fn verify_chain(chain: &[Cert], anchors: &[Cert], now: i64, name: Option<&str>, usage: Usage) -> Result<(), String>check a chain (leaf first) against trusted anchors: a path from the leaf through the other certificates of the chain (in any order) to an anchorfn verify_path(chain: &[Cert], anchors: &[Cert], now: i64, name: Option<&str>, usage: Usage) -> Result<Vec<Cert>, String>verify_chain, and the path it found: the leaf, the intermediates of the chain it went through (in their order up), the anchor (a root the chain left out: what a TLSA record of usage PKIX-TA may name, RFC 7671 5.4)fn check_leaf(leaf: &Cert, now: i64, name: Option<&str>, usage: Usage) -> Result<(), String>the checks of verify_chain that concern the leaf alone: no unknown critical extension, valid atnow, for this usage (extended key usage), allowed to sign (key usage digitalSignature), no CA's extensions on a certificate that is no CA (keyCertSign, name constraints: RFC 5280 4.2.1.9, 4.2.1.10), and the name. netio::roots asks them after a system's verifier said yes to the path, so the leaf follows the same rules everywherestruct CertBuilderwhat a new certificate saysserial: [u8; 16]cn: Stringorg: Stringnot_before: i64not_after: i64public_key: [u8; 32]is_ca: booldns: Vec<String>ips: Vec<IpAddr>server_auth: boolclient_auth: boolspki: Vec<u8>-- the subject's key as a SubjectPublicKeyInfo (PrivateKey::spki, spki_of); empty: the Ed25519 keypublic_keyocsp_urls: Vec<String>-- OCSP responders to name in the authority information access (http URIs)must_staple: bool-- a leaf that must come with a stapled OCSP response (the TLS feature status_request, RFC 7633)ocsp_signing: bool-- a leaf that signs OCSP responses for its issuer (id-kp-OCSPSigning, with id-pkix-ocsp-nocheck)
fn extension(oid: &[u64], critical: bool, value: &[u8]) -> Vec<u8>a DER Extension (oid, the critical flag, the DER value) for CertBuilder::sign_ext
impl CertBuilder
fn sign(&self, issuer: Option<&Cert>, key: &Keypair) -> Vec<u8>the DER certificate, signed bykey;issuer: the issuing certificate (None: self signed with the builder's own name)fn sign_ext(&self, issuer: Option<&Cert>, key: &Keypair, extra: &[Vec<u8>]) -> Vec<u8>sign with further extensions (each one fromextension: name constraints, a CA's extended key usage ...); one with the OID of an extension the builder writes itself replaces that one (basic constraints without a path length, other key usages)fn sign_key(&self, issuer: Option<&Cert>, key: &PrivateKey, extra: &[Vec<u8>]) -> Option<Vec<u8>>the DER certificate for the keyspki(any key), signed bykey(any key: ECDSA with the hash of its curve, RSA with PKCS #1 v1.5 and SHA-256, Ed25519) with further extensions as sign_ext; None whenspkiis not a SubjectPublicKeyInfofn ed25519_pkcs8(seed: &[u8; 32]) -> Vec<u8>the PKCS#8 form of an Ed25519 private key (for interoperable PEM files)fn ed25519_from_pkcs8(b: &[u8]) -> Option<[u8; 32]>the seed of a PKCS#8 Ed25519 private key
x509/csr.rs#
Source: lib/x509/csr.rs
csr -- certificate requests (PKCS #10, RFC 2986): what ACME's finalize sends (RFC 8555 7.4)
and what a private CA reads before it signs
CsrBuilder { dns, ips, cn, must_staple }.sign(&key) -> Option<DER>
Csr::parse(der) -> Option<Csr> the subject, the key, the requested names; its signature
checked (the requester holds the key)
The names go into an extensionRequest (PKCS #9) as a subject alternative name; the common
name is optional (ACME's CAs take the names from the extension).
struct CsrBuildera request to buildcn: String-- the common name (empty: none; ACME takes at most 64 bytes, RFC 5280's ub-common-name)dns: Vec<String>ips: Vec<IpAddr>must_staple: bool-- ask for a certificate that must come with a stapled OCSP response (RFC 7633)
impl CsrBuilder
fn for_names(names: &[&str]) -> CsrBuildera request for these DNS names (the first one also the common name when it fits)fn sign(&self, key: &PrivateKey) -> Option<Vec<u8>>the DER request, signed withkey(ECDSA with its curve's hash, RSA PKCS #1 v1.5 with SHA-256, Ed25519); None when a name is not a DNS name in the preferred syntax, or an RSA key is shorter than 2048 bits or not a whole number of bytes (as Csr::parse and certificates take them)struct Csra request read and its signature checkedder: Vec<u8>subject: Vec<u8>-- the subject (DER of the Name)cn: Stringspki: Vec<u8>-- the SubjectPublicKeyInfo (DER), for CertBuilder::spkikey: PubKeydns: Vec<String>-- the names of the requested subject alternative name (DNS names lower case)ips: Vec<IpAddr>tls_features: Vec<u16>-- the requested TLS features (RFC 7633)sig_alg: SigAlg
impl Csr
fn parse(b: &[u8]) -> Option<Csr>a request: version 0, a key this crate reads, a signature by that key; the names of an extensionRequest (other extensions are left to the CA, which decides what it signs). None when it is malformed or the signature does not verify
x509/der.rs#
Source: lib/x509/der.rs
der -- the DER subset X.509 needs: a bounded reader (definite lengths, no indefinite
forms, at most 16 MiB per element) and a writer
Der::new(bytes).read(tag) -> Option<(content, rest)>, peek_tag, int, oid, ...
writer: tlv(tag, content), seq(&[parts]), int_u(bytes), oid(&[arcs]), utf8(s) ...
BOOLEAN: u8 = 0x01
INTEGER: u8 = 0x02
BIT_STRING: u8 = 0x03
OCTET_STRING: u8 = 0x04
NULL: u8 = 0x05
OID: u8 = 0x06
ENUMERATED: u8 = 0x0a
UTF8: u8 = 0x0c
PRINTABLE: u8 = 0x13
IA5: u8 = 0x16
UTC_TIME: u8 = 0x17
GEN_TIME: u8 = 0x18
SEQUENCE: u8 = 0x30
SET: u8 = 0x31
struct Der<'a>a cursor over DER bytesb: &'a [u8]
impl<'a> Der<'a>
fn new(b: &'a [u8]) -> Der<'a>fn is_empty(&self) -> boolfn peek_tag(&self) -> Option<u8>fn next(&mut self) -> Option<(u8, &'a [u8], &'a [u8])>the next element: (tag, content, the whole element)fn read(&mut self, tag: u8) -> Option<&'a [u8]>the next element with this tag -> its contentfn read_raw(&mut self, tag: u8) -> Option<&'a [u8]>the next element with this tag -> the whole element (for signatures over it)fn optional(&mut self, tag: u8) -> Option<&'a [u8]>an optional element with this tagfn seq(&mut self) -> Option<Der<'a>>fn u64(&mut self) -> Option<u64>a non-negative INTEGER up to 64 bitsfn bool(&mut self) -> Option<bool>fn bits(&mut self) -> Option<&'a [u8]>a BIT STRING without unused bits -> its bytesfn oid_bytes(arcs: &[u64]) -> Vec<u8>the encoded OID content of dotted arcsfn tlv(tag: u8, content: &[u8]) -> Vec<u8>fn seq(parts: &[&[u8]]) -> Vec<u8>fn set(parts: &[&[u8]]) -> Vec<u8>fn int_u(b: &[u8]) -> Vec<u8>an INTEGER of unsigned big-endian bytes (leading zeros dropped, a zero byte added when the top bit is set)fn small_int(v: u64) -> Vec<u8>fn oid(arcs: &[u64]) -> Vec<u8>fn utf8(s: &str) -> Vec<u8>fn octets(b: &[u8]) -> Vec<u8>fn bits(b: &[u8]) -> Vec<u8>fn boolean(v: bool) -> Vec<u8>fn explicit(n: u8, content: &[u8]) -> Vec<u8>[n] EXPLICIT
x509/ip.rs#
Source: lib/x509/ip.rs
ip -- the IP addresses of certificates (subject alternative names, name constraints), as
plain octets with a parser and the text form of RFC 5952; the same shape as plat::net::IpAddr
(this crate needs no platform), so `IpAddr::from_octets` and `octets` convert
enum IpAddrV4([u8; 4])V6([u8; 16])
impl IpAddr
const LOCALHOST_V4: IpAddr = IpAddr::V4([127, 0, 0, 1])const UNSPECIFIED_V4: IpAddr = IpAddr::V4([0, 0, 0, 0])const LOCALHOST_V6: IpAddr = IpAddr::V6([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1])fn is_loopback(&self) -> boolfn is_unspecified(&self) -> boolfn mapped_v4(&self) -> Option<IpAddr>the IPv4 address inside an IPv4-mapped IPv6 address (::ffff:a.b.c.d)fn parse(s: &str) -> Option<IpAddr>"192.168.1.2" or "fe80::1" (RFC 5952 shortening)
impl IpAddr
fn from_octets(b: &[u8]) -> Option<IpAddr>the address of 4 or 16 octets (None for another length)fn octets(&self) -> &[u8]its 4 or 16 octets
x509/key.rs#
Source: lib/x509/key.rs
key -- private keys that sign: Ed25519, ECDSA on P-256 / P-384 and RSA
PrivateKey::from(ed25519::Keypair) PrivateKey::ecdsa(curve, secret)
PrivateKey::from_der(der) PKCS #8 (RFC 5958: Ed25519, EC, RSA), SEC 1's
ECPrivateKey (RFC 5915), PKCS #1's RSAPrivateKey
(RFC 8017 A.1.2); not encrypted ones
key.to_pkcs8() -> Option<DER> to store it (secret)
key.public_key() -> PubKey key.spki() -> SubjectPublicKeyInfo (DER)
key.sign(alg, data, random) -> Option<signature> Ed25519; ECDSA (DER, RFC 6979, `random`
mixed in as extra entropy); RSA PKCS #1 v1.5 or PSS
(the salt from `random`)
key.cert_alg() what it signs certificates with
An ECDSA key is read without a branch on its bytes and checked to be in [1, n - 1]; a public
key stored with it must be its own. An RSA key is read once (its numbers are checked against
each other in variable time, as a program does at start), then signs in constant time.
struct PrivateKeya private key that signs (Ed25519, ECDSA on P-256 or P-384, RSA)
impl PrivateKey
fn ecdsa(curve: Curve, secret: &[u8]) -> Option<PrivateKey>an ECDSA key from its secret scalar (curve.bytes() big-endian bytes in [1, n - 1])fn generate_ecdsa(curve: Curve, rand: &mut dyn FnMut(&mut [u8])) -> PrivateKeya new ECDSA key fromrand(the platform's random bytes): drawn again until it is in [1, n - 1]fn rsa(key: rsa::PrivateKey) -> Option<PrivateKey>an RSA keyfn from_der(b: &[u8]) -> Option<PrivateKey>a key in DER: PKCS #8 (PrivateKeyInfo / OneAsymmetricKey), an ECPrivateKey with its curve or an RSAPrivateKey; None for anything else (an encrypted PKCS #8 key among them)fn to_pkcs8(&self) -> Option<Vec<u8>>the PKCS #8 form (to store the key; secret); None only for a curve without a name herefn public_key(&self) -> PubKeythe public halffn spki(&self) -> Vec<u8>the public half as a SubjectPublicKeyInfo (DER), as certificates and CSRs carry itfn rsa_bits(&self) -> usizethe RSA modulus's bits (0 for other keys)fn ed25519(&self) -> Option<&Keypair>the Ed25519 key pair, if it is onefn can(&self, alg: SigAlg) -> boolwhether this key makes signatures ofalg(ECDSA: of its curve's size or any hash, as X.509 and TLS 1.2 allow; TLS 1.3 ties the hash to the curve itself; RSA-PSS: when the modulus holds the hash, the salt and two bytes, RFC 8017 9.1.1, so a 1024-bit key makes no PSS with SHA-512 and a salt as long)fn cert_alg(&self) -> SigAlgthe algorithm it signs certificates with: Ed25519, ECDSA with SHA-256 (P-256) or SHA-384 (P-384), RSA PKCS #1 v1.5 with SHA-256fn sign(&self, alg: SigAlg, data: &[u8], random: &[u8]) -> Option<Vec<u8>>a signature ofdatawithalg(None when the key does not make it): Ed25519's 64 bytes; ECDSA as DER (Ecdsa-Sig-Value), its nonce by RFC 6979 withrandommixed in (empty: the same signature each time); RSA PKCS #1 v1.5, or PSS with MGF1 of the same hash and a salt of the first bytes ofrandom(as long as the salt length, the hash length when the algorithm leaves it open; a shorterrandomgives None)fn spki_of(key: &PubKey) -> Vec<u8>the SubjectPublicKeyInfo of a public key (empty for PubKey::Other)
x509/ocsp.rs#
Source: lib/x509/ocsp.rs
ocsp -- the Online Certificate Status Protocol (RFC 6960, the lightweight profile of RFC
5019): what TLS staples (RFC 6066 8, RFC 8446 4.4.2.1) and what a private CA answers
CertId::new(&cert, &issuer) the certificate's id (SHA-1, as RFC 5019 asks;
CertId::with_hash for SHA-256 and longer)
request(&[id], nonce) -> DER an OCSPRequest (unsigned, RFC 6960 4.1)
Request::parse(der) the ids and the nonce of a request (a responder)
check(der, &cert, &issuer, now) -> Result<Response, String>
a response about `cert`: signed by its issuer or by
a responder the issuer delegated to, current at
`now`; Response { status, this_update, .. }
ResponseBuilder { status, .. }.sign(&cert, &issuer, responder, &key) -> DER
error_response(code) -> DER an unsuccessful one (tryLater, unauthorized, ..)
A response is current from thisUpdate (5 minutes of clock skew allowed) to nextUpdate (and
5 minutes after it); one without nextUpdate for a day after thisUpdate, as browsers take it.
Delegated responders (RFC 6960 4.2.2.2) must be issued directly by the issuer, carry
id-kp-OCSPSigning (and digitalSignature, when they have a key usage) and be valid, and a
response counts no longer than its responder's certificate; their own revocation is not
checked (they carry id-pkix-ocsp-nocheck as a rule). Unknown critical extensions refuse a
response, and a request.
/// the clock skew taken at either end of a response's time
SKEW: i64 = 300
/// how long a response without nextUpdate counts as current after its thisUpdate
NO_NEXT_UPDATE: i64 = 86_400
/// the response statuses of an unsuccessful OCSPResponse (RFC 6960 4.2.1)
MALFORMED_REQUEST: u8 = 1
INTERNAL_ERROR: u8 = 2
TRY_LATER: u8 = 3
SIG_REQUIRED: u8 = 5
UNAUTHORIZED: u8 = 6
enum IdHashthe hash of a CertIDSha1Sha256Sha384Sha512
struct CertIdwhich certificate a request or response is about (RFC 6960 4.1.1)hash: IdHashname_hash: Vec<u8>-- the hash of the issuer's name (its DER)key_hash: Vec<u8>-- the hash of the issuer's public key (the bytes of its subjectPublicKey)serial: Vec<u8>-- the certificate's serial number (the INTEGER's content)
impl CertId
fn new(cert: &Cert, issuer: &Cert) -> Option<CertId>the id ofcertwith SHA-1 (RFC 5019 2.1.1: what responders take); None whenissueris not the one that names it or its key cannot be readfn with_hash(cert: &Cert, issuer: &Cert, hash: IdHash) -> Option<CertId>fn encode(&self) -> Vec<u8>the DER CertID (a request's or a response's)fn request(ids: &[CertId], nonce: Option<&[u8]>) -> Vec<u8>an OCSPRequest for these certificates, unsigned;nonce(1 to 32 bytes) binds the answer to it (responders of RFC 5019 answer from a cache and leave it out)struct Requestwhat a request asks (for a responder)ids: Vec<CertId>nonce: Option<Vec<u8>>
impl Request
fn parse(b: &[u8]) -> Option<Request>an OCSPRequest: version 1, no requestor name, no signature (a signed one is not taken: None), at most 64 certificatesenum Statusthe status of a certificateGoodRevoked { time: i64, reason: Option<u8> }-- sincetime(Unix seconds), forreason(CRLReason, RFC 5280 5.3.1) when givenUnknown-- the responder does not know the certificate
struct Responsea checked responsestatus: Statusthis_update: i64-- Unix secondsnext_update: Option<i64>produced_at: i64nonce: Option<Vec<u8>>-- the nonce it carries (compare it with the request's)responder_until: Option<i64>-- the end of the delegated responder's certificate that signed it (None: the issuer signed it); the response counts no longer
impl Response
fn expires(&self) -> i64until when it counts as current: nextUpdate (or a day after thisUpdate), at most to the end of a delegated responder's certificatefn refresh_at(&self) -> i64when a server fetches the next one: halfway between thisUpdate and the end (as RFC 5019 6.2 and the CAs advise), an hour before the end where that comes earlier but not before thisUpdate (a short response gets less than an hour); never after the end (a thisUpdate ahead within the clock skew, a delegated responder about to expire)fn next_fetch(&self, now: i64) -> i64when a server that got it atnowfetches the next one: refresh_at, a minute from now at the earliest (no fetch loop), but 10 seconds before the response expires when that comes first (10 seconds from now at the earliest: a response that ends sooner than that lapses before the next fetch, the floor that keeps a loop away wins)fn check(b: &[u8], cert: &Cert, issuer: &Cert, now: i64) -> Result<Response, String>a response aboutcert, whichissuerissued, atnow(Unix seconds): its structure, its signature (the issuer, or a responder certificate in it that the issuer issued for OCSP), the entry forcert, its time. Ok with the status (a revoked one too: the caller decides); Err why it cannot be used (an unsuccessful response, tryLater among them). Thatissuersignedcertis the caller's to know (Cert::signed_by): the response is bound to the issuer's name and key, so one for another CA's certificate does not countstruct ResponseBuildera response to build and sign (a private CA's responder, tests)status: Statusthis_update: i64next_update: Option<i64>-- None: newer information is always there (a response without nextUpdate)produced_at: i64nonce: Option<Vec<u8>>-- the request's nonce, to answer itby_key: bool-- the responder named by the SHA-1 of its key (byKey, RFC 5019 2.2.3) instead of its namehash: IdHashextensions: Vec<Vec<u8>>-- further responseExtensions (each from x509::extension)
impl ResponseBuilder
fn good(now: i64) -> ResponseBuildergood, current fromnowfor four days, by keyfn sign(&self, cert: &Cert, issuer: &Cert, responder: Option<&Cert>, key: &PrivateKey) -> Option<Vec<u8>>the DER response aboutcert, signed withkey: the issuer's key (responderNone), or that of a responder certificate the issuer issued for OCSP (it goes into the response); None whenkeyis not that certificate's, or it signs nothing a certificate namesfn error_response(code: u8) -> Vec<u8>an unsuccessful OCSPResponse (MALFORMED_REQUEST, INTERNAL_ERROR, TRY_LATER, SIG_REQUIRED, UNAUTHORIZED): no responseBytes, nothing signed