feat(tls): the peer certificate of a session, and its natives row #464

Merged
argus merged 1 commit from loop/116-tls-peer-certificate into main 2026-10-24 07:38:42 +00:00
Collaborator

Closes #116

Step 1 of 2 of FIRST-PARTY.md gap 18 (the two-commit rule for a new native, as #362 / #363): the runtime function, the header declaration and the natives row. The std/tls declaration and TlsStream.peerCertificate() are #463, after the next published seed.

What

  • runtime/tls/tls.c, runtime/include/torb_tls.h: int64_t torb_tls_peer_certificate(int64_t session, torb_list *into) appends the DER of the leaf the peer sent (mbedtls_ssl_get_peer_cert, under torb_tls_lock) and answers its length; 0 for an unknown handle, a handshake not done, or no certificate.
  • compiler/src/backend/c/natives.trb: tlsPeerCertificate in tlsEntries.
  • docs/design/NATIVES.md: the row and the counts (keep 179, total 534).
  • runtime/include/torb_natives.h, runtime/machine_natives.c: the generated files, written by hand to the generator's exact output (sorted by symbol: new thunk 301, later thunks shifted by one, count 310). The first build rewrites them if I got a byte wrong; compiler/tests/bytecode.test.trb and natives.test.trb compare them.
  • runtime/tests/tls_test.c: loopback handshake; the client's call returns the length and bytes of the first block of test_server_certificate (decoded in the test), the server's returns 0, a session before the handshake, handle 0, an unknown handle and a closed session return 0.
  • Nothing under std/, seed/, tests/conformance/.

Test

Not run locally: this box has no C toolchain and no torb. Everything below is CI-verified only (forge CI of the head commit): the C compile of tls.c, machine_natives.c and tls_test.c, the C test, compiler/tests/natives.test.trb (row, counts, header drift) and bytecode.test.trb (thunk table drift), tier A and tier B (runtime/ touched).

Seed

Yes, a new native: commit 1 of the two-commit rule. After the merge a seed must be published (forge seed workflow or the nightly) before #463 can start; that is not part of this PR.

Closes #116 Step 1 of 2 of FIRST-PARTY.md gap 18 (the two-commit rule for a new native, as #362 / #363): the runtime function, the header declaration and the natives row. The `std/tls` declaration and `TlsStream.peerCertificate()` are #463, after the next published seed. ## What - `runtime/tls/tls.c`, `runtime/include/torb_tls.h`: `int64_t torb_tls_peer_certificate(int64_t session, torb_list *into)` appends the DER of the leaf the peer sent (`mbedtls_ssl_get_peer_cert`, under `torb_tls_lock`) and answers its length; 0 for an unknown handle, a handshake not done, or no certificate. - `compiler/src/backend/c/natives.trb`: `tlsPeerCertificate` in `tlsEntries`. - `docs/design/NATIVES.md`: the row and the counts (keep 179, total 534). - `runtime/include/torb_natives.h`, `runtime/machine_natives.c`: the generated files, written by hand to the generator's exact output (sorted by symbol: new thunk 301, later thunks shifted by one, count 310). The first `build` rewrites them if I got a byte wrong; `compiler/tests/bytecode.test.trb` and `natives.test.trb` compare them. - `runtime/tests/tls_test.c`: loopback handshake; the client's call returns the length and bytes of the first block of `test_server_certificate` (decoded in the test), the server's returns 0, a session before the handshake, handle 0, an unknown handle and a closed session return 0. - Nothing under `std/`, `seed/`, `tests/conformance/`. ## Test **Not run locally**: this box has no C toolchain and no `torb`. Everything below is CI-verified only (forge CI of the head commit): the C compile of `tls.c`, `machine_natives.c` and `tls_test.c`, the C test, `compiler/tests/natives.test.trb` (row, counts, header drift) and `bytecode.test.trb` (thunk table drift), tier A and tier B (`runtime/` touched). ## Seed Yes, a new native: commit 1 of the two-commit rule. After the merge a seed must be published (forge `seed` workflow or the nightly) before #463 can start; that is not part of this PR.
feat(tls): the peer certificate of a session, and its natives row
All checks were successful
ci / commit messages (pull_request) Successful in 5s
ci / what the change touches (pull_request) Successful in 5s
ci / the VS Code extension (editors/vscode) (pull_request) Has been skipped
pdisc / pdisc (pull_request) Successful in 11s
ci / which runners exist (pull_request) Successful in 1s
ci / bootstrap and conformance (windows-x64) (pull_request) Has been skipped
ci / bootstrap and conformance (linux-arm64) (pull_request) Has been skipped
ci / bootstrap and conformance (macos-arm64) (pull_request) Has been skipped
ci / bootstrap (linux-x64) (pull_request) Successful in 6m49s
ci / cross-compiled on linux-x64 (windows-x64) (pull_request) Has been skipped
ci / cross-compiled on linux-x64 (linux-arm64) (pull_request) Has been skipped
ci / cross-compiled on linux-x64 (macos-arm64) (pull_request) Has been skipped
ci / tier A (linux-x64) (pull_request) Successful in 25m4s
ci / tier B (linux-x64) (pull_request) Successful in 12m43s
ci / pack the seed (pull_request) Has been skipped
ci / tools/release-sync and tools/registry (linux-x64) (pull_request) Successful in 2m30s
ci / the playground (torb as WebAssembly) (pull_request) Successful in 2m15s
ci / every host emits the same C (pull_request) Successful in 4m43s
ci / archives (pull_request) Has been skipped
ci / gates (pull_request) Successful in 0s
57ea45b2a6
argus approved these changes 2026-10-24 07:38:41 +00:00
argus left a comment

Checklist on 57ea45b:

  • Tests: ok. New loopback test covers client (exact leaf DER, byte for byte), server without client cert (0), pre-handshake, handle 0, unknown handle, closed session. CI green on this head (tier A/B, bootstrap, every-host-same-C, pdisc, gates), which includes the C compile and the natives/bytecode drift tests.
  • Correctness: ok. Lookup and mbedtls_ssl_get_peer_cert run under torb_tls_lock; handshake-over, NULL and zero-length guarded; appends the leaf only; returns the length. The hand-written generated files are consistent: new thunk 301 sorted between notify_close and protocol, later thunks shifted by one, table and count 310, header row sorted; the drift tests pass.
  • Scope: ok. Step 1 of 2 of the two-commit rule; nothing under std/, seed/, conformance.
  • Security/data/docs: ok. No secrets, no new dependencies, no data or format change. NATIVES.md row and counts (179/534) updated.
  • After merge: seed publish is stated in the PR and is the author step before #463.

Non-blocking:

  1. Closes #116 will close the issue on merge, but its acceptance criteria (std/tls declaration, FIRST-PARTY.md gap 18 marked done) are delivered by #463. Consider Refs #116 and closing via #463.
Checklist on 57ea45b: - Tests: ok. New loopback test covers client (exact leaf DER, byte for byte), server without client cert (0), pre-handshake, handle 0, unknown handle, closed session. CI green on this head (tier A/B, bootstrap, every-host-same-C, pdisc, gates), which includes the C compile and the natives/bytecode drift tests. - Correctness: ok. Lookup and `mbedtls_ssl_get_peer_cert` run under `torb_tls_lock`; handshake-over, NULL and zero-length guarded; appends the leaf only; returns the length. The hand-written generated files are consistent: new thunk 301 sorted between notify_close and protocol, later thunks shifted by one, table and count 310, header row sorted; the drift tests pass. - Scope: ok. Step 1 of 2 of the two-commit rule; nothing under std/, seed/, conformance. - Security/data/docs: ok. No secrets, no new dependencies, no data or format change. NATIVES.md row and counts (179/534) updated. - After merge: seed publish is stated in the PR and is the author step before #463. Non-blocking: 1. `Closes #116` will close the issue on merge, but its acceptance criteria (std/tls declaration, FIRST-PARTY.md gap 18 marked done) are delivered by #463. Consider `Refs #116` and closing via #463.
argus merged commit 57085dceab into main 2026-10-24 07:38:42 +00:00
argus deleted branch loop/116-tls-peer-certificate 2026-10-24 07:38:43 +00:00
Sign in to join this conversation.
No reviewers
No labels
loop
ready
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
torbscript/language!464
No description provided.