Skip to content

fix 1061 - #2762

Merged
ehartford merged 5 commits into
mainfrom
fix-1061
Oct 28, 2026
Merged

ehartford merged 5 commits into
mainfrom
fix-1061

Conversation

@ehartford

Copy link
Copy Markdown
Contributor

Stack created with GitHub Stacks CLI • Give Feedback 💬

Eric Hartford added 4 commits October 27, 2026 02:25
…nished (#1061)

std.tls completed handshakes without verifying anything: no chain building, no hostname check, no ServerKeyExchange signature check, and the server Finished was never compared. with get rides this channel, so a first download's lockfile hash arrived over the same unauthenticated connection it was meant to authenticate.

Root causes, by layer: - x509 parsed certificates but nothing ever verified a signature, validity window, CA bit, or name; the chain walk, SAN hostname match (no CN fallback), and PEM bundle parsing are new. - The trust anchors had no source: darwin/linux bundles are read in With; Windows enumerates the ROOT store through crypt32 (rt with_tls_load_windows_roots); SSL_CERT_FILE overrides, and a set-but-unreadable override refuses rather than falling back. - The handshake discarded the Certificate flight beyond the leaf, capped certificates at sizes real chains exceed, and skipped NewSessionTicket without hashing it into the transcript (a latent Finished failure); the flight is now kept as verification evidence and the peer is verified before ClientKeyExchange. - Verification needed what real chains use: SHA-384/512 (new sha512.w), P-384 (ec/ecdsa cores generalized over width, one owner per algorithm), RSA PKCS#1 with SHA-384/512 DigestInfo. TLS 1.2 supported_groups also bounds certificate curves (RFC 4492), so P-384 ECDHE landed too; a P-384-only server answered handshake_failure without it (alert 40 observed through a proxy). - FIPS: a digest shorter than the field width is z whole, not a refusal - LibreSSL signs SKE with SHA-256 under a P-384 key (lldb: x509_ecdsa_verify_der_bytes hash_len=32, curve_bits=384).

Unknown signature algorithms, explicit EC parameters, and unsupported curves refuse the handshake; nothing silently accepts. RSA-PSS and Ed25519 remain loud refusals.

Evidence: behav_1061_x509_chain_verify over a generated cert family (RSA root/EC intermediate/leaves, wrong SAN, self-signed, P-384), behav_1061_sha512_kats (FIPS vectors, cross-checked against openssl dgst), behav_1061_tls_peer_verification (openssl s_server stub peer: good chains accepted; wrong-SAN and untrusted refused; one-byte ServerKeyExchange-signature and Finished tampers through a With TCP proxy refused). Live: example.com 200, center2.conan.io reachable, badssl wrong-host/self-signed/expired refused. Pre-fix, the new fixtures fail (undefined x509_verify_chain_pem) and every badssl host connected.
Linux verification found two more defects in the first cut. The chain walk anchored only at the top presented certificate: from Linux, example.com presents a cross-signed ECC root issued by AAA Certificate Services, which the Debian bundle no longer holds, while the ECC root below it is in the store directly. OpenSSL anchors there; the walk now anchors at the first certificate a stored root issued, and certificates presented above the anchor are not on the path. And the stub-peer fixture's readiness budget was a try count: refused loopback connects return instantly on Linux (30 in under a millisecond, measured), expiring the budget before s_server exec'd; the budget is wall time now. Linux: fixtures and live probe green (example.com 200, conan reachable, badssl trio refused).
:unit-return-review flagged explicit -> Unit on the four new sha512 entry points (copied from sha256.w's reviewed spelling; inference knows), and :ceremony-census counted a redundant & at a &X509Cert parameter. Both spellings removed; the auto-referenced call and inferred returns check green.
The Windows runtime now enumerates the ROOT store (with_tls_load_windows_roots, previous commits on this branch), so the Windows rt bundle has undefined CertOpenSystemStoreA/CertEnumCertificatesInStore/CertCloseStore (llvm-nm on out/lib/cross/windows_x86_64/rt.o). crypt32 is an in-box DLL whose import library the SDK already generates (sdk_windows_import_libs, for its cmake); it joins the system set in Link.w (both lists) and the build layer's mirrors in build/compiler.w and build/emit_c.w. Runtime first, link second, per the bootstrap order: the seed links stage1 against its own runtime generation, stage1 links stage2 with this list.
@ehartford
ehartford added this pull request to stack #2768 October 27, 2026 20:27
runtime-domain-audit: CertOpenSystemStoreA, CertEnumCertificatesInStore
and CertCloseStore were declared externs with no domain row; silence
invalidates every declared domain (ruling 52). Plain rows: no
preserves claim, so each call may clobber the declared domains.
@ehartford
ehartford marked this pull request as ready for review October 28, 2026 00:35
@ehartford
ehartford merged commit 9b802fb into main Oct 28, 2026
@ehartford
ehartford deleted the fix-1061 branch October 28, 2026 00:37
ehartford added a commit that referenced this pull request Oct 29, 2026
#1953) (#2793)

* test: the #2530 sysroot cache-key test sets each host's sysroot and skips Windows (#2788)

On win10 the test failed: 'probe_key.h' file not found. It set only
WITH_SDKROOT, which host_c_sysroot reads on macOS alone; Linux reads
WITH_LINUX_SYSROOT, and on Windows host_c_sysroot is empty, so there is
no second sysroot for the cache key to tell apart. The test sets both
variables and skips Windows with that reason.

* build: the drop and move audits name the seed with the host's executable suffix (#2788)

On win10 the battery stopped drop-audit and move-audit before they ran:
"missing declared input: C:/Users/Eric/wtr/src/main". The seed there is
src/main.exe (#2759); build.w declared and ran "src/main" in five
places (the audits' input and baseline, the issue61 fixture's copy).
Each now says "src/main" ++ host_exe_suffix(), as the seed target does.

* resolve: the root module keeps the spelling it was given; its declarations keep it too (#809, #1953)

8f105fe seeded the root's declarations with resolve_normalize_path(name)
so they would match the module Resolve registered. That restored the
root's imports and broke every consumer that needs the spelling, on
every host (TMPDIR ends in '/', so any $TMPDIR program is one):

- `with build $TMPDIR/x.w --emit-obj` wrote an object with no main:
  Codegen.path_is_imported_module_symbol (CodegenTraits.w) compares a
  declaration's path with source_file, the given spelling, so every
  root function read as imported and was only declared (macOS 336 B
  against 2152 B; win10 behav_panic_path_is_canonical, empty .text).
- `__FILE__` and panic sites printed the normalized path, not the
  file byte for byte (win10 behav_1953: `C:/…/t/r/b/boom.w` for
  `C:\…\t\r\b\boom.w`).

The declarations carry the spelling again, and Resolve stores the root
module under that same spelling (resolve_from_root_pool_with_prefix);
identity stays resolve_canonical_module_key (#592). Sema's lookups by
the current module path (module_index_by_path, built from module_paths
by Frontend and by every Sema copy) find the root under the one
spelling everything carries.

Evidence: behav_809_root_path_spelling_keeps_imports now runs each
spelling (stdout must be the spelling, then 7) and emits an object
that must define main; it fails on the installed compiler (all three
spellings: normalized __FILE__, no main) and passes on stage1.

* runtime: Windows strtold is the UCRT's strtod, not mingwex's x87 strtold (#2788, #2176)

On win10 every f64 parse died with an access violation before printing
(behav_959, behav_750: "1.5".parse() into f64; a direct std.libc
strtold call too, while strtod passed). The PE imports no strtold: the
mingw ucrt.lib exports none, so the link took mingwex.lib's
gdtoa_strtopx.o strtold (llvm-nm), whose long double is the 80-bit x87
type returned through a hidden pointer. Called as f64 strtold(nptr,
endptr), the text was the result slot and the null endptr was read as
the text.

std.libc's strtold is the correctly rounded double (#2176). The UCRT's
own strtold is its strtod (its long double is a double), so both
Windows runtimes bind strtod, as the Linux runtimes already do.

* test: crypt32.dll is in the box (#2788, #1061)

behav_1915 refused every program on win10: "imports a DLL Windows does
not ship: crypt32.dll". The runtime reads the ROOT system trust store
through crypt32 since #1061 (#2762); crypt32.dll is a System32 DLL on
every Windows, so the test's in-box list names it.

* std.build: the fetch helper's connect probes end before its caller's deadline (#2788, #2412)

On win10 source-cache-tests failed: a source down at 127.0.0.1:1 was
reported as "no complete response within 20 s", not "no connection to
127.0.0.1:1". A refused connect takes 2077 ms there (Windows retries the
SYN; measured with tcp_connect_timeout), so five probes and their 1+2+3+4 s
pauses outlived the 20 s deadline fetch_url runs the helper under, and the
kill replaced the helper's reason with the deadline's. The probe schedule
assumed a refused connect is instant ("ten seconds in all"); a host that
drops SYNs breaks it on every OS.

fetch_url passes its deadline; the helper stops probing when the pause and
one more probe like the last would reach it, and says how many it made.
The test asks for more than one probe, not five.

---------

Co-authored-by: Eric Hartford <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant