Skip to content

net: TLS in the connection engine (ARIADNE_NET_ENGINE N3) - #1552

Merged
transfix merged 3 commits into
masterfrom
feat/net-engine-n3
Nov 27, 2026
Merged

transfix merged 3 commits into
masterfrom
feat/net-engine-n3

Conversation

@transfix

@transfix transfix commented Nov 26, 2026 •

Copy link
Copy Markdown
Owner

Part N3 of the native connection engine (docs/roadmap/ARIADNE_NET_ENGINE.md §2.5, §3): listener TLS, reload, the keyprint, and TLS detection on a plain port. It is for cy-pca/sublevels' NMDCS, which still runs on asyncio because the engine had no TLS.

What it adds

  • Listener TLS. listener_options.tls is a tls_options: certificate and key PEM files, TLS 1.2 and 1.3 with min_version as a setting, ciphers / ciphersuites, a client certificate asked for and accepted as sent (request_peer_certificate, on by default), handshake_timeout (10 s) and watch. The engine links OpenSSL's libssl (cvcpkg's openssl is already in the recipe), optionally: without it net_engine::tls_available() is false and a TLS listener fails to listen.
  • Within N1's model. Asio's ssl::stream would need a read buffer for each connection and its own async operations, so only ssl::context is used. Each session runs over a BIO of the engine's own, two strings the connection reads into and writes from through the same readiness waits. The queue still holds one refcounted buffer for every receiver of a broadcast, and each TLS connection encrypts as it writes, packing small sends into one record. A flushing close sends the queue, then close_notify.
  • conn_info. accepted is posted after the handshake, with tls_version, tls_cipher, tls_sni, tls_peer_sha256 (hex) and tls_peer_keyprint. A handshake that fails or times out closes with the new reason tls_handshake, which is counted but never posted, because the program never heard of that connection. net_counters.tls_accepted counts completed handshakes.
  • Detection. With listener_options.detect_tls (ms), the engine waits that long for the first byte: 0x16 starts TLS, any other byte makes the connection plain at once, and nothing in time makes it plain when the wait ends. accepted comes only after the decision, so NMDC's $Lock goes out on the right layer.
  • Reload. reload_tls(listener) rereads the files, and reload_tls(listener, tls) takes new options. Either serves new connections only; open ones keep their session. A reload that works posts tls_reloaded with the new keyprint. One that fails returns false (OSError in Python) and keeps the certificate in use. The watch loads a change once both files have kept their times for one interval, so a certificate and key written one after the other are read together. A watched load that fails posts the listener's error once.
  • Keyprint. tls_keyprint(listener) returns SHA256/ plus the unpadded base32 of the SHA-256 of the certificate's DER ([ADC-EXT] KEYP), for the hub to publish beside its nmdcs:// address.
  • N4 seam. Sessions start as servers. N4's client connections start the same layer as a client (SNI, verification, a pin).
  • pycvc / host.net. pycvc gains tls_options, tls_protocol_*, tls_available, reload_tls(listener, tls=None), tls_keyprint, and on net_listener the .keyprint property, .reload_tls() and .on_tls_reload(keyprint) (which runs on the loop). pycvc.ariadne.net has the names, and host.net's docstring shows a TLS listener.

Tests

  • net_engine_test adds ten TLS cases:
    • handshakes on 1.2 and 1.3 with version, cipher, SNI and a client certificate's digest, plus 500 small sends and a 1 MiB one;
    • a version below the minimum, a stalled handshake and plain bytes on a TLS port, all closed without the program hearing of them;
    • the keyprint against a fixed value from openssl x509 -outform DER | openssl dgst -sha256, against an EVP_Digest of i2d_X509, and against the openssl command at run time where one exists;
    • reload with open connections kept both ways, plus a bad file and new options;
    • the watch, including a broken file reported once;
    • detection with TLS, a plain client that speaks first, a slow TLS client, a silent plain one, and a TLS client later than the wait;
    • TLS slow_reader;
    • TLS writable;
    • a broadcast to a group mixing TLS and plain connections across three listeners, then flushing closes;
    • a TLS-vs-plain fan-out measurement.
  • Six of those are added to SAN_REQUIRED_NET.
  • test_pycvc_net.py gains a TLS section that uses Python's ssl as the client (keyprint against hashlib, conn_info, detection, reload and its OSError, a refused 1.2, on_tls_reload and an asyncio TLS client).
  • arisrvx_net runs a TLS listener too (run_arisrv.cmake now checks up to EXPECT9).

