Files
BackOne/SPEC.md
T
proitlabandClaude Opus 4.8 a224dbbc53
validate.yml / build_ubuntu (push) Canceled after 0s
build.yml / build_ubuntu (push) Canceled after 0s
build.yml / build_macos (push) Canceled after 0s
build.yml / build_windows (push) Canceled after 0s
Lint / clang-format (push) Canceled after 0s
PQ: fix membership for post-quantum nodes (three control-plane defects)
A PQ node could complete the hybrid handshake and still never join the
network: status ACCESS_DENIED, peers [], frames dropped. Three separate
defects, none in the key exchange itself.

1. EmbeddedNetworkController::_request gated known members with
   Identity(haveIdStr) != identity. HELLO carries only the classic
   projection (Identity::serializeClassic), so peer->identity() stays
   type 0 while a stored record is type 1, and operator== -- which
   compares PQ material -- always reported a mismatch. Use the existing
   sameClassicalIdentity(); PQ key rotation stays detectable via
   VERB_PQ_KEYS.

2. Peer::setPQPublicKeys() cached the received PQ keys for the crypto
   path only and never wrote them into _id. The controller's identity
   therefore stayed type 0 in every table, com.verify() returned 1, and
   Membership deferred for WHOIS forever -- a WHOIS cannot help, the
   keys arrive in VERB_PQ_KEYS. Add Identity::attachPQPublicKeys() and
   call it so the peer's Identity is complete once keys arrive.

3. OneServiceImpl::run constructed an EmbeddedNetworkController
   unconditionally, so a member-only node answered its own
   NETWORK_CONFIG_REQUESTs and self-signed a local config, never
   contacting the node that owned the network. Add
   settings.disableController (default false, so existing installs are
   unchanged) for member-only nodes.

Verified live on two hosts with pqcMode: hybrid on both sides: status OK,
peer DIRECT over 192.168.122.85/9993, pqcCapable and pqcHybridActive true
both directions, ping 0% loss both ways, selftest exit 0.

The selftest regression covers the controller match and keeps rejecting an
impostor identity at the same address.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-10-07 21:37:05 +00:00

20 KiB
Raw Blame History

SPEC — BackOne

§G (goal)

Make BackOne quantum ready: phases 1-6 of backone-quantum-fork-research.md — liboqs + hybrid X25519+ML-KEM-768 / Ed25519+ML-DSA-65 handshake, identity/COM v2 double-sign, capability-bit negotiation. Phase 7 (AES-256-GCM) OUT.

§C (constraints)

  • C++17. GNU make = real build. Top CMakeLists.txt = stub, never product build.
  • Deps vendored in ext/. No new dep for few-liners.
  • Tabs always, .clang-format LLVM/Stroustrup, indent 4. No reformat of untouched lines.
  • New .cpp/.hpp/.h gets 11-line BSL header verbatim (node/Mutex.hpp:1-12).
  • node/ stays OS-independent. Sockets/files → osdep/. Orchestration → service/. Persistence → controller/.
  • No exceptions across C API. Fatal ZT_ResultCode = 100–999.
  • One reactor thread (Phy::poll). Cross-thread wake only Phy::whack().
  • New compiled file → register in objects.mk or no link.
  • Platforms: Linux (primary), macOS, BSD/NetBSD, Windows (msbuild).
  • Header edits: no -MMD dep tracking → make clean after touching .h.
  • PQC lock: liboqs static vendored ext/; hybrid key = KDF(classical ‖ pq); presets hybrid (ML-KEM-768/ML-DSA-65) + pqconly (intended ML-KEM-1024/ML-DSA-87 — not yet distinct, see T25)
  • wire/identity/COM use versioned v2 + capability-bit fallback to classic
  • include/ZeroTierOne.h changes additive-only (Java/libzt ripple)
  • OUT: AES-256-GCM swap, trusted-path skipCrypto, forward secrecy, protocol standardization, crypto audit, production release/signing
  • ? address v2 derivation keeping 40-bit + PoW
  • ? VL1 fragmentation capacity for +4KB identity (check node/Packet.*)
  • ? liboqs version/tag + build flags for ext/
  • ? measured ML-KEM/ML-DSA latency (doc estimates unverified)
  • ? capability-bit placement in existing handshake

§I (public surfaces)

