feat(pqc): plumb pqcMode to identity path, hybrid HELLO ct, spec review fixes
- Node stores _pqcMode; Identity::generate(bool,int) derives pq from daemon mode - OneService reads local.conf settings.pqcMode before new Node (opt-in, absent=classic) - Peer/IncomingPacket: hybrid KEM ct in HELLO/OK, capability-bit fallback classic - tools/pqc-lab.sh two-node E2E lab + tools/zt-dissector.lua capture dissector - docs/pqc-test-scenario.md test plan - SPEC.md review pass: V12 evidence -> live daemon check, V14/V15 cite realign, T24/T25 tasks (pqconly preset gap documented)
This commit is contained in:
1 parent
1ead221c6a
commit
fa08792c78
13 files changed
+1058
-144
No files matched your search
+97
-32
@@ -11,18 +11,20 @@
|
||||
*/
|
||||
/****/
|
||||
|
||||
#include "Peer.hpp"
|
||||
|
||||
#include "../version.h"
|
||||
#include "Constants.hpp"
|
||||
#include "Peer.hpp"
|
||||
#include "Switch.hpp"
|
||||
#include "Network.hpp"
|
||||
#include "SelfAwareness.hpp"
|
||||
#include "Packet.hpp"
|
||||
#include "Trace.hpp"
|
||||
#include "InetAddress.hpp"
|
||||
#include "RingBuffer.hpp"
|
||||
#include "Utils.hpp"
|
||||
#include "Metrics.hpp"
|
||||
#include "Network.hpp"
|
||||
#include "PQHybrid.hpp"
|
||||
#include "Packet.hpp"
|
||||
#include "RingBuffer.hpp"
|
||||
#include "SelfAwareness.hpp"
|
||||
#include "Switch.hpp"
|
||||
#include "Trace.hpp"
|
||||
#include "Utils.hpp"
|
||||
|
||||
namespace ZeroTier {
|
||||
|
||||
@@ -70,6 +72,49 @@ Peer::Peer(const RuntimeEnvironment *renv,const Identity &myIdentity,const Ident
|
||||
KBKDFHMACSHA384(_key,ZT_KBKDF_LABEL_AES_GMAC_SIV_K1,0,0,ktmp);
|
||||
_aesKeys[1].init(ktmp);
|
||||
Utils::burn(ktmp,ZT_SYMMETRIC_KEY_SIZE);
|
||||
|
||||
// Keep the classical key for HELLO/OK(HELLO) armor for the life of the
|
||||
// peer; the session key may later be replaced by the hybrid one.
|
||||
memcpy(_keyClassical, _key, sizeof(_keyClassical));
|
||||
memcpy(_aesKeysClassical, _aesKeys, sizeof(_aesKeysClassical));
|
||||
_hybridCapable = false;
|
||||
_pendingHybridCtValid = 0;
|
||||
}
|
||||
|
||||
void Peer::_initAesKeys(const uint8_t* key, AES aesKeys[2])
|
||||
{
|
||||
uint8_t ktmp[ZT_SYMMETRIC_KEY_SIZE];
|
||||
KBKDFHMACSHA384(key, ZT_KBKDF_LABEL_AES_GMAC_SIV_K0, 0, 0, ktmp);
|
||||
aesKeys[0].init(ktmp);
|
||||
KBKDFHMACSHA384(key, ZT_KBKDF_LABEL_AES_GMAC_SIV_K1, 0, 0, ktmp);
|
||||
aesKeys[1].init(ktmp);
|
||||
Utils::burn(ktmp, ZT_SYMMETRIC_KEY_SIZE);
|
||||
}
|
||||
|
||||
void Peer::setHybridSessionKey(const void* key)
|
||||
{
|
||||
memcpy(_key, key, ZT_SYMMETRIC_KEY_SIZE);
|
||||
_initAesKeys(_key, _aesKeys);
|
||||
}
|
||||
|
||||
void Peer::setPendingHybridCt(const void* ct)
|
||||
{
|
||||
memcpy(_pendingHybridCt, ct, PQHybrid::MLKEM768_CT_LEN);
|
||||
_pendingHybridCtValid = 1;
|
||||
}
|
||||
|
||||
void Peer::ensurePendingHybridCt()
|
||||
{
|
||||
if ((_pendingHybridCtValid) || (! hybridEligible()) || (RR->identity.address() >= _id.address())) {
|
||||
return;
|
||||
}
|
||||
uint8_t ct[PQHybrid::MLKEM768_CT_LEN];
|
||||
uint8_t hkey[ZT_SYMMETRIC_KEY_SIZE];
|
||||
if (RR->identity.agreeHybridEncaps(_id, ct, hkey)) {
|
||||
setPendingHybridCt(ct);
|
||||
setHybridSessionKey(hkey);
|
||||
}
|
||||
Utils::burn(hkey, sizeof(hkey));
|
||||
}
|
||||
|
||||
void Peer::received(
|
||||
@@ -419,39 +464,59 @@ void Peer::sendHELLO(void *tPtr,const int64_t localSocket,const InetAddress &atA
|
||||
{
|
||||
Packet outp(_id.address(),RR->identity.address(),Packet::VERB_HELLO);
|
||||
|
||||
outp.append((unsigned char)ZT_PROTO_VERSION);
|
||||
outp.append((unsigned char)ZEROTIER_ONE_VERSION_MAJOR);
|
||||
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);
|
||||
atAddress.serialize(outp);
|
||||
try {
|
||||
outp.append((unsigned char)ZT_PROTO_VERSION);
|
||||
outp.append((unsigned char)ZEROTIER_ONE_VERSION_MAJOR);
|
||||
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);
|
||||
atAddress.serialize(outp);
|
||||
|
||||
outp.append((uint64_t)RR->topology->planetWorldId());
|
||||
outp.append((uint64_t)RR->topology->planetWorldTimestamp());
|
||||
outp.append((uint64_t)RR->topology->planetWorldId());
|
||||
outp.append((uint64_t)RR->topology->planetWorldTimestamp());
|
||||
|
||||
const unsigned int startCryptedPortionAt = outp.size();
|
||||
const unsigned int startCryptedPortionAt = outp.size();
|
||||
|
||||
std::vector<World> moons(RR->topology->moons());
|
||||
std::vector<uint64_t> moonsWanted(RR->topology->moonsWanted());
|
||||
outp.append((uint16_t)(moons.size() + moonsWanted.size()));
|
||||
for(std::vector<World>::const_iterator m(moons.begin());m!=moons.end();++m) {
|
||||
outp.append((uint8_t)m->type());
|
||||
outp.append((uint64_t)m->id());
|
||||
outp.append((uint64_t)m->timestamp());
|
||||
std::vector<World> moons(RR->topology->moons());
|
||||
std::vector<uint64_t> moonsWanted(RR->topology->moonsWanted());
|
||||
outp.append((uint16_t)(moons.size() + moonsWanted.size()));
|
||||
for (std::vector<World>::const_iterator m(moons.begin()); m != moons.end(); ++m) {
|
||||
outp.append((uint8_t)m->type());
|
||||
outp.append((uint64_t)m->id());
|
||||
outp.append((uint64_t)m->timestamp());
|
||||
}
|
||||
for (std::vector<uint64_t>::const_iterator m(moonsWanted.begin()); m != moonsWanted.end(); ++m) {
|
||||
outp.append((uint8_t)World::TYPE_MOON);
|
||||
outp.append(*m);
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
outp.cryptField(_keyClassical, startCryptedPortionAt, outp.size() - startCryptedPortionAt);
|
||||
}
|
||||
for(std::vector<uint64_t>::const_iterator m(moonsWanted.begin());m!=moonsWanted.end();++m) {
|
||||
outp.append((uint8_t)World::TYPE_MOON);
|
||||
outp.append(*m);
|
||||
outp.append((uint64_t)0);
|
||||
catch (int) {
|
||||
// G4 bound: Buffer<ZT_PROTO_MAX_PACKET_LENGTH> overflow would kill the
|
||||
// daemon via catch(int) in OneServiceImpl::run(); degrade to skipped HELLO.
|
||||
char addrBuf[11];
|
||||
fprintf(stderr, "WARNING: HELLO to %s exceeds ZT_PROTO_MAX_PACKET_LENGTH; not sent" ZT_EOL_S, _id.address().toString(addrBuf));
|
||||
return;
|
||||
}
|
||||
|
||||
outp.cryptField(_key,startCryptedPortionAt,outp.size() - startCryptedPortionAt);
|
||||
|
||||
Metrics::pkt_hello_out++;
|
||||
|
||||
if (atAddress) {
|
||||
outp.armor(_key,false,nullptr); // false == don't encrypt full payload, but add MAC
|
||||
outp.armor(_keyClassical, false, nullptr); // HELLO is always classical-armored
|
||||
RR->node->expectReplyTo(outp.packetId());
|
||||
RR->node->putPacket(tPtr,RR->node->lowBandwidthModeEnabled() ? localSocket : -1,atAddress,outp.data(),outp.size());
|
||||
} else {
|
||||
|
||||
Reference in new issue
Block a user