← Week 4: X.509 Certificates

Day 23: X.509 Certificate Structure — TBSCertificate

Phase 1 · June 5, 2026

← Week 4: X.509 Certificates

Agenda (2–3 hours)

  • Read (75 min): RFC 5280 §4.1 (Certificate and TBSCertificate) — read carefully, annotate
  • Study (30 min): Every field in TBSCertificate
  • Practice (45 min): Inspect a real cert field-by-field
  • Challenge (30 min): Rust cert parser
← Week 4: X.509 Certificates

X.509 Certificate ASN.1 Structure

Certificate ::= SEQUENCE {
    tbsCertificate   TBSCertificate,
    signatureAlgorithm AlgorithmIdentifier,
    signatureValue   BIT STRING
}

TBSCertificate ::= SEQUENCE {
    version         [0] EXPLICIT INTEGER DEFAULT v1,  -- v3 = 2
    serialNumber    CertificateSerialNumber,
    signature       AlgorithmIdentifier,
    issuer          Name,
    validity        Validity,
    subject         Name,
    subjectPublicKeyInfo SubjectPublicKeyInfo,
    issuerUniqueID  [1] IMPLICIT UniqueIdentifier OPTIONAL,
    subjectUniqueID [2] IMPLICIT UniqueIdentifier OPTIONAL,
    extensions      [3] EXPLICIT Extensions OPTIONAL
}
← Week 4: X.509 Certificates

Key Fields

version: must be v3 (integer 2) if extensions are present

serialNumber: must be unique per CA; recommended 20 bytes of random (RFC 5280 §4.1.2.2)

signature vs signatureAlgorithm: must match; the outer signatureAlgorithm and inner signature field must contain identical values

issuer / subject: Distinguished Names, e.g.:

C=US, O=Amazon, CN=Amazon Root CA 1

validity: UTCTime or GeneralizedTime

  • UTCTime: years 1950–2049 (YYMMDDHHMMSSZ)
  • GeneralizedTime: years outside that range (YYYYMMDDHHMMSSZ)
← Week 4: X.509 Certificates

SubjectPublicKeyInfo

SubjectPublicKeyInfo ::= SEQUENCE {
    algorithm   AlgorithmIdentifier,   -- OID + params
    subjectPublicKey BIT STRING        -- the actual key bytes
}

For EC keys: algorithm OID is 1.2.840.10045.2.1, params = named curve OID.
For RSA keys: algorithm OID is 1.2.840.113549.1.1.1, params = NULL.
The subjectPublicKey BIT STRING contains the raw key in algorithm-specific format.

← Week 4: X.509 Certificates

Distinguished Names

Name is a SEQUENCE OF relative distinguished names (RDNs):

Common attribute types:

OID Short Meaning
2.5.4.6 C Country
2.5.4.10 O Organization
2.5.4.11 OU Organizational Unit
2.5.4.3 CN Common Name
2.5.4.7 L Locality
1.2.840.113549.1.9.1 emailAddress Email

The CN field was historically used for hostnames; now SANs are required (Day 25).

← Week 4: X.509 Certificates

Practice Exercise

# Dump all TBSCertificate fields for a real cert
openssl s_client -connect amazon.com:443 2>/dev/null | \
  openssl x509 -noout -text 2>/dev/null | \
  grep -E "Version|Serial|Issuer|Subject|Not Before|Not After|Public Key"

# Show the public key
openssl s_client -connect amazon.com:443 2>/dev/null | \
  openssl x509 -noout -pubkey | openssl pkey -noout -text
← Week 4: X.509 Certificates

Challenge Assignment

Write a Rust program using x509-parser that reads a PEM certificate file and prints:

  1. Version (should be 3)
  2. Serial number (hex)
  3. Signature algorithm OID + name
  4. Issuer DN (all RDN components)
  5. Subject DN (all RDN components)
  6. Not Before / Not After as RFC 3339 strings
  7. Public key algorithm and key size in bits

Test against at least 3 different certificates: a root CA, an intermediate, and a leaf cert.

← Week 4: X.509 Certificates

Resources

  • RFC 5280 §4.1: Certificate and TBSCertificate — the primary reference today
  • RFC 5480: EC public key algorithm identifier in SubjectPublicKeyInfo
  • x509-parser crate: docs.rs/x509-parser