code wiki / _hdl_build / _h2_serve_loopback_gate.nx

_h2_serve_loopback_gate.nx

buildroot/runtime/_hdl_build/_h2_serve_loopback_gate.nx

16991 B359 linesdepth 19pulls 141 transitivereach 0 importersview sourcekind gate/prooftopic h2
docsdependenciesstructsconstsfunctions

about

_h2_serve_loopback_gate.nx -- TUTOR-BOOTSTRAP SCAFFOLD (Claude, authored under the B1 rung(3) ALPN-h2 SERVER workflow of the R4-H2 HTTP/2-transport ladder), NOT credited as team self-authoring. THE LIVE LOOPBACK SERVE GATE: a single fork-based organ that stands up OUR sovereign ALPN-h2 TLS 1.3 SERVER and drives OUR sovereign h2 CLIENT against it over a real loopback socket -- both halves OUR stack, no openssl/nghttp2. Modeled byte-for-byte on the GREEN fork pattern of nx_browse_text_test.nx:102- 126 (socket/bind/listen/fork; child spins then connects; parent accepts). PRE-FORK (shared address space, inherited by both sides): - generate an Ed25519 keypair + build a self-signed X.509 leaf with SAN=localhost (sovereign: nx_csprng_fill + ed25519_pub_from_priv + nx_x509_build_self_signed), validity window covering now. - parse the cert into an X509Cert and add it as the SOLE anchor of a 1-entry TrustStore (a self-signed leaf is its own root; the store is subject-DN-keyed so issuer DN == subject DN finds the anchor). NO permissive/insecure validation context is built (fake-green forbidden). CHILD (the h2 CLIENT): spin a short busy-loop, connect, then nx_tls13_client_session_run_h2 (advertises ALPN ["h2"] only, validates the cert against our 1-entry store) -> h2_tls_get GET "/" -> assert it recovered :status 200 + the exact body bytes OUR server sent. PARENT (the ALPN-h2 SERVER): accept, then nx_tls13_server_session_run_h2_ed25519 (SELECTS ALPN "h2" via emit_ee_alpn + signs CV with the Ed25519 priv) -> app_recv the client's h2 open -> h2_server_recv_request (assert :method GET, :path "/") -> app_send the h2 response (SETTINGS+ACK+HEADERS :status 200 + DATA END_STREAM via h2_server_send_response). Parent exit code IS the verdict. HONEST verdict discipline: GREEN ONLY if the parent observes a successful server handshake + a correctly-parsed GET / request AND the child observes :status 200 + the exact body end-to-end. Any handshake failure, cert-validate failure, or status mismatch -> a NAMED negative exit code, never a faked 200. This is the one organ whose GREEN depends on the NAMED cert-self-verify risk: if nx_cert_gen's self-signed Ed25519 cert does not cleanly self-verify under nx_https_cert_pipeline_verify_with_store with SAN=localhost, the live half fails HONESTLY here (the in-memory gate nx_h2_server.nx stays the GREEN floor). FOUNDED ON (composes, each imported EXACTLY ONCE, RC6 double-import avoided): - nx_h2_server.nx: h2_server_recv_request / h2_server_send_response (it

dependencies 13 imports · 0 importers

nx_syscalls.nx nx_connect.nx nx_h2_server.nx nx_tls13_server_session_run_h2.nx nx_tls13_server_session_app_data.n nx_tls13_client_h2run.nx nx_x25519_ephemeral.nx nx_csprng.nx nx_ed25519_signature.nx nx_x509_build.nx _h2_serve_loopback_gate.nx

diagram shows first 10 each side; +3 more imports, +0 more importers in the complete lists below.

imports: nx_syscalls.nxnx_connect.nxnx_h2_server.nxnx_tls13_server_session_run_h2.nxnx_tls13_server_session_app_data.nxnx_tls13_client_h2run.nxnx_x25519_ephemeral.nxnx_csprng.nxnx_ed25519_signature.nxnx_x509_build.nxnx_x509.nxnx_x509_trust_store.nxnx_tls13_read_record_from_fd.nx

imported by: nobody (leaf or entry point)

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

main sys_write sys_mmap hsl_make_cert nx_csprng_fill sys_mmap ↻ nx_csprng_urandom_path sys_openat_rd sys_read sys_close 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 sha512_gamma1 sha512_sigma1 sha512_ch sha512_k sha512_sigma0 sha512_maj sha512_final sha512_blk_set_byte ↻ sha512_compress ↻ ge_p3_alloc sys_mmap ↻ fe_alloc nx_scratch nx_scratch_init nx_scratch_oom sys_mmap ↻

structs

none

consts

72const HSL_PORT: i64 = 0x2333 // 9011

functions

76func hsl_civil_from_days(days: i64, out_y: *i64, out_m: *i64, out_d: *i64) -> i64
92func hsl_format_generalized_time(unix_sec: i64, out_15: *u8) -> i64
123func hsl_addr(out: *u8, port: i64) -> i64
called by 1: main
136func hsl_make_cert(
182func hsl_run_client(addr: *u8, store: *TrustStore, exp_body: *u8, exp_len: i64) -> i64
225func hsl_run_server(
270func hsl_log(verdict_green: i64, code: i64) -> i64
290func main() -> i64