5#include <cryptopp/aes.h>
6#include <cryptopp/filters.h>
7#include <cryptopp/hex.h>
8#include <cryptopp/modes.h>
9#include <cryptopp/osrng.h>
20 static TypeId tid = TypeId(
"ns3::ZtTlsHandshake")
22 .SetGroupName(
"ZeroTrust")
31 NS_LOG_FUNCTION(
this);
43 NS_LOG_FUNCTION(
this << client << server);
46 Log(
"[ZT-HANDSHAKE] Client not authorized by policy");
51 Log(
"[ZT-HANDSHAKE] Server not authorized by policy");
55 CryptoPP::AutoSeededRandomPool prng;
56 CryptoPP::byte key[CryptoPP::AES::DEFAULT_KEYLENGTH];
57 prng.GenerateBlock(key,
sizeof(key));
60 CryptoPP::StringSource ss(key,
sizeof(key),
true,
61 new CryptoPP::HexEncoder(
new CryptoPP::StringSink(encoded)));
66 Log(
"[ZT-HANDSHAKE] Session established between Client " + std::to_string(clientId) +
67 " and Server " + std::to_string(serverId) +
" | Key: " + encoded);
Simulates a Zero Trust-based TLS handshake mechanism between NS-3 nodes.
void StartHandshake(Ptr< Node > client, Ptr< Node > server, uint32_t clientId, uint32_t serverId)
Start a simulated TLS handshake between client and server nodes.
void SetExternalLogger(std::function< void(std::string)> logger)
Set an external logger for emitting TLS logs.
ZtTlsHandshake()
Constructor.
std::function< void(std::string)> m_logger
Optional external logger.
static TypeId GetTypeId()
Get the NS-3 TypeId.
std::string GetSessionKey(uint32_t peerId) const
Retrieve the session key for a peer in hexadecimal string format.
std::map< uint32_t, std::string > m_sessionKeys
Maps node IDs to session keys.
std::function< bool(uint32_t, std::string)> m_policyValidator
Optional external policy validator.
bool HasSession(uint32_t peerId) const
Check if a session exists for a given peer.
void Log(const std::string &msg) const
Emit a log message using the external logger or NS_LOG fallback.
void SetPolicyValidator(std::function< bool(uint32_t, std::string)> validator)
Set a policy validator for enforcing Zero Trust identity checks.
NS_LOG_COMPONENT_DEFINE("ZtPolicyEngine")