[WIP] Added wireguard, prepare to test and debug
This commit is contained in:
parent
e644575bc5
commit
7c7f77adc6
98 changed files with 4410 additions and 302 deletions
|
@ -46,7 +46,7 @@ constexpr auto PERMISSIONHELPER_CLASS =
|
|||
|
||||
} // namespace
|
||||
|
||||
AndroidVpnProtocol::AndroidVpnProtocol(Protocol protocol, const QJsonObject &configuration, QObject* parent)
|
||||
AndroidVpnProtocol::AndroidVpnProtocol(Proto protocol, const QJsonObject &configuration, QObject* parent)
|
||||
: VpnProtocol(configuration, parent),
|
||||
m_protocol(protocol),
|
||||
m_binder(this)
|
||||
|
|
|
@ -17,7 +17,7 @@ class AndroidVpnProtocol : public VpnProtocol,
|
|||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit AndroidVpnProtocol(Protocol protocol, const QJsonObject& configuration, QObject* parent = nullptr);
|
||||
explicit AndroidVpnProtocol(Proto protocol, const QJsonObject& configuration, QObject* parent = nullptr);
|
||||
static AndroidVpnProtocol* instance();
|
||||
|
||||
virtual ~AndroidVpnProtocol() override = default;
|
||||
|
@ -53,7 +53,7 @@ protected:
|
|||
|
||||
|
||||
private:
|
||||
Protocol m_protocol;
|
||||
Proto m_protocol;
|
||||
|
||||
bool m_serviceConnected = false;
|
||||
std::function<void(const QString&)> m_logCallback;
|
||||
|
|
51
client/protocols/ios_vpnprotocol.h
Normal file
51
client/protocols/ios_vpnprotocol.h
Normal file
|
@ -0,0 +1,51 @@
|
|||
#ifndef IOS_VPNPROTOCOL_H
|
||||
#define IOS_VPNPROTOCOL_H
|
||||
|
||||
#include "vpnprotocol.h"
|
||||
#include "protocols/protocols_defs.h"
|
||||
|
||||
using namespace amnezia;
|
||||
|
||||
|
||||
class IOSVpnProtocol : public VpnProtocol
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit IOSVpnProtocol(amnezia::Proto proto, const QJsonObject& configuration, QObject* parent = nullptr);
|
||||
static IOSVpnProtocol* instance();
|
||||
|
||||
virtual ~IOSVpnProtocol() = default;
|
||||
|
||||
bool initialize();
|
||||
|
||||
virtual ErrorCode start() override;
|
||||
virtual void stop() override;
|
||||
|
||||
void resume_start();
|
||||
|
||||
void checkStatus();
|
||||
|
||||
void setNotificationText(const QString& title, const QString& message,
|
||||
int timerSec);
|
||||
void setFallbackConnectedNotification();
|
||||
|
||||
void getBackendLogs(std::function<void(const QString&)>&& callback);
|
||||
|
||||
void cleanupBackendLogs();
|
||||
|
||||
signals:
|
||||
|
||||
protected slots:
|
||||
|
||||
protected:
|
||||
|
||||
private:
|
||||
Proto m_protocol;
|
||||
bool m_serviceConnected = false;
|
||||
bool m_checkingStatus = false;
|
||||
std::function<void(const QString&)> m_logCallback;
|
||||
};
|
||||
|
||||
|
||||
#endif // IOS_VPNPROTOCOL_H
|
298
client/protocols/ios_vpnprotocol.mm
Normal file
298
client/protocols/ios_vpnprotocol.mm
Normal file
|
@ -0,0 +1,298 @@
|
|||
#include <QDebug>
|
||||
#include <QHostAddress>
|
||||
#include <QJsonArray>
|
||||
#include <QJsonDocument>
|
||||
#include <QJsonObject>
|
||||
#include <QRandomGenerator>
|
||||
#include <QTextCodec>
|
||||
#include <QTimer>
|
||||
#include <QFile>
|
||||
|
||||
#include <QByteArray>
|
||||
|
||||
#include "json.h"
|
||||
|
||||
#include "ipaddressrange.h"
|
||||
#include "ios_vpnprotocol.h"
|
||||
#include "core/errorstrings.h"
|
||||
#include "AmneziaVPN-Swift.h"
|
||||
|
||||
namespace
|
||||
{
|
||||
IOSVpnProtocol* s_instance = nullptr;
|
||||
IOSVpnProtocolImpl* m_controller = nullptr;
|
||||
}
|
||||
|
||||
IOSVpnProtocol::IOSVpnProtocol(Proto proto, const QJsonObject &configuration, QObject* parent)
|
||||
: VpnProtocol(configuration, parent),
|
||||
m_protocol(proto) {}
|
||||
|
||||
IOSVpnProtocol* IOSVpnProtocol::instance() {
|
||||
return s_instance;
|
||||
}
|
||||
|
||||
bool IOSVpnProtocol::initialize()
|
||||
{
|
||||
qDebug() << "Initializing Swift Controller";
|
||||
|
||||
static bool creating = false;
|
||||
// No nested creation!
|
||||
Q_ASSERT(creating == false);
|
||||
creating = true;
|
||||
|
||||
if (!m_controller) {
|
||||
bool ok;
|
||||
QtJson::JsonObject result = QtJson::parse(QJsonDocument(m_rawConfig).toJson(), ok).toMap();
|
||||
|
||||
if(!ok) {
|
||||
qDebug() << QString("An error occurred during parsing");
|
||||
return false;
|
||||
}
|
||||
|
||||
QString vpnProto = result["protocol"].toString();
|
||||
qDebug() << "protocol: " << vpnProto;
|
||||
qDebug() << "config data => ";
|
||||
QtJson::JsonObject config = result["wireguard_config_data"].toMap();
|
||||
|
||||
QString privateKey = config["client_priv_key"].toString();
|
||||
QByteArray key = QByteArray::fromBase64(privateKey.toLocal8Bit());
|
||||
|
||||
qDebug() << " - " << "client_priv_key: " << config["client_priv_key"].toString();
|
||||
qDebug() << " - " << "client_pub_key: " << config["client_pub_key"].toString();
|
||||
qDebug() << " - " << "interface config: " << config["config"].toString();
|
||||
|
||||
QString addr = config["config"].toString().split("\n").takeAt(1).split(" = ").takeLast();
|
||||
QString dns = config["config"].toString().split("\n").takeAt(2).split(" = ").takeLast();
|
||||
QString privkey = config["config"].toString().split("\n").takeAt(3).split(" = ").takeLast();
|
||||
QString pubkey = config["config"].toString().split("\n").takeAt(6).split(" = ").takeLast();
|
||||
QString presharedkey = config["config"].toString().split("\n").takeAt(7).split(" = ").takeLast();
|
||||
QString allowedips = config["config"].toString().split("\n").takeAt(8).split(" = ").takeLast();
|
||||
QString endpoint = config["config"].toString().split("\n").takeAt(9).split(" = ").takeLast();
|
||||
QString keepalive = config["config"].toString().split("\n").takeAt(10).split(" = ").takeLast();
|
||||
qDebug() << " - " << "[Interface] address: " << addr;
|
||||
qDebug() << " - " << "[Interface] dns: " << dns;
|
||||
qDebug() << " - " << "[Interface] private key: " << privkey;
|
||||
qDebug() << " - " << "[Peer] public key: " << pubkey;
|
||||
qDebug() << " - " << "[Peer] preshared key: " << presharedkey;
|
||||
qDebug() << " - " << "[Peer] allowed ips: " << allowedips;
|
||||
qDebug() << " - " << "[Peer] endpoint: " << endpoint;
|
||||
qDebug() << " - " << "[Peer] keepalive: " << keepalive;
|
||||
|
||||
qDebug() << " - " << "hostName: " << config["hostName"].toString();
|
||||
qDebug() << " - " << "psk_key: " << config["psk_key"].toString();
|
||||
qDebug() << " - " << "server_pub_key: " << config["server_pub_key"].toString();
|
||||
|
||||
|
||||
|
||||
m_controller = [[IOSVpnProtocolImpl alloc] initWithBundleID:@VPN_NE_BUNDLEID
|
||||
privateKey:key.toNSData()
|
||||
deviceIpv4Address:addr.toNSString()
|
||||
deviceIpv6Address:@"::/0"
|
||||
closure:^(ConnectionState state, NSDate* date) {
|
||||
qDebug() << "Creation completed with connection state:" << state;
|
||||
creating = false;
|
||||
|
||||
switch (state) {
|
||||
case ConnectionStateError: {
|
||||
[m_controller dealloc];
|
||||
m_controller = nullptr;
|
||||
emit initialized(false, false, QDateTime());
|
||||
return;
|
||||
}
|
||||
case ConnectionStateConnected: {
|
||||
Q_ASSERT(date);
|
||||
QDateTime qtDate(QDateTime::fromNSDate(date));
|
||||
emit initialized(true, true, qtDate);
|
||||
return;
|
||||
}
|
||||
case ConnectionStateDisconnected:
|
||||
// Just in case we are connecting, let's call disconnect.
|
||||
[m_controller disconnect];
|
||||
emit initialized(true, false, QDateTime());
|
||||
return;
|
||||
}
|
||||
}
|
||||
callback:^(BOOL a_connected) {
|
||||
qDebug() << "State changed: " << a_connected;
|
||||
if (a_connected) {
|
||||
emit isConnected();
|
||||
return;
|
||||
}
|
||||
|
||||
emit isDisconnected();
|
||||
}];
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
ErrorCode IOSVpnProtocol::start()
|
||||
{
|
||||
bool ok;
|
||||
QtJson::JsonObject result = QtJson::parse(QJsonDocument(m_rawConfig).toJson(), ok).toMap();
|
||||
|
||||
if(!ok) {
|
||||
qDebug() << QString("An error occurred during config parsing");
|
||||
return InternalError;
|
||||
}
|
||||
QString protocol = result["protocol"].toString();
|
||||
QtJson::JsonObject config = result["wireguard_config_data"].toMap();
|
||||
|
||||
QString clientPrivateKey = config["client_priv_key"].toString();
|
||||
QByteArray key = QByteArray::fromBase64(clientPrivateKey.toLocal8Bit());
|
||||
QString clientPubKey = config["client_pub_key"].toString();
|
||||
|
||||
QString addr = config["config"].toString().split("\n").takeAt(1).split(" = ").takeLast();
|
||||
QStringList dnsServersList = config["config"].toString().split("\n").takeAt(2).split(" = ").takeLast().split(", ");
|
||||
QString privkey = config["config"].toString().split("\n").takeAt(3).split(" = ").takeLast();
|
||||
QString pubkey = config["config"].toString().split("\n").takeAt(6).split(" = ").takeLast();
|
||||
QString presharedkey = config["config"].toString().split("\n").takeAt(7).split(" = ").takeLast();
|
||||
QStringList allowedIPList = config["config"].toString().split("\n").takeAt(8).split(" = ").takeLast().split(", ");
|
||||
QString endpoint = config["config"].toString().split("\n").takeAt(9).split(" = ").takeLast();
|
||||
QString serverAddr = config["config"].toString().split("\n").takeAt(9).split(" = ").takeLast().split(":").takeFirst();
|
||||
QString port = config["config"].toString().split("\n").takeAt(9).split(" = ").takeLast().split(":").takeLast();
|
||||
QString keepalive = config["config"].toString().split("\n").takeAt(10).split(" = ").takeLast();
|
||||
|
||||
QString hostname = config["hostName"].toString();
|
||||
QString pskKey = config["psk_key"].toString();
|
||||
QString serverPubKey = config["server_pub_key"].toString();
|
||||
|
||||
qDebug() << "IOSVPNProtocol starts for" << hostname;
|
||||
qDebug() << "DNS:" << dnsServersList.takeFirst().toNSString();
|
||||
qDebug() << "serverPublicKey:" << serverPubKey.toNSString();
|
||||
qDebug() << "serverIpv4AddrIn:" << serverAddr.toNSString();
|
||||
qDebug() << "serverPort:" << (uint32_t)port.toInt();
|
||||
qDebug() << "allowed ip list" << allowedIPList;
|
||||
|
||||
NSMutableArray<VPNIPAddressRange*>* allowedIPAddressRangesNS =
|
||||
[NSMutableArray<VPNIPAddressRange*> arrayWithCapacity:allowedIPList.length()];
|
||||
for (const IPAddressRange item : allowedIPList) {
|
||||
VPNIPAddressRange* range =
|
||||
[[VPNIPAddressRange alloc] initWithAddress:item.ipAddress().toNSString()
|
||||
networkPrefixLength:item.range()
|
||||
isIpv6:item.type() == IPAddressRange::IPv6];
|
||||
[allowedIPAddressRangesNS addObject:[range autorelease]];
|
||||
}
|
||||
|
||||
[m_controller connectWithDnsServer:dnsServersList.takeFirst().toNSString()
|
||||
serverIpv6Gateway:@"FE80::1"
|
||||
serverPublicKey:serverPubKey.toNSString()
|
||||
serverIpv4AddrIn:serverAddr.toNSString()
|
||||
serverPort:port.toInt()
|
||||
allowedIPAddressRanges:allowedIPAddressRangesNS
|
||||
ipv6Enabled:NO
|
||||
reason:0
|
||||
failureCallback:^() {
|
||||
qDebug() << "IOSVPNProtocol - connection failed";
|
||||
emit isDisconnected();
|
||||
}];
|
||||
return NoError;
|
||||
}
|
||||
|
||||
void IOSVpnProtocol::stop()
|
||||
{
|
||||
if (!m_controller) {
|
||||
qDebug() << "Not correctly initialized";
|
||||
emit isDisconnected();
|
||||
return;
|
||||
}
|
||||
|
||||
[m_controller disconnect];
|
||||
}
|
||||
|
||||
void IOSVpnProtocol::resume_start()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void IOSVpnProtocol::checkStatus()
|
||||
{
|
||||
qDebug() << "Checking status";
|
||||
|
||||
if (m_checkingStatus) {
|
||||
qDebug() << "We are still waiting for the previous status.";
|
||||
return;
|
||||
}
|
||||
|
||||
if (!m_controller) {
|
||||
qDebug() << "Not correctly initialized";
|
||||
return;
|
||||
}
|
||||
|
||||
m_checkingStatus = true;
|
||||
|
||||
[m_controller checkStatusWithCallback:^(NSString* serverIpv4Gateway, NSString* deviceIpv4Address,
|
||||
NSString* configString) {
|
||||
QString config = QString::fromNSString(configString);
|
||||
|
||||
m_checkingStatus = false;
|
||||
|
||||
if (config.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
uint64_t txBytes = 0;
|
||||
uint64_t rxBytes = 0;
|
||||
|
||||
QStringList lines = config.split("\n");
|
||||
for (const QString& line : lines) {
|
||||
if (line.startsWith("tx_bytes=")) {
|
||||
txBytes = line.split("=")[1].toULongLong();
|
||||
} else if (line.startsWith("rx_bytes=")) {
|
||||
rxBytes = line.split("=")[1].toULongLong();
|
||||
}
|
||||
|
||||
if (txBytes && rxBytes) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
qDebug() << "ServerIpv4Gateway:" << QString::fromNSString(serverIpv4Gateway)
|
||||
<< "DeviceIpv4Address:" << QString::fromNSString(deviceIpv4Address)
|
||||
<< "RxBytes:" << rxBytes << "TxBytes:" << txBytes;
|
||||
emit bytesChanged(rxBytes, txBytes);
|
||||
|
||||
}];
|
||||
}
|
||||
|
||||
void IOSVpnProtocol::setNotificationText(const QString &title, const QString &message, int timerSec)
|
||||
{
|
||||
// TODO: add user notifications?
|
||||
}
|
||||
|
||||
void IOSVpnProtocol::setFallbackConnectedNotification()
|
||||
{
|
||||
// TODO: add default user notifications?
|
||||
}
|
||||
|
||||
void IOSVpnProtocol::getBackendLogs(std::function<void (const QString &)> &&callback)
|
||||
{
|
||||
std::function<void(const QString&)> a_callback = std::move(callback);
|
||||
|
||||
QString groupId(GROUP_ID);
|
||||
NSURL* groupPath = [[NSFileManager defaultManager]
|
||||
containerURLForSecurityApplicationGroupIdentifier:groupId.toNSString()];
|
||||
|
||||
NSURL* path = [groupPath URLByAppendingPathComponent:@"networkextension.log"];
|
||||
|
||||
QFile file(QString::fromNSString([path path]));
|
||||
if (!file.open(QIODevice::ReadOnly)) {
|
||||
a_callback("Network extension log file missing or unreadable.");
|
||||
return;
|
||||
}
|
||||
|
||||
QByteArray content = file.readAll();
|
||||
a_callback(content);
|
||||
}
|
||||
|
||||
void IOSVpnProtocol::cleanupBackendLogs()
|
||||
{
|
||||
QString groupId(GROUP_ID);
|
||||
NSURL* groupPath = [[NSFileManager defaultManager]
|
||||
containerURLForSecurityApplicationGroupIdentifier:groupId.toNSString()];
|
||||
|
||||
NSURL* path = [groupPath URLByAppendingPathComponent:@"networkextension.log"];
|
||||
|
||||
QFile file(QString::fromNSString([path path]));
|
||||
file.remove();
|
||||
}
|
||||
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
using namespace amnezia;
|
||||
|
||||
QDebug operator<<(QDebug debug, const amnezia::ProtocolEnumNS::Protocol &p)
|
||||
QDebug operator<<(QDebug debug, const amnezia::ProtocolEnumNS::Proto &p)
|
||||
{
|
||||
QDebugStateSaver saver(debug);
|
||||
debug.nospace() << ProtocolProps::protoToString(p);
|
||||
|
@ -10,29 +10,29 @@ QDebug operator<<(QDebug debug, const amnezia::ProtocolEnumNS::Protocol &p)
|
|||
return debug;
|
||||
}
|
||||
|
||||
amnezia::Protocol ProtocolProps::protoFromString(QString proto){
|
||||
QMetaEnum metaEnum = QMetaEnum::fromType<Protocol>();
|
||||
amnezia::Proto ProtocolProps::protoFromString(QString proto){
|
||||
QMetaEnum metaEnum = QMetaEnum::fromType<Proto>();
|
||||
for (int i = 0; i < metaEnum.keyCount(); ++i) {
|
||||
Protocol p = static_cast<Protocol>(i);
|
||||
Proto p = static_cast<Proto>(i);
|
||||
if (proto == protoToString(p)) return p;
|
||||
}
|
||||
return Protocol::Any;
|
||||
return Proto::Any;
|
||||
}
|
||||
|
||||
QString ProtocolProps::protoToString(amnezia::Protocol p){
|
||||
if (p == Protocol::Any) return "";
|
||||
QString ProtocolProps::protoToString(amnezia::Proto p){
|
||||
if (p == Proto::Any) return "";
|
||||
|
||||
QMetaEnum metaEnum = QMetaEnum::fromType<Protocol>();
|
||||
QMetaEnum metaEnum = QMetaEnum::fromType<Proto>();
|
||||
QString protoKey = metaEnum.valueToKey(static_cast<int>(p));
|
||||
return protoKey.toLower();
|
||||
}
|
||||
|
||||
QList<amnezia::Protocol> ProtocolProps::allProtocols()
|
||||
QList<amnezia::Proto> ProtocolProps::allProtocols()
|
||||
{
|
||||
QMetaEnum metaEnum = QMetaEnum::fromType<Protocol>();
|
||||
QList<Protocol> all;
|
||||
QMetaEnum metaEnum = QMetaEnum::fromType<Proto>();
|
||||
QList<Proto> all;
|
||||
for (int i = 0; i < metaEnum.keyCount(); ++i) {
|
||||
all.append(static_cast<Protocol>(i));
|
||||
all.append(static_cast<Proto>(i));
|
||||
}
|
||||
|
||||
return all;
|
||||
|
@ -48,7 +48,7 @@ TransportProto ProtocolProps::transportProtoFromString(QString p)
|
|||
return TransportProto::Udp;
|
||||
}
|
||||
|
||||
QString ProtocolProps::transportProtoToString(TransportProto proto, Protocol p)
|
||||
QString ProtocolProps::transportProtoToString(TransportProto proto, Proto p)
|
||||
{
|
||||
QMetaEnum metaEnum = QMetaEnum::fromType<TransportProto>();
|
||||
QString protoKey = metaEnum.valueToKey(static_cast<int>(proto));
|
||||
|
@ -66,124 +66,124 @@ QString ProtocolProps::transportProtoToString(TransportProto proto, Protocol p)
|
|||
}
|
||||
|
||||
|
||||
QMap<amnezia::Protocol, QString> ProtocolProps::protocolHumanNames()
|
||||
QMap<amnezia::Proto, QString> ProtocolProps::protocolHumanNames()
|
||||
{
|
||||
return {
|
||||
{Protocol::OpenVpn, "OpenVPN"},
|
||||
{Protocol::ShadowSocks, "ShadowSocks"},
|
||||
{Protocol::Cloak, "Cloak"},
|
||||
{Protocol::WireGuard, "WireGuard"},
|
||||
{Protocol::Ikev2, "IKEv2"},
|
||||
{Protocol::L2tp, "L2TP"},
|
||||
{Proto::OpenVpn, "OpenVPN"},
|
||||
{Proto::ShadowSocks, "ShadowSocks"},
|
||||
{Proto::Cloak, "Cloak"},
|
||||
{Proto::WireGuard, "WireGuard"},
|
||||
{Proto::Ikev2, "IKEv2"},
|
||||
{Proto::L2tp, "L2TP"},
|
||||
|
||||
{Protocol::TorWebSite, "Web site in TOR network"},
|
||||
{Protocol::Dns, "DNS Service"},
|
||||
{Protocol::FileShare, "File Sharing Service"},
|
||||
{Protocol::Sftp, QObject::tr("Sftp service")}
|
||||
{Proto::TorWebSite, "Web site in TOR network"},
|
||||
{Proto::Dns, "DNS Service"},
|
||||
{Proto::FileShare, "File Sharing Service"},
|
||||
{Proto::Sftp, QObject::tr("Sftp service")}
|
||||
};
|
||||
}
|
||||
|
||||
QMap<amnezia::Protocol, QString> ProtocolProps::protocolDescriptions()
|
||||
QMap<amnezia::Proto, QString> ProtocolProps::protocolDescriptions()
|
||||
{
|
||||
return {};
|
||||
}
|
||||
|
||||
amnezia::ServiceType ProtocolProps::protocolService(Protocol p)
|
||||
amnezia::ServiceType ProtocolProps::protocolService(Proto p)
|
||||
{
|
||||
switch (p) {
|
||||
case Protocol::Any : return ServiceType::None;
|
||||
case Protocol::OpenVpn : return ServiceType::Vpn;
|
||||
case Protocol::Cloak : return ServiceType::Vpn;
|
||||
case Protocol::ShadowSocks : return ServiceType::Vpn;
|
||||
case Protocol::WireGuard : return ServiceType::Vpn;
|
||||
case Protocol::TorWebSite : return ServiceType::Other;
|
||||
case Protocol::Dns : return ServiceType::Other;
|
||||
case Protocol::FileShare : return ServiceType::Other;
|
||||
case Proto::Any : return ServiceType::None;
|
||||
case Proto::OpenVpn : return ServiceType::Vpn;
|
||||
case Proto::Cloak : return ServiceType::Vpn;
|
||||
case Proto::ShadowSocks : return ServiceType::Vpn;
|
||||
case Proto::WireGuard : return ServiceType::Vpn;
|
||||
case Proto::TorWebSite : return ServiceType::Other;
|
||||
case Proto::Dns : return ServiceType::Other;
|
||||
case Proto::FileShare : return ServiceType::Other;
|
||||
default: return ServiceType::Other;
|
||||
}
|
||||
}
|
||||
|
||||
int ProtocolProps::defaultPort(Protocol p)
|
||||
int ProtocolProps::defaultPort(Proto p)
|
||||
{
|
||||
switch (p) {
|
||||
case Protocol::Any : return -1;
|
||||
case Protocol::OpenVpn : return 1194;
|
||||
case Protocol::Cloak : return 443;
|
||||
case Protocol::ShadowSocks : return 6789;
|
||||
case Protocol::WireGuard : return 51820;
|
||||
case Protocol::Ikev2 : return -1;
|
||||
case Protocol::L2tp : return -1;
|
||||
case Proto::Any : return -1;
|
||||
case Proto::OpenVpn : return 1194;
|
||||
case Proto::Cloak : return 443;
|
||||
case Proto::ShadowSocks : return 6789;
|
||||
case Proto::WireGuard : return 51820;
|
||||
case Proto::Ikev2 : return -1;
|
||||
case Proto::L2tp : return -1;
|
||||
|
||||
case Protocol::TorWebSite : return -1;
|
||||
case Protocol::Dns : return 53;
|
||||
case Protocol::FileShare : return 139;
|
||||
case Protocol::Sftp : return 222;
|
||||
case Proto::TorWebSite : return -1;
|
||||
case Proto::Dns : return 53;
|
||||
case Proto::FileShare : return 139;
|
||||
case Proto::Sftp : return 222;
|
||||
default: return -1;
|
||||
}
|
||||
}
|
||||
|
||||
bool ProtocolProps::defaultPortChangeable(Protocol p)
|
||||
bool ProtocolProps::defaultPortChangeable(Proto p)
|
||||
{
|
||||
switch (p) {
|
||||
case Protocol::Any : return false;
|
||||
case Protocol::OpenVpn : return true;
|
||||
case Protocol::Cloak : return true;
|
||||
case Protocol::ShadowSocks : return true;
|
||||
case Protocol::WireGuard : return true;
|
||||
case Protocol::Ikev2 : return false;
|
||||
case Protocol::L2tp : return false;
|
||||
case Proto::Any : return false;
|
||||
case Proto::OpenVpn : return true;
|
||||
case Proto::Cloak : return true;
|
||||
case Proto::ShadowSocks : return true;
|
||||
case Proto::WireGuard : return true;
|
||||
case Proto::Ikev2 : return false;
|
||||
case Proto::L2tp : return false;
|
||||
|
||||
|
||||
case Protocol::TorWebSite : return true;
|
||||
case Protocol::Dns : return false;
|
||||
case Protocol::FileShare : return false;
|
||||
case Proto::TorWebSite : return true;
|
||||
case Proto::Dns : return false;
|
||||
case Proto::FileShare : return false;
|
||||
default: return -1;
|
||||
}
|
||||
}
|
||||
|
||||
TransportProto ProtocolProps::defaultTransportProto(Protocol p)
|
||||
TransportProto ProtocolProps::defaultTransportProto(Proto p)
|
||||
{
|
||||
switch (p) {
|
||||
case Protocol::Any : return TransportProto::Udp;
|
||||
case Protocol::OpenVpn : return TransportProto::Udp;
|
||||
case Protocol::Cloak : return TransportProto::Tcp;
|
||||
case Protocol::ShadowSocks : return TransportProto::Tcp;
|
||||
case Protocol::WireGuard : return TransportProto::Udp;
|
||||
case Protocol::Ikev2 : return TransportProto::Udp;
|
||||
case Protocol::L2tp : return TransportProto::Udp;
|
||||
case Proto::Any : return TransportProto::Udp;
|
||||
case Proto::OpenVpn : return TransportProto::Udp;
|
||||
case Proto::Cloak : return TransportProto::Tcp;
|
||||
case Proto::ShadowSocks : return TransportProto::Tcp;
|
||||
case Proto::WireGuard : return TransportProto::Udp;
|
||||
case Proto::Ikev2 : return TransportProto::Udp;
|
||||
case Proto::L2tp : return TransportProto::Udp;
|
||||
// non-vpn
|
||||
case Protocol::TorWebSite : return TransportProto::Tcp;
|
||||
case Protocol::Dns : return TransportProto::Udp;
|
||||
case Protocol::FileShare : return TransportProto::Udp;
|
||||
case Protocol::Sftp : return TransportProto::Tcp;
|
||||
case Proto::TorWebSite : return TransportProto::Tcp;
|
||||
case Proto::Dns : return TransportProto::Udp;
|
||||
case Proto::FileShare : return TransportProto::Udp;
|
||||
case Proto::Sftp : return TransportProto::Tcp;
|
||||
}
|
||||
}
|
||||
|
||||
bool ProtocolProps::defaultTransportProtoChangeable(Protocol p)
|
||||
bool ProtocolProps::defaultTransportProtoChangeable(Proto p)
|
||||
{
|
||||
switch (p) {
|
||||
case Protocol::Any : return false;
|
||||
case Protocol::OpenVpn : return true;
|
||||
case Protocol::Cloak : return false;
|
||||
case Protocol::ShadowSocks : return false;
|
||||
case Protocol::WireGuard : return false;
|
||||
case Protocol::Ikev2 : return false;
|
||||
case Protocol::L2tp : return false;
|
||||
case Proto::Any : return false;
|
||||
case Proto::OpenVpn : return true;
|
||||
case Proto::Cloak : return false;
|
||||
case Proto::ShadowSocks : return false;
|
||||
case Proto::WireGuard : return false;
|
||||
case Proto::Ikev2 : return false;
|
||||
case Proto::L2tp : return false;
|
||||
// non-vpn
|
||||
case Protocol::TorWebSite : return false;
|
||||
case Protocol::Dns : return false;
|
||||
case Protocol::FileShare : return false;
|
||||
case Protocol::Sftp : return false;
|
||||
case Proto::TorWebSite : return false;
|
||||
case Proto::Dns : return false;
|
||||
case Proto::FileShare : return false;
|
||||
case Proto::Sftp : return false;
|
||||
default: return false;
|
||||
}
|
||||
}
|
||||
|
||||
QString ProtocolProps::key_proto_config_data(Protocol p)
|
||||
QString ProtocolProps::key_proto_config_data(Proto p)
|
||||
{
|
||||
return protoToString(p) + "_config_data";
|
||||
}
|
||||
|
||||
QString ProtocolProps::key_proto_config_path(Protocol p)
|
||||
QString ProtocolProps::key_proto_config_path(Proto p)
|
||||
{
|
||||
return protoToString(p) + "_config_path";
|
||||
}
|
||||
|
|
|
@ -24,7 +24,7 @@ constexpr char containers[] = "containers";
|
|||
constexpr char container[] = "container";
|
||||
constexpr char defaultContainer[] = "defaultContainer";
|
||||
|
||||
constexpr char protocol[] = "protocol";
|
||||
constexpr char vpnproto[] = "protocol";
|
||||
constexpr char protocols[] = "protocols";
|
||||
|
||||
constexpr char remote[] = "remote";
|
||||
|
@ -121,7 +121,7 @@ enum TransportProto {
|
|||
};
|
||||
Q_ENUM_NS(TransportProto)
|
||||
|
||||
enum Protocol {
|
||||
enum Proto {
|
||||
Any = 0,
|
||||
OpenVpn,
|
||||
ShadowSocks,
|
||||
|
@ -136,7 +136,7 @@ enum Protocol {
|
|||
FileShare,
|
||||
Sftp
|
||||
};
|
||||
Q_ENUM_NS(Protocol)
|
||||
Q_ENUM_NS(Proto)
|
||||
|
||||
enum ServiceType {
|
||||
None = 0,
|
||||
|
@ -153,29 +153,29 @@ class ProtocolProps : public QObject
|
|||
Q_OBJECT
|
||||
|
||||
public:
|
||||
Q_INVOKABLE static QList<Protocol> allProtocols();
|
||||
Q_INVOKABLE static QList<Proto> allProtocols();
|
||||
|
||||
// spelling may differ for various protocols - TCP for OpenVPN, tcp for others
|
||||
Q_INVOKABLE static TransportProto transportProtoFromString(QString p);
|
||||
Q_INVOKABLE static QString transportProtoToString(TransportProto proto, Protocol p = Protocol::Any);
|
||||
Q_INVOKABLE static QString transportProtoToString(TransportProto proto, Proto p = Proto::Any);
|
||||
|
||||
Q_INVOKABLE static Protocol protoFromString(QString p);
|
||||
Q_INVOKABLE static QString protoToString(Protocol p);
|
||||
Q_INVOKABLE static Proto protoFromString(QString p);
|
||||
Q_INVOKABLE static QString protoToString(Proto p);
|
||||
|
||||
Q_INVOKABLE static QMap<Protocol, QString> protocolHumanNames();
|
||||
Q_INVOKABLE static QMap<Protocol, QString> protocolDescriptions();
|
||||
Q_INVOKABLE static QMap<Proto, QString> protocolHumanNames();
|
||||
Q_INVOKABLE static QMap<Proto, QString> protocolDescriptions();
|
||||
|
||||
Q_INVOKABLE static ServiceType protocolService(Protocol p);
|
||||
Q_INVOKABLE static ServiceType protocolService(Proto p);
|
||||
|
||||
Q_INVOKABLE static int defaultPort(Protocol p);
|
||||
Q_INVOKABLE static bool defaultPortChangeable(Protocol p);
|
||||
Q_INVOKABLE static int defaultPort(Proto p);
|
||||
Q_INVOKABLE static bool defaultPortChangeable(Proto p);
|
||||
|
||||
Q_INVOKABLE static TransportProto defaultTransportProto(Protocol p);
|
||||
Q_INVOKABLE static bool defaultTransportProtoChangeable(Protocol p);
|
||||
Q_INVOKABLE static TransportProto defaultTransportProto(Proto p);
|
||||
Q_INVOKABLE static bool defaultTransportProtoChangeable(Proto p);
|
||||
|
||||
|
||||
Q_INVOKABLE static QString key_proto_config_data(Protocol p);
|
||||
Q_INVOKABLE static QString key_proto_config_path(Protocol p);
|
||||
Q_INVOKABLE static QString key_proto_config_data(Proto p);
|
||||
Q_INVOKABLE static QString key_proto_config_path(Proto p);
|
||||
|
||||
};
|
||||
|
||||
|
@ -207,6 +207,6 @@ static void declareQmlProtocolEnum() {
|
|||
|
||||
} // namespace amnezia
|
||||
|
||||
QDebug operator<<(QDebug debug, const amnezia::Protocol &p);
|
||||
QDebug operator<<(QDebug debug, const amnezia::Proto &p);
|
||||
|
||||
#endif // PROTOCOLS_DEFS_H
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
|
||||
VpnProtocol::VpnProtocol(const QJsonObject &configuration, QObject* parent)
|
||||
: QObject(parent),
|
||||
m_connectionState(ConnectionState::Unknown),
|
||||
m_connectionState(VpnConnectionState::Unknown),
|
||||
m_rawConfig(configuration),
|
||||
m_timeoutTimer(new QTimer(this)),
|
||||
m_receivedBytes(0),
|
||||
|
@ -29,7 +29,7 @@ void VpnProtocol::setLastError(ErrorCode lastError)
|
|||
{
|
||||
m_lastError = lastError;
|
||||
if (lastError){
|
||||
setConnectionState(ConnectionState::Error);
|
||||
setConnectionState(VpnConnectionState::Error);
|
||||
}
|
||||
qCritical().noquote() << "VpnProtocol error, code" << m_lastError << errorString(m_lastError);
|
||||
}
|
||||
|
@ -57,7 +57,7 @@ void VpnProtocol::stopTimeoutTimer()
|
|||
m_timeoutTimer->stop();
|
||||
}
|
||||
|
||||
VpnProtocol::ConnectionState VpnProtocol::connectionState() const
|
||||
VpnProtocol::VpnConnectionState VpnProtocol::connectionState() const
|
||||
{
|
||||
return m_connectionState;
|
||||
}
|
||||
|
@ -70,19 +70,19 @@ void VpnProtocol::setBytesChanged(quint64 receivedBytes, quint64 sentBytes)
|
|||
m_sentBytes = sentBytes;
|
||||
}
|
||||
|
||||
void VpnProtocol::setConnectionState(VpnProtocol::ConnectionState state)
|
||||
void VpnProtocol::setConnectionState(VpnProtocol::VpnConnectionState state)
|
||||
{
|
||||
qDebug() << "VpnProtocol::setConnectionState" << textConnectionState(state);
|
||||
|
||||
if (m_connectionState == state) {
|
||||
return;
|
||||
}
|
||||
if (m_connectionState == ConnectionState::Disconnected && state == ConnectionState::Disconnecting) {
|
||||
if (m_connectionState == VpnConnectionState::Disconnected && state == VpnConnectionState::Disconnecting) {
|
||||
return;
|
||||
}
|
||||
|
||||
m_connectionState = state;
|
||||
if (m_connectionState == ConnectionState::Disconnected) {
|
||||
if (m_connectionState == VpnConnectionState::Disconnected) {
|
||||
m_receivedBytes = 0;
|
||||
m_sentBytes = 0;
|
||||
}
|
||||
|
@ -116,17 +116,17 @@ QString VpnProtocol::routeGateway() const
|
|||
return m_routeGateway;
|
||||
}
|
||||
|
||||
QString VpnProtocol::textConnectionState(ConnectionState connectionState)
|
||||
QString VpnProtocol::textConnectionState(VpnConnectionState connectionState)
|
||||
{
|
||||
switch (connectionState) {
|
||||
case ConnectionState::Unknown: return tr("Unknown");
|
||||
case ConnectionState::Disconnected: return tr("Disconnected");
|
||||
case ConnectionState::Preparing: return tr("Preparing");
|
||||
case ConnectionState::Connecting: return tr("Connecting...");
|
||||
case ConnectionState::Connected: return tr("Connected");
|
||||
case ConnectionState::Disconnecting: return tr("Disconnecting...");
|
||||
case ConnectionState::Reconnecting: return tr("Reconnecting...");
|
||||
case ConnectionState::Error: return tr("Error");
|
||||
case VpnConnectionState::Unknown: return tr("Unknown");
|
||||
case VpnConnectionState::Disconnected: return tr("Disconnected");
|
||||
case VpnConnectionState::Preparing: return tr("Preparing");
|
||||
case VpnConnectionState::Connecting: return tr("Connecting...");
|
||||
case VpnConnectionState::Connected: return tr("Connected");
|
||||
case VpnConnectionState::Disconnecting: return tr("Disconnecting...");
|
||||
case VpnConnectionState::Reconnecting: return tr("Reconnecting...");
|
||||
case VpnConnectionState::Error: return tr("Error");
|
||||
default:
|
||||
;
|
||||
}
|
||||
|
@ -141,10 +141,10 @@ QString VpnProtocol::textConnectionState() const
|
|||
|
||||
bool VpnProtocol::isConnected() const
|
||||
{
|
||||
return m_connectionState == ConnectionState::Connected;
|
||||
return m_connectionState == VpnConnectionState::Connected;
|
||||
}
|
||||
|
||||
bool VpnProtocol::isDisconnected() const
|
||||
{
|
||||
return m_connectionState == ConnectionState::Disconnected;
|
||||
return m_connectionState == VpnConnectionState::Disconnected;
|
||||
}
|
||||
|
|
|
@ -20,10 +20,10 @@ public:
|
|||
explicit VpnProtocol(const QJsonObject& configuration, QObject* parent = nullptr);
|
||||
virtual ~VpnProtocol() override = default;
|
||||
|
||||
enum ConnectionState {Unknown, Disconnected, Preparing, Connecting, Connected, Disconnecting, Reconnecting, Error};
|
||||
Q_ENUM(ConnectionState)
|
||||
enum VpnConnectionState {Unknown, Disconnected, Preparing, Connecting, Connected, Disconnecting, Reconnecting, Error};
|
||||
Q_ENUM(VpnConnectionState)
|
||||
|
||||
static QString textConnectionState(ConnectionState connectionState);
|
||||
static QString textConnectionState(VpnConnectionState connectionState);
|
||||
|
||||
virtual ErrorCode prepare() { return ErrorCode::NoError; }
|
||||
|
||||
|
@ -32,7 +32,7 @@ public:
|
|||
virtual ErrorCode start() = 0;
|
||||
virtual void stop() = 0;
|
||||
|
||||
ConnectionState connectionState() const;
|
||||
VpnConnectionState connectionState() const;
|
||||
ErrorCode lastError() const;
|
||||
QString textConnectionState() const;
|
||||
void setLastError(ErrorCode lastError);
|
||||
|
@ -44,7 +44,7 @@ public:
|
|||
|
||||
signals:
|
||||
void bytesChanged(quint64 receivedBytes, quint64 sentBytes);
|
||||
void connectionStateChanged(VpnProtocol::ConnectionState state);
|
||||
void connectionStateChanged(VpnProtocol::VpnConnectionState state);
|
||||
void timeoutTimerEvent();
|
||||
void protocolError(amnezia::ErrorCode e);
|
||||
|
||||
|
@ -63,9 +63,9 @@ protected:
|
|||
void stopTimeoutTimer();
|
||||
|
||||
virtual void setBytesChanged(quint64 receivedBytes, quint64 sentBytes);
|
||||
virtual void setConnectionState(VpnProtocol::ConnectionState state);
|
||||
virtual void setConnectionState(VpnProtocol::VpnConnectionState state);
|
||||
|
||||
ConnectionState m_connectionState;
|
||||
VpnConnectionState m_connectionState;
|
||||
QString m_routeGateway;
|
||||
QString m_vpnLocalAddress;
|
||||
QString m_vpnGateway;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue