pqconly: enforce PQ peers, including on the config-serve path
`pqconly` selected a type-1 identity and then behaved exactly like `hybrid` at runtime: every handshake gate tested only `pqcMode() != CLASSIC`, so nothing distinguished the two modes and no non-capable peer was ever refused. Measured on the two-host lab, a `pqconly` node carried traffic with a fully classical peer at 0% loss. Add `Peer::pqconlyPeerRejected()` - true when this node is exactly `pqconly`, the peer did not advertise the HELLO capability bit, and its role is not PLANET/MOON (all four Earth roots are `pqcCapable:false` and enforcing against them would cut the node off the root topology). Three verbs are gated, and the third is load-bearing. The first implementation gated only `VERB_NETWORK_CONFIG` and `VERB_NETWORK_CREDENTIALS` and still let the classical peer join at 0% loss, because membership is granted by the *serve* direction: a classic peer asks the pqconly node's controller for its config, and the node enforcing the policy was the one handing it over. Gating `VERB_NETWORK_CONFIG_REQUEST` before the controller is consulted closes it. The rejection counter had been incrementing in the unrelated direction throughout, which is what made the false assurance possible. `hybrid` keeps its silent classical fallback - that is its contract - but now logs a downgrade WARNING once per peer, re-armed on recovery, so a downgraded link is no longer invisible. The gate keys on `_hybridCapable`, not `hybridSessionKeyInstalled()`: the encapsulating peer stages its hybrid key until the confirm tag arrives, so gating on the installed key would reject a healthy PQ peer for the entire staging window. Measured 2026-10-08, two-host lab, clean rebuild, selftest exit 0: - `pqconly` vs classical: network now sits at REQUESTING_CONFIGURATION with assignedAddresses [] and 100% loss, down from OK at 0% loss. - `pqconly` vs `pqconly`: 0% loss both directions, no false rejection.
This commit is contained in:
1 parent
975148525b
commit
2e2b0910a8
11 files changed
+258
-55
No files matched your search
+1
-1
@@ -1,7 +1,7 @@
|
||||
// PQC capability mode (local.conf settings.pqcMode / Identity::generate)
|
||||
#define ZT_PQC_MODE_CLASSIC 0 // off: C25519 key agreement only
|
||||
#define ZT_PQC_MODE_HYBRID 1 // hybrid: C25519 agreement with ML-KEM-768 mixed in
|
||||
#define ZT_PQC_MODE_PQCONLY 2 // pqconly: PQ-only identities, no classic fallback
|
||||
#define ZT_PQC_MODE_PQCONLY 2 // pqconly: same PQ material as hybrid, but enforces the peer requirement (see Peer::pqconlyPeerRejected)
|
||||
|
||||
/*
|
||||
* Copyright (c)2019 ZeroTier, Inc.
|
||||
|
||||
@@ -1082,6 +1082,15 @@ bool IncomingPacket::_doNETWORK_CREDENTIALS(const RuntimeEnvironment *RR,void *t
|
||||
return true;
|
||||
}
|
||||
|
||||
// Same pqconly rule as _doNETWORK_CONFIG, and it matters most here: a COM is
|
||||
// what establishes trust for a network, so letting one in over a silently
|
||||
// classical link would reinstate exactly the downgrade the mode forbids.
|
||||
if (peer->pqconlyPeerRejected()) {
|
||||
Metrics::pkt_network_credentials_in_pqconly_rejected++;
|
||||
RR->node->setPQCDowngradeWarning(peer->address(), true);
|
||||
return false;
|
||||
}
|
||||
|
||||
CertificateOfMembership com;
|
||||
Capability cap;
|
||||
Tag tag;
|
||||
@@ -1221,6 +1230,17 @@ bool IncomingPacket::_doNETWORK_CONFIG_REQUEST(const RuntimeEnvironment *RR,void
|
||||
const unsigned int hopCount = hops();
|
||||
const uint64_t requestPacketId = packetId();
|
||||
|
||||
// pqconly must also refuse to *serve* config. The receive-side gates in
|
||||
// _doNETWORK_CONFIG / _doNETWORK_CREDENTIALS only protect this node from a
|
||||
// downgraded peer, but a classic peer asks us for its own config and we are
|
||||
// the node in pqconly - gating only inbound let the network come up anyway.
|
||||
if (peer->pqconlyPeerRejected()) {
|
||||
Metrics::pkt_network_config_in_pqconly_rejected++;
|
||||
RR->node->setPQCDowngradeWarning(peer->address(), true);
|
||||
peer->received(tPtr,_path,hopCount,requestPacketId,payloadLength(),Packet::VERB_NETWORK_CONFIG_REQUEST,0,Packet::VERB_NOP,false,nwid,ZT_QOS_NO_FLOW);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (RR->localNetworkController) {
|
||||
const unsigned int metaDataLength = (ZT_PROTO_VERB_NETWORK_CONFIG_REQUEST_IDX_DICT_LEN <= size()) ? at<uint16_t>(ZT_PROTO_VERB_NETWORK_CONFIG_REQUEST_IDX_DICT_LEN) : 0;
|
||||
const char *metaDataBytes = (metaDataLength != 0) ? (const char *)field(ZT_PROTO_VERB_NETWORK_CONFIG_REQUEST_IDX_DICT,metaDataLength) : (const char *)0;
|
||||
@@ -1247,6 +1267,16 @@ bool IncomingPacket::_doNETWORK_CONFIG(const RuntimeEnvironment *RR,void *tPtr,c
|
||||
{
|
||||
Metrics::pkt_network_config_in++;
|
||||
const SharedPtr<Network> network(RR->node->network(at<uint64_t>(ZT_PACKET_IDX_PAYLOAD)));
|
||||
// pqconly refuses a network whose config would arrive over a link that
|
||||
// silently fell back to classical. Infrastructure roles are exempt inside
|
||||
// pqconlyPeerRejected(). This must run before handleConfigChunk(), or the
|
||||
// downgraded config is already applied by the time we notice.
|
||||
if (peer->pqconlyPeerRejected()) {
|
||||
Metrics::pkt_network_config_in_pqconly_rejected++;
|
||||
RR->node->setPQCDowngradeWarning(peer->address(), true);
|
||||
peer->received(tPtr,_path,hops(),packetId(),payloadLength(),Packet::VERB_NETWORK_CONFIG,0,Packet::VERB_NOP,false,at<uint64_t>(ZT_PACKET_IDX_PAYLOAD),ZT_QOS_NO_FLOW);
|
||||
return false;
|
||||
}
|
||||
if (network) {
|
||||
const uint64_t configUpdateId = network->handleConfigChunk(tPtr,packetId(),source(),*this,ZT_PACKET_IDX_PAYLOAD);
|
||||
if (configUpdateId) {
|
||||
|
||||
@@ -54,10 +54,14 @@ namespace ZeroTier {
|
||||
{ packets.Add({{"packet_type", "multicast_like"}, {"direction", "rx"}}) };
|
||||
prometheus::simpleapi::counter_metric_t pkt_network_credentials_in
|
||||
{ packets.Add({{"packet_type", "network_credentials"}, {"direction", "rx"}}) };
|
||||
prometheus::simpleapi::counter_metric_t pkt_network_credentials_in_pqconly_rejected
|
||||
{ packets.Add({{"packet_type", "network_credentials"}, {"direction", "rx"}, {"pqconly_rejected", "yes"}}) };
|
||||
prometheus::simpleapi::counter_metric_t pkt_network_config_request_in
|
||||
{ packets.Add({{"packet_type", "network_config_request"}, {"direction", "rx"}}) };
|
||||
prometheus::simpleapi::counter_metric_t pkt_network_config_in
|
||||
{ packets.Add({{"packet_type", "network_config"}, {"direction", "rx"}}) };
|
||||
prometheus::simpleapi::counter_metric_t pkt_network_config_in_pqconly_rejected
|
||||
{ packets.Add({{"packet_type", "network_config"}, {"direction", "rx"}, {"pqconly_rejected", "yes"}}) };
|
||||
prometheus::simpleapi::counter_metric_t pkt_multicast_gather_in
|
||||
{ packets.Add({{"packet_type", "multicast_gather"}, {"direction", "rx"}}) };
|
||||
prometheus::simpleapi::counter_metric_t pkt_multicast_frame_in
|
||||
|
||||
@@ -41,7 +41,9 @@ namespace ZeroTier {
|
||||
extern prometheus::simpleapi::counter_metric_t pkt_multicast_like_in;
|
||||
extern prometheus::simpleapi::counter_metric_t pkt_network_credentials_in;
|
||||
extern prometheus::simpleapi::counter_metric_t pkt_network_config_request_in;
|
||||
extern prometheus::simpleapi::counter_metric_t pkt_network_credentials_in_pqconly_rejected;
|
||||
extern prometheus::simpleapi::counter_metric_t pkt_network_config_in;
|
||||
extern prometheus::simpleapi::counter_metric_t pkt_network_config_in_pqconly_rejected;
|
||||
extern prometheus::simpleapi::counter_metric_t pkt_multicast_gather_in;
|
||||
extern prometheus::simpleapi::counter_metric_t pkt_multicast_frame_in;
|
||||
extern prometheus::simpleapi::counter_metric_t pkt_push_direct_paths_in;
|
||||
|
||||
@@ -624,6 +624,11 @@ ZT_PeerList *Node::peers() const
|
||||
// ever sees the ciphertext, so hybridEligible() reports True a full
|
||||
// round trip early and the decapsulator's failure goes unnoticed.
|
||||
p->pqcHybridActive = pi->second->hybridSessionKeyInstalled();
|
||||
// A peer that has since advertised the capability clears its downgrade
|
||||
// warning, so a later failure warns again instead of staying silent.
|
||||
if (p->pqcCapable) {
|
||||
setPQCDowngradeWarning(pi->second->identity().address(), false);
|
||||
}
|
||||
|
||||
std::vector< SharedPtr<Path> > paths(pi->second->paths(_now));
|
||||
SharedPtr<Path> bestp(pi->second->getAppropriatePath(_now,false));
|
||||
@@ -749,6 +754,64 @@ void Node::setNetconfMaster(void *networkControllerInstance)
|
||||
}
|
||||
}
|
||||
|
||||
// Records a PQC downgrade and warns once per peer per state. Without this a
|
||||
// node configured for hybrid/pqconly silently keeps running on the classical
|
||||
// key against a peer that never offered PQ material, with no log line at all.
|
||||
// Warns on entry to the downgraded state and again on recovery, so a peer that
|
||||
// flaps is visible without log-spamming every packet.
|
||||
void Node::setPQCDowngradeWarning(const Address &addr, bool rejected) const
|
||||
{
|
||||
if (_pqcMode == ZT_PQC_MODE_CLASSIC) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Decide under the lock, print after it is released: fprintf under a lock
|
||||
// would serialize every peer handshake behind the log write.
|
||||
bool shouldWarn = false;
|
||||
{
|
||||
Mutex::Lock _l(_pqcDowngradeWarned_m);
|
||||
|
||||
bool known = false;
|
||||
for(std::vector<Address>::iterator i=_pqcDowngradeWarned.begin();i!=_pqcDowngradeWarned.end();++i) {
|
||||
if (*i == addr) {
|
||||
known = true;
|
||||
if (!rejected) {
|
||||
_pqcDowngradeWarned.erase(i); // recovered, allow a future warning
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (rejected) {
|
||||
if (!known) {
|
||||
_pqcDowngradeWarned.push_back(addr);
|
||||
shouldWarn = true;
|
||||
}
|
||||
} else {
|
||||
shouldWarn = known; // only report a recovery if we warned
|
||||
}
|
||||
}
|
||||
|
||||
if (!shouldWarn) {
|
||||
return;
|
||||
}
|
||||
|
||||
char addrStr[11];
|
||||
addr.toString(addrStr);
|
||||
if (rejected) {
|
||||
fprintf(stderr,
|
||||
"WARNING: peer %s cannot do post-quantum key exchange but this node is in pqcMode "
|
||||
"%s; traffic to it is classical%s" ZT_EOL_S,
|
||||
addrStr,
|
||||
(_pqcMode == ZT_PQC_MODE_PQCONLY) ? "pqconly" : "hybrid",
|
||||
(_pqcMode == ZT_PQC_MODE_PQCONLY) ? " and network config from it is REFUSED." : ".");
|
||||
} else {
|
||||
fprintf(stderr,
|
||||
"INFO: peer %s now reports post-quantum capability; downgrade cleared." ZT_EOL_S,
|
||||
addrStr);
|
||||
}
|
||||
}
|
||||
|
||||
/****************************************************************************/
|
||||
/* Node methods used only within node/ */
|
||||
/****************************************************************************/
|
||||
|
||||
@@ -100,6 +100,7 @@ public:
|
||||
void clearLocalInterfaceAddresses();
|
||||
int sendUserMessage(void *tptr,uint64_t dest,uint64_t typeId,const void *data,unsigned int len);
|
||||
void setNetconfMaster(void *networkControllerInstance);
|
||||
void setPQCDowngradeWarning(const Address &addr, bool rejected) const;
|
||||
|
||||
// Internal functions ------------------------------------------------------
|
||||
|
||||
@@ -345,6 +346,8 @@ public:
|
||||
bool _online;
|
||||
bool _lowBandwidthMode;
|
||||
int _pqcMode;
|
||||
mutable std::vector<Address> _pqcDowngradeWarned;
|
||||
mutable Mutex _pqcDowngradeWarned_m;
|
||||
};
|
||||
|
||||
} // namespace ZeroTier
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
#include "RingBuffer.hpp"
|
||||
#include "SelfAwareness.hpp"
|
||||
#include "Switch.hpp"
|
||||
#include "Topology.hpp"
|
||||
#include "Trace.hpp"
|
||||
#include "Utils.hpp"
|
||||
|
||||
@@ -169,6 +170,18 @@ void Peer::ensurePendingHybridCt()
|
||||
Utils::burn(hkey, sizeof(hkey));
|
||||
}
|
||||
|
||||
bool Peer::pqconlyPeerRejected() const
|
||||
{
|
||||
if (RR->node->pqcMode() != ZT_PQC_MODE_PQCONLY) {
|
||||
return false;
|
||||
}
|
||||
if (_hybridCapable) {
|
||||
return false;
|
||||
}
|
||||
const ZT_PeerRole r = RR->topology->role(address());
|
||||
return ((r != ZT_PEER_ROLE_PLANET) && (r != ZT_PEER_ROLE_MOON));
|
||||
}
|
||||
|
||||
void Peer::received(
|
||||
void *tPtr,
|
||||
const SharedPtr<Path> &path,
|
||||
|
||||
@@ -433,6 +433,24 @@ public:
|
||||
inline bool hybridEligible() const
|
||||
{ return ((RR->node->pqcMode() != ZT_PQC_MODE_CLASSIC) && (_hybridCapable) && (RR->identity.hasPQ()) && _pqKeysValid); }
|
||||
|
||||
/**
|
||||
* True when this node enforces pqconly and the peer is a non-infrastructure
|
||||
* peer that cannot do PQ, i.e. traffic to it would be silently classical.
|
||||
*
|
||||
* The gate keys on _hybridCapable -- set once at HELLO and stable -- and not
|
||||
* on hybridSessionKeyInstalled(). A capable peer stages its hybrid key until
|
||||
* the confirm tag arrives, so testing the installed key would reject a
|
||||
* perfectly good PQ peer for the whole staging window.
|
||||
*
|
||||
* Roots are exempt: planets and moons are infrastructure this node dials for
|
||||
* world/world routing, they are not network members, and no classical planet
|
||||
* build will ever advertise the capability bit. Enforcing against them would
|
||||
* cut the node off from the root topology.
|
||||
*
|
||||
* Defined in Peer.cpp: Topology is only forward-declared here.
|
||||
*/
|
||||
bool pqconlyPeerRejected() const;
|
||||
|
||||
/**
|
||||
* Rate limit gate for VERB_PUSH_DIRECT_PATHS
|
||||
*/
|
||||
|
||||
Reference in new issue
Block a user