Zero Trust IoT library
Loading...
Searching...
No Matches
zt-logger.cc
Go to the documentation of this file.
1#include "zt-logger.h"
2#include <ns3/core-module.h>
3#include <sstream>
4#include <iomanip>
5#include <ctime>
6
7using namespace ns3;
8
11
16void ZtLogger::EnableTimestamps(bool enable) {
17 timestampsEnabled = enable;
18}
19
25void ZtLogger::Log(const std::string &tag, const std::string &message) {
26 std::ostringstream output;
27
29 std::time_t now = std::time(nullptr);
30 std::tm *lt = std::localtime(&now);
31 output << "[" << std::put_time(lt, "%H:%M:%S") << "] ";
32 }
33
34 output << "[" << tag << "] " << message;
35 NS_LOG_UNCOND(output.str());
36}
37
38// === Certificate Logs ===
39
46void ZtLogger::LogCertIssued(uint32_t nodeId, const std::string &role, time_t expiry) {
47 std::ostringstream msg;
48 msg << "Issued certificate to Node " << nodeId << " | Role: " << role
49 << " | Expiry: " << expiry;
50 Log("ZT-CERT", msg.str());
51}
52
58void ZtLogger::LogCertValidationResult(uint32_t nodeId, bool valid) {
59 Log("ZT-CERT", "Validation for Node " + std::to_string(nodeId) +
60 (valid ? ": VALID" : ": INVALID"));
61}
62
67void ZtLogger::LogCertRevoked(uint32_t nodeId) {
68 Log("ZT-CERT", "Node " + std::to_string(nodeId) + " certificate revoked");
69}
70
75void ZtLogger::LogCertRejected(const std::string &reason) {
76 Log("ZT-CERT", "Certificate rejected: " + reason);
77}
78
79// === Encryption Logs ===
80
86void ZtLogger::LogEncryption(const std::string &payload, const std::string &ivHex) {
87 Log("ZT-ENC", "Payload encrypted | IV: " + ivHex + " | Data: " + payload);
88}
89
94void ZtLogger::LogDecryption(const std::string &payload) {
95 Log("ZT-DEC", "Decrypted Payload: " + payload);
96}
97
102 Log("ZT-DEC", "Decryption failed: Invalid session or corrupt data");
103}
104
static void LogCertRejected(const std::string &reason)
Logs a rejected certificate attempt with a reason.
Definition zt-logger.cc:75
static void LogCertIssued(uint32_t nodeId, const std::string &role, time_t expiry)
Logs a certificate issuance event.
Definition zt-logger.cc:46
static void LogCertRevoked(uint32_t nodeId)
Logs a certificate revocation event.
Definition zt-logger.cc:67
static void LogDecryption(const std::string &payload)
Logs a successful decryption event.
Definition zt-logger.cc:94
static void LogCertValidationResult(uint32_t nodeId, bool valid)
Logs the result of certificate validation.
Definition zt-logger.cc:58
static void LogDecryptionFailure()
Logs a decryption failure event.
Definition zt-logger.cc:101
static void EnableTimestamps(bool enable)
Enables or disables timestamp logging.
Definition zt-logger.cc:16
static void Log(const std::string &tag, const std::string &message)
Logs a general message with a specified tag.
Definition zt-logger.cc:25
static void LogEncryption(const std::string &payload, const std::string &ivHex)
Logs an encryption event with payload and IV.
Definition zt-logger.cc:86
static bool timestampsEnabled
Flag to indicate if timestamps are enabled in logs.
Definition zt-logger.h:76