diff options
-rw-r--r-- | receiver.cpp | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/receiver.cpp b/receiver.cpp index fdeee05..9e622d9 100644 --- a/receiver.cpp +++ b/receiver.cpp | |||
@@ -16,6 +16,7 @@ | |||
16 | 16 | ||
17 | #include <string> | 17 | #include <string> |
18 | #include <map> | 18 | #include <map> |
19 | #include <set> | ||
19 | #include <iostream> | 20 | #include <iostream> |
20 | 21 | ||
21 | const unsigned short PORT = 58132; | 22 | const unsigned short PORT = 58132; |
@@ -176,6 +177,7 @@ private: | |||
176 | }; | 177 | }; |
177 | 178 | ||
178 | std::map<uint64_t, std::unique_ptr<Session>> g_sessions; | 179 | std::map<uint64_t, std::unique_ptr<Session>> g_sessions; |
180 | std::set<std::string> g_used_ivs; | ||
179 | 181 | ||
180 | static uint8_t hex2nyble(char c) | 182 | static uint8_t hex2nyble(char c) |
181 | { | 183 | { |
@@ -283,12 +285,19 @@ int main() { | |||
283 | if (session == g_sessions.end()) | 285 | if (session == g_sessions.end()) |
284 | g_sessions[session_id] = std::make_unique<Session>(session_id, rsa_plain_text); | 286 | g_sessions[session_id] = std::make_unique<Session>(session_id, rsa_plain_text); |
285 | break; | 287 | break; |
286 | case 1: | 288 | case 1: { |
289 | std::string sessid_iv(packet + 1, packet + 1 + SESSION_ID_LENGTH + GCM_IV_LENGTH); | ||
290 | if (g_used_ivs.find(sessid_iv) != g_used_ivs.end()) { | ||
291 | std::cerr << "Error: Session " << std::hex << session_id << " reused IV. Dropping packet" << std::endl; | ||
292 | break; | ||
293 | } | ||
294 | g_used_ivs.insert(sessid_iv); | ||
287 | if (session != g_sessions.end()) | 295 | if (session != g_sessions.end()) |
288 | session->second->write_log(packet + 1 + SESSION_ID_LENGTH, len - 1 - SESSION_ID_LENGTH); | 296 | session->second->write_log(packet + 1 + SESSION_ID_LENGTH, len - 1 - SESSION_ID_LENGTH); |
289 | else | 297 | else |
290 | std::cerr << "Error: Can't log to unknown session " << std::hex << session_id << std::endl; | 298 | std::cerr << "Error: Can't log to unknown session " << std::hex << session_id << std::endl; |
291 | break; | 299 | break; |
300 | } | ||
292 | default: | 301 | default: |
293 | break; | 302 | break; |
294 | } | 303 | } |