Yarilo v0.9.9
WPA2 Decrypter & Packet Analyzer
Loading...
Searching...
No Matches
database.h
Go to the documentation of this file.
1#ifndef DATABASE_H
2#define DATABASE_H
3
4#include <spdlog/logger.h>
5#include <sqlite3.h>
6#include <string>
7#include <vector>
8
9#include "proto/service.pb.h"
10#include "uuid.h"
11
12namespace yarilo {
13
14class Database {
15public:
16 explicit Database(const std::string &db_path);
17 ~Database();
18
19 bool initialize();
20 bool execute_query(const std::string &query);
21 std::vector<std::vector<std::string>> select_query(const std::string &query);
22 bool check_vendors(bool seeding = false);
23 bool insert_recording(const uuid::UUIDv4 &uuid,
24 const std::string &display_name,
25 const std::string &file_path, int64_t start,
26 int64_t end, proto::DataLinkType data_link);
27 std::vector<std::vector<std::string>> get_recordings();
28 std::vector<std::string> get_recording(const uuid::UUIDv4 &uuid);
29 bool delete_recording(const uuid::UUIDv4 &uuid) const;
30 bool recording_exists(const uuid::UUIDv4 &uuid);
31 bool recording_exists_path(const std::string &file_path);
32 bool load_vendors(const std::string &OID_path);
33 bool insert_vendors(
34 const std::vector<std::pair<std::string, std::string>> &vendors);
35 std::vector<std::vector<std::string>> get_vendors();
36 std::string get_vendor_name(const std::string &oid);
37 bool vendor_exists(const std::string &oid);
38 bool insert_network(const std::string &ssid, const std::string &bssid,
39 const std::string &psk, uint32_t total_packet_count,
40 uint32_t decrypted_packet_count,
41 uint32_t group_packet_count, const std::string &security,
42 std::string recording_id, uint32_t group_rekeys,
43 const std::string &vendor_oid);
44 bool insert_group_window(const std::string &network_id, uint64_t start,
45 uint64_t end, uint32_t packet_count);
46 std::vector<std::vector<std::string>> get_group_windows();
47 bool insert_client(const std::string &address, uint32_t packet_count,
48 uint32_t decrypted_packet_count,
49 const std::string &network_id);
50 std::vector<std::vector<std::string>> get_clients();
51 bool insert_client_window(const std::string &client_address,
52 const std::string &network_id, uint64_t start,
53 uint64_t end, uint32_t packet_count);
54 std::vector<std::vector<std::string>> get_client_windows();
55 bool refresh_database();
56
57private:
58 sqlite3 *db;
59 std::shared_ptr<spdlog::logger> logger;
60 std::string db_path;
61 const std::string schema = R"(
62CREATE TABLE IF NOT EXISTS Vendors (
63 oid TEXT PRIMARY KEY, -- MAC address prefix (first 3 bytes)
64 name TEXT
65);
66
67CREATE TABLE IF NOT EXISTS Recordings (
68 id TEXT PRIMARY KEY,
69 display_name TEXT,
70 file_path TEXT,
71 start INTEGER,
72 end INTEGER,
73 data_link INTEGER
74);
75
76CREATE TABLE IF NOT EXISTS Networks (
77 ssid TEXT,
78 bssid TEXT PRIMARY KEY,
79 psk TEXT,
80 total_packet_count INTEGER,
81 decrypted_packet_count INTEGER,
82 group_packet_count INTEGER,
83 security TEXT, -- Numbers separated by space (ex. "3 4")
84 recording_id TEXT,
85 group_rekeys INTEGER,
86 vendor_oid TEXT,
87 FOREIGN KEY (vendor_oid) REFERENCES Vendors(oid),
88 FOREIGN KEY (recording_id) REFERENCES Recordings(id) ON DELETE CASCADE
89);
90
91CREATE TABLE IF NOT EXISTS GroupDecryptionWindow (
92 network_bssid TEXT,
93 start INTEGER,
94 end INTEGER,
95 packet_count INTEGER,
96 FOREIGN KEY (network_bssid) REFERENCES Networks(bssid) ON DELETE CASCADE
97);
98
99CREATE TABLE IF NOT EXISTS Clients (
100 address TEXT PRIMARY KEY,
101 packet_count INTEGER,
102 decrypted_packet_count INTEGER,
103 network_bssid TEXT,
104 FOREIGN KEY (network_bssid) REFERENCES Networks(bssid) ON DELETE CASCADE
105);
106
107CREATE TABLE IF NOT EXISTS ClientDecryptionWindow (
108 client_address TEXT,
109 network_bssid TEXT,
110 start INTEGER,
111 end INTEGER,
112 packet_count INTEGER,
113 FOREIGN KEY (client_address) REFERENCES Clients(address) ON DELETE CASCADE,
114 FOREIGN KEY (network_bssid) REFERENCES Networks(bssid) ON DELETE CASCADE
115);
116)";
117};
118
119} // namespace yarilo
120
121#endif // DATABASE_H
Definition database.h:14
bool execute_query(const std::string &query)
Definition database.cpp:33
bool recording_exists(const uuid::UUIDv4 &uuid)
Definition database.cpp:117
bool initialize()
Definition database.cpp:16
std::vector< std::vector< std::string > > get_clients()
Definition database.cpp:420
std::vector< std::vector< std::string > > get_group_windows()
Definition database.cpp:386
Database(const std::string &db_path)
Definition database.cpp:7
bool insert_recording(const uuid::UUIDv4 &uuid, const std::string &display_name, const std::string &file_path, int64_t start, int64_t end, proto::DataLinkType data_link)
Definition database.cpp:90
bool vendor_exists(const std::string &oid)
Definition database.cpp:286
std::vector< std::vector< std::string > > get_recordings()
Definition database.cpp:103
bool delete_recording(const uuid::UUIDv4 &uuid) const
Definition database.cpp:155
bool insert_client(const std::string &address, uint32_t packet_count, uint32_t decrypted_packet_count, const std::string &network_id)
Definition database.cpp:391
bool refresh_database()
Definition database.cpp:462
std::vector< std::string > get_recording(const uuid::UUIDv4 &uuid)
Definition database.cpp:108
bool load_vendors(const std::string &OID_path)
Definition database.cpp:190
std::vector< std::vector< std::string > > get_vendors()
Definition database.cpp:272
bool insert_vendors(const std::vector< std::pair< std::string, std::string > > &vendors)
Definition database.cpp:227
bool insert_group_window(const std::string &network_id, uint64_t start, uint64_t end, uint32_t packet_count)
Definition database.cpp:355
std::vector< std::vector< std::string > > select_query(const std::string &query)
Definition database.cpp:45
~Database()
Definition database.cpp:11
bool insert_client_window(const std::string &client_address, const std::string &network_id, uint64_t start, uint64_t end, uint32_t packet_count)
Definition database.cpp:425
std::string get_vendor_name(const std::string &oid)
Definition database.cpp:277
bool check_vendors(bool seeding=false)
Definition database.cpp:69
std::vector< std::vector< std::string > > get_client_windows()
Definition database.cpp:457
bool insert_network(const std::string &ssid, const std::string &bssid, const std::string &psk, uint32_t total_packet_count, uint32_t decrypted_packet_count, uint32_t group_packet_count, const std::string &security, std::string recording_id, uint32_t group_rekeys, const std::string &vendor_oid)
Definition database.cpp:293
bool recording_exists_path(const std::string &file_path)
Definition database.cpp:136
std::string UUIDv4
Definition uuid.h:11
Definition access_point.cpp:22