-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmitm-hmac.h
49 lines (37 loc) · 1.41 KB
/
mitm-hmac.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#pragma once
#include "veins/modules/application/ieee80211p/DemoBaseApplLayer.h"
#include "veins/modules/application/traci/TraCIDemo11pMessage_m.h"
namespace veins {
class MITMAttackApp : public DemoBaseApplLayer {
public:
MITMAttackApp() : sendMessageEvt(nullptr),
isAttacker(false),
hasAttacked(false), hasReceivedWarning(false),
hasSentMessage(false), nodeId(-1), senderNode(-1) {}
virtual ~MITMAttackApp() {
cancelAndDelete(sendMessageEvt);
}
protected:
virtual void initialize(int stage) override;
virtual void handleSelfMsg(cMessage* msg) override;
virtual void onWSM(BaseFrame1609_4* wsm) override;
virtual void finish() override;
private:
// Function to send a normal message with HMAC
void sendNormalMessage();
// Helper functions for HMAC generation and verification
std::string generateHMAC(const std::string& message, const std::string& key);
bool verifyHMAC(const std::string& message, const std::string& receivedHMAC, const std::string& key);
// Simulation variables
cMessage* sendMessageEvt;
bool isAttacker;
bool hasAttacked;
bool hasReceivedWarning;
bool hasSentMessage;
int nodeId;
int senderNode;
double attackTime;
// Shared secret key (optional: move to a secure location)
const std::string sharedSecretKey = "shared_secret_key";
};
}