JFLib

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 Usage

    • Server
    • Client
  • enum PubKey a public key

    • Other -- a key type this code does not use
    • Ed25519([u8; 32])
    • Rsa { n: Vec<u8>, e: Vec<u8> } -- modulus and exponent, big-endian without leading zero bytes
    • Ec { curve: Curve, point: Vec<u8> } -- an uncompressed point (04 || x || y)
  • enum SigAlg a signature algorithm (of certificates and of TLS handshakes)

    • Unknown
    • Ed25519
    • RsaPkcs1(HashAlg)
    • RsaPss(HashAlg, Option<usize>) -- salt length None: any (TLS fixes it to the hash length)
    • Ecdsa(HashAlg)
  • struct NameConstraints the name constraints of a CA

    • permitted_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 RDNs
    • excluded_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 Cert

    • der: 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: String
    • subject_org: String -- the subject's organization, the issuer's common name and organization (for dialogs)
    • issuer_cn: String
    • issuer_org: String
    • not_before: i64
    • not_after: i64
    • public_key: Vec<u8> -- Ed25519 public key (empty for other key types)
    • key: PubKey
    • ed25519_signed: bool
    • sig_alg: SigAlg
    • signature: Vec<u8>
    • version: u8 -- 1 or 3
    • name_constraints: Option<NameConstraints>
    • is_ca: bool
    • path_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 to
    • uris: Vec<String> -- uniformResourceIdentifier entries of the subject alternative name
    • dirs: 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 itself
    • unknown_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 carries

  • fn ocsp_signer(&self) -> bool whether 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) -> bool whether it must come with a stapled OCSP response (RFC 7633)

  • fn fingerprint_bytes(&self) -> [u8; 32] SHA-256 of the certificate

  • fn fingerprint_text(&self) -> String the fingerprint in hex with colons, as certificate dialogs write it

  • fn self_signed(&self) -> bool it names itself as issuer and its own key made the signature

  • fn 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 addresses

  • fn bytes(&self) -> usize bytes it holds (an estimate for a memory budget)

  • fn fingerprint(&self) -> String SHA-256 of the certificate (hex)

  • fn verify(&self, alg: SigAlg, data: &[u8], sig: &[u8]) -> bool whether a signature over data was made with this certificate's key

  • fn signed_by(&self, issuer: &Cert) -> bool whether issuer signed this certificate

  • fn eku_allows(&self, u: Usage) -> bool whether the extended key usage allows this purpose (no extended key usage: every purpose)

  • fn names(&self, host: &str) -> bool whether 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 anchor

  • fn 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 at now, 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 everywhere

  • struct CertBuilder what a new certificate says

    • serial: [u8; 16]
    • cn: String
    • org: String
    • not_before: i64
    • not_after: i64
    • public_key: [u8; 32]
    • is_ca: bool
    • dns: Vec<String>
    • ips: Vec<IpAddr>
    • server_auth: bool
    • client_auth: bool
    • spki: Vec<u8> -- the subject's key as a SubjectPublicKeyInfo (PrivateKey::spki, spki_of); empty: the Ed25519 key public_key
    • ocsp_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 by key; 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 from extension: 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 key spki (any key), signed by key (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 when spki is not a SubjectPublicKeyInfo

  • fn 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 CsrBuilder a request to build
    • cn: 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]) -> CsrBuilder a 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 with key (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 Csr a request read and its signature checked

    • der: Vec<u8>
    • subject: Vec<u8> -- the subject (DER of the Name)
    • cn: String
    • spki: Vec<u8> -- the SubjectPublicKeyInfo (DER), for CertBuilder::spki
    • key: PubKey
    • dns: 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 bytes
    • b: &'a [u8]

impl<'a> Der<'a>

  • fn new(b: &'a [u8]) -> Der<'a>

  • fn is_empty(&self) -> bool

  • fn 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 content

  • fn 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 tag

  • fn seq(&mut self) -> Option<Der<'a>>

  • fn u64(&mut self) -> Option<u64> a non-negative INTEGER up to 64 bits

  • fn bool(&mut self) -> Option<bool>

  • fn bits(&mut self) -> Option<&'a [u8]> a BIT STRING without unused bits -> its bytes

  • fn oid_bytes(arcs: &[u64]) -> Vec<u8> the encoded OID content of dotted arcs

  • fn 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 IpAddr
    • V4([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) -> bool
  • fn is_unspecified(&self) -> bool
  • fn 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 PrivateKey a 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])) -> PrivateKey a new ECDSA key from rand (the platform's random bytes): drawn again until it is in [1, n - 1]

  • fn rsa(key: rsa::PrivateKey) -> Option<PrivateKey> an RSA key

  • fn 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 here

  • fn public_key(&self) -> PubKey the public half

  • fn spki(&self) -> Vec<u8> the public half as a SubjectPublicKeyInfo (DER), as certificates and CSRs carry it

  • fn rsa_bits(&self) -> usize the RSA modulus's bits (0 for other keys)

  • fn ed25519(&self) -> Option<&Keypair> the Ed25519 key pair, if it is one

  • fn can(&self, alg: SigAlg) -> bool whether this key makes signatures of alg (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) -> SigAlg the algorithm it signs certificates with: Ed25519, ECDSA with SHA-256 (P-256) or SHA-384 (P-384), RSA PKCS #1 v1.5 with SHA-256

  • fn sign(&self, alg: SigAlg, data: &[u8], random: &[u8]) -> Option<Vec<u8>> a signature of data with alg (None when the key does not make it): Ed25519's 64 bytes; ECDSA as DER (Ecdsa-Sig-Value), its nonce by RFC 6979 with random mixed 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 of random (as long as the salt length, the hash length when the algorithm leaves it open; a shorter random gives 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 IdHash the hash of a CertID

    • Sha1
    • Sha256
    • Sha384
    • Sha512
  • struct CertId which certificate a request or response is about (RFC 6960 4.1.1)

    • hash: IdHash
    • name_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 of cert with SHA-1 (RFC 5019 2.1.1: what responders take); None when issuer is not the one that names it or its key cannot be read

  • fn 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 Request what 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 certificates

  • enum Status the status of a certificate

    • Good
    • Revoked { time: i64, reason: Option<u8> } -- since time (Unix seconds), for reason (CRLReason, RFC 5280 5.3.1) when given
    • Unknown -- the responder does not know the certificate
  • struct Response a checked response

    • status: Status
    • this_update: i64 -- Unix seconds
    • next_update: Option<i64>
    • produced_at: i64
    • nonce: 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) -> i64 until when it counts as current: nextUpdate (or a day after thisUpdate), at most to the end of a delegated responder's certificate

  • fn refresh_at(&self) -> i64 when 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) -> i64 when a server that got it at now fetches 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 about cert, which issuer issued, at now (Unix seconds): its structure, its signature (the issuer, or a responder certificate in it that the issuer issued for OCSP), the entry for cert, 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). That issuer signed cert is 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 count

  • struct ResponseBuilder a response to build and sign (a private CA's responder, tests)

    • status: Status
    • this_update: i64
    • next_update: Option<i64> -- None: newer information is always there (a response without nextUpdate)
    • produced_at: i64
    • nonce: Option<Vec<u8>> -- the request's nonce, to answer it
    • by_key: bool -- the responder named by the SHA-1 of its key (byKey, RFC 5019 2.2.3) instead of its name
    • hash: IdHash
    • extensions: Vec<Vec<u8>> -- further responseExtensions (each from x509::extension)

impl ResponseBuilder

  • fn good(now: i64) -> ResponseBuilder good, current from now for four days, by key

  • fn sign(&self, cert: &Cert, issuer: &Cert, responder: Option<&Cert>, key: &PrivateKey) -> Option<Vec<u8>> the DER response about cert, signed with key: the issuer's key (responder None), or that of a responder certificate the issuer issued for OCSP (it goes into the response); None when key is not that certificate's, or it signs nothing a certificate names

  • fn error_response(code: u8) -> Vec<u8> an unsuccessful OCSPResponse (MALFORMED_REQUEST, INTERNAL_ERROR, TRY_LATER, SIG_REQUIRED, UNAUTHORIZED): no responseBytes, nothing signed

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