x509.nx
buildroot/runtime/x509.nx
about
x509.nx -- minimal X.509 v3 certificate parser (RFC 5280).
Reader-only subset that extracts the fields needed for TLS 1.3
certificate chain verification:
- tbsCertificate bytes + length (to hash for signature verify)
- serialNumber (for revocation / pinning)
- subjectPublicKeyInfo (the public key we trust)
- signatureAlgorithm OID (tells us which verify to use)
- signatureValue BIT STRING (the actual signature bytes)
ASN.1 structure (abbreviated from RFC 5280 ยง4.1):
Certificate ::= SEQUENCE {
tbsCertificate TBSCertificate,
signatureAlgorithm AlgorithmIdentifier,
signatureValue BIT STRING
}
TBSCertificate ::= SEQUENCE {
version [0] EXPLICIT Version DEFAULT v1,
serialNumber CertificateSerialNumber,
signature AlgorithmIdentifier,
issuer Name,
validity Validity,
subject Name,
subjectPublicKeyInfo SubjectPublicKeyInfo,
... optional extensions
}
Invariants:
X1 Returns pointers into the caller's DER buffer; nothing
copied. Caller owns the buffer's lifetime.
X2 All bounds-checks delegated to asn1.nx (A1 invariant).
Malformed certs fail with a negative return code, never
silent truncation.
X3 Version field is optional (DEFAULT v1); we detect the [0]
EXPLICIT wrapper and skip over it if present.
X4 Extensions (v3 only) are parsed enough to find
Subject Alternative Name -- the rest is skipped. Extension
OID matching is caller-driven via x509_next_extension.
dependencies 2 imports · 0 importers
imports: syscalls.nxasn1.nx
imported by: nobody (leaf or entry point)
call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown
structs
| 45 | struct X509Cert { |
consts
| none |
functions
| 59 | func x509_read_tlv(buf: *u8, c: *Asn1Cursor, |
| 75 | func x509_read_alg_id(buf: *u8, c: *Asn1Cursor, |
| 94 | func x509_parse(buf: *u8, buf_len: i64, cert: *X509Cert) -> i64 {
called by 1: main calls 5: asn1_cursor_initasn1_expect_tagasn1_read_lengthx509_read_tlvx509_read_alg_id |
| 218 | func main() -> i64 {
calls 1: x509_parse |