Verified locally (prettyhatemachine, gcc 13, OpenSSL 3.4.1 from deps)

All on the pushed head (e619f11):

  • net_engine_test Release: 34/34, five runs.
  • The same suite with -DCVC_NET_ASYNC_WRITES=1, the Windows write path: 34/34, three runs.
  • gcc TSan (setarch -R): 34/34, three runs, no reports.
  • The TLS cases alone: 20 more runs, no failures. Before the watch's settle-for-one-interval change, one run in about eight failed AWatchedListenerReloadsWhenItsFilesChange: a tick fell between the test's two writes and reported a second error.
  • test_pycvc_net.py, three runs, passes. It has to be run by hand here: this box needs deps' lib dir on LD_LIBRARY_PATH for libcurl's libssl 3.2.
  • arisrvx_net passes and prints net_program: tls ok: b'$Lock tls|' TLSv1.3 SHA256/IIEB….
  • clang-format 18 is clean.
  • The writable-data scan of cvc flags nothing in net_engine.cpp. The BIO method lives in each loaded context, not in a static.

Not verified: Windows and macOS (CI will show). clang's TSan was not run locally.

Measured

NetEngineTlsFanOut (1000 receivers per group, 2 I/O threads, load 7), I/O CPU per receiver per message:

TLS plain
one broadcast 25.0–26.2 µs 17.3–17.8 µs
burst of 10 2.3–2.7 µs 1.4–2.3 µs

SSL_MODE_RELEASE_BUFFERS made no measurable difference, so it stays on.

Design doc

The doc now marks N3 built. It corrects §1, which claimed libcvc already used OpenSSL's TLS through its transports: it linked only libcrypto, and its TLS client was libcurl's. It adds an (N3) block to §2.5 and the TLS counters to §2.10. One difference from the design: first_frame_timeout now counts from accepted, so on TLS it starts after the handshake.

Not for merge without Joe's OK.

Listener TLS for cvc::net's connection engine, through OpenSSL's libssl
(optional; Boost.Asio's ssl::context loads the files):

- listener_options.tls (tls_options): certificate and key files, TLS 1.2
  and 1.3 with the minimum as a setting, cipher lists, a client
  certificate asked for and accepted as sent, a handshake timeout, and a
  watch on the files' modification times.
- Each session runs over a BIO of the engine's own, inside N1's readiness
  loop: the queue still holds one refcounted buffer a broadcast, and each
  TLS connection encrypts as it writes, small sends packed into a record.
- accepted is posted after the handshake, with conn_info's tls_version,
  tls_cipher, tls_sni and the client certificate's SHA-256 and keyprint.
  A failed or timed-out handshake closes as tls_handshake, counted and
  never posted.
- listener_options.detect_tls: a plain port that also speaks TLS. The
  first byte decides (0x16 starts TLS), or the wait's end makes it plain;
  accepted comes after the decision, so NMDC's $Lock goes out on the
  right layer.
- reload_tls(listener[, tls]) serves new files to new connections and
  keeps open ones; tls_reloaded carries the new keyprint. The watch loads
  a change once both files have kept their times for one interval.
- tls_keyprint(listener): SHA256/ and the unpadded base32 of the DER's
  SHA-256 ([ADC-EXT] KEYP).
- pycvc: tls_options, tls_protocol_*, reload_tls, tls_keyprint,
  net_listener.keyprint, .reload_tls() and .on_tls_reload on the loop;
  pycvc.ariadne.net has the names, and arisrvx_net runs a TLS listener.

Tests: net_engine_test's TLS cases (handshakes on 1.2 and 1.3, a refused
version and a stalled handshake, the keyprint against the openssl
command, reloads with open connections, the watch, detection with TLS,
plain, slow and silent clients, TLS backpressure and writable, a
broadcast to a group mixing TLS and plain, a TLS fan-out measurement),
required in the sanitizer lanes; test_pycvc_net's TLS section.
@transfix
transfix enabled auto-merge (squash) November 26, 2026 08:59
… Enter

Two package-linux / libcvc-debug failures on PRs this week, neither in
their changes:

- PhysicsFieldWake.PackedBodiesStayBoundedAndSleep ran 1059 s in that
  lane on master (c7b050f) and timed out at 1200 s on #1552's and
  #1553's runs, three tries each. physics_field_test gets 2400 s.
