nx_cert_autorenew.nx
buildroot/runtime/nx_cert_autorenew.nx
about
nx_cert_autorenew.nx -- SOVEREIGN AUTO-RENEWAL for the per-domain wildcard TLS certs.
Closes the gap that started this whole arc: a per-domain wildcard cert SILENTLY lapsed because nothing
renewed it. This organ MONITORS the live SNI certs and RENEWS any inside the 21d warn window -- unattended.
COMPOSES ONLY PROVEN PIECES (rule 15 DRY; no new high-stakes mechanism):
nx_cert_autorenew_lib -- domain->path mapping + WARN/EXPIRED trigger (gate-proven)
nx_cert_monitor -- CM_* verdict vocabulary + cm_status (local re-parse) + cm_name
nx_tls13_client_session_run + nx_trust_store_load_from_certdata -- the SAME live TLS-1.3-with-SNI probe
nx_torrent_live_probe uses (validates the SERVED cert against the Mozilla CA store at a chosen epoch)
_offc/nx_secret_cli.elf get porkbun -- Porkbun creds from the vault -> /tmp/nxsecret.out
_offc/nx_sov_build_run.elf + /tmp/nx_acme_dns01_issue.sov.elf <domain> -- LE-1.3 DNS-01 wildcard issuance
_offc/nx_aw_send.elf <local> <remote> -- vault-keyed SSH push to the NAS (proven)
_offc/nx_aw_hostctl.elf deploy -- atomic sites.elf swap + respawn = cert RELOAD (proven)
MONITOR (live, location-independent): for each configured domain, drive a TLS handshake to the web host
presenting that SNI and validate the SERVED leaf at now AND at now+21d. valid-at-now + invalid-at-now+21d
= inside the warn window (CM_WARN); invalid-at-now = CM_EXPIRED; unreachable = CM_NOCERT (no false trigger).
This is best-in-class external SSL-expiry monitoring -- it watches what clients actually receive, from
anywhere, so it does not depend on the conductor sharing a filesystem with the NAS.
RENEW (fail-safe BY CONSTRUCTION -- rule 12/13/14): issue to /tmp -> RE-PARSE the fresh cert locally
(never push a bad cert) -> push the per-domain fullchain+key to the live le_<label>_* paths -> stage the
durable current-good binary as sites.elf.new -> deploy (respawn=reload) -> VERIFY the served leaf advanced
past the warn window. Any step fails -> ABORT + structured log, leaving a working state: we renew EARLY
(21d slack) and the new cert is LE-validated, so the worst partial outcome still serves a valid cert.
SCHEDULE: the conductor (nx_team_pulse tp_tail_d) calls this EVERY beat; a daily-check guard runs the real
sweep at most once/CHECK_INTERVAL, and a per-domain cooldown caps issuance at one/domain/COOLDOWN -- so the
per-beat call is cheap + idempotent + LE-budget-safe (rule 10/21).
license_tier: ORIGINAL
dependencies 8 imports · 0 importers
imports: nx_cert_autorenew_lib.nxnx_connect.nxnx_syscalls.nxnx_x509_trust_store.nxnx_trust_store_load_from_certdata.nxnx_tls13_client_validate_certificate.nxnx_tls13_client_session_run.nxnx_csprng.nx
imported by: nobody (leaf or entry point)
call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown
structs
| none |
consts
| 39 | const CAR_MAGIC_86400: i64 = 86400 |
| 40 | const CAR_MAGIC_4000: i64 = 4000 |
| 41 | const CAR_MAGIC_8192: i64 = 8192 |
| 42 | const CAR_MAGIC_4194304: i64 = 4194304 |
| 45 | const CAR_TRUST_STORE: *u8 = "/mnt/c/Users/elder/nishi-core/nxc2/data/mozilla_certdata.txt\x00" as *u8 |
| 46 | const CAR_NAS_IP: i64 = (192 << 24) | (168 << 16) | (8 << 8) | 240 // the web TLS host (nx_torrent_live_probe) |
| 47 | const CAR_TLS_PORT: i64 = 8443 |
| 48 | const CAR_VERIFY_FUTURE_DAYS: i64 = 30 // > 21d warn window, << chain validity (~years): proves notAfter advanced |
| 49 | const CAR_CHECK_INTERVAL: i64 = 86400 // run the real sweep at most once/day (daily cadence over per-beat calls) |
| 50 | const CAR_COOLDOWN: i64 = 86400 // at most one LE issuance / domain / day (LE-budget guard) |
| 51 | const CAR_DOMAINS_CONF: *u8 = "knowledge/hosting/cert_domains.conf\x00" as *u8 |
| 52 | const CAR_CHECK_STAMP: *u8 = "knowledge/status/cert_autorenew_lastcheck\x00" as *u8 |
| 53 | const CAR_RENEW_LOG: *u8 = "knowledge/status/cert_renew.log\x00" as *u8 |
| 54 | const CAR_STAMP_DIR: *u8 = "knowledge/status/cert_renew_\x00" as *u8 |
| 57 | const CAR_SITES_BINARY: *u8 = "_offc/sites_live.elf\x00" as *u8 |
| 58 | const CAR_SITES_NEW: *u8 = "/volume1/homes/elderwesto/nishihost/sites.elf.new\x00" as *u8 |
| 63 | const CAR_ARM_FILE: *u8 = "knowledge/hosting/cert_autorenew.enabled\x00" as *u8 |
functions
| 66 | func car_p(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return 0 } |
| 67 | func car_pn(v: i64) -> i64 |
| 73 | func car_log(s: *u8) -> i64 |
| 82 | func car_run(path: *u8, argv: *i64) -> i64 |
| 96 | func car_epoch_read(path: *u8) -> i64 |
| 103 | func car_epoch_write(path: *u8, epoch: i64) -> i64 |
| 109 | func car_stamp_path(label: *u8, out: *u8) -> i64 |
| 114 | func car_cooldown_ok(label: *u8, now: i64) -> i64 |
| 123 | func car_handshake_ok(domain: *u8, dlen: i64, store: *TrustStore, now_epoch: i64) -> i64 |
| 149 | func car_live_verdict(domain: *u8, dlen: i64, store: *TrustStore, now: i64) -> i64 |
| 160 | func car_binary_ok() -> i64 |
| 165 | func car_armed() -> i64 |
| 171 | func car_renew_domain(domain: *u8, store: *TrustStore) -> i64 |
| 255 | func car_sweep_one(domain: *u8, store: *TrustStore, now: i64) -> i64 called by 2: car_sweep_linecar_sweep calls 11: car_slencar_live_verdictcar_pcm_namecar_should_renewcar_armed+5 |
| 272 | func car_sweep_line(buf: *u8, start: i64, end: i64, store: *TrustStore, now: i64) -> i64 |
| 287 | func car_read_file(path: *u8, buf: *u8, cap: i64) -> i64 |
| 296 | func car_sweep(store: *TrustStore, now: i64) -> i64 |
| 316 | func main(argc: i64, argv: *i64) -> i64 |