Yarilo v0.9.9
WPA2 Decrypter & Packet Analyzer
Loading...
Searching...
No Matches
service.h
Go to the documentation of this file.
1#ifndef SNIFF_SERVICE
2#define SNIFF_SERVICE
3
4#include "decrypter.h"
5#include "proto/service.grpc.pb.h"
6#include "proto/service.pb.h"
7#include "sniffer.h"
8#include "uuid.h"
9#include <filesystem>
10#include <grpcpp/server_context.h>
11#include <grpcpp/support/sync_stream.h>
12#include <optional>
13#include <tins/sniffer.h>
14#include <unordered_map>
15
16#include "database.h"
17
18namespace yarilo {
19
23class Service : public proto::Sniffer::Service {
24public:
28 struct config {
30 std::filesystem::path saves_path;
31 std::filesystem::path db_file;
32 std::filesystem::path oid_file;
33 std::filesystem::path battery_file_path;
34 std::vector<MACAddress> ignored_bssids;
35 };
36
37 Service(const config &cfg);
38
39 std::optional<uuid::UUIDv4>
40 add_file_sniffer(const std::filesystem::path &file);
41 std::optional<uuid::UUIDv4> add_iface_sniffer(const std::string &iface_name);
42 void shutdown();
43 void clean_save_dir();
44
45 grpc::Status SnifferCreate(grpc::ServerContext *context,
46 const proto::SnifferCreateRequest *request,
47 proto::SnifferID *reply) override;
48
49 grpc::Status SnifferDestroy(grpc::ServerContext *context,
50 const proto::SnifferID *request,
51 proto::Empty *reply) override;
52
53 grpc::Status SnifferList(grpc::ServerContext *context,
54 const proto::Empty *request,
55 proto::SnifferListResponse *reply) override;
56
57 grpc::Status AccessPointList(grpc::ServerContext *context,
58 const proto::SnifferID *request,
59 proto::APListResponse *reply) override;
60
61 grpc::Status AccessPointGet(grpc::ServerContext *context,
62 const proto::APGetRequest *request,
63 proto::APGetResponse *reply) override;
64
65 grpc::Status
66 AccessPointProvidePassword(grpc::ServerContext *context,
67 const proto::APProvidePasswordRequest *request,
68 proto::APProvidePasswordResponse *reply) override;
69
71 grpc::ServerContext *context,
72 const proto::APGetDeryptedStreamRequest *request,
73 grpc::ServerWriter<proto::Packet> *writer) override;
74
75 grpc::Status AccessPointDeauth(grpc::ServerContext *context,
76 const proto::APDeauthRequest *request,
77 proto::Empty *reply) override;
78
79 grpc::Status
80 AccessPointDeauthClient(grpc::ServerContext *context,
81 const proto::APDeauthClientRequest *request,
82 proto::Empty *reply) override;
83
84 grpc::Status AccessPointGetHash(grpc::ServerContext *context,
85 const proto::APGetHashRequest *request,
86 proto::APGetHashResponse *reply) override;
87
88 grpc::Status AccessPointIgnore(grpc::ServerContext *context,
89 const proto::APIgnoreRequest *request,
90 proto::Empty *reply) override;
91
92 grpc::Status AccessPointListIgnored(grpc::ServerContext *context,
93 const proto::SnifferID *request,
94 proto::APListResponse *reply) override;
95
96 grpc::Status
97 AccessPointCreateRecording(grpc::ServerContext *context,
98 const proto::APCreateRecordingRequest *request,
99 proto::APCreateRecordingResponse *reply) override;
100
101 grpc::Status FocusStart(grpc::ServerContext *context,
102 const proto::FocusStartRequest *request,
103 proto::FocusStartResponse *reply) override;
104
105 grpc::Status FocusGetActive(grpc::ServerContext *context,
106 const proto::SnifferID *request,
107 proto::FocusGetActiveResponse *reply) override;
108
109 grpc::Status FocusStop(grpc::ServerContext *context,
110 const proto::SnifferID *request,
111 proto::Empty *reply) override;
112
113 grpc::Status RecordingCreate(grpc::ServerContext *context,
114 const proto::RecordingCreateRequest *request,
115 proto::RecordingCreateResponse *reply) override;
116
117 grpc::Status RecordingList(grpc::ServerContext *context,
118 const proto::RecordingListRequest *request,
119 proto::RecordingListResponse *reply) override;
120
121 grpc::Status
122 RecordingLoadDecrypted(grpc::ServerContext *context,
123 const proto::RecordingLoadDecryptedRequest *request,
124 grpc::ServerWriter<proto::Packet> *writer) override;
125
126 grpc::Status
127 NetworkInterfaceList(grpc::ServerContext *context,
128 const proto::Empty *request,
129 proto::NetworkInterfaceListResponse *reply) override;
130
131 grpc::Status
132 LogGetStream(grpc::ServerContext *context, const proto::Empty *request,
133 grpc::ServerWriter<proto::LogEntry> *writer) override;
134
135 grpc::Status BatteryGetLevel(grpc::ServerContext *context,
136 const proto::Empty *request,
137 proto::BatteryGetLevelResponse *reply) override;
138
139private:
147 std::optional<std::unique_ptr<PacketChannel>>
148 get_recording_stream(const uuid::UUIDv4 &uuid);
149
150 std::unordered_map<uuid::UUIDv4, std::unique_ptr<Sniffer>> sniffers;
151 std::unordered_map<uuid::UUIDv4, std::unique_ptr<Sniffer>>
152 erased_sniffers; // Kept for shutdown logic
153 std::shared_ptr<spdlog::logger> logger;
154 const config cfg;
155 Database db;
156};
157
158} // namespace yarilo
159
160#endif // SNIFF_SERVICE
Definition database.h:14
Service delivering an external gRPC API.
Definition service.h:23
grpc::Status SnifferCreate(grpc::ServerContext *context, const proto::SnifferCreateRequest *request, proto::SnifferID *reply) override
Definition service.cpp:173
grpc::Status SnifferList(grpc::ServerContext *context, const proto::Empty *request, proto::SnifferListResponse *reply) override
Definition service.cpp:225
grpc::Status RecordingList(grpc::ServerContext *context, const proto::RecordingListRequest *request, proto::RecordingListResponse *reply) override
Definition service.cpp:701
grpc::Status AccessPointListIgnored(grpc::ServerContext *context, const proto::SnifferID *request, proto::APListResponse *reply) override
Definition service.cpp:581
void shutdown()
Definition service.cpp:118
grpc::Status FocusStop(grpc::ServerContext *context, const proto::SnifferID *request, proto::Empty *reply) override
Definition service.cpp:664
grpc::Status AccessPointDeauth(grpc::ServerContext *context, const proto::APDeauthRequest *request, proto::Empty *reply) override
Definition service.cpp:452
std::optional< uuid::UUIDv4 > add_iface_sniffer(const std::string &iface_name)
Definition service.cpp:83
grpc::Status AccessPointGetHash(grpc::ServerContext *context, const proto::APGetHashRequest *request, proto::APGetHashResponse *reply) override
Definition service.cpp:515
grpc::Status AccessPointGet(grpc::ServerContext *context, const proto::APGetRequest *request, proto::APGetResponse *reply) override
Definition service.cpp:261
grpc::Status RecordingLoadDecrypted(grpc::ServerContext *context, const proto::RecordingLoadDecryptedRequest *request, grpc::ServerWriter< proto::Packet > *writer) override
Definition service.cpp:728
grpc::Status BatteryGetLevel(grpc::ServerContext *context, const proto::Empty *request, proto::BatteryGetLevelResponse *reply) override
Definition service.cpp:784
grpc::Status FocusStart(grpc::ServerContext *context, const proto::FocusStartRequest *request, proto::FocusStartResponse *reply) override
Definition service.cpp:625
grpc::Status FocusGetActive(grpc::ServerContext *context, const proto::SnifferID *request, proto::FocusGetActiveResponse *reply) override
Definition service.cpp:646
std::optional< uuid::UUIDv4 > add_file_sniffer(const std::filesystem::path &file)
Definition service.cpp:64
grpc::Status SnifferDestroy(grpc::ServerContext *context, const proto::SnifferID *request, proto::Empty *reply) override
Definition service.cpp:213
grpc::Status AccessPointGetDeryptedStream(grpc::ServerContext *context, const proto::APGetDeryptedStreamRequest *request, grpc::ServerWriter< proto::Packet > *writer) override
Definition service.cpp:408
grpc::Status AccessPointProvidePassword(grpc::ServerContext *context, const proto::APProvidePasswordRequest *request, proto::APProvidePasswordResponse *reply) override
Definition service.cpp:368
grpc::Status AccessPointDeauthClient(grpc::ServerContext *context, const proto::APDeauthClientRequest *request, proto::Empty *reply) override
Definition service.cpp:484
grpc::Status NetworkInterfaceList(grpc::ServerContext *context, const proto::Empty *request, proto::NetworkInterfaceListResponse *reply) override
Definition service.cpp:760
grpc::Status LogGetStream(grpc::ServerContext *context, const proto::Empty *request, grpc::ServerWriter< proto::LogEntry > *writer) override
Definition service.cpp:769
void clean_save_dir()
Definition service.cpp:132
grpc::Status AccessPointIgnore(grpc::ServerContext *context, const proto::APIgnoreRequest *request, proto::Empty *reply) override
Definition service.cpp:551
grpc::Status AccessPointList(grpc::ServerContext *context, const proto::SnifferID *request, proto::APListResponse *reply) override
Definition service.cpp:245
Service(const config &cfg)
Definition service.cpp:42
grpc::Status RecordingCreate(grpc::ServerContext *context, const proto::RecordingCreateRequest *request, proto::RecordingCreateResponse *reply) override
Definition service.cpp:682
grpc::Status AccessPointCreateRecording(grpc::ServerContext *context, const proto::APCreateRecordingRequest *request, proto::APCreateRecordingResponse *reply) override
Definition service.cpp:597
std::string UUIDv4
Definition uuid.h:11
Definition access_point.cpp:22
Configuration of the service.
Definition service.h:28
std::filesystem::path oid_file
Definition service.h:32
std::filesystem::path db_file
Definition service.h:31
bool save_on_shutdown
Definition service.h:29
std::vector< MACAddress > ignored_bssids
Definition service.h:34
std::filesystem::path battery_file_path
Definition service.h:33
std::filesystem::path saves_path
Definition service.h:30