code wiki / (root) / nx_sni_cert_select.nx

nx_sni_cert_select.nx

buildroot/runtime/nx_sni_cert_select.nx

5596 B104 linesdepth 3pulls 3 transitivereach 4 importersview sourcekind tooltopic sni
docsdependenciesstructsconstsfunctions

about

nx_sni_cert_select.nx -- SNI -> per-domain wildcard-cert SELECTION for the SNI-aware sovereign TLS site daemon (Route B). The SNI host_name is CLEARTEXT in the first ClientHello record (RFC 6066), so the daemon can peek it BEFORE terminating TLS and decide WHICH loaded wildcard chain+key pair to present: index 0 = NISHI (*.nishifamily.com + nishifamily.com) <- the DEFAULT index 1 = ANDELIN (*.andelinwest.com + andelinwest.com) Matching is LABEL-AWARE and case-insensitive (DNS labels are case-insensitive): a host matches a domain iff it EQUALS the domain (registrable apex) OR ends with ".<domain>" (a real sub-label) -- so "app.nishifamily.com" matches but the look-alike "evilnishifamily.com" does NOT (it falls to the default instead of being mis-selected). FAIL-SAFE BY CONSTRUCTION (rule 12 + rule 14): a missing / empty / malformed / unknown SNI returns the DEFAULT index, never an error and never a crash. This function only CHOOSES which already-validated cert to present; it AUTHORIZES nothing -- a client that sends a bogus SNI simply gets the default cert and fails validation on ITS side. Composes the proven, bounds-checked sni_extract_hostname parser (nx_sni_extract.nx, the same organ nx_sni_router peeks with) -- it does NOT add a second ClientHello parser (rule 15 DRY). Pure decision logic so both the daemon AND the gate share ONE codepath. license_tier: ORIGINAL

dependencies 2 imports · 4 importers

nx_syscalls.nx nx_sni_extract.nx nx_sni_cert_select.nx nx_sites_daemon.nx nx_sites_daemon_v2.nx nx_sites_reconciled.nx nx_sites_sni_cert_gate.nx

imports: nx_syscalls.nxnx_sni_extract.nx

imported by: nx_sites_daemon.nxnx_sites_daemon_v2.nxnx_sites_reconciled.nxnx_sites_sni_cert_gate.nx

structs

none

consts

30const NX_SCS_CERT_NISHI: i64 = 0
31const NX_SCS_CERT_ANDELIN: i64 = 1

functions

34func scs_lc(c: i64) -> i64
called by 1: scs_label_endswith
43func scs_label_endswith(host: *u8, host_n: i64, suf: *u8, suf_n: i64) -> i64
59func scs_pick_index(host: *u8, host_n: i64) -> i64
70func scs_pick_from_clienthello(hello: *u8, n: i64, host_scratch: *u8, host_cap: i64) -> i64
84func scs_pick_index_table(host: *u8, host_n: i64, suf_ptrs: *i64, suf_lens: *i64, count: i64) -> i64
96func scs_pick_from_clienthello_table(hello: *u8, n: i64, host_scratch: *u8, host_cap: i64,
104func main() -> i64 { return 0 }