- ari_run_file_pick_upload_tvision failed three tries on both: the Open
  file window showed the typed name but never took the Enter (tvision
  reads keys that come in one burst as a paste). Enter now goes once the
  field shows the name, and again, up to three times, while the window
  stays open.
@transfix
transfix disabled auto-merge November 26, 2026 20:02
@transfix
transfix enabled auto-merge (squash) November 26, 2026 20:02
transfix pushed a commit that referenced this pull request Nov 26, 2026
… Enter

Two package-linux / libcvc-debug failures on PRs this week, neither in
their changes:

- PhysicsFieldWake.PackedBodiesStayBoundedAndSleep ran 1059 s in that
  lane on master (c7b050f) and timed out at 1200 s on #1552's and
  #1553's runs, three tries each. physics_field_test gets 2400 s.
- ari_run_file_pick_upload_tvision failed three tries on both: the Open
  file window showed the typed name but never took the Enter (tvision
  reads keys that come in one burst as a paste). Enter now goes once the
  field shows the name, and again, up to three times, while the window
  stays open.
@transfix
transfix disabled auto-merge November 26, 2026 21:08
@transfix
transfix enabled auto-merge (squash) November 26, 2026 21:08
transfix added a commit that referenced this pull request Nov 27, 2026
* chore: bump libcvc to 4.0.10

* arigl_web_smoke: run the silent-relay case on arigl-web alone; master's ariglx-web (wasm-mt) is red

#1546 gated the case on the browser's WebSocket API in the module's glue. ariglx-web's threaded
(wasm-mt) ariglx.js has that API even though the package is built without the WebSocket transport,
so the case ran there, the page never dialed ("this build has no conference transport"), and the
job failed: on #1546's last head and on master since c7b050f. The single-threaded ariglx-web
job skipped it as meant. The case now runs only on arigl-web (arigl.js, no ariglx.js), the one
package with a conference transport.

* tests: physics_field_test's Debug budget, and the tvision file pick's Enter

Two package-linux / libcvc-debug failures on PRs this week, neither in
their changes:

- PhysicsFieldWake.PackedBodiesStayBoundedAndSleep ran 1059 s in that
  lane on master (c7b050f) and timed out at 1200 s on #1552's and
  #1553's runs, three tries each. physics_field_test gets 2400 s.
- ari_run_file_pick_upload_tvision failed three tries on both: the Open
  file window showed the typed name but never took the Enter (tvision
  reads keys that come in one burst as a paste). Enter now goes once the
  field shows the name, and again, up to three times, while the window
  stays open.

* cvcgl_volume_grid_segment: a volume large enough that a cooperative run spans frames on any runner

The live-labels check needs a cooperative run (CVC_SLICED_THREADING=cooperative, about 4 ms of
work a frame) to span several frames, so some frame sees the labels so far. On a package-linux
runner (#1556's run, 2026-11-26) the 56^3 run finished inside one frame's slice
on all three tries: "labels so far shown while marching (56^3, cooperative): no". 96^3 is about
five times the work.

---------

Co-authored-by: Joe Rivera <[email protected]>
@transfix
transfix merged commit 6fc811b into master Nov 27, 2026
52 of 55 checks passed
@transfix
transfix deleted the feat/net-engine-n3 branch November 27, 2026 07:32
transfix added a commit to cy-pca/sublevels that referenced this pull request Nov 28, 2026
install.sh pins libcvc 4.0.10+cvc.2 with arisrvx and pycvc-cp312
4.0.10+cvc.1. Every libcvc symbol they import is defined there
(checked with nm: arisrvx 268, _pycvc.so 1359, none missing).

4.0.10 has the engine's TLS (N3, transfix/libcvc#1552). On the engine
transport, NMDCS is now an engine listener beside plain NMDC, sharing
one engine and one fan-out, so a group send is still one broadcast:
- TLS 1.2 and up, the engine's default minimum;
- the hub publishes the listener's keyprint (net_listener.keyprint, the
  same SHA256/<base32> form);
- the engine's watch reloads the certificate and key when they change,
  and on_tls_reload hands the hub the new keyprint.
An engine without TLS (libcvc before 4.0.10, or built without libssl)
keeps NMDCS on asyncio, as before, and says so.

The arisrvx smoke run requires NMDCS on arisrvx's engine with a
published keyprint. The NMDCS login and keyprint-reload socket tests
run on both transports. The CI header and READMEs no longer say NMDCS
waits for N3.
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