id surface detail
I.capi C API include/ZeroTierOne.h, ZT_Node_* (lines 1796-2258), ZT_SDK_API. Ripples to Java/libzt/SDK
I.api HTTP JSON API 127.0.0.1:9993, /status /peer /network /member /controller /metrics /info, auth X-ZT1-Auth header or ?auth= from authtoken.secret
I.cli CLI backone-cli info|listpeers|listnetworks|join|leave (-j -p -D), backone-idtool generate|validate|getpublic|sign|verify|mkcom — symlink dispatch on argv[0]
I.cfg config home /var/lib/backone (macOS /Library/Application Support/BackOne), local.conf, identity.secret, networks.d/, controller.db, backone.port, backone.pid
I.build build make, make one, make selftest, make core, make debug, make install, make debian/redhat, make central-controller; env ZT_* knobs
I.ffi Rust FFI rustybits/zeroidc (zeroidc_new…), smeeclient — C header zeroidc.h, link on ZT_SSO_SUPPORTED=1/ZT_CONTROLLER=1
I.jni Java SDK java/jni/…Node.cpp, ant targets build_java/build_android/build_jar
I.pqc.cfg config local.conf settings.pqcMode (off/hybrid/pqconly); absent = off/classic (opt-in), unknown value = warn + classic. Per-algorithm kem/sig selection is not wired (research doc only, see T25)
I.pqc.wire wire static-static hybrid, no ephemeral exchange: identity v2 (type byte 1) stores ML-KEM-768 + ML-DSA-65 pub on disk, but HELLO carries only the classic projection (Identity::serializeClassic) so vanilla peers parse it; peer PQ keys arrive in VERB_PQ_KEYS (0x17); agree = KDF(X25519-identity-agree ‖ ML-KEM-encaps(peer static pub)); the agreed key is confirmed by a trailing 4 B tag in the same verb (optional, V19), since ML-KEM cannot report a mismatched decapsulation; capability via HELLO protocol-version high bit; identity.secret/identity.public v2 on disk
I.pqc.com credentials COM double-sign/verify — controller + node/CertificateOfMembership.*
I.rules rules compiler node rule-compiler/cli.js <rules> → rules/tags JSON

§V (invariants)

Derived from selftest.cpp + CI gates. ? = code-derived, no test yet.

