restructuring
This commit is contained in:
parent
4d020014c0
commit
a0ce50b7cd
11 changed files with 158 additions and 46 deletions
|
|
@ -1,4 +1,4 @@
|
|||
add_library(mitmproxy_plugin MODULE mitmproxy_network.cpp mitmproxy_network.h)
|
||||
target_include_directories(mitmproxy_plugin PRIVATE ../../include/)
|
||||
target_link_libraries(mitmproxy_plugin PRIVATE Qt5::Core)
|
||||
target_link_libraries(mitmproxy_plugin PRIVATE Qt5::Core cppzmq)
|
||||
set_target_properties(mitmproxy_plugin PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${PLUGIN_DIR})
|
||||
|
|
|
|||
|
|
@ -1 +1,86 @@
|
|||
#include <mitmproxy_network.h>
|
||||
|
||||
void mitmproxyPlugin::connect()
|
||||
{
|
||||
socket = new zmq::socket_t(context, zmq::socket_type::pair);
|
||||
int linger_time = 0;
|
||||
socket->set(zmq::sockopt::linger, linger_time);
|
||||
try {
|
||||
socket->bind(this->path);
|
||||
} catch (zmq::error_t err) {
|
||||
qDebug() << "failed binding socket" << err.what();
|
||||
emit error(err.what());
|
||||
throw;
|
||||
};
|
||||
is_connected = true;
|
||||
qDebug() << "connected";
|
||||
}
|
||||
|
||||
void mitmproxyPlugin::reconnect()
|
||||
{
|
||||
this->disconnect();
|
||||
this->connect();
|
||||
}
|
||||
|
||||
void mitmproxyPlugin::process(std::string path)
|
||||
{
|
||||
this->path = path;
|
||||
connect();
|
||||
while(true) {
|
||||
zmq::message_t response;
|
||||
const auto ret = socket->recv(response, zmq::recv_flags::dontwait);
|
||||
if(!ret) {
|
||||
continue;
|
||||
}
|
||||
json j;
|
||||
try {
|
||||
j = json::parse(response.to_string());
|
||||
} catch (nlohmann::detail::parse_error& err) {
|
||||
qDebug() << err.what();
|
||||
qDebug() << "malformed json received " << response.to_string().c_str();
|
||||
}
|
||||
//std::cout << std::setw(4) << j << "\n\n";
|
||||
std::string msg_type;
|
||||
if(!json_get(j, msg_type, "msg")) {
|
||||
qDebug() << "broken message received " << response.to_string().c_str();
|
||||
} else if(msg_type == "responseheaders") {
|
||||
qDebug() << "received " << msg_type.c_str();
|
||||
} else if(msg_type == "response") {
|
||||
qDebug() << "received " << msg_type.c_str();
|
||||
//emit httpMessage(j);
|
||||
} else if(msg_type == "requestheaders") {
|
||||
qDebug() << "received " << msg_type.c_str();
|
||||
} else if(msg_type == "request") {
|
||||
qDebug() << "received " << msg_type.c_str();
|
||||
} else if(msg_type == "ping") {
|
||||
qDebug() << "received " << msg_type.c_str();
|
||||
} else if(msg_type == "error") {
|
||||
qDebug() << "received " << msg_type.c_str();
|
||||
|
||||
// websocket events
|
||||
} else if(msg_type == "websocket_handshake") {
|
||||
qDebug() << "received " << msg_type.c_str();
|
||||
} else if(msg_type == "websocket_start") {
|
||||
qDebug() << "received " << msg_type.c_str();
|
||||
std::cout << std::setw(4) << j << "\n\n";
|
||||
} else if(msg_type == "websocket_message") {
|
||||
qDebug() << "received " << msg_type.c_str();
|
||||
} else if(msg_type == "websocket_end") {
|
||||
qDebug() << "received " << msg_type.c_str();
|
||||
} else if(msg_type == "websocket_error") {
|
||||
} else {
|
||||
qDebug() << "unknown or broken message type received: " << msg_type.c_str();
|
||||
}
|
||||
|
||||
qDebug() << "sending ack";
|
||||
std::string m = "{\"msg\": \"ack\"}";
|
||||
socket->send(zmq::buffer(m.c_str(), m.length()), zmq::send_flags::dontwait);
|
||||
}
|
||||
}
|
||||
|
||||
void mitmproxyPlugin::disconnect()
|
||||
{
|
||||
delete socket;
|
||||
is_connected = false;
|
||||
qDebug() << "disconnected";
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,12 +4,34 @@
|
|||
#include "proxyinterface.h"
|
||||
#include <QObject>
|
||||
|
||||
class mitmproxyPlugin : public QObject,
|
||||
public http::ProxyInterface
|
||||
#include <set>
|
||||
#include <zmq.hpp>
|
||||
|
||||
class mitmproxyPlugin : public http::ProxyInterface
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PLUGIN_METADATA(IID "bigsnitch.api.HTTPProxyInterface/100" FILE "mitmproxy.json")
|
||||
Q_INTERFACES(http::ProxyInterface)
|
||||
private:
|
||||
std::set<std::string> received;
|
||||
zmq::context_t context;
|
||||
zmq::socket_t *socket;
|
||||
std::set<std::string> accepted_flows;
|
||||
std::string path;
|
||||
bool is_connected = false;
|
||||
void connect();
|
||||
void reconnect();
|
||||
public:
|
||||
//! called in a custom thread, may block.
|
||||
void process(std::string path) override;
|
||||
//! returns, whether the proxy is currently connected
|
||||
bool connected() override;
|
||||
//! disconnects the handle
|
||||
void disconnect() override;
|
||||
// options/settings
|
||||
signals:
|
||||
//void finished();
|
||||
//void error(QString err);
|
||||
//void message(http::Flow flow);
|
||||
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue