Zero Trust IoT library
Loading...
Searching...
No Matches
ns3::ZtTlsHandshake Class Reference

Simulates a Zero Trust-based TLS handshake mechanism between NS-3 nodes. More...

#include <zt-tls-handshake.h>

Inheritance diagram for ns3::ZtTlsHandshake:
Collaboration diagram for ns3::ZtTlsHandshake:

Public Member Functions

 ZtTlsHandshake ()
 Constructor.
 
void StartHandshake (Ptr< Node > client, Ptr< Node > server, uint32_t clientId, uint32_t serverId)
 Start a simulated TLS handshake between client and server nodes.
 
bool HasSession (uint32_t peerId) const
 Check if a session exists for a given peer.
 
std::string GetSessionKey (uint32_t peerId) const
 Retrieve the session key for a peer in hexadecimal string format.
 
void SetExternalLogger (std::function< void(std::string)> logger)
 Set an external logger for emitting TLS logs.
 
void SetPolicyValidator (std::function< bool(uint32_t, std::string)> validator)
 Set a policy validator for enforcing Zero Trust identity checks.
 

Static Public Member Functions

static TypeId GetTypeId ()
 Get the NS-3 TypeId.
 

Private Member Functions

void Log (const std::string &msg) const
 Emit a log message using the external logger or NS_LOG fallback.
 

Private Attributes

std::map< uint32_t, std::string > m_sessionKeys
 Maps node IDs to session keys.
 
std::function< void(std::string)> m_logger
 Optional external logger.
 
std::function< bool(uint32_t, std::string)> m_policyValidator
 Optional external policy validator.
 

Detailed Description

Simulates a Zero Trust-based TLS handshake mechanism between NS-3 nodes.

This class is responsible for performing identity-validated TLS-like handshakes between IoT nodes, establishing symmetric session keys, and enforcing policy-based authentication using injected policy validation logic.

Definition at line 23 of file zt-tls-handshake.h.

Constructor & Destructor Documentation

◆ ZtTlsHandshake()

ns3::ZtTlsHandshake::ZtTlsHandshake ( )

Constructor.

Definition at line 30 of file zt-tls-handshake.cc.

30 {
31 NS_LOG_FUNCTION(this);
32}

Member Function Documentation

◆ GetSessionKey()

std::string ns3::ZtTlsHandshake::GetSessionKey ( uint32_t  peerId) const

Retrieve the session key for a peer in hexadecimal string format.

Retrieve session key for a given peer.

Parameters
peerIdNode ID of the peer.
Returns
Hex-encoded session key if it exists, empty string otherwise.
Parameters
peerIdNode ID of the peer
Returns
Hex-encoded session key, or empty string if not found

Definition at line 86 of file zt-tls-handshake.cc.

86 {
87 auto it = m_sessionKeys.find(peerId);
88 return (it != m_sessionKeys.end()) ? it->second : "";
89}
std::map< uint32_t, std::string > m_sessionKeys
Maps node IDs to session keys.

◆ GetTypeId()

TypeId ns3::ZtTlsHandshake::GetTypeId ( )
static

Get the NS-3 TypeId.

Get the ns-3 TypeId for ZtTlsHandshake.

Returns
TypeId of the ZtTlsHandshake class.
The TypeId

Definition at line 19 of file zt-tls-handshake.cc.

19 {
20 static TypeId tid = TypeId("ns3::ZtTlsHandshake")
21 .SetParent<Object>()
22 .SetGroupName("ZeroTrust")
23 .AddConstructor<ZtTlsHandshake>();
24 return tid;
25}
ZtTlsHandshake()
Constructor.

◆ HasSession()

bool ns3::ZtTlsHandshake::HasSession ( uint32_t  peerId) const

Check if a session exists for a given peer.

Check if a session key exists for a peer.

Parameters
peerIdNode ID of the peer.
Returns
true if a session exists, false otherwise.
Parameters
peerIdNode ID of the peer
Returns
True if session exists, otherwise false

Definition at line 76 of file zt-tls-handshake.cc.

76 {
77 return m_sessionKeys.find(peerId) != m_sessionKeys.end();
78}

◆ Log()

void ns3::ZtTlsHandshake::Log ( const std::string &  msg) const
private

Emit a log message using the external logger or NS_LOG fallback.

Internal logging wrapper.

Parameters
msgThe message to log.
msgLog message

Definition at line 114 of file zt-tls-handshake.cc.

114 {
115 if (m_logger) {
116 m_logger(msg);
117 } else {
118 NS_LOG_INFO(msg);
119 }
120}
std::function< void(std::string)> m_logger
Optional external logger.
Here is the caller graph for this function:

◆ SetExternalLogger()

void ns3::ZtTlsHandshake::SetExternalLogger ( std::function< void(std::string)>  logger)

Set an external logger for emitting TLS logs.

Set external logging function.

Parameters
loggerFunction accepting a string message.
loggerFunction to be used for logging

Definition at line 96 of file zt-tls-handshake.cc.

96 {
97 m_logger = logger;
98}

◆ SetPolicyValidator()

void ns3::ZtTlsHandshake::SetPolicyValidator ( std::function< bool(uint32_t, std::string)>  validator)

Set a policy validator for enforcing Zero Trust identity checks.

Set policy validation function for authorization.

Parameters
validatorFunction taking node ID and role string, returns true if authorized.
validatorFunction that validates (nodeId, role)

Definition at line 105 of file zt-tls-handshake.cc.

105 {
106 m_policyValidator = validator;
107}
std::function< bool(uint32_t, std::string)> m_policyValidator
Optional external policy validator.

◆ StartHandshake()

void ns3::ZtTlsHandshake::StartHandshake ( Ptr< Node >  client,
Ptr< Node >  server,
uint32_t  clientId,
uint32_t  serverId 
)

Start a simulated TLS handshake between client and server nodes.

Start a simulated handshake between client and server.

Performs mutual policy validation and generates a symmetric session key shared by both nodes.

Parameters
clientPointer to the client node.
serverPointer to the server node.
clientIdUnique identifier for the client node.
serverIdUnique identifier for the server node.
clientPointer to the client Node
serverPointer to the server Node
clientIdID of the client node
serverIdID of the server node

Definition at line 42 of file zt-tls-handshake.cc.

42 {
43 NS_LOG_FUNCTION(this << client << server);
44
45 if (m_policyValidator && !m_policyValidator(clientId, "client")) {
46 Log("[ZT-HANDSHAKE] Client not authorized by policy");
47 return;
48 }
49
50 if (m_policyValidator && !m_policyValidator(serverId, "server")) {
51 Log("[ZT-HANDSHAKE] Server not authorized by policy");
52 return;
53 }
54
55 CryptoPP::AutoSeededRandomPool prng;
56 CryptoPP::byte key[CryptoPP::AES::DEFAULT_KEYLENGTH];
57 prng.GenerateBlock(key, sizeof(key));
58
59 std::string encoded;
60 CryptoPP::StringSource ss(key, sizeof(key), true,
61 new CryptoPP::HexEncoder(new CryptoPP::StringSink(encoded)));
62
63 m_sessionKeys[serverId] = encoded;
64 m_sessionKeys[clientId] = encoded;
65
66 Log("[ZT-HANDSHAKE] Session established between Client " + std::to_string(clientId) +
67 " and Server " + std::to_string(serverId) + " | Key: " + encoded);
68}
void Log(const std::string &msg) const
Emit a log message using the external logger or NS_LOG fallback.
Here is the call graph for this function:

Field Documentation

◆ m_logger

std::function<void(std::string)> ns3::ZtTlsHandshake::m_logger
private

Optional external logger.

Definition at line 83 of file zt-tls-handshake.h.

◆ m_policyValidator

std::function<bool(uint32_t, std::string)> ns3::ZtTlsHandshake::m_policyValidator
private

Optional external policy validator.

Definition at line 84 of file zt-tls-handshake.h.

◆ m_sessionKeys

std::map<uint32_t, std::string> ns3::ZtTlsHandshake::m_sessionKeys
private

Maps node IDs to session keys.

Definition at line 82 of file zt-tls-handshake.h.


The documentation for this class was generated from the following files: