X.509
Source: std/x509.mw.
Parses DER certificates, loads PEM bundles and verifies a chain against a set of trust anchors, including validity dates, CA constraints, key usage and host name matching.
X.509 certificates (RFC 5280): parsing, hostname matching, chain building checks and a PEM trust store. Supported: RSA (PKCS#1 v1.5) and ECDSA (P-256 / P-384) signatures with SHA-1/256/384/512, and the extensions basicConstraints, keyUsage, extKeyUsage and subjectAltName. Unknown *critical* extensions make a certificate unacceptable.
Constants
Section titled “Constants”| Name | Type | Value | Notes |
|---|---|---|---|
X509_KEY_RSA |
i64 |
1 |
|
X509_KEY_EC |
i64 |
2 |
|
X509_OK |
i64 |
0 |
|
X509_E_EMPTY |
i64 |
1 |
|
X509_E_VALIDITY |
i64 |
2 |
|
X509_E_SIGNATURE |
i64 |
3 |
|
X509_E_ISSUER |
i64 |
4 |
|
X509_E_UNTRUSTED |
i64 |
5 |
|
X509_E_HOSTNAME |
i64 |
6 |
|
X509_E_NOT_CA |
i64 |
7 |
|
X509_E_PATHLEN |
i64 |
8 |
|
X509_E_USAGE |
i64 |
9 |
struct Cert { der: *u8; derlen: i64; tbs: *u8; tbslen: i64; issuer: *u8; issuerlen: i64; subject: *u8; subjectlen: i64; not_before: i64; not_after: i64; key_type: i64; curve: i64; key1: *u8; key1len: i64; key2: *u8; key2len: i64; sig_scheme: i64; sig_hash: i64; sig: *u8; siglen: i64; has_bc: i64; is_ca: i64; pathlen: i64; has_ku: i64; ku: i64; has_eku: i64; eku_ok: i64; san: *u8; sanlen: i64;}Functions
Section titled “Functions”x509_strerror
Section titled “x509_strerror”fn x509_strerror(code: i64) -> *u8x509_free
Section titled “x509_free”fn x509_free(c: *Cert)x509_parse
Section titled “x509_parse”fn x509_parse(der: *u8, derlen: i64) -> *CertParses a DER certificate (the bytes are copied). Returns null if the certificate is malformed or uses unsupported algorithms/critical extensions.
x509_check_signature
Section titled “x509_check_signature”fn x509_check_signature(c: *Cert, issuer: *Cert) -> boolx509_host_match
Section titled “x509_host_match”fn x509_host_match(c: *Cert, host: *u8) -> boolx509_load_pem
Section titled “x509_load_pem”fn x509_load_pem(buf: *u8, len: i64, out: *VecPtr) -> i64Appends every certificate found in a PEM buffer to out (a VecPtr of *Cert). Returns how many were added.
x509_load_pem_file
Section titled “x509_load_pem_file”fn x509_load_pem_file(path: *u8, out: *VecPtr) -> i64x509_load_system_roots
Section titled “x509_load_system_roots”fn x509_load_system_roots(out: *VecPtr) -> i64Loads the system trust store from the usual bundle locations.
x509_valid_at
Section titled “x509_valid_at”fn x509_valid_at(c: *Cert, now: i64) -> boolx509_verify_chain
Section titled “x509_verify_chain”fn x509_verify_chain(chain: *VecPtr, anchors: *VecPtr, host: *u8, now: i64) -> i64Checks chain (leaf first; a VecPtr of *Cert as sent by the server) against anchors, for host (null skips the name check) at Unix time now. Returns X509_OK or an X509_E_* code.