code wiki / (root) / nx_x509_leaf_emit.nx

nx_x509_leaf_emit.nx

buildroot/runtime/nx_x509_leaf_emit.nx

10579 B197 linesdepth 10pulls 16 transitivereach 14 importersview sourcekind tooltopic x509
docsdependenciesstructsconstsfunctions

about

nx_x509_leaf_emit.nx -- self-signed Ed25519 X.509 leaf-certificate emitter (RFC 5280 + RFC 8410). mTLS rung R4 of the NO-COOKIE session carrier. Mints the CLIENT IDENTITY certificate the browser presents at the TLS layer: a self-signed Ed25519 leaf whose Subject CN carries the sovereign identity (e.g. hex(user_id_hash)). R5 derives the keypair from the OPAQUE export_key + packages this cert as PKCS#12; R3 verifies a presented cert's CertificateVerify against the pubkey parsed out of it; R6 reads the Subject CN -> handle -> HR entitlements. Certificate ::= SEQUENCE { tbsCertificate, signatureAlgorithm, signatureValue BIT STRING } TBSCertificate ::= SEQUENCE { [0]{INTEGER v3(2)}, serial INTEGER, sigAlg, issuer Name, validity, subject Name, subjectPublicKeyInfo } (extensions omitted -- OPTIONAL) Self-signed: issuer == subject; signatureValue = Ed25519 over DER(tbsCertificate). SYSCALL-VARIANT NOTE (Rule 23 -- comment the WHY): the x509 VERIFY stack (nx_x509 / nx_x509_validate / nx_ed25519_signature) imports nx_syscalls.nx, but nx_x509_csr_emit imports nx_syscalls_x86_64.nx -- importing both = duplicate sys_* link error. So this file stays on nx_syscalls.nx and reimplements the few small ASN.1 Name/SPKI helpers inline (pure nxae_ compositions) rather than import the CSR emitter. Composes nx_asn1_emit (DER) + nx_ed25519_signature (sign). license_tier: ORIGINAL expect_exit: 0

dependencies 5 imports · 4 importers

nx_syscalls.nx nx_asn1_emit.nx nx_ed25519_signature.nx nx_x509.nx nx_x509_validate.nx nx_x509_leaf_emit.nx nx_mtls_authz.nx nx_mtls_identity.nx nx_mtls_pkcs12.nx nx_tls13_server_clientauth.nx

imports: nx_syscalls.nxnx_asn1_emit.nxnx_ed25519_signature.nxnx_x509.nxnx_x509_validate.nx

imported by: nx_mtls_authz.nxnx_mtls_identity.nxnx_mtls_pkcs12.nxnx_tls13_server_clientauth.nx

call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown

main lf_w sys_write sys_mmap ed25519_pub_from_priv sys_mmap ↻ ed25519_sha512 sys_mmap ↻ sha512_init sha512_update sha512_blk_set_byte blk_get_i64 blk_set_i64 sha512_compress sys_mmap ↻ blk_get_i64 ↻ sha512_gamma0 rotr64_v shr64_v sha512_gamma1 rotr64_v ↻ shr64_v ↻ sha512_sigma1 rotr64_v ↻ sha512_ch sha512_k sha512_sigma0 rotr64_v ↻ sha512_maj sha512_final sha512_blk_set_byte ↻ sha512_compress ↻ ge_p3_alloc sys_mmap ↻ fe_alloc nx_scratch nx_scratch_init sys_mmap ↻ nx_scratch_oom sys_write ↻

structs

none

consts

24const K_MAGIC_2048: i64 = 2048
25const K_MAGIC_4096: i64 = 4096

functions

27func lf_oid_ed25519(out: *u8) -> i64 { out[0] = 0x2b as u8; out[1] = 0x65 as u8; out[2] = 0x70 as u8; return 3 }
28func lf_oid_cn(out: *u8) -> i64 { out[0] = 0x55 as u8; out[1] = 0x04 as u8; out[2] = 0x03 as u8; return 3 }
called by 1: lf_emit_name_cn
31func lf_emit_spki_ed25519(out: *u8, off: *i64, cap: i64, pubkey_32: *u8) -> i64
43func lf_emit_name_cn(out: *u8, off: *i64, cap: i64, cn: *u8, cn_n: i64) -> i64
57func lf_emit_sigalg(out: *u8, off: *i64, cap: i64) -> i64
66func lf_emit_validity(out: *u8, off: *i64, cap: i64, nb_13: *u8, na_13: *u8) -> i64
76func nx_x509_leaf_emit_ed25519(
127func lf_w(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return 0 }
called by 2: lf_rowmain calls 1: sys_write
128func lf_len(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n }
called by 1: main
129func lf_row(name: *u8, ok: i64) -> i64 { if ok == 1 { lf_w(" PASS " as *u8) } else { lf_w(" FAIL " as *u8) } lf_w(name); lf_w("\n" as *u8); return ok }
called by 1: main calls 1: lf_w
131func main() -> i64