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>
This commit is contained in:
1 parent
ad01fbcccb
commit
a224dbbc53
24 files changed
+1423
-168
No files matched your search
+127
-13
@@ -78,7 +78,15 @@ Peer::Peer(const RuntimeEnvironment *renv,const Identity &myIdentity,const Ident
|
||||
memcpy(_keyClassical, _key, sizeof(_keyClassical));
|
||||
memcpy(_aesKeysClassical, _aesKeys, sizeof(_aesKeysClassical));
|
||||
_hybridCapable = false;
|
||||
_pqKeysValid = false;
|
||||
_pqKeysSent = false;
|
||||
_pqKeysAcked = false;
|
||||
_pqKeysStale = false;
|
||||
_lastPQKeysSentAt = 0;
|
||||
_pendingHybridCtValid = 0;
|
||||
_pendingHybridKeyValid = 0;
|
||||
memset(_pendingHybridKey, 0, sizeof(_pendingHybridKey));
|
||||
_hybridSessionKeyInstalled = false;
|
||||
}
|
||||
|
||||
void Peer::_initAesKeys(const uint8_t* key, AES aesKeys[2])
|
||||
@@ -95,6 +103,7 @@ void Peer::setHybridSessionKey(const void* key)
|
||||
{
|
||||
memcpy(_key, key, ZT_SYMMETRIC_KEY_SIZE);
|
||||
_initAesKeys(_key, _aesKeys);
|
||||
_hybridSessionKeyInstalled = true;
|
||||
}
|
||||
|
||||
void Peer::setPendingHybridCt(const void* ct)
|
||||
@@ -103,6 +112,44 @@ void Peer::setPendingHybridCt(const void* ct)
|
||||
_pendingHybridCtValid = 1;
|
||||
}
|
||||
|
||||
|
||||
void Peer::setPendingHybridKey(const void* key)
|
||||
{
|
||||
memcpy(_pendingHybridKey, key, ZT_SYMMETRIC_KEY_SIZE);
|
||||
_pendingHybridKeyValid = 1;
|
||||
}
|
||||
|
||||
void Peer::commitPendingHybridKey()
|
||||
{
|
||||
if (_pendingHybridKeyValid) {
|
||||
setHybridSessionKey(_pendingHybridKey);
|
||||
_pendingHybridKeyValid = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void Peer::dropPendingHybridKey()
|
||||
{
|
||||
Utils::burn(_pendingHybridKey, sizeof(_pendingHybridKey));
|
||||
_pendingHybridKeyValid = 0;
|
||||
}
|
||||
|
||||
bool Peer::setPQPublicKeys(const uint8_t* mlkemPk, const uint8_t* mldsaPk)
|
||||
{
|
||||
// True when this is material we had not seen before, so the caller knows
|
||||
// to answer with its own keys.
|
||||
const bool firstView = (!_pqKeysValid);
|
||||
memcpy(_pqMlkemPk, mlkemPk, PQHybrid::MLKEM768_PK_LEN);
|
||||
memcpy(_pqMldsaPk, mldsaPk, PQHybrid::MLDSA65_PK_LEN);
|
||||
_pqKeysValid = true;
|
||||
// Keep the peer's Identity itself complete, not just these crypto caches:
|
||||
// anything that verifies a type 2 COM reads the controller's identity back
|
||||
// through Topology::getIdentity(), which hands out peer->identity(). HELLO
|
||||
// only carries the classic projection, so without this the controller stays
|
||||
// type 0 here and its signatures never verify.
|
||||
_id.attachPQPublicKeys(mlkemPk, mldsaPk);
|
||||
return firstView;
|
||||
}
|
||||
|
||||
void Peer::ensurePendingHybridCt()
|
||||
{
|
||||
if ((_pendingHybridCtValid) || (! hybridEligible()) || (RR->identity.address() >= _id.address())) {
|
||||
@@ -110,9 +157,14 @@ void Peer::ensurePendingHybridCt()
|
||||
}
|
||||
uint8_t ct[PQHybrid::MLKEM768_CT_LEN];
|
||||
uint8_t hkey[ZT_SYMMETRIC_KEY_SIZE];
|
||||
if (RR->identity.agreeHybridEncaps(_id, ct, hkey)) {
|
||||
if (RR->identity.agreeHybridEncaps(_id, _pqMlkemPk, ct, hkey)) {
|
||||
setPendingHybridCt(ct);
|
||||
setHybridSessionKey(hkey);
|
||||
// Staged, not installed: the far side derives this same key only once
|
||||
// the ciphertext reaches it. Installing now would armor outgoing data
|
||||
// frames with a key the peer cannot yet reproduce, so those frames
|
||||
// fail its MAC. commitPendingHybridKey() runs once the peer's confirm
|
||||
// tag proves it derived the same value.
|
||||
setPendingHybridKey(hkey);
|
||||
}
|
||||
Utils::burn(hkey, sizeof(hkey));
|
||||
}
|
||||
@@ -470,7 +522,9 @@ void Peer::sendHELLO(void *tPtr,const int64_t localSocket,const InetAddress &atA
|
||||
outp.append((unsigned char)ZEROTIER_ONE_VERSION_MINOR);
|
||||
outp.append((uint16_t)(ZEROTIER_ONE_VERSION_REVISION | ((RR->node->pqcMode() != ZT_PQC_MODE_CLASSIC) ? ZT_PROTO_VERB_HELLO_REVISION_CAPABILITY_BIT : 0)));
|
||||
outp.append(now);
|
||||
RR->identity.serialize(outp, false);
|
||||
// Classic projection only: a vanilla ZeroTier peer must be able to parse
|
||||
// this HELLO. PQ public keys go out in VERB_PQ_KEYS instead.
|
||||
RR->identity.serializeClassic(outp);
|
||||
atAddress.serialize(outp);
|
||||
|
||||
outp.append((uint64_t)RR->topology->planetWorldId());
|
||||
@@ -492,16 +546,8 @@ void Peer::sendHELLO(void *tPtr,const int64_t localSocket,const InetAddress &atA
|
||||
outp.append((uint64_t)0);
|
||||
}
|
||||
|
||||
const bool sendHybridCt = (hybridEligible() && (RR->identity.address() < _id.address()));
|
||||
if (sendHybridCt) {
|
||||
// Lowest address encapsulates. One ct per attempt, re-encapsulated only
|
||||
// while the peer has not yet confirmed the previous one.
|
||||
ensurePendingHybridCt();
|
||||
if (_pendingHybridCtValid) {
|
||||
outp.append((uint8_t)1); // hybrid ciphertext present
|
||||
outp.append(_pendingHybridCt, PQHybrid::MLKEM768_CT_LEN);
|
||||
}
|
||||
}
|
||||
// The hybrid ciphertext is not carried here -- it would push HELLO past
|
||||
// the MTU. It rides in VERB_PQ_KEYS once the peer is known capable.
|
||||
|
||||
outp.cryptField(_keyClassical, startCryptedPortionAt, outp.size() - startCryptedPortionAt);
|
||||
}
|
||||
@@ -523,6 +569,73 @@ void Peer::sendHELLO(void *tPtr,const int64_t localSocket,const InetAddress &atA
|
||||
RR->node->expectReplyTo(outp.packetId());
|
||||
RR->sw->send(tPtr,outp,false); // false == don't encrypt full payload, but add MAC
|
||||
}
|
||||
|
||||
// A capable peer learns our PQ public keys out of band (VERB_PQ_KEYS), since
|
||||
// they do not fit in HELLO. Driven from the peer timer rather than from
|
||||
// sendHELLO: HELLO always carries a concrete address, so an address-based
|
||||
// gate there never fires.
|
||||
|
||||
}
|
||||
|
||||
void Peer::sendPQKeys(void *tPtr,int64_t now)
|
||||
{
|
||||
Packet outp(_id.address(),RR->identity.address(),Packet::VERB_PQ_KEYS);
|
||||
|
||||
try {
|
||||
// The lowest address encapsulates; the other side derives the same key
|
||||
// from its own secret when the ciphertext arrives. Neither side needs an
|
||||
// ephemeral key: ML-KEM decapsulation consumes only sk and ct.
|
||||
bool haveCt = false;
|
||||
if (RR->identity.address() < _id.address()) {
|
||||
ensurePendingHybridCt();
|
||||
haveCt = _pendingHybridCtValid;
|
||||
}
|
||||
|
||||
|
||||
// Bit 0: we are the encapsulating side and carry a ciphertext.
|
||||
// Bit 1: we already hold the peer's keys, so this doubles as the
|
||||
// acknowledgement that ends its retry; without it both sides keep
|
||||
// re-offering forever. Both bits ride in one byte because the receiver
|
||||
// parses the keys from a fixed offset after it.
|
||||
outp.append((uint8_t)((haveCt ? 0x01 : 0x00) | (_pqKeysValid ? 0x02 : 0x00)));
|
||||
|
||||
uint8_t mlkemPk[PQHybrid::MLKEM768_PK_LEN];
|
||||
uint8_t mldsaPk[PQHybrid::MLDSA65_PK_LEN];
|
||||
RR->identity.pqKemKey(mlkemPk);
|
||||
RR->identity.pqSigKey(mldsaPk);
|
||||
outp.append(mlkemPk, sizeof(mlkemPk));
|
||||
outp.append(mldsaPk, sizeof(mldsaPk));
|
||||
if (haveCt) {
|
||||
outp.append(_pendingHybridCt, PQHybrid::MLKEM768_CT_LEN);
|
||||
}
|
||||
|
||||
// Key confirmation, appended last so its position is unambiguous and a
|
||||
// shorter packet from an older build still parses. This is what makes a
|
||||
// mismatched derivation detectable: ML-KEM's implicit rejection gives
|
||||
// both sides a well-formed but different key, and every later data frame
|
||||
// fails its MAC with no other signal that renegotiation is needed.
|
||||
uint8_t confirm[ZT_PQ_KEYS_CONFIRM_LEN];
|
||||
pqConfirmTag(confirm);
|
||||
outp.append(confirm, sizeof(confirm));
|
||||
|
||||
// Exceeds the MTU by design; Switch::send fragments it like a
|
||||
// NETWORK_CONFIG. Armored with the classical key so it is readable
|
||||
// before either side has switched to the hybrid session key.
|
||||
// FLAGS is AAD-covered, so the FRAGMENTED bit must be set here,
|
||||
// before armor() computes the MAC -- Switch::_sendViaSpecificPath
|
||||
// cannot set it on an already-armored packet without invalidating it.
|
||||
outp.setFragmented(true);
|
||||
outp.armor(_keyClassical, true, _aesKeysClassical);
|
||||
}
|
||||
catch (int e) {
|
||||
// Buffer overflow would kill the daemon via catch(int) in
|
||||
// OneServiceImpl::run(); degrade to a skipped exchange.
|
||||
return;
|
||||
}
|
||||
|
||||
RR->node->expectReplyTo(outp.packetId());
|
||||
RR->sw->send(tPtr, outp, true);
|
||||
setPQKeysSent(RR->node->now());
|
||||
}
|
||||
|
||||
void Peer::attemptToContactAt(void *tPtr,const int64_t localSocket,const InetAddress &atAddress,int64_t now,bool sendFullHello)
|
||||
@@ -664,6 +777,7 @@ unsigned int Peer::doPingAndKeepalive(void *tPtr,int64_t now)
|
||||
#ifndef ZT_NO_PEER_METRICS
|
||||
_peer_latency.Observe(latency(now));
|
||||
#endif
|
||||
|
||||
return sent;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user