id invariant evidence
V1 Crypto KATs pass: Salsa20 vectors, C25519 agreement, Ed25519 sign/verify, SHA512, Poly1305 selftest.cpp:137 testCrypto
V2 Identity known-good accepted, known-bad rejected selftest.cpp:475 testIdentity
V3 CertificateOfMembership signs and agreesWith roundtrip selftest.cpp:577 testCertificate
V4 Packet encode/decode roundtrip exact selftest.cpp:641 testPacket
V5 Phy UDP+TCP loopback on 127.0.0.1 works, no root selftest.cpp:1002 testPhy
V6 Zero definite leaks under valgrind; test exit code 0 .github/workflows/validate-report.sh
V7 ? No exception crosses C API; ZT_ResultCode_isFatal only 100–999 include/ZeroTierOne.h:426
V8 ? node/ contains no OS calls (sockets/files/interfaces) node/README.md rule
V9 hybrid↔vanilla negotiates classic, link stays up interop matrix
V10 identity v2 survives 1280B MTU tunnel intact; v2 = type byte 1 (wire Identity.hpp:219, string slot Identity.cpp:173); address derivation hashes X25519 material only → v1/v2 addresses bit-identical; v1 parser rejects type ≠ 0 cleanly interop matrix
V11 ML-KEM/ML-DSA KATs + hybrid KDF vector + identity v2 roundtrip + COM double-sign verify pass extended selftest.cpp
V12 pqcMode negotiation honors local.conf (off -> no v2 fields) live daemon: bogus settings.pqcMode -> WARNING (service/OneService.cpp:1478), hybrid -> clean (2026-10-03); selftest has no pqcMode coverage
V13 hybrid agree = KDF(X25519-identity-agree ‖ ML-KEM static-static), no ephemeral exchange; hybrid↔hybrid agree + hybrid↔vanilla classic fallback pass node/Peer.cpp ensurePendingHybridCt (encaps) / setHybridSessionKey (install); node/IncomingPacket.cpp _doPQ_KEYS (parse + decaps)
V14 COM double-sign = type byte 1→2 appends ML-DSA sig alongside Ed25519; v1 verify path unchanged; v1 rejects type 2 cleanly node/CertificateOfMembership.hpp:222-296, node/CertificateOfMembership.cpp:97-162, selftest.cpp:717
V15 handshake vs fragment loss measured: classic HELLO stays 137 B → 1 frag in every mode (max 7 Packet.hpp:235); PQ material moved off the critical path, so HELLO no longer depends on fragment reassembly selftest.cpp PQ section
V16 hybrid handshake puts a 1088 B ML-KEM-768 ct on the wire and both sides derive the same hybrid _key; classic/off peers never receive VERB_PQ_KEYS and fall back see V17 for the live evidence
V17 PQ public keys travel out of band in VERB_PQ_KEYS (0x17), never inside HELLO: HELLO carries only Identity::serializeClassic so a vanilla peer can parse it, and VERB_PQ_KEYS (4253 B → 3 frags) carries ML-KEM-768 + ML-DSA-65 public keys plus, from the lowest address, the 1088 B ct. Flag byte: bit0 = ct present, bit1 = "I already hold your keys" (ends the retry loop). A 4 B key-confirmation tag follows the keys (after the ct when present), see V19. 2-node moon lab: pqcCapable:true, pqcHybridActive:true, 3 active direct paths at 172.31.0.1/19993 (2026-10-06)
V18 FLAGS is inside the AES-GMAC-SIV AAD and dearmor keeps the FRAGMENTED bit, so setFragmented(true) must precede armor(); Switch::_sendViaSpecificPath may not set it on an already-armored packet. dearmor decrypts to scratch and commits only on success, so a failed attempt does not destroy the ciphertext a later key would need. selftest.cpp PQ section: fragmented pre-armed packet dearmors, late-set flag does not (verified FAIL-AS-EXPECTED)
V19 The hybrid session key is confirmed, never merely assumed. ML-KEM uses implicit rejection: decapsulating with a secret that does not match the peer's public key returns a well-formed but wrong shared secret instead of an error, so a peer whose PQ material drifted derived a different key, believed agreement succeeded, and every data frame then failed its MAC — with _pqKeysAcked already latched at the first handshake, so the retry timer never fired again and only a one-sided daemon restart recovered. A 4 B tag = HMAC-SHA384(_key, peer_address), under its own KBKDF label (ZT_KBKDF_LABEL_PQ_CONFIRM '2') so it cannot collide with session-key material, rides at the end of VERB_PQ_KEYS and is optional on the wire (a build without it still interoperates). Mismatch → resetPQExchange(), which reverts _key to classical, so the inbound path's hybrid-then-classical fallback (IncomingPacket.cpp) keeps working throughout. A peer that rolled its PQ keys still holds ours and therefore sets the ack bit in the very message where the rotation is detected, so that ack is dropped for that exchange — honouring it would re-latch the state just cleared and suppress the reply that carries the fresh ciphertext. selftest.cpp "Key confirmation detects mismatched hybrid key"; direct test against libbackonecore.a: honest session confirms, mismatched derivation is caught, renegotiation converges to agreeing keys. Live 2-node hybrid session (n2 joins n1's network) produced zero confirmation failures, so healthy sessions are not reset

§T (tasks)

id status task cites
T1 x Fix CI build smoke: build.yml runs ./zerotier-selftest, build emits backone-selftest (also tar zerotier-one → backone) I.build,V6
T2 x Fix validate-linux.sh binary names: invokes ./zerotier-one, ./zerotier-cli (lines 41-43,105,111,451), builds backone* I.cli,V6
T3 x Wire ZT_COVERAGE into makefiles — consumed by none, gcovr likely reports zeros ? I.build
T4 x make install manpage rule: expects doc/backone.8, doc/backone-cli.1, doc/backone-idtool.1; doc/ only has zerotier-*, no rename rule I.build
T5 x make redhat: backone.spec %install copies missing debian/backone.service + ext/installfiles/linux/backone.init.rhel6 (actual files zerotier-*) I.build
T6 x Rebrand make-bsd.mk/make-netbsd.mk: still emit/install zerotier-one, /var/db/zerotier-one vs code writing backone.pid I.build
T7 x Dockerfile.ci: copies zerotier-one from build → fails; binary is backone I.build
T8 . pkg/snap/snapcraft.yaml: builds upstream github.com/zerotier/zerotierone.git, expects usr/sbin/zerotier-one I.build
T9 . Wire orphaned java/test/StringUtilsTest.java (JUnit4) into java/build.xml target or delete I.jni
T10 . Replace rule-compiler/package.json npm test failing placeholder with real test of rule-compiler.js I.rules
T11 . ? Add #[test] coverage for rustybits/zeroidc FFI parse/exchange paths I.ffi,V7
T12 x Implement Redis config TODO (service/OneService.cpp:1467 // TODO: Redis config) I.cfg
T13 . Implement LFDB::eraseNetwork/eraseMember TODOs (controller/LFDB.cpp:383,388) I.cfg
T14 . Lint gate done: make lint (tools/lint.sh, changed-lines clang-format) + .github/workflows/lint.yml I.build
T15 . Fix -Wsign-compare suppression FIXME (node/Bond.cpp:23, node/Node.cpp:40) I.build
T16 x Federation identity-collision payload FIXME (node/IncomingPacket.cpp:211) ? scope I.capi,V7
T17 x Phase 1: vendor liboqs static into ext/, wire make-linux.mk + objects.mk, pin version/tag + flags I.build
T18 x Phase 2: node/PQHybrid.* hybrid agree = KDF(X25519-identity-agree ‖ ML-KEM-768 encaps over peer static pub); phase-2 ephemeral-field mockup dropped I.pqc.wire,V13
T19 x Phase 3: identity v2 type byte 1, append ML-KEM+ML-DSA pubs, address hash X25519-only, v1 clean reject type ≠ 0 I.pqc.wire,V10
T20 x Phase 4: COM type byte 2 double-sign (Ed25519+ML-DSA-65), v1 rejects cleanly I.pqc.com,V14
T21 . Phase 5: local.conf settings.pqcMode parse (off/hybrid/pqconly) + capability negotiation via HELLO protocol-version bytes, fallback classic. Mode now selects whether PQ material is used; which preset is still hardcoded (T24) I.pqc.cfg,V12,V9
T22 x Phase 6: selftest extension — ML-KEM/ML-DSA KATs, hybrid KDF vector, identity v2 roundtrip + address stability, COM double-sign, interop hybrid↔vanilla matrix I.build,V11,V10,V14
T23 x Phase 6: handshake-vs-fragment-loss benchmark for PQC HELLO; cap/segment if loss breaks handshake V15
T24 x Plumb settings.pqcMode through the identity path: Node(…,int pqcMode) stores _pqcMode; Identity::generate(bool pq,int pqcMode) derives pq from the daemon mode; OneService reads local.conf before new Node — a fresh hybrid/pqconly node writes a type-1 identity, a classic one type-0. Fixes the G1 defect. I.pqc.cfg,V12
T25 . Distinct PQ parameter sets: node/PQHybrid.* hardcodes ML-KEM-768/ML-DSA-65 (PQHybrid.cpp static_asserts OQS_KEM_ml_kem_768/OQS_SIG_ml_dsa_65), so hybrid and pqconly currently select identical material, while SPEC §C claims ML-KEM-1024/ML-DSA-87 for pqconly. Parameterize the preset (key sizes, ct len, _pendingHybridCt buffer) or drop the pqconly claim. The HELLO MTU objection recorded here no longer applies — PQ material rides in VERB_PQ_KEYS (V17) — so the only remaining coupling is the buffer sizes in Peer.hpp. I.pqc.wire,I.pqc.cfg,V15,V17
T26 . Expose real PQ state in /peer: pqcCapable/pqcHybridActive are copied from the ZT_Peer snapshot, which never populates them, so both always read false (B6). Add a Node accessor for a live peer by address and populate both fields in the three _peerToJson call sites. Needs a ZT_Node C API entry point, so it ripples to include/ZeroTierOne.h, java/jni, and the SDKs — budget for that rather than reaching into node/ from service/. I.pqc.wire,I.capi,V19

T1/T2 = prerequisites — CI must invoke backone-selftest before PQC gates mean anything. T1–T16 backlog (rebrand/CI/lint leftovers); T17–T25 = PQC phases 1–6 + the pqconly preset gap; T26 = PQ state is not observable via /peer.

Not tracked (low value ?): one.cpp:256 port/token cleanup, MacKextEthernetTap.cpp:480 iface status, VLAN TODOs in NetBSDEthernetTap.cpp:468/MacKextEthernetTap.cpp:685, Phy.hpp:325 unix sock type comment.

§B (bug log)

id date cause fix
B1 2026-10-02 Phase 5 (T21) advertised PQC capability in HELLO but never consumed it: Peer::_key was derived classically in the constructor and the hybrid ciphertext had no place in the HELLO/OK(HELLO) layout, so hybridEligible() was dead. Wire hybrid static-static KEM ct into HELLO (lowest-address side writes [moon count][moons][flag(1B)][ct 1088B], crypted with the classical key) and echo it in OK(HELLO); parser order matches Peer::sendHELLO/_doHELLO; Peer::ensurePendingHybridCt() lazily encapsulates on first capability sighting so the handshake completes in one round trip; direction guard sender == lowest address on both parses. Refuse to start when the on-disk identity cannot satisfy settings.pqcMode (classic↔PQ migration changes the address).
B2 2026-10-02 settings.pqcMode absent (or unrecognized) resolved to HYBRID, and Node's pqcMode default was HYBRID with no way to tell "unconfigured" from "configured hybrid". Every existing type-0 install would hit the B1 refusal guard at startup; the C API ZT_Node_new path would silently generate type-1 identities. Absent/unknown settings.pqcMode now resolves to ZT_PQC_MODE_CLASSIC (PQC is opt-in, matching the research doc); Node(…,int pqcMode = ZT_PQC_MODE_CLASSIC). Verified: classic identity + no config boots on 2.0.0 and stays 141 B; fresh node w/o config makes type-0; fresh node with "hybrid" makes type-1 (6415 B); classic + explicit "off" boots; classic + explicit "hybrid" still refuses; unknown value warns and runs classic.
B3 2026-10-06 The hybrid handshake never completed. Three defects stacked: (a) HELLO carried the full 6415 B type-1 identity, so every peer had to reassemble a 3-fragment packet before it could even answer, and a vanilla peer could not parse it at all; (b) Switch::_sendViaSpecificPath called packet.setFragmented(...) on packets that were already armored — FLAGS is inside the AES-GMAC-SIV AAD, so flipping the bit after armor() invalidated the MAC and the receiver dropped every VERB_PQ_KEYS as "invalid MAC"; (c) Packet::dearmor decrypted in place, so a failed attempt destroyed the ciphertext a later key would need. PQ material moved out of HELLO into VERB_PQ_KEYS; HELLO now emits only Identity::serializeClassic. _sendViaSpecificPath sets FRAGMENTED only on unencrypted packets; sendPQKeys sets it before armor(). dearmor decrypts to a scratch buffer and commits only on success. Regression test in selftest.cpp asserts both directions (fragmented-and-pre-armed authenticates; armed-then-flagged does not), verified failing against the old ordering.
B4 2026-10-06 Reported symptom was backone-cli peers showing a wall of PLANET -1 RELAY rows. Two things were wrong with the reading: the leading 200 is the HTTP status code that one.cpp:453 prints, not a peer count; and the rows are the four hardcoded Earth roots, which a host with no UDP egress to 9993.zerotier.com can never reach — hence RELAY and latency -1 with no path. No code change. Documented here so the symptom is not re-read as a PQ failure: a node that cannot reach a root shows exactly this table, independent of pqcMode.
B5 2026-10-07 A hybrid session could wedge permanently and silently. ML-KEM uses implicit rejection: agreeHybridDecaps with a secret that does not match the peer's public key returns a well-formed but wrong shared secret rather than an error, so both sides believed agreement had succeeded and installed it. A peer whose PQ material drifted (restore from backup, identity roll) derived a different key than its counterpart, and every data frame thereafter failed its MAC. _pqKeysAcked had already latched at the first handshake, so pqKeysDue never fired again and the retry path could not repair it — recovery required restarting one daemon. Compounding it, a peer that rolled its keys still holds ours and so sets the ack bit in the very message announcing the rotation, so the ack re-latched the state being cleared and suppressed the reply that carried the fresh ciphertext. Added key confirmation: 4 B HMAC-SHA384(_key, peer_address) at the tail of VERB_PQ_KEYS, optional on the wire, under its own KBKDF label. Mismatch, or advertised public keys that differ from the installed ones, calls resetPQExchange() — drops the hybrid key, reverts _key to classical (the inbound hybrid-then-classical fallback keeps traffic alive throughout), re-arms the retry, and re-encapsulates. The stale ack is dropped for that exchange so the reply is not suppressed. agreeHybridDecaps failure is no longer silently ignored. Verified in selftest.cpp and directly against libbackonecore.a; live 2-node hybrid session shows zero false confirmations.
B6 2026-10-07 Reported wrong and withdrawn. Originally logged as "pqcCapable/pqcHybridActive in /peer are copied from a ZT_Peer snapshot that never populates them, so both always report false." That was false: Node::peers() populates both at node/Node.cpp:621,626 from Peer::hybridCapable() and Peer::hybridSessionKeyInstalled(), and no C API change was ever needed — the fields are BackOne additions to ZT_Peer itself (include/ZeroTierOne.h:1460,1467). What was true is narrower and much less interesting: a stale comment at service/OneService.cpp:621 asserted the snapshot lacked the fields, which contradicted the two lines directly beneath it and would have sent the next reader looking for a missing C API accessor that already existed. The fields were always live. Deleted the stale comment. No functional change. Verified against a live 2-node hybrid lab: /peer reports pqcHybridActive:true on both sides once the key is installed, and false on a classical peer — the same field tools/pqc-lab.sh G4 gates on. Kept here because "the observability does not exist" is an expensive wrong assumption to propagate into the C API surface.