Some XRay improvements (#1075)
This commit is contained in:
parent
862e83ddf5
commit
a22a9448ca
16 changed files with 252 additions and 122 deletions
|
@ -61,6 +61,7 @@ qt_add_executable(${PROJECT} MANUAL_FINALIZATION)
|
||||||
if(WIN32 OR (APPLE AND NOT IOS) OR (LINUX AND NOT ANDROID))
|
if(WIN32 OR (APPLE AND NOT IOS) OR (LINUX AND NOT ANDROID))
|
||||||
qt_add_repc_replicas(${PROJECT} ${CMAKE_CURRENT_LIST_DIR}/../ipc/ipc_interface.rep)
|
qt_add_repc_replicas(${PROJECT} ${CMAKE_CURRENT_LIST_DIR}/../ipc/ipc_interface.rep)
|
||||||
qt_add_repc_replicas(${PROJECT} ${CMAKE_CURRENT_LIST_DIR}/../ipc/ipc_process_interface.rep)
|
qt_add_repc_replicas(${PROJECT} ${CMAKE_CURRENT_LIST_DIR}/../ipc/ipc_process_interface.rep)
|
||||||
|
qt_add_repc_replicas(${PROJECT} ${CMAKE_CURRENT_LIST_DIR}/../ipc/ipc_process_tun2socks.rep)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
qt6_add_resources(QRC ${QRC} ${CMAKE_CURRENT_LIST_DIR}/resources.qrc)
|
qt6_add_resources(QRC ${QRC} ${CMAKE_CURRENT_LIST_DIR}/resources.qrc)
|
||||||
|
|
|
@ -29,6 +29,12 @@ QSharedPointer<IpcInterfaceReplica> IpcClient::Interface()
|
||||||
return Instance()->m_ipcClient;
|
return Instance()->m_ipcClient;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QSharedPointer<IpcProcessTun2SocksReplica> IpcClient::InterfaceTun2Socks()
|
||||||
|
{
|
||||||
|
if (!Instance()) return nullptr;
|
||||||
|
return Instance()->m_Tun2SocksClient;
|
||||||
|
}
|
||||||
|
|
||||||
bool IpcClient::init(IpcClient *instance)
|
bool IpcClient::init(IpcClient *instance)
|
||||||
{
|
{
|
||||||
m_instance = instance;
|
m_instance = instance;
|
||||||
|
@ -44,6 +50,12 @@ bool IpcClient::init(IpcClient *instance)
|
||||||
qWarning() << "IpcClient replica is not connected!";
|
qWarning() << "IpcClient replica is not connected!";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Instance()->m_Tun2SocksClient.reset(Instance()->m_ClientNode.acquire<IpcProcessTun2SocksReplica>());
|
||||||
|
Instance()->m_Tun2SocksClient->waitForSource(1000);
|
||||||
|
|
||||||
|
if (!Instance()->m_Tun2SocksClient->isReplicaValid()) {
|
||||||
|
qWarning() << "IpcClient::m_Tun2SocksClient replica is not connected!";
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
connect(Instance()->m_localSocket, &QLocalSocket::disconnected, [instance](){
|
connect(Instance()->m_localSocket, &QLocalSocket::disconnected, [instance](){
|
||||||
|
@ -51,16 +63,16 @@ bool IpcClient::init(IpcClient *instance)
|
||||||
});
|
});
|
||||||
|
|
||||||
Instance()->m_localSocket->connectToServer(amnezia::getIpcServiceUrl());
|
Instance()->m_localSocket->connectToServer(amnezia::getIpcServiceUrl());
|
||||||
|
|
||||||
Instance()->m_localSocket->waitForConnected();
|
Instance()->m_localSocket->waitForConnected();
|
||||||
|
|
||||||
if (!Instance()->m_ipcClient) {
|
if (!Instance()->m_ipcClient) {
|
||||||
qDebug() << "IpcClient::init failed";
|
qDebug() << "IpcClient::init failed";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
qDebug() << "IpcClient::init succeed";
|
qDebug() << "IpcClient::init succeed";
|
||||||
|
|
||||||
return Instance()->m_ipcClient->isReplicaValid();
|
return (Instance()->m_ipcClient->isReplicaValid() && Instance()->m_Tun2SocksClient->isReplicaValid());
|
||||||
}
|
}
|
||||||
|
|
||||||
QSharedPointer<PrivilegedProcess> IpcClient::CreatePrivilegedProcess()
|
QSharedPointer<PrivilegedProcess> IpcClient::CreatePrivilegedProcess()
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
|
|
||||||
#include "ipc.h"
|
#include "ipc.h"
|
||||||
#include "rep_ipc_interface_replica.h"
|
#include "rep_ipc_interface_replica.h"
|
||||||
|
#include "rep_ipc_process_tun2socks_replica.h"
|
||||||
|
|
||||||
#include "privileged_process.h"
|
#include "privileged_process.h"
|
||||||
|
|
||||||
|
@ -18,6 +19,7 @@ public:
|
||||||
static IpcClient *Instance();
|
static IpcClient *Instance();
|
||||||
static bool init(IpcClient *instance);
|
static bool init(IpcClient *instance);
|
||||||
static QSharedPointer<IpcInterfaceReplica> Interface();
|
static QSharedPointer<IpcInterfaceReplica> Interface();
|
||||||
|
static QSharedPointer<IpcProcessTun2SocksReplica> InterfaceTun2Socks();
|
||||||
static QSharedPointer<PrivilegedProcess> CreatePrivilegedProcess();
|
static QSharedPointer<PrivilegedProcess> CreatePrivilegedProcess();
|
||||||
|
|
||||||
bool isSocketConnected() const;
|
bool isSocketConnected() const;
|
||||||
|
@ -28,8 +30,11 @@ private:
|
||||||
~IpcClient() override;
|
~IpcClient() override;
|
||||||
|
|
||||||
QRemoteObjectNode m_ClientNode;
|
QRemoteObjectNode m_ClientNode;
|
||||||
|
QRemoteObjectNode m_Tun2SocksNode;
|
||||||
QSharedPointer<IpcInterfaceReplica> m_ipcClient;
|
QSharedPointer<IpcInterfaceReplica> m_ipcClient;
|
||||||
QPointer<QLocalSocket> m_localSocket;
|
QPointer<QLocalSocket> m_localSocket;
|
||||||
|
QPointer<QLocalSocket> m_tun2socksSocket;
|
||||||
|
QSharedPointer<IpcProcessTun2SocksReplica> m_Tun2SocksClient;
|
||||||
|
|
||||||
struct ProcessDescriptor {
|
struct ProcessDescriptor {
|
||||||
ProcessDescriptor () {
|
ProcessDescriptor () {
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
#include <QTcpSocket>
|
#include <QTcpSocket>
|
||||||
#include <QNetworkInterface>
|
#include <QNetworkInterface>
|
||||||
|
|
||||||
|
#include "core/networkUtilities.h"
|
||||||
#include "logger.h"
|
#include "logger.h"
|
||||||
#include "openvpnprotocol.h"
|
#include "openvpnprotocol.h"
|
||||||
#include "utilities.h"
|
#include "utilities.h"
|
||||||
|
@ -127,7 +128,6 @@ void OpenVpnProtocol::sendManagementCommand(const QString &command)
|
||||||
|
|
||||||
uint OpenVpnProtocol::selectMgmtPort()
|
uint OpenVpnProtocol::selectMgmtPort()
|
||||||
{
|
{
|
||||||
|
|
||||||
for (int i = 0; i < 100; ++i) {
|
for (int i = 0; i < 100; ++i) {
|
||||||
quint32 port = QRandomGenerator::global()->generate();
|
quint32 port = QRandomGenerator::global()->generate();
|
||||||
port = (double)(65000 - 15001) * port / UINT32_MAX + 15001;
|
port = (double)(65000 - 15001) * port / UINT32_MAX + 15001;
|
||||||
|
@ -137,7 +137,6 @@ uint OpenVpnProtocol::selectMgmtPort()
|
||||||
if (ok)
|
if (ok)
|
||||||
return port;
|
return port;
|
||||||
}
|
}
|
||||||
|
|
||||||
return m_managementPort;
|
return m_managementPort;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -343,7 +342,8 @@ void OpenVpnProtocol::updateVpnGateway(const QString &line)
|
||||||
}
|
}
|
||||||
m_configData.insert("vpnAdapterIndex", netInterfaces.at(i).index());
|
m_configData.insert("vpnAdapterIndex", netInterfaces.at(i).index());
|
||||||
m_configData.insert("vpnGateway", m_vpnGateway);
|
m_configData.insert("vpnGateway", m_vpnGateway);
|
||||||
m_configData.insert("vpnServer", m_configData.value(amnezia::config_key::hostName).toString());
|
m_configData.insert("vpnServer",
|
||||||
|
NetworkUtilities::getIPAddress(m_configData.value(amnezia::config_key::hostName).toString()));
|
||||||
IpcClient::Interface()->enablePeerTraffic(m_configData);
|
IpcClient::Interface()->enablePeerTraffic(m_configData);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -352,6 +352,8 @@ void OpenVpnProtocol::updateVpnGateway(const QString &line)
|
||||||
#if defined(Q_OS_LINUX) || defined(Q_OS_MACOS)
|
#if defined(Q_OS_LINUX) || defined(Q_OS_MACOS)
|
||||||
// killSwitch toggle
|
// killSwitch toggle
|
||||||
if (QVariant(m_configData.value(config_key::killSwitchOption).toString()).toBool()) {
|
if (QVariant(m_configData.value(config_key::killSwitchOption).toString()).toBool()) {
|
||||||
|
m_configData.insert("vpnServer",
|
||||||
|
NetworkUtilities::getIPAddress(m_configData.value(amnezia::config_key::hostName).toString()));
|
||||||
IpcClient::Interface()->enableKillSwitch(m_configData, 0);
|
IpcClient::Interface()->enableKillSwitch(m_configData, 0);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -17,6 +17,7 @@ XrayProtocol::XrayProtocol(const QJsonObject &configuration, QObject *parent):
|
||||||
m_routeGateway = NetworkUtilities::getGatewayAndIface();
|
m_routeGateway = NetworkUtilities::getGatewayAndIface();
|
||||||
m_vpnGateway = amnezia::protocols::xray::defaultLocalAddr;
|
m_vpnGateway = amnezia::protocols::xray::defaultLocalAddr;
|
||||||
m_vpnLocalAddress = amnezia::protocols::xray::defaultLocalAddr;
|
m_vpnLocalAddress = amnezia::protocols::xray::defaultLocalAddr;
|
||||||
|
m_t2sProcess = IpcClient::InterfaceTun2Socks();
|
||||||
}
|
}
|
||||||
|
|
||||||
XrayProtocol::~XrayProtocol()
|
XrayProtocol::~XrayProtocol()
|
||||||
|
@ -65,7 +66,7 @@ ErrorCode XrayProtocol::start()
|
||||||
});
|
});
|
||||||
|
|
||||||
connect(&m_xrayProcess, QOverload<int, QProcess::ExitStatus>::of(&QProcess::finished), this, [this](int exitCode, QProcess::ExitStatus exitStatus) {
|
connect(&m_xrayProcess, QOverload<int, QProcess::ExitStatus>::of(&QProcess::finished), this, [this](int exitCode, QProcess::ExitStatus exitStatus) {
|
||||||
qDebug().noquote() << "XrayProtocol finished, exitCode, exiStatus" << exitCode << exitStatus;
|
qDebug().noquote() << "XrayProtocol finished, exitCode, exitStatus" << exitCode << exitStatus;
|
||||||
setConnectionState(Vpn::ConnectionState::Disconnected);
|
setConnectionState(Vpn::ConnectionState::Disconnected);
|
||||||
if (exitStatus != QProcess::NormalExit) {
|
if (exitStatus != QProcess::NormalExit) {
|
||||||
emit protocolError(amnezia::ErrorCode::XrayExecutableCrashed);
|
emit protocolError(amnezia::ErrorCode::XrayExecutableCrashed);
|
||||||
|
@ -91,116 +92,80 @@ ErrorCode XrayProtocol::start()
|
||||||
|
|
||||||
ErrorCode XrayProtocol::startTun2Sock()
|
ErrorCode XrayProtocol::startTun2Sock()
|
||||||
{
|
{
|
||||||
if (!QFileInfo::exists(Utils::tun2socksPath())) {
|
|
||||||
setLastError(ErrorCode::Tun2SockExecutableMissing);
|
|
||||||
return lastError();
|
|
||||||
}
|
|
||||||
|
|
||||||
m_t2sProcess = IpcClient::CreatePrivilegedProcess();
|
|
||||||
|
|
||||||
if (!m_t2sProcess) {
|
|
||||||
setLastError(ErrorCode::AmneziaServiceConnectionFailed);
|
|
||||||
return ErrorCode::AmneziaServiceConnectionFailed;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_t2sProcess->waitForSource(1000);
|
|
||||||
if (!m_t2sProcess->isInitialized()) {
|
|
||||||
qWarning() << "IpcProcess replica is not connected!";
|
|
||||||
setLastError(ErrorCode::AmneziaServiceConnectionFailed);
|
|
||||||
return ErrorCode::AmneziaServiceConnectionFailed;
|
|
||||||
}
|
|
||||||
|
|
||||||
QString XrayConStr = "socks5://127.0.0.1:" + QString::number(m_localPort);
|
|
||||||
|
|
||||||
m_t2sProcess->setProgram(PermittedProcess::Tun2Socks);
|
|
||||||
#ifdef Q_OS_WIN
|
|
||||||
m_configData.insert("inetAdapterIndex", NetworkUtilities::AdapterIndexTo(QHostAddress(m_remoteAddress)));
|
|
||||||
QStringList arguments({"-device", "tun://tun2", "-proxy", XrayConStr, "-tun-post-up",
|
|
||||||
QString("cmd /c netsh interface ip set address name=\"tun2\" static %1 255.255.255.255").arg(amnezia::protocols::xray::defaultLocalAddr)});
|
|
||||||
#endif
|
|
||||||
#ifdef Q_OS_LINUX
|
|
||||||
QStringList arguments({"-device", "tun://tun2", "-proxy", XrayConStr});
|
|
||||||
#endif
|
|
||||||
#ifdef Q_OS_MAC
|
|
||||||
QStringList arguments({"-device", "utun22", "-proxy", XrayConStr});
|
|
||||||
#endif
|
|
||||||
m_t2sProcess->setArguments(arguments);
|
|
||||||
|
|
||||||
qDebug() << arguments.join(" ");
|
|
||||||
connect(m_t2sProcess.data(), &PrivilegedProcess::errorOccurred,
|
|
||||||
[&](QProcess::ProcessError error) { qDebug() << "PrivilegedProcess errorOccurred" << error; });
|
|
||||||
|
|
||||||
connect(m_t2sProcess.data(), &PrivilegedProcess::stateChanged,
|
|
||||||
[&](QProcess::ProcessState newState) {
|
|
||||||
qDebug() << "PrivilegedProcess stateChanged" << newState;
|
|
||||||
if (newState == QProcess::Running)
|
|
||||||
{
|
|
||||||
setConnectionState(Vpn::ConnectionState::Connecting);
|
|
||||||
QList<QHostAddress> dnsAddr;
|
|
||||||
dnsAddr.push_back(QHostAddress(m_configData.value(config_key::dns1).toString()));
|
|
||||||
dnsAddr.push_back(QHostAddress(m_configData.value(config_key::dns2).toString()));
|
|
||||||
|
|
||||||
#ifdef Q_OS_MACOS
|
|
||||||
QThread::msleep(5000);
|
|
||||||
IpcClient::Interface()->createTun("utun22", amnezia::protocols::xray::defaultLocalAddr);
|
|
||||||
IpcClient::Interface()->updateResolvers("utun22", dnsAddr);
|
|
||||||
#endif
|
|
||||||
#ifdef Q_OS_WINDOWS
|
|
||||||
QThread::msleep(7000);
|
|
||||||
#endif
|
|
||||||
#ifdef Q_OS_LINUX
|
|
||||||
QThread::msleep(1000);
|
|
||||||
IpcClient::Interface()->createTun("tun2", amnezia::protocols::xray::defaultLocalAddr);
|
|
||||||
IpcClient::Interface()->updateResolvers("tun2", dnsAddr);
|
|
||||||
#endif
|
|
||||||
#if defined(Q_OS_LINUX) || defined(Q_OS_MACOS)
|
|
||||||
// killSwitch toggle
|
|
||||||
if (QVariant(m_configData.value(config_key::killSwitchOption).toString()).toBool()) {
|
|
||||||
IpcClient::Interface()->enableKillSwitch(m_configData, 0);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
if (m_routeMode == 0) {
|
|
||||||
IpcClient::Interface()->routeAddList(m_vpnGateway, QStringList() << "0.0.0.0/1");
|
|
||||||
IpcClient::Interface()->routeAddList(m_vpnGateway, QStringList() << "128.0.0.0/1");
|
|
||||||
IpcClient::Interface()->routeAddList(m_routeGateway, QStringList() << m_remoteAddress);
|
|
||||||
}
|
|
||||||
IpcClient::Interface()->StopRoutingIpv6();
|
|
||||||
#ifdef Q_OS_WIN
|
|
||||||
IpcClient::Interface()->updateResolvers("tun2", dnsAddr);
|
|
||||||
QList<QNetworkInterface> netInterfaces = QNetworkInterface::allInterfaces();
|
|
||||||
for (int i = 0; i < netInterfaces.size(); i++) {
|
|
||||||
for (int j=0; j < netInterfaces.at(i).addressEntries().size(); j++)
|
|
||||||
{
|
|
||||||
// killSwitch toggle
|
|
||||||
if (m_vpnLocalAddress == netInterfaces.at(i).addressEntries().at(j).ip().toString()) {
|
|
||||||
if (QVariant(m_configData.value(config_key::killSwitchOption).toString()).toBool()) {
|
|
||||||
IpcClient::Interface()->enableKillSwitch(QJsonObject(), netInterfaces.at(i).index());
|
|
||||||
}
|
|
||||||
m_configData.insert("vpnAdapterIndex", netInterfaces.at(i).index());
|
|
||||||
m_configData.insert("vpnGateway", m_vpnGateway);
|
|
||||||
m_configData.insert("vpnServer", m_remoteAddress);
|
|
||||||
IpcClient::Interface()->enablePeerTraffic(m_configData);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
setConnectionState(Vpn::ConnectionState::Connected);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
#if !defined(Q_OS_MACOS)
|
|
||||||
connect(m_t2sProcess.data(), &PrivilegedProcess::finished, this,
|
|
||||||
[&]() {
|
|
||||||
setConnectionState(Vpn::ConnectionState::Disconnected);
|
|
||||||
IpcClient::Interface()->deleteTun("tun2");
|
|
||||||
IpcClient::Interface()->StartRoutingIpv6();
|
|
||||||
IpcClient::Interface()->clearSavedRoutes();
|
|
||||||
});
|
|
||||||
#endif
|
|
||||||
|
|
||||||
m_t2sProcess->start();
|
m_t2sProcess->start();
|
||||||
|
|
||||||
|
#ifdef Q_OS_WIN
|
||||||
|
m_configData.insert("inetAdapterIndex", NetworkUtilities::AdapterIndexTo(QHostAddress(m_remoteAddress)));
|
||||||
|
#endif
|
||||||
|
|
||||||
|
connect(m_t2sProcess.data(), &IpcProcessTun2SocksReplica::stateChanged, this,
|
||||||
|
[&](QProcess::ProcessState newState) { qDebug() << "PrivilegedProcess stateChanged" << newState; });
|
||||||
|
|
||||||
|
connect(m_t2sProcess.data(), &IpcProcessTun2SocksReplica::setConnectionState, this,
|
||||||
|
[&](int vpnState) {
|
||||||
|
qDebug() << "PrivilegedProcess setConnectionState " << vpnState;
|
||||||
|
if (vpnState == Vpn::ConnectionState::Connected)
|
||||||
|
{
|
||||||
|
setConnectionState(Vpn::ConnectionState::Connecting);
|
||||||
|
QList<QHostAddress> dnsAddr;
|
||||||
|
dnsAddr.push_back(QHostAddress(m_configData.value(config_key::dns1).toString()));
|
||||||
|
dnsAddr.push_back(QHostAddress(m_configData.value(config_key::dns2).toString()));
|
||||||
|
#ifdef Q_OS_WIN
|
||||||
|
QThread::msleep(8000);
|
||||||
|
#endif
|
||||||
|
#ifdef Q_OS_MACOS
|
||||||
|
QThread::msleep(5000);
|
||||||
|
IpcClient::Interface()->createTun("utun22", amnezia::protocols::xray::defaultLocalAddr);
|
||||||
|
IpcClient::Interface()->updateResolvers("utun22", dnsAddr);
|
||||||
|
#endif
|
||||||
|
#ifdef Q_OS_LINUX
|
||||||
|
QThread::msleep(1000);
|
||||||
|
IpcClient::Interface()->createTun("tun2", amnezia::protocols::xray::defaultLocalAddr);
|
||||||
|
IpcClient::Interface()->updateResolvers("tun2", dnsAddr);
|
||||||
|
#endif
|
||||||
|
#if defined(Q_OS_LINUX) || defined(Q_OS_MACOS)
|
||||||
|
// killSwitch toggle
|
||||||
|
if (QVariant(m_configData.value(config_key::killSwitchOption).toString()).toBool()) {
|
||||||
|
m_configData.insert("vpnServer", m_remoteAddress);
|
||||||
|
IpcClient::Interface()->enableKillSwitch(m_configData, 0);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
if (m_routeMode == 0) {
|
||||||
|
IpcClient::Interface()->routeAddList(m_vpnGateway, QStringList() << "0.0.0.0/1");
|
||||||
|
IpcClient::Interface()->routeAddList(m_vpnGateway, QStringList() << "128.0.0.0/1");
|
||||||
|
IpcClient::Interface()->routeAddList(m_routeGateway, QStringList() << m_remoteAddress);
|
||||||
|
}
|
||||||
|
IpcClient::Interface()->StopRoutingIpv6();
|
||||||
|
#ifdef Q_OS_WIN
|
||||||
|
IpcClient::Interface()->updateResolvers("tun2", dnsAddr);
|
||||||
|
QList<QNetworkInterface> netInterfaces = QNetworkInterface::allInterfaces();
|
||||||
|
for (int i = 0; i < netInterfaces.size(); i++) {
|
||||||
|
for (int j = 0; j < netInterfaces.at(i).addressEntries().size(); j++)
|
||||||
|
{
|
||||||
|
// killSwitch toggle
|
||||||
|
if (m_vpnLocalAddress == netInterfaces.at(i).addressEntries().at(j).ip().toString()) {
|
||||||
|
if (QVariant(m_configData.value(config_key::killSwitchOption).toString()).toBool()) {
|
||||||
|
IpcClient::Interface()->enableKillSwitch(QJsonObject(), netInterfaces.at(i).index());
|
||||||
|
}
|
||||||
|
m_configData.insert("vpnAdapterIndex", netInterfaces.at(i).index());
|
||||||
|
m_configData.insert("vpnGateway", m_vpnGateway);
|
||||||
|
m_configData.insert("vpnServer", m_remoteAddress);
|
||||||
|
IpcClient::Interface()->enablePeerTraffic(m_configData);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
setConnectionState(Vpn::ConnectionState::Connected);
|
||||||
|
}
|
||||||
|
#if !defined(Q_OS_MACOS)
|
||||||
|
if (vpnState == Vpn::ConnectionState::Disconnected) {
|
||||||
|
setConnectionState(Vpn::ConnectionState::Disconnected);
|
||||||
|
IpcClient::Interface()->deleteTun("tun2");
|
||||||
|
IpcClient::Interface()->StartRoutingIpv6();
|
||||||
|
IpcClient::Interface()->clearSavedRoutes();
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
});
|
||||||
|
|
||||||
return ErrorCode::NoError;
|
return ErrorCode::NoError;
|
||||||
}
|
}
|
||||||
|
@ -214,7 +179,7 @@ void XrayProtocol::stop()
|
||||||
qDebug() << "XrayProtocol::stop()";
|
qDebug() << "XrayProtocol::stop()";
|
||||||
m_xrayProcess.terminate();
|
m_xrayProcess.terminate();
|
||||||
if (m_t2sProcess) {
|
if (m_t2sProcess) {
|
||||||
m_t2sProcess->close();
|
m_t2sProcess->stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef Q_OS_WIN
|
#ifdef Q_OS_WIN
|
||||||
|
|
|
@ -34,9 +34,10 @@ private:
|
||||||
QString m_secondaryDNS;
|
QString m_secondaryDNS;
|
||||||
#ifndef Q_OS_IOS
|
#ifndef Q_OS_IOS
|
||||||
QProcess m_xrayProcess;
|
QProcess m_xrayProcess;
|
||||||
QSharedPointer<PrivilegedProcess> m_t2sProcess;
|
QSharedPointer<IpcProcessTun2SocksReplica> m_t2sProcess;
|
||||||
#endif
|
#endif
|
||||||
QTemporaryFile m_xrayCfgFile;
|
QTemporaryFile m_xrayCfgFile;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // XRAYPROTOCOL_H
|
#endif // XRAYPROTOCOL_H
|
||||||
|
|
|
@ -7,7 +7,6 @@
|
||||||
class IpcInterface
|
class IpcInterface
|
||||||
{
|
{
|
||||||
SLOT( int createPrivilegedProcess() ); // return local pid
|
SLOT( int createPrivilegedProcess() ); // return local pid
|
||||||
//SIGNAL(sendMessage(const QByteArray &message));
|
|
||||||
|
|
||||||
// Route functions
|
// Route functions
|
||||||
SLOT( int routeAddList(const QString &gw, const QStringList &ips) );
|
SLOT( int routeAddList(const QString &gw, const QStringList &ips) );
|
||||||
|
|
|
@ -3,7 +3,6 @@
|
||||||
|
|
||||||
class IpcProcessInterface
|
class IpcProcessInterface
|
||||||
{
|
{
|
||||||
//SLOT( start(const QString &program, const QStringList &args) );
|
|
||||||
SLOT( start() );
|
SLOT( start() );
|
||||||
SLOT( close() );
|
SLOT( close() );
|
||||||
|
|
||||||
|
|
11
ipc/ipc_process_tun2socks.rep
Normal file
11
ipc/ipc_process_tun2socks.rep
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
#include <QtCore>
|
||||||
|
#include <QString>
|
||||||
|
|
||||||
|
class IpcProcessTun2Socks
|
||||||
|
{
|
||||||
|
SLOT( start() );
|
||||||
|
SLOT( stop() );
|
||||||
|
|
||||||
|
SIGNAL( setConnectionState(int state) );
|
||||||
|
SIGNAL( stateChanged(QProcess::ProcessState newState) );
|
||||||
|
};
|
|
@ -8,6 +8,7 @@
|
||||||
#include "logger.h"
|
#include "logger.h"
|
||||||
#include "router.h"
|
#include "router.h"
|
||||||
|
|
||||||
|
#include "../core/networkUtilities.h"
|
||||||
#include "../client/protocols/protocols_defs.h"
|
#include "../client/protocols/protocols_defs.h"
|
||||||
#ifdef Q_OS_WIN
|
#ifdef Q_OS_WIN
|
||||||
#include "../client/platforms/windows/daemon/windowsdaemon.h"
|
#include "../client/platforms/windows/daemon/windowsdaemon.h"
|
||||||
|
@ -209,7 +210,7 @@ bool IpcServer::enableKillSwitch(const QJsonObject &configStr, int vpnAdapterInd
|
||||||
if (splitTunnelType == 0) {
|
if (splitTunnelType == 0) {
|
||||||
blockAll = true;
|
blockAll = true;
|
||||||
allowNets = true;
|
allowNets = true;
|
||||||
allownets.append(configStr.value(amnezia::config_key::hostName).toString());
|
allownets.append(configStr.value("vpnServer").toString());
|
||||||
} else if (splitTunnelType == 1) {
|
} else if (splitTunnelType == 1) {
|
||||||
blockNets = true;
|
blockNets = true;
|
||||||
for (auto v : splitTunnelSites) {
|
for (auto v : splitTunnelSites) {
|
||||||
|
@ -218,7 +219,7 @@ bool IpcServer::enableKillSwitch(const QJsonObject &configStr, int vpnAdapterInd
|
||||||
} else if (splitTunnelType == 2) {
|
} else if (splitTunnelType == 2) {
|
||||||
blockAll = true;
|
blockAll = true;
|
||||||
allowNets = true;
|
allowNets = true;
|
||||||
allownets.append(configStr.value(amnezia::config_key::hostName).toString());
|
allownets.append(configStr.value("vpnServer").toString());
|
||||||
for (auto v : splitTunnelSites) {
|
for (auto v : splitTunnelSites) {
|
||||||
allownets.append(v.toString());
|
allownets.append(v.toString());
|
||||||
}
|
}
|
||||||
|
@ -329,7 +330,7 @@ bool IpcServer::enablePeerTraffic(const QJsonObject &configStr)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
config.m_excludedAddresses.append(configStr.value(amnezia::config_key::hostName).toString());
|
config.m_excludedAddresses.append(configStr.value("vpnServer").toString());
|
||||||
if (splitTunnelType == 2) {
|
if (splitTunnelType == 2) {
|
||||||
for (auto v : splitTunnelSites) {
|
for (auto v : splitTunnelSites) {
|
||||||
QString ipRange = v.toString();
|
QString ipRange = v.toString();
|
||||||
|
@ -351,7 +352,6 @@ bool IpcServer::enablePeerTraffic(const QJsonObject &configStr)
|
||||||
|
|
||||||
WindowsDaemon::instance()->prepareActivation(config, inetAdapterIndex);
|
WindowsDaemon::instance()->prepareActivation(config, inetAdapterIndex);
|
||||||
WindowsDaemon::instance()->activateSplitTunnel(config, vpnAdapterIndex);
|
WindowsDaemon::instance()->activateSplitTunnel(config, vpnAdapterIndex);
|
||||||
return true;
|
|
||||||
#endif
|
#endif
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,8 +9,10 @@
|
||||||
|
|
||||||
#include "ipc.h"
|
#include "ipc.h"
|
||||||
#include "ipcserverprocess.h"
|
#include "ipcserverprocess.h"
|
||||||
|
#include "ipctun2socksprocess.h"
|
||||||
|
|
||||||
#include "rep_ipc_interface_source.h"
|
#include "rep_ipc_interface_source.h"
|
||||||
|
#include "rep_ipc_process_tun2socks_source.h"
|
||||||
|
|
||||||
class IpcServer : public IpcInterfaceSource
|
class IpcServer : public IpcInterfaceSource
|
||||||
{
|
{
|
||||||
|
@ -44,10 +46,12 @@ private:
|
||||||
ProcessDescriptor (QObject *parent = nullptr) {
|
ProcessDescriptor (QObject *parent = nullptr) {
|
||||||
serverNode = QSharedPointer<QRemoteObjectHost>(new QRemoteObjectHost(parent));
|
serverNode = QSharedPointer<QRemoteObjectHost>(new QRemoteObjectHost(parent));
|
||||||
ipcProcess = QSharedPointer<IpcServerProcess>(new IpcServerProcess(parent));
|
ipcProcess = QSharedPointer<IpcServerProcess>(new IpcServerProcess(parent));
|
||||||
|
tun2socksProcess = QSharedPointer<IpcProcessTun2Socks>(new IpcProcessTun2Socks(parent));
|
||||||
localServer = QSharedPointer<QLocalServer>(new QLocalServer(parent));
|
localServer = QSharedPointer<QLocalServer>(new QLocalServer(parent));
|
||||||
}
|
}
|
||||||
|
|
||||||
QSharedPointer<IpcServerProcess> ipcProcess;
|
QSharedPointer<IpcServerProcess> ipcProcess;
|
||||||
|
QSharedPointer<IpcProcessTun2Socks> tun2socksProcess;
|
||||||
QSharedPointer<QRemoteObjectHost> serverNode;
|
QSharedPointer<QRemoteObjectHost> serverNode;
|
||||||
QSharedPointer<QLocalServer> localServer;
|
QSharedPointer<QLocalServer> localServer;
|
||||||
};
|
};
|
||||||
|
|
74
ipc/ipctun2socksprocess.cpp
Normal file
74
ipc/ipctun2socksprocess.cpp
Normal file
|
@ -0,0 +1,74 @@
|
||||||
|
#include "ipctun2socksprocess.h"
|
||||||
|
#include "ipc.h"
|
||||||
|
#include <QProcess>
|
||||||
|
#include <QString>
|
||||||
|
|
||||||
|
#include "../protocols/protocols_defs.h"
|
||||||
|
|
||||||
|
#ifndef Q_OS_IOS
|
||||||
|
|
||||||
|
IpcProcessTun2Socks::IpcProcessTun2Socks(QObject *parent) :
|
||||||
|
IpcProcessTun2SocksSource(parent),
|
||||||
|
m_t2sProcess(QSharedPointer<QProcess>(new QProcess()))
|
||||||
|
{
|
||||||
|
connect(m_t2sProcess.data(), &QProcess::stateChanged, this, &IpcProcessTun2Socks::stateChanged);
|
||||||
|
qDebug() << "IpcProcessTun2Socks::IpcProcessTun2Socks()";
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
IpcProcessTun2Socks::~IpcProcessTun2Socks()
|
||||||
|
{
|
||||||
|
qDebug() << "IpcProcessTun2Socks::~IpcProcessTun2Socks()";
|
||||||
|
}
|
||||||
|
|
||||||
|
void IpcProcessTun2Socks::start()
|
||||||
|
{
|
||||||
|
qDebug() << "IpcProcessTun2Socks::start()";
|
||||||
|
m_t2sProcess->setProgram(amnezia::permittedProcessPath(static_cast<amnezia::PermittedProcess>(amnezia::PermittedProcess::Tun2Socks)));
|
||||||
|
QString XrayConStr = "socks5://127.0.0.1:10808";
|
||||||
|
|
||||||
|
#ifdef Q_OS_WIN
|
||||||
|
QStringList arguments({"-device", "tun://tun2", "-proxy", XrayConStr, "-tun-post-up",
|
||||||
|
QString("cmd /c netsh interface ip set address name=\"tun2\" static %1 255.255.255.255")
|
||||||
|
.arg(amnezia::protocols::xray::defaultLocalAddr)});
|
||||||
|
#endif
|
||||||
|
#ifdef Q_OS_LINUX
|
||||||
|
QStringList arguments({"-device", "tun://tun2", "-proxy", XrayConStr});
|
||||||
|
#endif
|
||||||
|
#ifdef Q_OS_MAC
|
||||||
|
QStringList arguments({"-device", "utun22", "-proxy", XrayConStr});
|
||||||
|
#endif
|
||||||
|
|
||||||
|
m_t2sProcess->setArguments(arguments);
|
||||||
|
|
||||||
|
Utils::killProcessByName(m_t2sProcess->program());
|
||||||
|
m_t2sProcess->start();
|
||||||
|
|
||||||
|
connect(m_t2sProcess.data(), &QProcess::readyReadStandardOutput, this, [this]() {
|
||||||
|
QString line = m_t2sProcess.data()->readAllStandardOutput();
|
||||||
|
if (line.contains("[STACK] tun://") && line.contains("<-> socks5://127.0.0.1")) {
|
||||||
|
emit setConnectionState(Vpn::ConnectionState::Connected);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
connect(m_t2sProcess.data(), QOverload<int, QProcess::ExitStatus>::of(&QProcess::finished), this, [this](int exitCode, QProcess::ExitStatus exitStatus) {
|
||||||
|
qDebug().noquote() << "tun2socks finished, exitCode, exiStatus" << exitCode << exitStatus;
|
||||||
|
emit setConnectionState(Vpn::ConnectionState::Disconnected);
|
||||||
|
if (exitStatus != QProcess::NormalExit){
|
||||||
|
stop();
|
||||||
|
}
|
||||||
|
if (exitCode !=0 ){
|
||||||
|
stop();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
m_t2sProcess->start();
|
||||||
|
m_t2sProcess->waitForStarted();
|
||||||
|
}
|
||||||
|
|
||||||
|
void IpcProcessTun2Socks::stop()
|
||||||
|
{
|
||||||
|
qDebug() << "IpcProcessTun2Socks::stop()";
|
||||||
|
m_t2sProcess->close();
|
||||||
|
}
|
||||||
|
#endif
|
52
ipc/ipctun2socksprocess.h
Normal file
52
ipc/ipctun2socksprocess.h
Normal file
|
@ -0,0 +1,52 @@
|
||||||
|
#ifndef IPCTUN2SOCKSPROCESS_H
|
||||||
|
#define IPCTUN2SOCKSPROCESS_H
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
|
||||||
|
#ifndef Q_OS_IOS
|
||||||
|
#include "rep_ipc_process_tun2socks_source.h"
|
||||||
|
|
||||||
|
namespace Vpn
|
||||||
|
{
|
||||||
|
Q_NAMESPACE
|
||||||
|
enum ConnectionState {
|
||||||
|
Unknown,
|
||||||
|
Disconnected,
|
||||||
|
Preparing,
|
||||||
|
Connecting,
|
||||||
|
Connected,
|
||||||
|
Disconnecting,
|
||||||
|
Reconnecting,
|
||||||
|
Error
|
||||||
|
};
|
||||||
|
Q_ENUM_NS(ConnectionState)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class IpcProcessTun2Socks : public IpcProcessTun2SocksSource
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
explicit IpcProcessTun2Socks(QObject *parent = nullptr);
|
||||||
|
virtual ~IpcProcessTun2Socks();
|
||||||
|
|
||||||
|
void start() override;
|
||||||
|
void stop() override;
|
||||||
|
|
||||||
|
signals:
|
||||||
|
|
||||||
|
private:
|
||||||
|
QSharedPointer<QProcess> m_t2sProcess;
|
||||||
|
};
|
||||||
|
|
||||||
|
#else
|
||||||
|
class IpcProcessTun2Socks : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit IpcProcessTun2Socks(QObject *parent = nullptr);
|
||||||
|
};
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif // IPCTUN2SOCKSPROCESS_H
|
|
@ -18,6 +18,7 @@ set(HEADERS
|
||||||
${CMAKE_CURRENT_LIST_DIR}/../../ipc/ipc.h
|
${CMAKE_CURRENT_LIST_DIR}/../../ipc/ipc.h
|
||||||
${CMAKE_CURRENT_LIST_DIR}/../../ipc/ipcserver.h
|
${CMAKE_CURRENT_LIST_DIR}/../../ipc/ipcserver.h
|
||||||
${CMAKE_CURRENT_LIST_DIR}/../../ipc/ipcserverprocess.h
|
${CMAKE_CURRENT_LIST_DIR}/../../ipc/ipcserverprocess.h
|
||||||
|
${CMAKE_CURRENT_LIST_DIR}/../../ipc/ipctun2socksprocess.h
|
||||||
${CMAKE_CURRENT_LIST_DIR}/localserver.h
|
${CMAKE_CURRENT_LIST_DIR}/localserver.h
|
||||||
${CMAKE_CURRENT_LIST_DIR}/../../common/logger/logger.h
|
${CMAKE_CURRENT_LIST_DIR}/../../common/logger/logger.h
|
||||||
${CMAKE_CURRENT_LIST_DIR}/router.h
|
${CMAKE_CURRENT_LIST_DIR}/router.h
|
||||||
|
@ -30,6 +31,7 @@ set(SOURCES
|
||||||
${CMAKE_CURRENT_LIST_DIR}/../../client/core/networkUtilities.cpp
|
${CMAKE_CURRENT_LIST_DIR}/../../client/core/networkUtilities.cpp
|
||||||
${CMAKE_CURRENT_LIST_DIR}/../../ipc/ipcserver.cpp
|
${CMAKE_CURRENT_LIST_DIR}/../../ipc/ipcserver.cpp
|
||||||
${CMAKE_CURRENT_LIST_DIR}/../../ipc/ipcserverprocess.cpp
|
${CMAKE_CURRENT_LIST_DIR}/../../ipc/ipcserverprocess.cpp
|
||||||
|
${CMAKE_CURRENT_LIST_DIR}/../../ipc/ipctun2socksprocess.cpp
|
||||||
${CMAKE_CURRENT_LIST_DIR}/localserver.cpp
|
${CMAKE_CURRENT_LIST_DIR}/localserver.cpp
|
||||||
${CMAKE_CURRENT_LIST_DIR}/../../common/logger/logger.cpp
|
${CMAKE_CURRENT_LIST_DIR}/../../common/logger/logger.cpp
|
||||||
${CMAKE_CURRENT_LIST_DIR}/main.cpp
|
${CMAKE_CURRENT_LIST_DIR}/main.cpp
|
||||||
|
@ -279,6 +281,7 @@ endif()
|
||||||
|
|
||||||
qt_add_repc_sources(${PROJECT} ${CMAKE_CURRENT_LIST_DIR}/../../ipc/ipc_interface.rep)
|
qt_add_repc_sources(${PROJECT} ${CMAKE_CURRENT_LIST_DIR}/../../ipc/ipc_interface.rep)
|
||||||
qt_add_repc_sources(${PROJECT} ${CMAKE_CURRENT_LIST_DIR}/../../ipc/ipc_process_interface.rep)
|
qt_add_repc_sources(${PROJECT} ${CMAKE_CURRENT_LIST_DIR}/../../ipc/ipc_process_interface.rep)
|
||||||
|
qt_add_repc_sources(${PROJECT} ${CMAKE_CURRENT_LIST_DIR}/../../ipc/ipc_process_tun2socks.rep)
|
||||||
|
|
||||||
# copy deploy artifacts required to run the application to the debug build folder
|
# copy deploy artifacts required to run the application to the debug build folder
|
||||||
if(WIN32)
|
if(WIN32)
|
||||||
|
|
|
@ -37,6 +37,7 @@ LocalServer::LocalServer(QObject *parent) : QObject(parent),
|
||||||
if (!m_isRemotingEnabled) {
|
if (!m_isRemotingEnabled) {
|
||||||
m_isRemotingEnabled = true;
|
m_isRemotingEnabled = true;
|
||||||
m_serverNode.enableRemoting(&m_ipcServer);
|
m_serverNode.enableRemoting(&m_ipcServer);
|
||||||
|
m_serverNode.enableRemoting(&m_tun2socks);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -38,6 +38,7 @@ public:
|
||||||
~LocalServer();
|
~LocalServer();
|
||||||
QSharedPointer<QLocalServer> m_server;
|
QSharedPointer<QLocalServer> m_server;
|
||||||
IpcServer m_ipcServer;
|
IpcServer m_ipcServer;
|
||||||
|
IpcProcessTun2Socks m_tun2socks;
|
||||||
QRemoteObjectHost m_serverNode;
|
QRemoteObjectHost m_serverNode;
|
||||||
bool m_isRemotingEnabled = false;
|
bool m_isRemotingEnabled = false;
|
||||||
#ifdef Q_OS_LINUX
|
#ifdef Q_OS_LINUX
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue