Compare commits
14 Commits
dev-killsw
...
dev-netada
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0d0c29493b | ||
|
|
4abfc58ad0 | ||
|
|
5245fe103c | ||
|
|
3dd207a3a1 | ||
|
|
1a16a61ced | ||
|
|
340639b3c8 | ||
|
|
dd427f89bc | ||
|
|
051487d6ef | ||
|
|
97d3b92988 | ||
|
|
8262d743d8 | ||
|
|
18654ca4ef | ||
|
|
44bc831b7f | ||
|
|
3424068993 | ||
|
|
90a92bea1b |
1
.gitignore
vendored
@@ -47,7 +47,6 @@ client/amneziavpn_qml_plugin_import.cpp
|
||||
client/qmlcache_loader.cpp
|
||||
client/rep_ipc_interface_replica.h
|
||||
client/resources_qmlcache.qrc
|
||||
client/3rd/OpenVPNAdpter/build/
|
||||
|
||||
# QtCreator
|
||||
|
||||
|
||||
6
.gitmodules
vendored
@@ -7,9 +7,3 @@
|
||||
[submodule "client/3rd/wireguard-apple"]
|
||||
path = client/3rd/wireguard-apple
|
||||
url = https://github.com/WireGuard/wireguard-apple
|
||||
[submodule "client/3rd/OpenVPNAdapter"]
|
||||
path = client/3rd/OpenVPNAdapter
|
||||
url = https://github.com/ss-abramchuk/OpenVPNAdapter.git
|
||||
[submodule "client/3rd/qzxing"]
|
||||
path = client/3rd/qzxing
|
||||
url = https://github.com/ftylitak/qzxing.git
|
||||
|
||||
7
client/3rd/AdpInfo/adpinfo.pri
Normal file
@@ -0,0 +1,7 @@
|
||||
HEADERS += \
|
||||
3rd/AdpInfo/netadpinfo.h \
|
||||
|
||||
win32: {
|
||||
SOURCES += \
|
||||
3rd/AdpInfo/win_netadpinfo.cc \
|
||||
}
|
||||
71
client/3rd/AdpInfo/netadpinfo.h
Normal file
@@ -0,0 +1,71 @@
|
||||
#pragma once
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <tuple>
|
||||
#include <memory>
|
||||
|
||||
|
||||
namespace adpinfo{
|
||||
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
// {false,""} - no error
|
||||
// {true,"descr"} - error with description
|
||||
using RET_TYPE = std::tuple<bool, std::string>;
|
||||
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
/*
|
||||
* Getting the route table
|
||||
*/
|
||||
typedef struct route_table{
|
||||
std::string szDestIp{};
|
||||
std::string szMaskIp{};
|
||||
std::string szGatewayIp{};
|
||||
std::string szInterfaceIp{};
|
||||
unsigned long ulIfIndex{};
|
||||
}route_table;
|
||||
std::vector</*std::tuple<std::string,std::string,std::string,std::string>*/route_table>get_route_table(std::string_view);
|
||||
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
/*
|
||||
* The object uses for collect the information about active network adapters/interfaces
|
||||
*/
|
||||
class NetAdpInfo final{
|
||||
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
class Adapter{
|
||||
std::string name{};
|
||||
std::string descr{};
|
||||
std::string route{};
|
||||
std::string address{};
|
||||
std::string gateway{};
|
||||
public:
|
||||
explicit Adapter() = default;
|
||||
~Adapter() = default;
|
||||
|
||||
void set_name(std::string_view);
|
||||
std::string_view get_name()const;
|
||||
void set_description(std::string_view);
|
||||
std::string_view get_description()const;
|
||||
void set_route_gateway(std::string_view);
|
||||
std::string_view get_route_gateway()const;
|
||||
void set_local_address(std::string_view);
|
||||
std::string_view get_local_address()const;
|
||||
void set_local_gateway(std::string_view);
|
||||
std::string_view get_local_gateway()const;
|
||||
};
|
||||
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
int16_t _index_of_adapter{};
|
||||
std::vector<std::shared_ptr<Adapter>>_adapters{};
|
||||
|
||||
RET_TYPE collect_adapters_data();
|
||||
|
||||
public:
|
||||
explicit NetAdpInfo() = default;
|
||||
~NetAdpInfo() = default;
|
||||
|
||||
RET_TYPE get_adapter_info(std::string_view );
|
||||
std::string_view get_adapter_route_gateway()const;
|
||||
std::string_view get_adapter_local_address()const;
|
||||
std::string_view get_adapter_local_gateway()const;
|
||||
|
||||
};
|
||||
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
} //end namespace
|
||||
321
client/3rd/AdpInfo/win_netadpinfo.cc
Normal file
@@ -0,0 +1,321 @@
|
||||
#include "netadpinfo.h"
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
#include <algorithm>
|
||||
#include <iterator>
|
||||
#include <cassert>
|
||||
|
||||
#include <windows.h>
|
||||
#include <iphlpapi.h>
|
||||
|
||||
#pragma comment(lib, "iphlpapi.lib")
|
||||
|
||||
|
||||
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
//static std::string convert_wide_to_ansi(const std::wstring& widestring) {
|
||||
// auto nchars = WideCharToMultiByte(
|
||||
// CP_ACP,
|
||||
// 0,
|
||||
// widestring.c_str(),
|
||||
// static_cast<int>(widestring.length() + 1),
|
||||
// nullptr,
|
||||
// 0,
|
||||
// nullptr,
|
||||
// nullptr);
|
||||
// std::string converted_string{};
|
||||
// converted_string.resize(nchars);
|
||||
// WideCharToMultiByte(CP_ACP,
|
||||
// 0,
|
||||
// widestring.c_str(),
|
||||
// -1,
|
||||
// &converted_string[0],
|
||||
// static_cast<int>(widestring.length()),
|
||||
// nullptr,
|
||||
// nullptr);
|
||||
// return converted_string;
|
||||
//}
|
||||
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
//static std::string get_founded_route(std::string_view ip_address){
|
||||
|
||||
// MIB_IPFORWARDROW br{0};
|
||||
// ZeroMemory(&br, sizeof(MIB_IPFORWARDROW));
|
||||
// struct in_addr ia;
|
||||
// std::string sTmp{};
|
||||
// DWORD dwRes = GetBestRoute(inet_addr(ip_address.data()), 0, &br);
|
||||
// if( dwRes == NO_ERROR ){
|
||||
// ia.S_un.S_addr = (u_long) br.dwForwardDest;
|
||||
// sTmp = inet_ntoa(ia);
|
||||
// qDebug()<<"Best Route:"<< sTmp.data();
|
||||
// }
|
||||
// return sTmp;
|
||||
//}
|
||||
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
static std::string get_route_gateway()
|
||||
{
|
||||
std::string route_gateway{};
|
||||
PMIB_IPFORWARDTABLE pIpForwardTable{nullptr};
|
||||
DWORD dwSize = 0;
|
||||
BOOL bOrder = FALSE;
|
||||
|
||||
struct in_addr IpAddr;
|
||||
char szGatewayIp[128]{'\0'};
|
||||
|
||||
DWORD dwStatus = GetIpForwardTable(pIpForwardTable, &dwSize, bOrder);
|
||||
if (dwStatus == ERROR_INSUFFICIENT_BUFFER) {
|
||||
if (!(pIpForwardTable = (PMIB_IPFORWARDTABLE) malloc(dwSize))) {
|
||||
return {"Out of memory"};
|
||||
}
|
||||
dwStatus = GetIpForwardTable(pIpForwardTable, &dwSize, bOrder);
|
||||
}
|
||||
if (dwStatus != ERROR_SUCCESS) {
|
||||
if (pIpForwardTable)
|
||||
free(pIpForwardTable);
|
||||
return {"getIpForwardTable failed"};
|
||||
}
|
||||
const DWORD end = pIpForwardTable->dwNumEntries;
|
||||
for (DWORD i = 0; i < end; i++) {
|
||||
if (pIpForwardTable->table[i].dwForwardDest == 0) {
|
||||
IpAddr.S_un.S_addr =
|
||||
(u_long) pIpForwardTable->table[i].dwForwardNextHop;
|
||||
strcpy_s(szGatewayIp, sizeof (szGatewayIp), inet_ntoa(IpAddr));
|
||||
route_gateway = std::string(szGatewayIp);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (pIpForwardTable)
|
||||
free(pIpForwardTable);
|
||||
|
||||
return route_gateway;
|
||||
}
|
||||
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
static std::string get_interface_ip(DWORD index){
|
||||
std::string _ipaddr{'\0'};
|
||||
std::vector<BYTE> buffer{};
|
||||
IP_ADAPTER_INFO *adapter_info{nullptr};
|
||||
DWORD result{ERROR_BUFFER_OVERFLOW};
|
||||
ULONG buffer_len = sizeof(IP_ADAPTER_INFO) * 10;
|
||||
while (result == ERROR_BUFFER_OVERFLOW){
|
||||
buffer.resize(buffer_len);
|
||||
adapter_info = reinterpret_cast<IP_ADAPTER_INFO*>(&buffer[0]);
|
||||
result = GetAdaptersInfo(adapter_info, &buffer_len);
|
||||
if (result == ERROR_NO_DATA){
|
||||
return _ipaddr;
|
||||
}
|
||||
}//end while
|
||||
if (result != NO_ERROR){
|
||||
return _ipaddr;
|
||||
}
|
||||
IP_ADAPTER_INFO *adapter_iterator = adapter_info;
|
||||
while(adapter_iterator){
|
||||
if (adapter_iterator->Index == index)
|
||||
break;
|
||||
adapter_iterator = adapter_iterator->Next;
|
||||
}//end while
|
||||
if ( adapter_iterator != nullptr || adapter_iterator != 0x0 || adapter_iterator != NULL )
|
||||
_ipaddr = std::string(adapter_iterator->IpAddressList.IpAddress.String, 16);
|
||||
else
|
||||
_ipaddr = "127.0.0.1";
|
||||
return _ipaddr;
|
||||
}
|
||||
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
namespace adpinfo {
|
||||
|
||||
std::vector<route_table>get_route_table(std::string_view ipifaddrs){
|
||||
|
||||
/*std::tuple<std::string, std::string, std::string, std::string >*/
|
||||
std::vector<route_table>ret_table{};
|
||||
PMIB_IPFORWARDTABLE p_table{nullptr};
|
||||
struct in_addr ip_addr{};
|
||||
DWORD size{};
|
||||
p_table = (MIB_IPFORWARDTABLE *) HeapAlloc(GetProcessHeap(), 0, (sizeof (MIB_IPFORWARDTABLE)));
|
||||
if (p_table == nullptr)
|
||||
{
|
||||
return ret_table;
|
||||
}
|
||||
if (GetIpForwardTable(p_table, &size, 0) == ERROR_INSUFFICIENT_BUFFER) {
|
||||
HeapFree(GetProcessHeap(), 0, p_table);
|
||||
p_table = (MIB_IPFORWARDTABLE *) HeapAlloc(GetProcessHeap(), 0, size);
|
||||
if (p_table == nullptr) {
|
||||
return ret_table;
|
||||
}
|
||||
}
|
||||
DWORD ret = GetIpForwardTable(p_table, &size, 0);
|
||||
if (ret == NO_ERROR) {
|
||||
const int &numEntries = static_cast<int>(p_table->dwNumEntries);
|
||||
for (int i = 0; i <numEntries; ++i) {
|
||||
char szDestIp[128]{};
|
||||
char szMaskIp[128]{};
|
||||
char szGatewayIp[128]{};
|
||||
char szInterfaceIp[21]{};
|
||||
ip_addr.S_un.S_addr = (u_long) p_table->table[i].dwForwardDest;
|
||||
strcpy_s(szDestIp, sizeof (szDestIp), inet_ntoa(ip_addr));
|
||||
ip_addr.S_un.S_addr = (u_long) p_table->table[i].dwForwardMask;
|
||||
strcpy_s(szMaskIp, sizeof (szMaskIp), inet_ntoa(ip_addr));
|
||||
ip_addr.S_un.S_addr = (u_long) p_table->table[i].dwForwardNextHop;
|
||||
strcpy_s(szGatewayIp, sizeof (szGatewayIp), inet_ntoa(ip_addr));
|
||||
const auto &ifname = get_interface_ip(p_table->table[i].dwForwardIfIndex);
|
||||
const auto &ifnameSize = ifname.length() + 1;
|
||||
strcpy_s(szInterfaceIp, ifnameSize, ifname.data());
|
||||
if (ipifaddrs.length() == 0){
|
||||
//std::make_tuple(std::string(szDestIp), std::string(szMaskIp), std::string(szGatewayIp), std::string(szInterfaceIp));
|
||||
const route_table &mt = {
|
||||
std::string(szDestIp),
|
||||
std::string(szMaskIp),
|
||||
std::string(szGatewayIp),
|
||||
std::string(szInterfaceIp),
|
||||
p_table->table[i].dwForwardIfIndex
|
||||
};
|
||||
ret_table.emplace_back(mt);
|
||||
}else{
|
||||
bool in_not_empty = (ifname.find(ipifaddrs) != std::string::npos);
|
||||
//bool in_as_destIp = ( std::string(szDestIp).find(ipifaddrs) != std::string::npos);
|
||||
bool destIp_as_zero = (std::string(szDestIp).find("0.0.0.0") != std::string::npos);
|
||||
bool mask_as_zero = (std::string(szMaskIp).find("0.0.0.0") != std::string::npos);
|
||||
// bool ip_the_same = (
|
||||
// std::string(szDestIp).find(ipifaddrs) != std::string::npos &&
|
||||
// std::string(szDestIp).find(szGatewayIp) != std::string::npos &&
|
||||
// std::string(szDestIp).find(szInterfaceIp) != std::string::npos
|
||||
// );
|
||||
// bool not_default = (std::string(szDestIp).find("127.0.0.1") == std::string::npos);
|
||||
|
||||
if ( in_not_empty &&
|
||||
// in_as_destIp &&
|
||||
destIp_as_zero &&
|
||||
mask_as_zero//) || ( ip_the_same && not_default )
|
||||
)
|
||||
{
|
||||
// finded
|
||||
const route_table &mt = {
|
||||
std::string(szDestIp),
|
||||
std::string(szMaskIp),
|
||||
std::string(szGatewayIp),
|
||||
std::string(szInterfaceIp),
|
||||
p_table->table[i].dwForwardIfIndex
|
||||
};//std::make_tuple(std::string(szDestIp), std::string(szMaskIp), std::string(szGatewayIp), std::string(szInterfaceIp));
|
||||
ret_table.emplace_back(mt);
|
||||
}
|
||||
}
|
||||
}//end for
|
||||
}//end if
|
||||
return ret_table;
|
||||
}
|
||||
}//end namespace adpinfo
|
||||
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
namespace adpinfo {
|
||||
|
||||
void NetAdpInfo::Adapter::set_name(std::string_view value){
|
||||
name = value;
|
||||
}
|
||||
std::string_view NetAdpInfo::Adapter::get_name()const{
|
||||
|
||||
return name;
|
||||
}
|
||||
void NetAdpInfo::Adapter::set_description(std::string_view value){
|
||||
descr = value;
|
||||
}
|
||||
std::string_view NetAdpInfo::Adapter::get_description()const{
|
||||
return descr;
|
||||
}
|
||||
void NetAdpInfo::Adapter::set_route_gateway(std::string_view value){
|
||||
route = value;
|
||||
}
|
||||
std::string_view NetAdpInfo::Adapter::get_route_gateway()const{
|
||||
return route;
|
||||
|
||||
}
|
||||
void NetAdpInfo::Adapter::set_local_address(std::string_view value){
|
||||
address = value;
|
||||
}
|
||||
std::string_view NetAdpInfo::Adapter::get_local_address()const{
|
||||
return address;
|
||||
}
|
||||
void NetAdpInfo::Adapter::set_local_gateway(std::string_view value){
|
||||
gateway = value;
|
||||
}
|
||||
std::string_view NetAdpInfo::Adapter::get_local_gateway()const{
|
||||
return gateway;
|
||||
}
|
||||
|
||||
RET_TYPE NetAdpInfo::collect_adapters_data(){
|
||||
_adapters.clear();
|
||||
std::vector<BYTE> buffer{};
|
||||
IP_ADAPTER_INFO *adapter_info{nullptr};
|
||||
DWORD result{ERROR_BUFFER_OVERFLOW};
|
||||
ULONG buffer_len = sizeof(IP_ADAPTER_INFO) * 10;
|
||||
while (result == ERROR_BUFFER_OVERFLOW){
|
||||
buffer.resize(buffer_len);
|
||||
adapter_info = reinterpret_cast<IP_ADAPTER_INFO*>(&buffer[0]);
|
||||
result = GetAdaptersInfo(adapter_info, &buffer_len);
|
||||
if (result == ERROR_NO_DATA){
|
||||
return {true, "GetAdaptersInfo return ERROR_NO_DATA"};
|
||||
}
|
||||
}//end while
|
||||
if (result != NO_ERROR){
|
||||
const std::string &error = "GetAdaptersInfo failed :" + std::to_string(result);
|
||||
return {true, error};
|
||||
}
|
||||
IP_ADAPTER_INFO *adapter_iterator = adapter_info;
|
||||
while(adapter_iterator){
|
||||
std::shared_ptr<Adapter>_tmp{std::make_shared<Adapter>()};
|
||||
_tmp->set_name(adapter_iterator->AdapterName);
|
||||
_tmp->set_description(adapter_iterator->Description);
|
||||
_tmp->set_local_address(adapter_iterator->IpAddressList.IpAddress.String);
|
||||
std::string lgw = adapter_iterator->GatewayList.IpAddress.String;
|
||||
// if (lgw.length() == 0 || lgw.find("0.0.0.0") != std::string::npos)
|
||||
// {
|
||||
// //lgw = get_founded_route("8.8.8.8");
|
||||
// if (adapter_iterator->DhcpEnabled == 1)
|
||||
// {
|
||||
// lgw = adapter_iterator->DhcpServer.IpAddress.String;
|
||||
// }
|
||||
// }
|
||||
_tmp->set_local_gateway(lgw);
|
||||
_tmp->set_route_gateway(get_route_gateway());
|
||||
_adapters.emplace_back(_tmp);
|
||||
adapter_iterator = adapter_iterator->Next;
|
||||
}
|
||||
return {false, ""};
|
||||
}
|
||||
|
||||
RET_TYPE NetAdpInfo::get_adapter_info(std::string_view _adapter_name){
|
||||
|
||||
_index_of_adapter = -1;
|
||||
const auto result{collect_adapters_data()};
|
||||
if (std::get<0>(result) == true){
|
||||
_index_of_adapter = -1;
|
||||
return result;
|
||||
}
|
||||
const int16_t &len = static_cast<int16_t>(_adapters.size());
|
||||
for (auto i = 0; i< len; ++i){
|
||||
auto adap_name = _adapters[i]->get_name();
|
||||
auto adap_desc = _adapters[i]->get_description();
|
||||
if ( adap_name.find(_adapter_name) != std::string::npos || adap_desc.find(_adapter_name) != std::string::npos ){
|
||||
_index_of_adapter = i;
|
||||
return {false, ""};
|
||||
}
|
||||
}
|
||||
return {true, "adapters no founded"};
|
||||
}
|
||||
|
||||
std::string_view NetAdpInfo::get_adapter_route_gateway()const{
|
||||
if (_index_of_adapter < 0)
|
||||
return "error adapter index";
|
||||
return _adapters.at(_index_of_adapter)->get_route_gateway();
|
||||
}
|
||||
std::string_view NetAdpInfo::get_adapter_local_address()const{
|
||||
if (_index_of_adapter < 0)
|
||||
return "error adapter index";
|
||||
return _adapters.at(_index_of_adapter)->get_local_address();
|
||||
}
|
||||
std::string_view NetAdpInfo::get_adapter_local_gateway()const{
|
||||
if (_index_of_adapter < 0)
|
||||
return "error adapter index";
|
||||
return _adapters.at(_index_of_adapter)->get_local_gateway();
|
||||
}
|
||||
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
//std::string NetAdpInfo::get_system_route(){
|
||||
// return get_route_gateway();
|
||||
//}
|
||||
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
}// end namespace
|
||||
1802
client/3rd/QRCodeGenerator/QRCodeGenerator.cpp
Normal file
129
client/3rd/QRCodeGenerator/QRCodeGenerator.h
Normal file
@@ -0,0 +1,129 @@
|
||||
|
||||
#if !defined(AFX_QR_ENCODE_H__AC886DF7_C0AE_4C9F_AC7A_FCDA8CB1DD37__INCLUDED_)
|
||||
#define AFX_QR_ENCODE_H__AC886DF7_C0AE_4C9F_AC7A_FCDA8CB1DD37__INCLUDED_
|
||||
|
||||
#if _MSC_VER > 1000
|
||||
#pragma once
|
||||
#endif // _MSC_VER > 1000
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//
|
||||
#define QR_LEVEL_L 0
|
||||
#define QR_LEVEL_M 1
|
||||
#define QR_LEVEL_Q 2
|
||||
#define QR_LEVEL_H 3
|
||||
|
||||
//
|
||||
#define QR_MODE_NUMERAL 0
|
||||
#define QR_MODE_ALPHABET 1
|
||||
#define QR_MODE_8BIT 2
|
||||
#define QR_MODE_KANJI 3
|
||||
|
||||
//
|
||||
#define QR_VRESION_S 0
|
||||
#define QR_VRESION_M 1
|
||||
#define QR_VRESION_L 2
|
||||
|
||||
#define MAX_ALLCODEWORD 3706
|
||||
#define MAX_DATACODEWORD 2956
|
||||
#define MAX_CODEBLOCK 153
|
||||
#define MAX_MODULESIZE 177
|
||||
|
||||
#define QR_MARGIN 0
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
typedef struct tagRS_BLOCKINFO
|
||||
{
|
||||
int ncRSBlock;
|
||||
int ncAllCodeWord;
|
||||
int ncDataCodeWord;
|
||||
|
||||
} RS_BLOCKINFO, *LPRS_BLOCKINFO;
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
typedef struct tagQR_VERSIONINFO
|
||||
{
|
||||
int nVersionNo;
|
||||
int ncAllCodeWord;
|
||||
|
||||
int ncDataCodeWord[4];
|
||||
|
||||
int ncAlignPoint;
|
||||
int nAlignPoint[6];
|
||||
|
||||
RS_BLOCKINFO RS_BlockInfo1[4];
|
||||
RS_BLOCKINFO RS_BlockInfo2[4];
|
||||
|
||||
} QR_VERSIONINFO, *LPQR_VERSIONINFO;
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class CQR_Encode
|
||||
{
|
||||
public:
|
||||
CQR_Encode();
|
||||
~CQR_Encode();
|
||||
|
||||
public:
|
||||
int m_nLevel;
|
||||
int m_nVersion;
|
||||
bool m_bAutoExtent;
|
||||
int m_nMaskingNo;
|
||||
|
||||
public:
|
||||
int m_nSymbleSize;
|
||||
unsigned char m_byModuleData[MAX_MODULESIZE][MAX_MODULESIZE]; // [x][y]
|
||||
|
||||
private:
|
||||
int m_ncDataCodeWordBit;
|
||||
unsigned char m_byDataCodeWord[MAX_DATACODEWORD];
|
||||
|
||||
int m_ncDataBlock;
|
||||
unsigned char m_byBlockMode[MAX_DATACODEWORD];
|
||||
int m_nBlockLength[MAX_DATACODEWORD];
|
||||
|
||||
int m_ncAllCodeWord;
|
||||
unsigned char m_byAllCodeWord[MAX_ALLCODEWORD];
|
||||
unsigned char m_byRSWork[MAX_CODEBLOCK];
|
||||
|
||||
public:
|
||||
bool EncodeData(int nLevel, int nVersion, bool bAutoExtent, int nMaskingNo, const char* lpsSource, int ncSource = 0);
|
||||
|
||||
private:
|
||||
int GetEncodeVersion(int nVersion, const char* lpsSource, int ncLength);
|
||||
bool EncodeSourceData(const char* lpsSource, int ncLength, int nVerGroup);
|
||||
|
||||
int GetBitLength(unsigned char nMode, int ncData, int nVerGroup);
|
||||
|
||||
int SetBitStream(int nIndex, unsigned short wData, int ncData);
|
||||
|
||||
bool IsNumeralData(unsigned char c);
|
||||
bool IsAlphabetData(unsigned char c);
|
||||
bool IsKanjiData(unsigned char c1, unsigned char c2);
|
||||
|
||||
unsigned char AlphabetToBinaly(unsigned char c);
|
||||
unsigned short KanjiToBinaly(unsigned short wc);
|
||||
|
||||
void GetRSCodeWord(unsigned char * lpbyRSWork, int ncDataCodeWord, int ncRSCodeWord);
|
||||
|
||||
private:
|
||||
void FormatModule();
|
||||
|
||||
void SetFunctionModule();
|
||||
void SetFinderPattern(int x, int y);
|
||||
void SetAlignmentPattern(int x, int y);
|
||||
void SetVersionPattern();
|
||||
void SetCodeWordPattern();
|
||||
void SetMaskingPattern(int nPatternNo);
|
||||
void SetFormatInfoPattern(int nPatternNo);
|
||||
int CountPenalty();
|
||||
};
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#endif // !defined(AFX_QR_ENCODE_H__AC886DF7_C0AE_4C9F_AC7A_FCDA8CB1DD37__INCLUDED_)
|
||||
5
client/3rd/QRCodeGenerator/QRCodeGenerator.pri
Normal file
@@ -0,0 +1,5 @@
|
||||
HEADERS += \
|
||||
3rd/QRCodeGenerator/QRCodeGenerator.h \
|
||||
|
||||
SOURCES += \
|
||||
3rd/QRCodeGenerator/QRCodeGenerator.cpp \
|
||||
@@ -11,7 +11,7 @@ win32 {
|
||||
-lcrypt32 \
|
||||
|
||||
!contains(QMAKE_TARGET.arch, x86_64) {
|
||||
INCLUDEPATH += $$PWD/windows/x86
|
||||
INCLUDEPATH += $$PWD/windows/x86_64
|
||||
HEADERS += $$PWD/windows/x86/botan_all.h
|
||||
SOURCES += $$PWD/windows/x86/botan_all.cpp
|
||||
}
|
||||
|
||||
@@ -940,8 +940,8 @@ void SshConnectionPrivate::connectToHost()
|
||||
this, &SshConnectionPrivate::handleSocketConnected);
|
||||
connect(m_socket, &QIODevice::readyRead,
|
||||
this, &SshConnectionPrivate::handleIncomingData);
|
||||
connect(m_socket, &QAbstractSocket::errorOccurred,
|
||||
this, &SshConnectionPrivate::handleSocketError);
|
||||
connect(m_socket, SIGNAL(error(QAbstractSocket::SocketError)), this,
|
||||
SLOT(handleSocketError()));
|
||||
connect(m_socket, &QAbstractSocket::disconnected,
|
||||
this, &SshConnectionPrivate::handleSocketDisconnected);
|
||||
connect(&m_timeoutTimer, &QTimer::timeout, this, &SshConnectionPrivate::handleTimeout);
|
||||
|
||||
@@ -217,9 +217,7 @@ enum ConnectionState : NSInteger;
|
||||
SWIFT_CLASS("_TtC10AmneziaVPN18IOSVpnProtocolImpl")
|
||||
@interface IOSVpnProtocolImpl : NSObject
|
||||
- (nonnull instancetype)initWithBundleID:(NSString * _Nonnull)bundleID privateKey:(NSData * _Nonnull)privateKey deviceIpv4Address:(NSString * _Nonnull)deviceIpv4Address deviceIpv6Address:(NSString * _Nonnull)deviceIpv6Address closure:(void (^ _Nonnull)(enum ConnectionState, NSDate * _Nullable))closure callback:(void (^ _Nonnull)(BOOL))callback OBJC_DESIGNATED_INITIALIZER;
|
||||
- (nonnull instancetype)initWithBundleID:(NSString * _Nonnull)bundleID config:(NSString * _Nonnull)config closure:(void (^ _Nonnull)(enum ConnectionState, NSDate * _Nullable))closure callback:(void (^ _Nonnull)(BOOL))callback;
|
||||
- (void)connectWithDnsServer:(NSString * _Nonnull)dnsServer serverIpv6Gateway:(NSString * _Nonnull)serverIpv6Gateway serverPublicKey:(NSString * _Nonnull)serverPublicKey presharedKey:(NSString * _Nonnull)presharedKey serverIpv4AddrIn:(NSString * _Nonnull)serverIpv4AddrIn serverPort:(NSInteger)serverPort allowedIPAddressRanges:(NSArray<VPNIPAddressRange *> * _Nonnull)allowedIPAddressRanges ipv6Enabled:(Boolean)enabled reason:(NSInteger)reason failureCallback:(void (^ _Nonnull)(void))failureCallback;
|
||||
- (void)connectWithOvpnConfig:(NSString * _Nonnull)ovpnConfig failureCallback:(void (^ _Nonnull)(void))failureCallback;
|
||||
- (void)disconnect;
|
||||
- (void)checkStatusWithCallback:(void (^ _Nonnull)(NSString * _Nonnull, NSString * _Nonnull, NSString * _Nonnull))callback;
|
||||
- (nonnull instancetype)init SWIFT_UNAVAILABLE;
|
||||
@@ -232,6 +230,8 @@ typedef SWIFT_ENUM(NSInteger, ConnectionState, closed) {
|
||||
ConnectionStateDisconnected = 2,
|
||||
};
|
||||
|
||||
|
||||
|
||||
SWIFT_CLASS("_TtC10AmneziaVPN17VPNIPAddressRange")
|
||||
@interface VPNIPAddressRange : NSObject
|
||||
- (nonnull instancetype)initWithAddress:(NSString * _Nonnull)address networkPrefixLength:(uint8_t)networkPrefixLength isIpv6:(BOOL)isIpv6 OBJC_DESIGNATED_INITIALIZER;
|
||||
|
||||
@@ -2,13 +2,12 @@
|
||||
<manifest package="org.amnezia.vpn" xmlns:android="http://schemas.android.com/apk/res/android" android:versionName="-- %%INSERT_VERSION_NAME%% --" android:versionCode="-- %%INSERT_VERSION_CODE%% --" android:installLocation="auto">
|
||||
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
|
||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
|
||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
||||
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
|
||||
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
|
||||
<uses-permission android:name="android.permission.QUERY_ALL_PACKAGES"/>
|
||||
<uses-permission android:name="android.permission.CAMERA"/>
|
||||
|
||||
|
||||
<!-- The following comment will be replaced upon deployment with default features based on the dependencies of the application.
|
||||
Remove the comment if you do not require these default features. -->
|
||||
|
||||
@@ -38,9 +38,13 @@ apply plugin: 'kotlinx-serialization'
|
||||
dependencies {
|
||||
implementation fileTree(dir: 'libs', include: ['*.jar', '*.aar'])
|
||||
implementation 'androidx.core:core-ktx:1.1.0'
|
||||
implementation 'com.android.installreferrer:installreferrer:2.2'
|
||||
implementation 'com.android.billingclient:billing-ktx:4.0.0'
|
||||
implementation "androidx.lifecycle:lifecycle-livedata-ktx:2.4.0-alpha02"
|
||||
implementation "androidx.security:security-crypto:1.1.0-alpha03"
|
||||
implementation "androidx.security:security-identity-credential:1.0.0-alpha02"
|
||||
implementation 'com.adjust.sdk:adjust-android:4.28.2'
|
||||
implementation 'com.google.android.gms:play-services-ads-identifier:17.0.1'
|
||||
implementation "org.jetbrains.kotlinx:kotlinx-serialization-json:1.2.2"
|
||||
coreLibraryDesugaring "com.android.tools:desugar_jdk_libs:1.0.10"
|
||||
}
|
||||
@@ -102,8 +106,8 @@ android {
|
||||
resConfig "en"
|
||||
minSdkVersion = 24
|
||||
targetSdkVersion = 30
|
||||
versionCode 7 // Change to a higher number
|
||||
versionName "2.0.7" // Change to a higher number
|
||||
versionCode 2 // Change to a higher number
|
||||
versionName "2.0.1" // Change to a higher number
|
||||
}
|
||||
|
||||
buildTypes {
|
||||
|
||||
@@ -1,6 +0,0 @@
|
||||
package org.ftylitak.qzxing;
|
||||
|
||||
public class NativeFunctions {
|
||||
public static native void onPermissionsGranted();
|
||||
public static native void onPermissionsDenied();
|
||||
}
|
||||
@@ -1,25 +0,0 @@
|
||||
package org.ftylitak.qzxing;
|
||||
|
||||
import android.Manifest;
|
||||
import android.content.pm.PackageManager;
|
||||
import org.qtproject.qt5.android.bindings.QtActivity;
|
||||
import static org.ftylitak.qzxing.Utilities.REQUEST_CAMERA;
|
||||
|
||||
public class QZXingLiveActivity extends QtActivity {
|
||||
@Override
|
||||
public void onRequestPermissionsResult(int requestCode,
|
||||
String permissions[], int[] grantResults) {
|
||||
switch (requestCode) {
|
||||
case REQUEST_CAMERA: {
|
||||
// If request is cancelled, the result arrays are empty.
|
||||
if (grantResults.length > 0
|
||||
&& grantResults[0] == PackageManager.PERMISSION_GRANTED) {
|
||||
NativeFunctions.onPermissionsGranted();
|
||||
} else {
|
||||
NativeFunctions.onPermissionsDenied();
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,42 +0,0 @@
|
||||
package org.ftylitak.qzxing;
|
||||
|
||||
import android.Manifest;
|
||||
import android.app.Activity;
|
||||
import android.content.pm.PackageManager;
|
||||
import androidx.core.app.ActivityCompat;
|
||||
import androidx.core.content.ContextCompat;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class Utilities {
|
||||
|
||||
public static final int REQUEST_CAMERA = 0;
|
||||
|
||||
public static final String[] requiredPermissionsModifyPhoneState = {
|
||||
Manifest.permission.CAMERA,
|
||||
Manifest.permission.READ_EXTERNAL_STORAGE,
|
||||
Manifest.permission.WRITE_EXTERNAL_STORAGE
|
||||
};
|
||||
|
||||
public static void checkAndRequestPermissionList(Activity activity, String[] permissions) {
|
||||
ArrayList<String> permissionsToRequest = new ArrayList<>();
|
||||
for (int i = 0; i < permissions.length; i++) {
|
||||
if (ContextCompat.checkSelfPermission(activity, permissions[i])
|
||||
!= PackageManager.PERMISSION_GRANTED)
|
||||
permissionsToRequest.add(permissions[i]);
|
||||
}
|
||||
|
||||
if (permissionsToRequest.size() != 0)
|
||||
ActivityCompat.requestPermissions(activity,
|
||||
permissionsToRequest.toArray(new String[0]),
|
||||
REQUEST_CAMERA);
|
||||
else
|
||||
NativeFunctions.onPermissionsGranted();
|
||||
}
|
||||
|
||||
public static void requestQZXingPermissions(Activity activity) {
|
||||
checkAndRequestPermissionList(activity, requiredPermissionsModifyPhoneState);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -5,17 +5,15 @@ TEMPLATE = app
|
||||
#CONFIG += console
|
||||
|
||||
CONFIG += qtquickcompiler
|
||||
CONFIG += qzxing_multimedia \
|
||||
enable_decoder_qr_code \
|
||||
enable_encoder_qr_code
|
||||
|
||||
DEFINES += QT_DEPRECATED_WARNINGS
|
||||
|
||||
include("3rd/QtSsh/src/ssh/qssh.pri")
|
||||
include("3rd/QtSsh/src/botan/botan.pri")
|
||||
!android:!ios:include("3rd/SingleApplication/singleapplication.pri")
|
||||
include("3rd/QRCodeGenerator/QRCodeGenerator.pri")
|
||||
include ("3rd/SortFilterProxyModel/SortFilterProxyModel.pri")
|
||||
include("3rd/QZXing/src/QZXing-components.pri")
|
||||
include("3rd/AdpInfo/adpinfo.pri")
|
||||
|
||||
INCLUDEPATH += $$PWD/3rd/OpenSSL/include
|
||||
DEPENDPATH += $$PWD/3rd/OpenSSL/include
|
||||
@@ -51,7 +49,6 @@ HEADERS += \
|
||||
ui/pages_logic/NetworkSettingsLogic.h \
|
||||
ui/pages_logic/NewServerProtocolsLogic.h \
|
||||
ui/pages_logic/PageLogicBase.h \
|
||||
ui/pages_logic/QrDecoderLogic.h \
|
||||
ui/pages_logic/ServerConfiguringProgressLogic.h \
|
||||
ui/pages_logic/ServerContainersLogic.h \
|
||||
ui/pages_logic/ServerListLogic.h \
|
||||
@@ -107,7 +104,6 @@ SOURCES += \
|
||||
ui/pages_logic/NetworkSettingsLogic.cpp \
|
||||
ui/pages_logic/NewServerProtocolsLogic.cpp \
|
||||
ui/pages_logic/PageLogicBase.cpp \
|
||||
ui/pages_logic/QrDecoderLogic.cpp \
|
||||
ui/pages_logic/ServerConfiguringProgressLogic.cpp \
|
||||
ui/pages_logic/ServerContainersLogic.cpp \
|
||||
ui/pages_logic/ServerListLogic.cpp \
|
||||
@@ -146,14 +142,12 @@ win32 {
|
||||
RC_FILE = platform_win/vpnclient.rc
|
||||
|
||||
HEADERS += \
|
||||
protocols/ikev2_vpn_protocol_windows.h \
|
||||
ui/framelesswindow.h
|
||||
ui/framelesswindow.h \
|
||||
|
||||
SOURCES += \
|
||||
protocols/ikev2_vpn_protocol_windows.cpp \
|
||||
ui/framelesswindow.cpp
|
||||
|
||||
VERSION = 2.0.0.0
|
||||
VERSION = 1.0.0.0
|
||||
QMAKE_TARGET_COMPANY = "AmneziaVPN"
|
||||
QMAKE_TARGET_PRODUCT = "AmneziaVPN"
|
||||
|
||||
@@ -204,6 +198,7 @@ win32|macx|linux:!android {
|
||||
HEADERS += \
|
||||
ui/systemtray_notificationhandler.h \
|
||||
protocols/openvpnprotocol.h \
|
||||
protocols/ikev2_vpn_protocol.h \
|
||||
protocols/openvpnovercloakprotocol.h \
|
||||
protocols/shadowsocksvpnprotocol.h \
|
||||
protocols/wireguardprotocol.h \
|
||||
@@ -211,6 +206,7 @@ win32|macx|linux:!android {
|
||||
SOURCES += \
|
||||
ui/systemtray_notificationhandler.cpp \
|
||||
protocols/openvpnprotocol.cpp \
|
||||
protocols/ikev2_vpn_protocol.cpp \
|
||||
protocols/openvpnovercloakprotocol.cpp \
|
||||
protocols/shadowsocksvpnprotocol.cpp \
|
||||
protocols/wireguardprotocol.cpp \
|
||||
@@ -223,13 +219,11 @@ android {
|
||||
INCLUDEPATH += platforms/android
|
||||
|
||||
HEADERS += \
|
||||
platforms/android/native.h \
|
||||
platforms/android/android_controller.h \
|
||||
platforms/android/android_notificationhandler.h \
|
||||
protocols/android_vpnprotocol.h
|
||||
|
||||
SOURCES += \
|
||||
platforms/android/native.cpp \
|
||||
platforms/android/android_controller.cpp \
|
||||
platforms/android/android_notificationhandler.cpp \
|
||||
protocols/android_vpnprotocol.cpp
|
||||
@@ -283,11 +277,6 @@ ios {
|
||||
LIBS += -framework StoreKit
|
||||
LIBS += -framework UserNotifications
|
||||
|
||||
# LIBS += $$PWD/3rd/OpenVPNAdapter/build/Debug-iphoneos/LZ4.framework
|
||||
# LIBS += $$PWD/3rd/OpenVPNAdapter/build/Debug-iphoneos/mbedTLS.framework
|
||||
# LIBS += $$PWD/3rd/OpenVPNAdapter/build/Debug-iphoneos/OpenVPNClient.framework
|
||||
# LIBS += $$PWD/3rd/OpenVPNAdapter/build/Debug-iphoneos/OpenVPNAdapter.framework
|
||||
|
||||
DEFINES += MVPN_IOS
|
||||
|
||||
HEADERS += \
|
||||
@@ -321,7 +310,7 @@ ios {
|
||||
QMAKE_DEVELOPMENT_TEAM = X7UJ388FXK
|
||||
QMAKE_PROVISIONING_PROFILE = f2fefb59-14aa-4aa9-ac14-1d5531b06dcc
|
||||
QMAKE_XCODE_CODE_SIGN_IDENTITY = "Apple Distribution"
|
||||
QMAKE_INFO_PLIST = $$PWD/ios/app/Info.plist
|
||||
QMAKE_INFO_PLIST= $$PWD/ios/app/Info.plist
|
||||
|
||||
XCODEBUILD_FLAGS += -allowProvisioningUpdates
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ Ikev2Configurator::ConnectionData Ikev2Configurator::prepareIkev2Config(const Se
|
||||
connData.host = credentials.hostName;
|
||||
connData.clientId = Utils::getRandomString(16);
|
||||
connData.password = Utils::getRandomString(16);
|
||||
connData.password = "";
|
||||
//connData.password = "";
|
||||
|
||||
QString certFileName = "/opt/amnezia/ikev2/clients/" + connData.clientId + ".p12";
|
||||
|
||||
|
||||
@@ -50,7 +50,7 @@ WireguardConfigurator::ConnectionData WireguardConfigurator::genClientKeys()
|
||||
}
|
||||
|
||||
WireguardConfigurator::ConnectionData WireguardConfigurator::prepareWireguardConfig(const ServerCredentials &credentials,
|
||||
DockerContainer container, const QJsonObject &containerConfig, ErrorCode *errorCode)
|
||||
DockerContainer container, ErrorCode *errorCode)
|
||||
{
|
||||
WireguardConfigurator::ConnectionData connData = WireguardConfigurator::genClientKeys();
|
||||
connData.host = credentials.hostName;
|
||||
@@ -61,49 +61,6 @@ WireguardConfigurator::ConnectionData WireguardConfigurator::prepareWireguardCon
|
||||
}
|
||||
|
||||
ErrorCode e = ErrorCode::NoError;
|
||||
|
||||
// Get list of already created clients (only IP addreses)
|
||||
QString nextIpNumber;
|
||||
{
|
||||
QString script = QString("cat %1 | grep AllowedIPs").arg(amnezia::protocols::wireguard::serverConfigPath);
|
||||
QString stdOut;
|
||||
auto cbReadStdOut = [&](const QString &data, QSharedPointer<QSsh::SshRemoteProcess> proc) {
|
||||
stdOut += data + "\n";
|
||||
};
|
||||
|
||||
ServerController::runContainerScript(credentials, container, script, cbReadStdOut);
|
||||
stdOut.replace("AllowedIPs = ", "");
|
||||
stdOut.replace("/32", "");
|
||||
QStringList ips = stdOut.split("\n", Qt::SkipEmptyParts);
|
||||
|
||||
// Calc next IP address
|
||||
if (ips.isEmpty()) {
|
||||
nextIpNumber = "2";
|
||||
}
|
||||
else {
|
||||
int next = ips.last().split(".").last().toInt() + 1;
|
||||
if (next > 254) {
|
||||
if (errorCode) *errorCode = ErrorCode::AddressPoolError;
|
||||
return connData;
|
||||
}
|
||||
nextIpNumber = QString::number(next);
|
||||
}
|
||||
}
|
||||
|
||||
QString subnetIp = containerConfig.value(config_key::subnet_address).toString(protocols::wireguard::defaultSubnetAddress);
|
||||
{
|
||||
QStringList l = subnetIp.split(".", Qt::SkipEmptyParts);
|
||||
if (l.isEmpty()) {
|
||||
if (errorCode) *errorCode = ErrorCode::AddressPoolError;
|
||||
return connData;
|
||||
}
|
||||
l.removeLast();
|
||||
l.append(nextIpNumber);
|
||||
|
||||
connData.clientIP = l.join(".");
|
||||
}
|
||||
|
||||
// Get keys
|
||||
connData.serverPubKey = ServerController::getTextFileFromContainer(container, credentials, amnezia::protocols::wireguard::serverPublicKeyPath, &e);
|
||||
connData.serverPubKey.replace("\n", "");
|
||||
if (e) {
|
||||
@@ -119,15 +76,18 @@ WireguardConfigurator::ConnectionData WireguardConfigurator::prepareWireguardCon
|
||||
return connData;
|
||||
}
|
||||
|
||||
// Add client to config
|
||||
|
||||
QString configPart = QString(
|
||||
"[Peer]\n"
|
||||
"PublicKey = %1\n"
|
||||
"PresharedKey = %2\n"
|
||||
"AllowedIPs = %3/32\n\n").
|
||||
"AllowedIPs = $WIREGUARD_SUBNET_IP/$WIREGUARD_SUBNET_CIDR\n\n").
|
||||
arg(connData.clientPubKey).
|
||||
arg(connData.pskKey).
|
||||
arg(connData.clientIP);
|
||||
arg(connData.pskKey);
|
||||
|
||||
configPart = ServerController::replaceVars(configPart, ServerController::genVarsForScript(credentials, container));
|
||||
|
||||
qDebug().noquote() << "Adding wg conf part to server" << configPart;
|
||||
|
||||
e = ServerController::uploadTextFileToContainer(container, credentials, configPart,
|
||||
protocols::wireguard::serverConfigPath, QSsh::SftpOverwriteMode::SftpAppendToExisting);
|
||||
@@ -156,13 +116,12 @@ QString WireguardConfigurator::genWireguardConfig(const ServerCredentials &crede
|
||||
QString config = ServerController::replaceVars(amnezia::scriptData(ProtocolScriptType::wireguard_template, container),
|
||||
ServerController::genVarsForScript(credentials, container, containerConfig));
|
||||
|
||||
ConnectionData connData = prepareWireguardConfig(credentials, container, containerConfig, errorCode);
|
||||
ConnectionData connData = prepareWireguardConfig(credentials, container, errorCode);
|
||||
if (errorCode && *errorCode) {
|
||||
return "";
|
||||
}
|
||||
|
||||
config.replace("$WIREGUARD_CLIENT_PRIVATE_KEY", connData.clientPrivKey);
|
||||
config.replace("$WIREGUARD_CLIENT_IP", connData.clientIP);
|
||||
config.replace("$WIREGUARD_SERVER_PUBLIC_KEY", connData.serverPubKey);
|
||||
config.replace("$WIREGUARD_PSK", connData.pskKey);
|
||||
|
||||
@@ -171,7 +130,6 @@ QString WireguardConfigurator::genWireguardConfig(const ServerCredentials &crede
|
||||
|
||||
jConfig[config_key::hostName] = connData.host;
|
||||
jConfig[config_key::client_priv_key] = connData.clientPrivKey;
|
||||
jConfig[config_key::client_ip] = connData.clientIP;
|
||||
jConfig[config_key::client_pub_key] = connData.clientPubKey;
|
||||
jConfig[config_key::psk_key] = connData.pskKey;
|
||||
jConfig[config_key::server_pub_key] = connData.serverPubKey;
|
||||
|
||||
@@ -15,7 +15,6 @@ public:
|
||||
struct ConnectionData {
|
||||
QString clientPrivKey; // client private key
|
||||
QString clientPubKey; // client public key
|
||||
QString clientIP; // internal client IP address
|
||||
QString serverPubKey; // tls-auth key
|
||||
QString pskKey; // preshared key
|
||||
QString host; // host ip
|
||||
@@ -30,7 +29,7 @@ public:
|
||||
|
||||
private:
|
||||
static ConnectionData prepareWireguardConfig(const ServerCredentials &credentials,
|
||||
DockerContainer container, const QJsonObject &containerConfig, ErrorCode *errorCode = nullptr);
|
||||
DockerContainer container, ErrorCode *errorCode = nullptr);
|
||||
|
||||
static ConnectionData genClientKeys();
|
||||
|
||||
|
||||
@@ -6,8 +6,6 @@
|
||||
|
||||
namespace amnezia {
|
||||
|
||||
constexpr const qint16 qrMagicCode = 1984;
|
||||
|
||||
struct ServerCredentials
|
||||
{
|
||||
QString hostName;
|
||||
@@ -60,7 +58,6 @@ enum ErrorCode
|
||||
OpenVpnAdaptersInUseError,
|
||||
OpenVpnUnknownError,
|
||||
OpenVpnTapAdapterError,
|
||||
AddressPoolError,
|
||||
|
||||
// 3rd party utils errors
|
||||
OpenSslFailed,
|
||||
|
||||
@@ -45,7 +45,6 @@ QString errorString(ErrorCode code){
|
||||
// VPN errors
|
||||
case (OpenVpnAdaptersInUseError): return QObject::tr("Can't connect: another VPN connection is active");
|
||||
case (OpenVpnTapAdapterError): return QObject::tr("Can't setup OpenVPN TAP network adapter");
|
||||
case (AddressPoolError): return QObject::tr("VPN pool error: no available addresses");
|
||||
|
||||
case(InternalError):
|
||||
default:
|
||||
|
||||
@@ -165,9 +165,8 @@ ErrorCode ServerController::uploadTextFileToContainer(DockerContainer container,
|
||||
};
|
||||
|
||||
// mkdir
|
||||
QString mkdir = QString("sudo docker exec -i $CONTAINER_NAME mkdir -p \"$(dirname %1)\"")
|
||||
.arg(path);
|
||||
|
||||
QFileInfo fi(path);
|
||||
QString mkdir = "sudo docker exec -i $CONTAINER_NAME mkdir -p " + fi.absoluteDir().absolutePath();
|
||||
e = runScript(credentials,
|
||||
replaceVars(mkdir, genVarsForScript(credentials, container)));
|
||||
if (e) return e;
|
||||
@@ -478,10 +477,8 @@ QJsonObject ServerController::createContainerInitialConfig(DockerContainer conta
|
||||
|
||||
bool ServerController::isReinstallContainerRequred(DockerContainer container, const QJsonObject &oldConfig, const QJsonObject &newConfig)
|
||||
{
|
||||
Proto mainProto = ContainerProps::defaultProtocol(container);
|
||||
|
||||
const QJsonObject &oldProtoConfig = oldConfig.value(ProtocolProps::protoToString(mainProto)).toObject();
|
||||
const QJsonObject &newProtoConfig = newConfig.value(ProtocolProps::protoToString(mainProto)).toObject();
|
||||
const QJsonObject &oldProtoConfig = oldConfig[ContainerProps::containerToString(container)].toObject();
|
||||
const QJsonObject &newProtoConfig = newConfig[ContainerProps::containerToString(container)].toObject();
|
||||
|
||||
if (container == DockerContainer::OpenVpn) {
|
||||
if (oldProtoConfig.value(config_key::transport_proto).toString(protocols::openvpn::defaultTransportProto) !=
|
||||
@@ -669,9 +666,9 @@ ServerController::Vars ServerController::genVarsForScript(const ServerCredential
|
||||
vars.append({{"$FAKE_WEB_SITE_ADDRESS", cloakConfig.value(config_key::site).toString(protocols::cloak::defaultRedirSite) }});
|
||||
|
||||
// Wireguard vars
|
||||
vars.append({{"$WIREGUARD_SUBNET_IP", wireguarConfig.value(config_key::subnet_address).toString(protocols::wireguard::defaultSubnetAddress) }});
|
||||
vars.append({{"$WIREGUARD_SUBNET_CIDR", wireguarConfig.value(config_key::subnet_cidr).toString(protocols::wireguard::defaultSubnetCidr) }});
|
||||
vars.append({{"$WIREGUARD_SUBNET_MASK", wireguarConfig.value(config_key::subnet_mask).toString(protocols::wireguard::defaultSubnetMask) }});
|
||||
vars.append({{"$WIREGUARD_SUBNET_IP", openvpnConfig.value(config_key::subnet_address).toString(protocols::wireguard::defaultSubnetAddress) }});
|
||||
vars.append({{"$WIREGUARD_SUBNET_CIDR", openvpnConfig.value(config_key::subnet_cidr).toString(protocols::wireguard::defaultSubnetCidr) }});
|
||||
vars.append({{"$WIREGUARD_SUBNET_MASK", openvpnConfig.value(config_key::subnet_mask).toString(protocols::wireguard::defaultSubnetMask) }});
|
||||
|
||||
vars.append({{"$WIREGUARD_SERVER_PORT", wireguarConfig.value(config_key::port).toString(protocols::wireguard::defaultPort) }});
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
#define APPLICATION_NAME "AmneziaVPN"
|
||||
#define SERVICE_NAME "AmneziaVPN-service"
|
||||
#define ORGANIZATION_NAME "AmneziaVPN.ORG"
|
||||
#define APP_MAJOR_VERSION "2.0.7"
|
||||
#define APP_VERSION "2.0.7.0"
|
||||
#define APP_MAJOR_VERSION "2.0.1"
|
||||
#define APP_VERSION "2.0.1.0"
|
||||
|
||||
#endif // DEFINES_H
|
||||
|
||||
|
Before Width: | Height: | Size: 499 KiB |
|
Before Width: | Height: | Size: 16 KiB |
|
Before Width: | Height: | Size: 27 KiB |
|
Before Width: | Height: | Size: 3.5 KiB |
|
Before Width: | Height: | Size: 5.9 KiB |
|
Before Width: | Height: | Size: 6.1 KiB |
|
Before Width: | Height: | Size: 9.0 KiB |
|
Before Width: | Height: | Size: 10 KiB |
@@ -1,62 +0,0 @@
|
||||
{
|
||||
"images" : [
|
||||
{
|
||||
"filename" : "icon_40x40.png",
|
||||
"idiom" : "iphone",
|
||||
"scale" : "2x",
|
||||
"size" : "20x20"
|
||||
},
|
||||
{
|
||||
"filename" : "icon_60x60.png",
|
||||
"idiom" : "iphone",
|
||||
"scale" : "3x",
|
||||
"size" : "20x20"
|
||||
},
|
||||
{
|
||||
"filename" : "icon_58x58.png",
|
||||
"idiom" : "iphone",
|
||||
"scale" : "2x",
|
||||
"size" : "29x29"
|
||||
},
|
||||
{
|
||||
"filename" : "icon_87x87.png",
|
||||
"idiom" : "iphone",
|
||||
"scale" : "3x",
|
||||
"size" : "29x29"
|
||||
},
|
||||
{
|
||||
"filename" : "icon_80x80.png",
|
||||
"idiom" : "iphone",
|
||||
"scale" : "2x",
|
||||
"size" : "40x40"
|
||||
},
|
||||
{
|
||||
"filename" : "icon_120x120.png",
|
||||
"idiom" : "iphone",
|
||||
"scale" : "3x",
|
||||
"size" : "40x40"
|
||||
},
|
||||
{
|
||||
"filename" : "icon_120x120-1.png",
|
||||
"idiom" : "iphone",
|
||||
"scale" : "2x",
|
||||
"size" : "60x60"
|
||||
},
|
||||
{
|
||||
"filename" : "icon_180x180.png",
|
||||
"idiom" : "iphone",
|
||||
"scale" : "3x",
|
||||
"size" : "60x60"
|
||||
},
|
||||
{
|
||||
"filename" : "icon_1024x1024.png",
|
||||
"idiom" : "ios-marketing",
|
||||
"scale" : "1x",
|
||||
"size" : "1024x1024"
|
||||
}
|
||||
],
|
||||
"info" : {
|
||||
"author" : "xcode",
|
||||
"version" : 1
|
||||
}
|
||||
}
|
||||
|
Before Width: | Height: | Size: 499 KiB |
|
Before Width: | Height: | Size: 16 KiB |
|
Before Width: | Height: | Size: 16 KiB |
|
Before Width: | Height: | Size: 27 KiB |
|
Before Width: | Height: | Size: 3.5 KiB |
|
Before Width: | Height: | Size: 5.9 KiB |
|
Before Width: | Height: | Size: 6.1 KiB |
|
Before Width: | Height: | Size: 9.0 KiB |
|
Before Width: | Height: | Size: 10 KiB |
@@ -1,6 +0,0 @@
|
||||
{
|
||||
"info" : {
|
||||
"author" : "xcode",
|
||||
"version" : 1
|
||||
}
|
||||
}
|
||||
@@ -16,9 +16,8 @@
|
||||
#include "ui/pages_logic/AppSettingsLogic.h"
|
||||
#include "ui/pages_logic/GeneralSettingsLogic.h"
|
||||
#include "ui/pages_logic/NetworkSettingsLogic.h"
|
||||
#include "ui/pages_logic/NewServerProtocolsLogic.h"
|
||||
#include "ui/pages_logic/QrDecoderLogic.h"
|
||||
#include "ui/pages_logic/ServerConfiguringProgressLogic.h"
|
||||
#include "ui/pages_logic/NewServerProtocolsLogic.h"
|
||||
#include "ui/pages_logic/ServerContainersLogic.h"
|
||||
#include "ui/pages_logic/ServerListLogic.h"
|
||||
#include "ui/pages_logic/ServerSettingsLogic.h"
|
||||
@@ -35,8 +34,6 @@
|
||||
|
||||
#include "ui/uilogic.h"
|
||||
|
||||
#include "QZXing.h"
|
||||
|
||||
#include "debug.h"
|
||||
#include "defines.h"
|
||||
|
||||
@@ -51,10 +48,6 @@
|
||||
#include "Windows.h"
|
||||
#endif
|
||||
|
||||
#if defined(Q_OS_ANDROID)
|
||||
#include "native.h"
|
||||
#endif
|
||||
|
||||
static void loadTranslator()
|
||||
{
|
||||
QTranslator* translator = new QTranslator;
|
||||
@@ -86,11 +79,6 @@ int main(int argc, char *argv[])
|
||||
QApplication app(argc, argv);
|
||||
#endif
|
||||
|
||||
#if defined(Q_OS_ANDROID)
|
||||
NativeHelpers::registerApplicationInstance(&app);
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef Q_OS_WIN
|
||||
AllowSetForegroundWindow(0);
|
||||
#endif
|
||||
@@ -128,8 +116,6 @@ int main(int argc, char *argv[])
|
||||
|
||||
app.setQuitOnLastWindowClosed(false);
|
||||
|
||||
QZXing::registerQMLTypes();
|
||||
|
||||
qRegisterMetaType<VpnProtocol::VpnConnectionState>("VpnProtocol::VpnConnectionState");
|
||||
qRegisterMetaType<ServerCredentials>("ServerCredentials");
|
||||
|
||||
@@ -170,9 +156,8 @@ int main(int argc, char *argv[])
|
||||
engine->rootContext()->setContextProperty("AppSettingsLogic", uiLogic->appSettingsLogic());
|
||||
engine->rootContext()->setContextProperty("GeneralSettingsLogic", uiLogic->generalSettingsLogic());
|
||||
engine->rootContext()->setContextProperty("NetworkSettingsLogic", uiLogic->networkSettingsLogic());
|
||||
engine->rootContext()->setContextProperty("NewServerProtocolsLogic", uiLogic->newServerProtocolsLogic());
|
||||
engine->rootContext()->setContextProperty("QrDecoderLogic", uiLogic->qrDecoderLogic());
|
||||
engine->rootContext()->setContextProperty("ServerConfiguringProgressLogic", uiLogic->serverConfiguringProgressLogic());
|
||||
engine->rootContext()->setContextProperty("NewServerProtocolsLogic", uiLogic->newServerProtocolsLogic());
|
||||
engine->rootContext()->setContextProperty("ServerListLogic", uiLogic->serverListLogic());
|
||||
engine->rootContext()->setContextProperty("ServerSettingsLogic", uiLogic->serverSettingsLogic());
|
||||
engine->rootContext()->setContextProperty("ServerContainersLogic", uiLogic->serverprotocolsLogic());
|
||||
|
||||
@@ -1,54 +0,0 @@
|
||||
#include "native.h"
|
||||
#include <QMetaObject>
|
||||
#if defined(Q_OS_ANDROID)
|
||||
#include <jni.h>
|
||||
#endif // Q_OS_ANDROID
|
||||
|
||||
|
||||
QObject *NativeHelpers::application_p_ = 0;
|
||||
|
||||
#if defined(Q_OS_ANDROID)
|
||||
|
||||
// define our native static functions
|
||||
// these are the functions that Java part will call directly from Android UI thread
|
||||
static void onPermissionsGranted(JNIEnv * /*env*/, jobject /*obj*/)
|
||||
{
|
||||
QMetaObject::invokeMethod(NativeHelpers::getApplicationInstance(), "onPermissionsGranted"
|
||||
, Qt::QueuedConnection);
|
||||
}
|
||||
|
||||
static void onPermissionsDenied(JNIEnv * /*env*/, jobject /*obj*/)
|
||||
{
|
||||
QMetaObject::invokeMethod(NativeHelpers::getApplicationInstance(), "onPermissionsDenied"
|
||||
, Qt::QueuedConnection);
|
||||
}
|
||||
|
||||
//create a vector with all our JNINativeMethod(s)
|
||||
static JNINativeMethod methods[] = {
|
||||
{"onPermissionsGranted", "()V", (void *)onPermissionsGranted},
|
||||
{"onPermissionsDenied", "()V", (void *)onPermissionsDenied},
|
||||
};
|
||||
|
||||
// this method is called automatically by Java after the .so file is loaded
|
||||
JNIEXPORT jint JNI_OnLoad(JavaVM* vm, void* /*reserved*/)
|
||||
{
|
||||
JNIEnv* env;
|
||||
// get the JNIEnv pointer.
|
||||
if (vm->GetEnv(reinterpret_cast<void**>(&env), JNI_VERSION_1_6) != JNI_OK)
|
||||
return JNI_ERR;
|
||||
|
||||
// search for Java class which declares the native methods
|
||||
jclass javaClass = env->FindClass("org/ftylitak/qzxing/NativeFunctions");
|
||||
if (!javaClass)
|
||||
return JNI_ERR;
|
||||
|
||||
// register our native methods
|
||||
if (env->RegisterNatives(javaClass, methods,
|
||||
sizeof(methods) / sizeof(methods[0])) < 0) {
|
||||
return JNI_ERR;
|
||||
}
|
||||
|
||||
return JNI_VERSION_1_6;
|
||||
}
|
||||
|
||||
#endif // Q_OS_ANDROID
|
||||
@@ -1,20 +0,0 @@
|
||||
#ifndef NATIVE_H
|
||||
#define NATIVE_H
|
||||
|
||||
#include <QObject>
|
||||
|
||||
class NativeHelpers {
|
||||
public:
|
||||
static void registerApplicationInstance(QObject *app_p) {
|
||||
application_p_ = app_p;
|
||||
}
|
||||
|
||||
static QObject* getApplicationInstance() {
|
||||
return application_p_;
|
||||
}
|
||||
|
||||
private:
|
||||
static QObject *application_p_;
|
||||
};
|
||||
|
||||
#endif // NATIVE_H
|
||||
@@ -4,72 +4,94 @@
|
||||
import Foundation
|
||||
import NetworkExtension
|
||||
import os
|
||||
import OpenVPNAdapter
|
||||
|
||||
enum TunnelProtoType: String {
|
||||
case wireguard, openvpn, none
|
||||
}
|
||||
|
||||
class PacketTunnelProvider: NEPacketTunnelProvider {
|
||||
|
||||
|
||||
private lazy var wgAdapter: WireGuardAdapter = {
|
||||
return WireGuardAdapter(with: self) { logLevel, message in
|
||||
wg_log(logLevel.osLogLevel, message: message)
|
||||
}
|
||||
}()
|
||||
|
||||
private lazy var ovpnAdapter: OpenVPNAdapter = {
|
||||
let adapter = OpenVPNAdapter()
|
||||
adapter.delegate = self
|
||||
return adapter
|
||||
}()
|
||||
|
||||
let vpnReachability = OpenVPNReachability()
|
||||
|
||||
var startHandler: ((Error?) -> Void)?
|
||||
var stopHandler: (() -> Void)?
|
||||
var protoType: TunnelProtoType = .wireguard
|
||||
|
||||
override func startTunnel(options: [String: NSObject]?, completionHandler: @escaping (Error?) -> Void) {
|
||||
let activationAttemptId = options?["activationAttemptId"] as? String
|
||||
let errorNotifier = ErrorNotifier(activationAttemptId: activationAttemptId)
|
||||
|
||||
|
||||
Logger.configureGlobal(tagged: "NET", withFilePath: FileManager.logFileURL?.path)
|
||||
|
||||
if let protocolConfiguration = self.protocolConfiguration as? NETunnelProviderProtocol,
|
||||
let providerConfiguration = protocolConfiguration.providerConfiguration,
|
||||
let _: Data = providerConfiguration["ovpn"] as? Data {
|
||||
protoType = .openvpn
|
||||
} else {
|
||||
protoType = .wireguard
|
||||
|
||||
wg_log(.info, message: "Starting tunnel from the " + (activationAttemptId == nil ? "OS directly, rather than the app" : "app"))
|
||||
|
||||
guard let tunnelProviderProtocol = self.protocolConfiguration as? NETunnelProviderProtocol,
|
||||
let tunnelConfiguration = tunnelProviderProtocol.asTunnelConfiguration() else {
|
||||
errorNotifier.notify(PacketTunnelProviderError.savedProtocolConfigurationIsInvalid)
|
||||
completionHandler(PacketTunnelProviderError.savedProtocolConfigurationIsInvalid)
|
||||
return
|
||||
}
|
||||
|
||||
switch protoType {
|
||||
case .wireguard:
|
||||
startWireguard(activationAttemptId: activationAttemptId,
|
||||
errorNotifier: errorNotifier,
|
||||
completionHandler: completionHandler)
|
||||
case .openvpn:
|
||||
startOpenVPN(completionHandler: completionHandler)
|
||||
case .none:
|
||||
break
|
||||
|
||||
// Start the tunnel
|
||||
wgAdapter.start(tunnelConfiguration: tunnelConfiguration) { adapterError in
|
||||
guard let adapterError = adapterError else {
|
||||
let interfaceName = self.wgAdapter.interfaceName ?? "unknown"
|
||||
|
||||
wg_log(.info, message: "Tunnel interface is \(interfaceName)")
|
||||
|
||||
completionHandler(nil)
|
||||
return
|
||||
}
|
||||
|
||||
switch adapterError {
|
||||
case .cannotLocateTunnelFileDescriptor:
|
||||
wg_log(.error, staticMessage: "Starting tunnel failed: could not determine file descriptor")
|
||||
errorNotifier.notify(PacketTunnelProviderError.couldNotDetermineFileDescriptor)
|
||||
completionHandler(PacketTunnelProviderError.couldNotDetermineFileDescriptor)
|
||||
|
||||
case .dnsResolution(let dnsErrors):
|
||||
let hostnamesWithDnsResolutionFailure = dnsErrors.map { $0.address }
|
||||
.joined(separator: ", ")
|
||||
wg_log(.error, message: "DNS resolution failed for the following hostnames: \(hostnamesWithDnsResolutionFailure)")
|
||||
errorNotifier.notify(PacketTunnelProviderError.dnsResolutionFailure)
|
||||
completionHandler(PacketTunnelProviderError.dnsResolutionFailure)
|
||||
|
||||
case .setNetworkSettings(let error):
|
||||
wg_log(.error, message: "Starting tunnel failed with setTunnelNetworkSettings returning \(error.localizedDescription)")
|
||||
errorNotifier.notify(PacketTunnelProviderError.couldNotSetNetworkSettings)
|
||||
completionHandler(PacketTunnelProviderError.couldNotSetNetworkSettings)
|
||||
|
||||
case .startWireGuardBackend(let errorCode):
|
||||
wg_log(.error, message: "Starting tunnel failed with wgTurnOn returning \(errorCode)")
|
||||
errorNotifier.notify(PacketTunnelProviderError.couldNotStartBackend)
|
||||
completionHandler(PacketTunnelProviderError.couldNotStartBackend)
|
||||
|
||||
case .invalidState:
|
||||
// Must never happen
|
||||
fatalError()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
override func stopTunnel(with reason: NEProviderStopReason, completionHandler: @escaping () -> Void) {
|
||||
switch protoType {
|
||||
case .wireguard:
|
||||
stopWireguard(with: reason, completionHandler: completionHandler)
|
||||
case .openvpn:
|
||||
stopOpenVPN(with: reason, completionHandler: completionHandler)
|
||||
case .none:
|
||||
break
|
||||
wg_log(.info, staticMessage: "Stopping tunnel")
|
||||
|
||||
wgAdapter.stop { error in
|
||||
ErrorNotifier.removeLastErrorFile()
|
||||
|
||||
if let error = error {
|
||||
wg_log(.error, message: "Failed to stop WireGuard adapter: \(error.localizedDescription)")
|
||||
}
|
||||
completionHandler()
|
||||
|
||||
#if os(macOS)
|
||||
// HACK: This is a filthy hack to work around Apple bug 32073323 (dup'd by us as 47526107).
|
||||
// Remove it when they finally fix this upstream and the fix has been rolled out to
|
||||
// sufficient quantities of users.
|
||||
exit(0)
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
override func handleAppMessage(_ messageData: Data, completionHandler: ((Data?) -> Void)? = nil) {
|
||||
guard let completionHandler = completionHandler else { return }
|
||||
|
||||
|
||||
if messageData.count == 1 && messageData[0] == 0 {
|
||||
wgAdapter.getRuntimeConfiguration { settings in
|
||||
var data: Data?
|
||||
@@ -86,144 +108,31 @@ class PacketTunnelProvider: NEPacketTunnelProvider {
|
||||
completionHandler(nil)
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
do {
|
||||
let tunnelConfiguration = try TunnelConfiguration(fromWgQuickConfig: configString)
|
||||
wgAdapter.update(tunnelConfiguration: tunnelConfiguration) { error in
|
||||
if let error = error {
|
||||
wg_log(.error, message: "Failed to switch tunnel configuration: \(error.localizedDescription)")
|
||||
completionHandler(nil)
|
||||
return
|
||||
}
|
||||
|
||||
self.wgAdapter.getRuntimeConfiguration { settings in
|
||||
var data: Data?
|
||||
if let settings = settings {
|
||||
data = settings.data(using: .utf8)!
|
||||
}
|
||||
completionHandler(data)
|
||||
}
|
||||
let tunnelConfiguration = try TunnelConfiguration(fromWgQuickConfig: configString)
|
||||
wgAdapter.update(tunnelConfiguration: tunnelConfiguration) { error in
|
||||
if let error = error {
|
||||
wg_log(.error, message: "Failed to switch tunnel configuration: \(error.localizedDescription)")
|
||||
completionHandler(nil)
|
||||
return
|
||||
}
|
||||
|
||||
self.wgAdapter.getRuntimeConfiguration { settings in
|
||||
var data: Data?
|
||||
if let settings = settings {
|
||||
data = settings.data(using: .utf8)!
|
||||
}
|
||||
completionHandler(data)
|
||||
}
|
||||
}
|
||||
} catch {
|
||||
completionHandler(nil)
|
||||
completionHandler(nil)
|
||||
}
|
||||
} else {
|
||||
completionHandler(nil)
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: Private methods
|
||||
private func startWireguard(activationAttemptId: String?,
|
||||
errorNotifier: ErrorNotifier,
|
||||
completionHandler: @escaping (Error?) -> Void) {
|
||||
guard let tunnelProviderProtocol = self.protocolConfiguration as? NETunnelProviderProtocol,
|
||||
let tunnelConfiguration = tunnelProviderProtocol.asTunnelConfiguration() else {
|
||||
errorNotifier.notify(PacketTunnelProviderError.savedProtocolConfigurationIsInvalid)
|
||||
completionHandler(PacketTunnelProviderError.savedProtocolConfigurationIsInvalid)
|
||||
return
|
||||
}
|
||||
wg_log(.info, message: "Starting wireguard tunnel from the " + (activationAttemptId == nil ? "OS directly, rather than the app" : "app"))
|
||||
|
||||
// Start the tunnel
|
||||
wgAdapter.start(tunnelConfiguration: tunnelConfiguration) { adapterError in
|
||||
guard let adapterError = adapterError else {
|
||||
let interfaceName = self.wgAdapter.interfaceName ?? "unknown"
|
||||
|
||||
wg_log(.info, message: "Tunnel interface is \(interfaceName)")
|
||||
|
||||
completionHandler(nil)
|
||||
return
|
||||
}
|
||||
|
||||
switch adapterError {
|
||||
case .cannotLocateTunnelFileDescriptor:
|
||||
wg_log(.error, staticMessage: "Starting tunnel failed: could not determine file descriptor")
|
||||
errorNotifier.notify(PacketTunnelProviderError.couldNotDetermineFileDescriptor)
|
||||
completionHandler(PacketTunnelProviderError.couldNotDetermineFileDescriptor)
|
||||
|
||||
case .dnsResolution(let dnsErrors):
|
||||
let hostnamesWithDnsResolutionFailure = dnsErrors.map { $0.address }
|
||||
.joined(separator: ", ")
|
||||
wg_log(.error, message: "DNS resolution failed for the following hostnames: \(hostnamesWithDnsResolutionFailure)")
|
||||
errorNotifier.notify(PacketTunnelProviderError.dnsResolutionFailure)
|
||||
completionHandler(PacketTunnelProviderError.dnsResolutionFailure)
|
||||
|
||||
case .setNetworkSettings(let error):
|
||||
wg_log(.error, message: "Starting tunnel failed with setTunnelNetworkSettings returning \(error.localizedDescription)")
|
||||
errorNotifier.notify(PacketTunnelProviderError.couldNotSetNetworkSettings)
|
||||
completionHandler(PacketTunnelProviderError.couldNotSetNetworkSettings)
|
||||
|
||||
case .startWireGuardBackend(let errorCode):
|
||||
wg_log(.error, message: "Starting tunnel failed with wgTurnOn returning \(errorCode)")
|
||||
errorNotifier.notify(PacketTunnelProviderError.couldNotStartBackend)
|
||||
completionHandler(PacketTunnelProviderError.couldNotStartBackend)
|
||||
|
||||
case .invalidState:
|
||||
// Must never happen
|
||||
fatalError()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private func startOpenVPN(completionHandler: @escaping (Error?) -> Void) {
|
||||
guard let protocolConfiguration = self.protocolConfiguration as? NETunnelProviderProtocol,
|
||||
let providerConfiguration = protocolConfiguration.providerConfiguration,
|
||||
let ovpnConfiguration: Data = providerConfiguration["ovpn"] as? Data else {
|
||||
return
|
||||
}
|
||||
|
||||
let configuration = OpenVPNConfiguration()
|
||||
configuration.fileContent = ovpnConfiguration
|
||||
// configuration.settings = [] // Additional setting if needed any
|
||||
// configuration.tunPersist = true // keep tun active during pauses/reconections
|
||||
let evaluation: OpenVPNConfigurationEvaluation
|
||||
do {
|
||||
evaluation = try ovpnAdapter.apply(configuration: configuration)
|
||||
} catch {
|
||||
completionHandler(error)
|
||||
return
|
||||
}
|
||||
|
||||
if !evaluation.autologin {
|
||||
print("Implement login with user credentials")
|
||||
}
|
||||
|
||||
vpnReachability.startTracking { [weak self] status in
|
||||
guard status == .reachableViaWiFi else { return }
|
||||
self?.ovpnAdapter.reconnect(afterTimeInterval: 5)
|
||||
}
|
||||
|
||||
startHandler = completionHandler
|
||||
ovpnAdapter.connect(using: packetFlow)
|
||||
}
|
||||
|
||||
private func stopWireguard(with reason: NEProviderStopReason, completionHandler: @escaping () -> Void) {
|
||||
wg_log(.info, staticMessage: "Stopping tunnel")
|
||||
|
||||
wgAdapter.stop { error in
|
||||
ErrorNotifier.removeLastErrorFile()
|
||||
|
||||
if let error = error {
|
||||
wg_log(.error, message: "Failed to stop WireGuard adapter: \(error.localizedDescription)")
|
||||
}
|
||||
completionHandler()
|
||||
|
||||
#if os(macOS)
|
||||
// HACK: This is a filthy hack to work around Apple bug 32073323 (dup'd by us as 47526107).
|
||||
// Remove it when they finally fix this upstream and the fix has been rolled out to
|
||||
// sufficient quantities of users.
|
||||
exit(0)
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
private func stopOpenVPN(with reason: NEProviderStopReason, completionHandler: @escaping () -> Void) {
|
||||
stopHandler = completionHandler
|
||||
if vpnReachability.isTracking {
|
||||
vpnReachability.stopTracking()
|
||||
}
|
||||
ovpnAdapter.disconnect()
|
||||
}
|
||||
}
|
||||
|
||||
extension WireGuardLogLevel {
|
||||
@@ -236,87 +145,3 @@ extension WireGuardLogLevel {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extension NEPacketTunnelFlow: OpenVPNAdapterPacketFlow {}
|
||||
|
||||
extension PacketTunnelProvider: OpenVPNAdapterDelegate {
|
||||
|
||||
// OpenVPNAdapter calls this delegate method to configure a VPN tunnel.
|
||||
// `completionHandler` callback requires an object conforming to `OpenVPNAdapterPacketFlow`
|
||||
// protocol if the tunnel is configured without errors. Otherwise send nil.
|
||||
// `OpenVPNAdapterPacketFlow` method signatures are similar to `NEPacketTunnelFlow` so
|
||||
// you can just extend that class to adopt `OpenVPNAdapterPacketFlow` protocol and
|
||||
// send `self.packetFlow` to `completionHandler` callback.
|
||||
func openVPNAdapter(
|
||||
_ openVPNAdapter: OpenVPNAdapter,
|
||||
configureTunnelWithNetworkSettings networkSettings: NEPacketTunnelNetworkSettings?,
|
||||
completionHandler: @escaping (Error?) -> Void
|
||||
) {
|
||||
// In order to direct all DNS queries first to the VPN DNS servers before the primary DNS servers
|
||||
// send empty string to NEDNSSettings.matchDomains
|
||||
networkSettings?.dnsSettings?.matchDomains = [""]
|
||||
|
||||
// Set the network settings for the current tunneling session.
|
||||
setTunnelNetworkSettings(networkSettings, completionHandler: completionHandler)
|
||||
}
|
||||
|
||||
// Process events returned by the OpenVPN library
|
||||
func openVPNAdapter(
|
||||
_ openVPNAdapter: OpenVPNAdapter,
|
||||
handleEvent event:
|
||||
OpenVPNAdapterEvent, message: String?
|
||||
) {
|
||||
switch event {
|
||||
case .connected:
|
||||
if reasserting {
|
||||
reasserting = false
|
||||
}
|
||||
|
||||
guard let startHandler = startHandler else { return }
|
||||
|
||||
startHandler(nil)
|
||||
self.startHandler = nil
|
||||
|
||||
case .disconnected:
|
||||
guard let stopHandler = stopHandler else { return }
|
||||
|
||||
if vpnReachability.isTracking {
|
||||
vpnReachability.stopTracking()
|
||||
}
|
||||
|
||||
stopHandler()
|
||||
self.stopHandler = nil
|
||||
|
||||
case .reconnecting:
|
||||
reasserting = true
|
||||
|
||||
default:
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
// Handle errors thrown by the OpenVPN library
|
||||
func openVPNAdapter(_ openVPNAdapter: OpenVPNAdapter, handleError error: Error) {
|
||||
// Handle only fatal errors
|
||||
guard let fatal = (error as NSError).userInfo[OpenVPNAdapterErrorFatalKey] as? Bool,
|
||||
fatal == true else { return }
|
||||
|
||||
if vpnReachability.isTracking {
|
||||
vpnReachability.stopTracking()
|
||||
}
|
||||
|
||||
if let startHandler = startHandler {
|
||||
startHandler(error)
|
||||
self.startHandler = nil
|
||||
} else {
|
||||
cancelTunnelWithError(error)
|
||||
}
|
||||
}
|
||||
|
||||
// Use this method to process any log message returned by OpenVPN library.
|
||||
func openVPNAdapter(_ openVPNAdapter: OpenVPNAdapter, handleLogMessage logMessage: String) {
|
||||
// Handle log messages
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
import Foundation
|
||||
import NetworkExtension
|
||||
|
||||
let vpnName = "Amnezia WireguardVPN"
|
||||
let vpnName = "AmneziaVPN"
|
||||
var vpnBundleID = "";
|
||||
|
||||
@objc class VPNIPAddressRange : NSObject {
|
||||
@@ -30,102 +30,27 @@ public class IOSVpnProtocolImpl : NSObject {
|
||||
private var deviceIpv4Address: String? = nil
|
||||
private var deviceIpv6Address: String? = nil
|
||||
|
||||
@objc enum ConnectionState: Int { case Error, Connected, Disconnected }
|
||||
|
||||
@objc init(bundleID: String,
|
||||
config: String,
|
||||
closure: @escaping (ConnectionState, Date?) -> Void,
|
||||
callback: @escaping (Bool) -> Void) {
|
||||
super.init()
|
||||
Logger.configureGlobal(tagged: "APP", withFilePath: "")
|
||||
|
||||
print("Config from caller: \(config)")
|
||||
@objc enum IOSConnectionState: Int { case Error, Connected, Disconnected }
|
||||
|
||||
vpnBundleID = bundleID;
|
||||
precondition(!vpnBundleID.isEmpty)
|
||||
|
||||
stateChangeCallback = callback
|
||||
|
||||
NotificationCenter.default.removeObserver(self)
|
||||
NotificationCenter.default.addObserver(self,
|
||||
selector: #selector(self.vpnStatusDidChange(notification:)),
|
||||
name: Notification.Name.NEVPNStatusDidChange,
|
||||
object: nil)
|
||||
|
||||
NETunnelProviderManager.loadAllFromPreferences { [weak self] managers, error in
|
||||
if let error = error {
|
||||
Logger.global?.log(message: "Loading from preference failed: \(error)")
|
||||
closure(ConnectionState.Error, nil)
|
||||
return
|
||||
}
|
||||
|
||||
if self == nil {
|
||||
Logger.global?.log(message: "We are shutting down.")
|
||||
return
|
||||
}
|
||||
|
||||
let nsManagers = managers ?? []
|
||||
Logger.global?.log(message: "We have received \(nsManagers.count) managers.")
|
||||
print("We have received \(nsManagers.count) managers.")
|
||||
|
||||
let tunnel = nsManagers.first(where: IOSVpnProtocolImpl.isOurManager(_:))
|
||||
|
||||
// if let name = tunnel?.localizedDescription, name == vpnName {
|
||||
// tunnel?.removeFromPreferences(completionHandler: { removeError in
|
||||
// if let error = removeError {
|
||||
// Logger.global?.log(message: "WireguardVPN Tunnel Remove from Prefs Error: \(error)")
|
||||
// closure(ConnectionState.Error, nil)
|
||||
// return
|
||||
// }
|
||||
// })
|
||||
// }
|
||||
|
||||
if tunnel == nil {
|
||||
Logger.global?.log(message: "Creating the tunnel")
|
||||
print("Creating the tunnel")
|
||||
self!.tunnel = NETunnelProviderManager()
|
||||
closure(ConnectionState.Disconnected, nil)
|
||||
return
|
||||
}
|
||||
|
||||
Logger.global?.log(message: "Tunnel already exists")
|
||||
print("Tunnel already exists")
|
||||
|
||||
self!.tunnel = tunnel
|
||||
if tunnel?.connection.status == .connected {
|
||||
closure(ConnectionState.Connected, tunnel?.connection.connectedDate)
|
||||
} else {
|
||||
closure(ConnectionState.Disconnected, nil)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@objc init(bundleID: String,
|
||||
privateKey: Data,
|
||||
deviceIpv4Address: String,
|
||||
deviceIpv6Address: String,
|
||||
closure: @escaping (ConnectionState, Date?) -> Void,
|
||||
callback: @escaping (Bool) -> Void) {
|
||||
@objc init(bundleID: String, privateKey: Data, deviceIpv4Address: String, deviceIpv6Address: String, closure: @escaping (IOSConnectionState, Date?) -> Void, callback: @escaping (Bool) -> Void) {
|
||||
super.init()
|
||||
|
||||
Logger.configureGlobal(tagged: "APP", withFilePath: "")
|
||||
|
||||
vpnBundleID = bundleID;
|
||||
precondition(!vpnBundleID.isEmpty)
|
||||
|
||||
|
||||
stateChangeCallback = callback
|
||||
self.privateKey = PrivateKey(rawValue: privateKey)
|
||||
self.deviceIpv4Address = deviceIpv4Address
|
||||
self.deviceIpv6Address = deviceIpv6Address
|
||||
|
||||
NotificationCenter.default.removeObserver(self)
|
||||
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(self.vpnStatusDidChange(notification:)), name: Notification.Name.NEVPNStatusDidChange, object: nil)
|
||||
|
||||
NETunnelProviderManager.loadAllFromPreferences { [weak self] managers, error in
|
||||
if let error = error {
|
||||
Logger.global?.log(message: "Loading from preference failed: \(error)")
|
||||
closure(ConnectionState.Error, nil)
|
||||
closure(IOSConnectionState.Error, nil)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -139,34 +64,22 @@ public class IOSVpnProtocolImpl : NSObject {
|
||||
print("We have received \(nsManagers.count) managers.")
|
||||
|
||||
let tunnel = nsManagers.first(where: IOSVpnProtocolImpl.isOurManager(_:))
|
||||
|
||||
// if let name = tunnel?.localizedDescription, name != vpnName {
|
||||
// tunnel?.removeFromPreferences(completionHandler: { removeError in
|
||||
// if let error = removeError {
|
||||
// Logger.global?.log(message: "OpenVpn Tunnel Remove from Prefs Error: \(error)")
|
||||
// closure(ConnectionState.Error, nil)
|
||||
// return
|
||||
// }
|
||||
// })
|
||||
// }
|
||||
|
||||
if tunnel == nil {
|
||||
Logger.global?.log(message: "Creating the tunnel")
|
||||
print("Creating the tunnel")
|
||||
self!.tunnel = NETunnelProviderManager()
|
||||
closure(ConnectionState.Disconnected, nil)
|
||||
closure(IOSConnectionState.Disconnected, nil)
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
Logger.global?.log(message: "Tunnel already exists")
|
||||
print("Tunnel already exists")
|
||||
|
||||
self!.tunnel = tunnel
|
||||
|
||||
if tunnel?.connection.status == .connected {
|
||||
closure(ConnectionState.Connected, tunnel?.connection.connectedDate)
|
||||
closure(IOSConnectionState.Connected, tunnel?.connection.connectedDate)
|
||||
} else {
|
||||
closure(ConnectionState.Disconnected, nil)
|
||||
closure(IOSConnectionState.Disconnected, nil)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -229,22 +142,6 @@ public class IOSVpnProtocolImpl : NSObject {
|
||||
print("Found the manager with the correct bundle identifier: \(tunnelProto.providerBundleIdentifier!)")
|
||||
return true
|
||||
}
|
||||
|
||||
@objc func connect(ovpnConfig: String, failureCallback: @escaping () -> Void) {
|
||||
Logger.global?.log(message: "Connecting")
|
||||
assert(tunnel != nil)
|
||||
|
||||
let addr: String = ovpnConfig
|
||||
.splitToArray(separator: "\n", trimmingCharacters: nil)
|
||||
.first { $0.starts(with: "remote ") }
|
||||
.splitToArray(separator: " ", trimmingCharacters: nil)[1]
|
||||
print("server: \(addr)")
|
||||
|
||||
// Let's remove the previous config if it exists.
|
||||
(tunnel?.protocolConfiguration as? NETunnelProviderProtocol)?.destroyConfigurationReference()
|
||||
|
||||
self.configureOpenVPNTunnel(serverAddress: addr, config: ovpnConfig, failureCallback: failureCallback)
|
||||
}
|
||||
|
||||
@objc func connect(dnsServer: String, serverIpv6Gateway: String, serverPublicKey: String, presharedKey: String, serverIpv4AddrIn: String, serverPort: Int, allowedIPAddressRanges: Array<VPNIPAddressRange>, ipv6Enabled: Bool, reason: Int, failureCallback: @escaping () -> Void) {
|
||||
Logger.global?.log(message: "Connecting")
|
||||
@@ -350,46 +247,6 @@ public class IOSVpnProtocolImpl : NSObject {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func configureOpenVPNTunnel(serverAddress: String, config: String, failureCallback: @escaping () -> Void) {
|
||||
let tunnelProtocol = NETunnelProviderProtocol()
|
||||
tunnelProtocol.serverAddress = serverAddress
|
||||
tunnelProtocol.providerBundleIdentifier = vpnBundleID
|
||||
tunnelProtocol.providerConfiguration = ["ovpn": Data(config.utf8)]
|
||||
tunnel?.protocolConfiguration = tunnelProtocol
|
||||
tunnel?.localizedDescription = "Amnezia OpenVPN"
|
||||
tunnel?.isEnabled = true
|
||||
|
||||
tunnel?.saveToPreferences { [unowned self] saveError in
|
||||
if let error = saveError {
|
||||
Logger.global?.log(message: "Connect OpenVPN Tunnel Save Error: \(error)")
|
||||
failureCallback()
|
||||
return
|
||||
}
|
||||
|
||||
Logger.global?.log(message: "Saving the OpenVPN tunnel succeeded")
|
||||
|
||||
self.tunnel?.loadFromPreferences { error in
|
||||
if let error = error {
|
||||
Logger.global?.log(message: "Connect OpenVPN Tunnel Load Error: \(error)")
|
||||
failureCallback()
|
||||
return
|
||||
}
|
||||
|
||||
Logger.global?.log(message: "Loading the OpenVPN tunnel succeeded")
|
||||
print("Loading the openvpn tunnel succeeded")
|
||||
|
||||
do {
|
||||
print("starting openvpn tunnel")
|
||||
try self.tunnel?.connection.startVPNTunnel()
|
||||
} catch let error {
|
||||
Logger.global?.log(message: "Something went wrong: \(error)")
|
||||
failureCallback()
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@objc func disconnect() {
|
||||
Logger.global?.log(message: "Disconnecting")
|
||||
@@ -400,74 +257,7 @@ public class IOSVpnProtocolImpl : NSObject {
|
||||
@objc func checkStatus(callback: @escaping (String, String, String) -> Void) {
|
||||
Logger.global?.log(message: "Check status")
|
||||
assert(tunnel != nil)
|
||||
|
||||
let protoType = (tunnel!.localizedDescription ?? "").toTunnelType
|
||||
|
||||
switch protoType {
|
||||
case .wireguard:
|
||||
checkWireguardStatus(callback: callback)
|
||||
case .openvpn:
|
||||
checkOVPNStatus(callback: callback)
|
||||
case .empty:
|
||||
break
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private func checkOVPNStatus(callback: @escaping (String, String, String) -> Void) {
|
||||
Logger.global?.log(message: "Check OpenVPN")
|
||||
guard let proto = tunnel?.protocolConfiguration as? NETunnelProviderProtocol else {
|
||||
callback("", "", "")
|
||||
return
|
||||
}
|
||||
|
||||
guard let configData = proto.providerConfiguration?["ovpn"] as? Data,
|
||||
let ovpnConfig = String(data: configData, encoding: .utf8) else {
|
||||
callback("", "", "")
|
||||
return
|
||||
}
|
||||
|
||||
let serverIpv4Gateway: String = ovpnConfig
|
||||
.splitToArray(separator: "\n", trimmingCharacters: nil)
|
||||
.first { $0.starts(with: "remote ") }
|
||||
.splitToArray(separator: " ", trimmingCharacters: nil)[1]
|
||||
|
||||
print("server IP: \(serverIpv4Gateway)")
|
||||
|
||||
|
||||
let deviceIpv4Address = getTunIPAddress()
|
||||
print("device IP: \(serverIpv4Gateway)")
|
||||
if deviceIpv4Address == nil {
|
||||
callback("", "", "")
|
||||
return
|
||||
}
|
||||
|
||||
guard let session = tunnel?.connection as? NETunnelProviderSession else {
|
||||
callback("", "", "")
|
||||
return
|
||||
}
|
||||
|
||||
do {
|
||||
try session.sendProviderMessage(Data([UInt8(0)])) { [callback] data in
|
||||
guard let data = data,
|
||||
let configString = String(data: data, encoding: .utf8)
|
||||
else {
|
||||
Logger.global?.log(message: "Failed to convert data to string")
|
||||
callback("", "", "")
|
||||
return
|
||||
}
|
||||
|
||||
callback("\(serverIpv4Gateway)", "\(deviceIpv4Address!)", configString)
|
||||
}
|
||||
} catch {
|
||||
Logger.global?.log(message: "Failed to retrieve data from session")
|
||||
callback("", "", "")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private func checkWireguardStatus(callback: @escaping (String, String, String) -> Void) {
|
||||
Logger.global?.log(message: "Check Wireguard")
|
||||
let proto = tunnel!.protocolConfiguration as? NETunnelProviderProtocol
|
||||
if proto == nil {
|
||||
callback("", "", "")
|
||||
@@ -515,50 +305,4 @@ public class IOSVpnProtocolImpl : NSObject {
|
||||
callback("", "", "")
|
||||
}
|
||||
}
|
||||
|
||||
private func getTunIPAddress() -> String? {
|
||||
var address: String? = nil
|
||||
var interfaces: UnsafeMutablePointer<ifaddrs>? = nil
|
||||
var temp_addr: UnsafeMutablePointer<ifaddrs>? = nil
|
||||
var success: Int = 0
|
||||
|
||||
// retrieve the current interfaces - returns 0 on success
|
||||
success = Int(getifaddrs(&interfaces))
|
||||
if success == 0 {
|
||||
// Loop through linked list of interfaces
|
||||
temp_addr = interfaces
|
||||
while temp_addr != nil {
|
||||
if temp_addr?.pointee.ifa_addr == nil {
|
||||
continue
|
||||
}
|
||||
if temp_addr?.pointee.ifa_addr.pointee.sa_family == UInt8(AF_INET) {
|
||||
// Check if interface is en0 which is the wifi connection on the iPhone
|
||||
if let name = temp_addr?.pointee.ifa_name, ((String(utf8String: name)?.contains("tun")) != nil) {
|
||||
// Get NSString from C String
|
||||
if let value = temp_addr?.pointee.ifa_addr as? sockaddr_in {
|
||||
address = String(utf8String: inet_ntoa(value.sin_addr))
|
||||
}
|
||||
}
|
||||
}
|
||||
temp_addr = temp_addr?.pointee.ifa_next
|
||||
}
|
||||
}
|
||||
freeifaddrs(interfaces)
|
||||
return address
|
||||
}
|
||||
}
|
||||
|
||||
enum TunnelType: String {
|
||||
case wireguard, openvpn, empty
|
||||
}
|
||||
|
||||
extension String {
|
||||
var toTunnelType: TunnelType {
|
||||
switch self {
|
||||
case "wireguard": return .wireguard
|
||||
case "openvpn": return .openvpn
|
||||
default:
|
||||
return .empty
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,41 +1,47 @@
|
||||
#include <QCoreApplication>
|
||||
#include <QFileInfo>
|
||||
#include <QProcess>
|
||||
|
||||
#include <QThread>
|
||||
|
||||
#include <chrono>
|
||||
#include <algorithm>
|
||||
|
||||
#include "debug.h"
|
||||
#include "ikev2_vpn_protocol_windows.h"
|
||||
#include "ikev2_vpn_protocol.h"
|
||||
#include "utils.h"
|
||||
|
||||
static Ikev2Protocol* self = nullptr;
|
||||
static std::mutex rasDialFuncMutex;
|
||||
|
||||
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
extern "C" {
|
||||
static void WINAPI RasDialFuncCallback(UINT unMsg,
|
||||
RASCONNSTATE rasconnstate,
|
||||
DWORD dwError );
|
||||
}
|
||||
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
Ikev2Protocol::Ikev2Protocol(const QJsonObject &configuration, QObject* parent) :
|
||||
VpnProtocol(configuration, parent)
|
||||
{
|
||||
self = this;
|
||||
//m_configFile.setFileTemplate(QDir::tempPath() + QDir::separator() + serviceName() + ".conf");
|
||||
readIkev2Configuration(configuration);
|
||||
}
|
||||
|
||||
Ikev2Protocol::~Ikev2Protocol()
|
||||
{
|
||||
qDebug() << "IpsecProtocol::~IpsecProtocol()";
|
||||
#ifdef Q_OS_WIN
|
||||
disconnect_vpn();
|
||||
#endif
|
||||
Ikev2Protocol::stop();
|
||||
}
|
||||
|
||||
void Ikev2Protocol::stop()
|
||||
{
|
||||
setConnectionState(VpnProtocol::Disconnecting);
|
||||
#ifdef Q_OS_WINDOWS
|
||||
{
|
||||
if (! disconnect_vpn() ){
|
||||
qDebug()<<"We don't disconnect";
|
||||
@@ -45,6 +51,7 @@ void Ikev2Protocol::stop()
|
||||
setConnectionState(VpnProtocol::Disconnected);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void Ikev2Protocol::newConnectionStateEventReceived(UINT unMsg, tagRASCONNSTATE rasconnstate, DWORD dwError)
|
||||
@@ -54,40 +61,40 @@ void Ikev2Protocol::newConnectionStateEventReceived(UINT unMsg, tagRASCONNSTATE
|
||||
switch (rasconnstate)
|
||||
{
|
||||
case RASCS_OpenPort:
|
||||
//qDebug()<<__FUNCTION__ << __LINE__;
|
||||
qDebug()<<__FUNCTION__ << __LINE__;
|
||||
setConnectionState(Preparing);
|
||||
break;
|
||||
case RASCS_PortOpened:
|
||||
//qDebug()<<__FUNCTION__ << __LINE__;
|
||||
qDebug()<<__FUNCTION__ << __LINE__;
|
||||
setConnectionState(Preparing);
|
||||
break;
|
||||
case RASCS_ConnectDevice:
|
||||
//qDebug()<<__FUNCTION__ << __LINE__;
|
||||
qDebug()<<__FUNCTION__ << __LINE__;
|
||||
setConnectionState(Preparing);
|
||||
break;
|
||||
case RASCS_DeviceConnected:
|
||||
//qDebug()<<__FUNCTION__ << __LINE__;
|
||||
qDebug()<<__FUNCTION__ << __LINE__;
|
||||
setConnectionState(Preparing);
|
||||
break;
|
||||
case RASCS_AllDevicesConnected:
|
||||
//qDebug()<<__FUNCTION__ << __LINE__;
|
||||
qDebug()<<__FUNCTION__ << __LINE__;
|
||||
setConnectionState(Preparing);
|
||||
break;
|
||||
case RASCS_Authenticate:
|
||||
//qDebug()<<__FUNCTION__ << __LINE__;
|
||||
qDebug()<<__FUNCTION__ << __LINE__;
|
||||
setConnectionState(Preparing);
|
||||
break;
|
||||
case RASCS_AuthNotify:
|
||||
//qDebug()<<__FUNCTION__ << __LINE__;
|
||||
qDebug()<<__FUNCTION__ << __LINE__;
|
||||
if (dwError != 0) {
|
||||
//qDebug() << "have error" << dwError;
|
||||
qDebug() << "have error" << dwError;
|
||||
setConnectionState(Disconnected);
|
||||
} else {
|
||||
//qDebug() << "RASCS_AuthNotify but no error" << dwError;
|
||||
qDebug() << "RASCS_AuthNotify but no error" << dwError;
|
||||
}
|
||||
break;
|
||||
case RASCS_AuthRetry:
|
||||
//qDebug()<<__FUNCTION__ << __LINE__;
|
||||
qDebug()<<__FUNCTION__ << __LINE__;
|
||||
setConnectionState(Preparing);
|
||||
break;
|
||||
case RASCS_AuthCallback:
|
||||
@@ -106,10 +113,10 @@ void Ikev2Protocol::newConnectionStateEventReceived(UINT unMsg, tagRASCONNSTATE
|
||||
qDebug()<<__FUNCTION__ << __LINE__;
|
||||
break;
|
||||
case RASCS_ReAuthenticate:
|
||||
//qDebug()<<__FUNCTION__ << __LINE__;
|
||||
qDebug()<<__FUNCTION__ << __LINE__;
|
||||
break;
|
||||
case RASCS_Authenticated:
|
||||
//qDebug()<<__FUNCTION__ << __LINE__;
|
||||
qDebug()<<__FUNCTION__ << __LINE__;
|
||||
break;
|
||||
case RASCS_PrepareForCallback:
|
||||
qDebug()<<__FUNCTION__ << __LINE__;
|
||||
@@ -157,14 +164,51 @@ void Ikev2Protocol::newConnectionStateEventReceived(UINT unMsg, tagRASCONNSTATE
|
||||
|
||||
case RASCS_Connected: // = RASCS_DONE:
|
||||
setConnectionState(Connected);
|
||||
//qDebug()<<__FUNCTION__ << __LINE__;
|
||||
qDebug()<<__FUNCTION__ << __LINE__;
|
||||
//printf ("RASCS_Connected = %d\n", _connection_state);
|
||||
//printf ("Connection completed.\n");
|
||||
//SetEvent(gEvent_handle);
|
||||
{
|
||||
//get the network settings of adapters
|
||||
std::this_thread::sleep_for(std::chrono::seconds(4));
|
||||
std::string p1,p2,p3;
|
||||
const auto ret = adpInfo.get_adapter_info(tunnelName().toStdString());
|
||||
if (std::get<0>(ret) == false){
|
||||
p1 = adpInfo.get_adapter_route_gateway();
|
||||
p2 = adpInfo.get_adapter_local_address();
|
||||
p3 = adpInfo.get_adapter_local_gateway();
|
||||
m_routeGateway = QString::fromStdString(p1);
|
||||
m_vpnLocalAddress = QString::fromStdString(p2);
|
||||
m_vpnGateway = QString::fromStdString(p3);
|
||||
qDebug()<<"My ikev2 m_routeGateway "<<m_routeGateway;
|
||||
qDebug()<<"My ikev2 m_vpnLocalAddress "<<m_vpnLocalAddress;
|
||||
qDebug()<<"My ikev2 m_vpnGateway "<< m_vpnGateway;
|
||||
auto ret = adpinfo::get_route_table(p2.c_str());
|
||||
{
|
||||
for (const auto &itret: ret){
|
||||
const auto ip = itret.szDestIp;//std::get<0>(itret);
|
||||
const auto msk = itret.szMaskIp;//std::get<1>(itret);
|
||||
const auto gw = itret.szGatewayIp;//std::get<2>(itret);
|
||||
const auto itf = itret.szInterfaceIp;//std::get<3>(itret);
|
||||
const auto itfInd = itret.ulIfIndex;
|
||||
qDebug()<<"IP["<<ip.c_str()<<"]"<<"Mask["<<msk.c_str()<<"]"<<"gateway["<<gw.c_str()<<"]"<<"Interface["<<itf.c_str()<<"]"<<"Interface index["<<itfInd<<"]";
|
||||
emit route_avaible(QString::fromStdString(ip),
|
||||
QString::fromStdString(msk),
|
||||
QString::fromStdString(gw),
|
||||
QString::fromStdString(itf),
|
||||
itfInd);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case RASCS_Disconnected:
|
||||
setConnectionState(Disconnected);
|
||||
//qDebug()<<__FUNCTION__ << __LINE__;
|
||||
qDebug()<<__FUNCTION__ << __LINE__;
|
||||
break;
|
||||
default:
|
||||
//qDebug()<<__FUNCTION__ << __LINE__;
|
||||
qDebug()<<__FUNCTION__ << __LINE__;
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -176,6 +220,7 @@ void Ikev2Protocol::readIkev2Configuration(const QJsonObject &configuration)
|
||||
|
||||
ErrorCode Ikev2Protocol::start()
|
||||
{
|
||||
#ifdef Q_OS_WINDOWS
|
||||
QByteArray cert = QByteArray::fromBase64(m_config[config_key::cert].toString().toUtf8());
|
||||
setConnectionState(Connecting);
|
||||
|
||||
@@ -200,15 +245,18 @@ ErrorCode Ikev2Protocol::start()
|
||||
return ErrorCode::AmneziaServiceConnectionFailed;
|
||||
}
|
||||
certInstallProcess->setProgram("certutil");
|
||||
QStringList arguments({"-f" , "-importpfx",
|
||||
"-p", m_config[config_key::password].toString(),
|
||||
certFile.fileName(), "NoExport"
|
||||
QStringList arguments({"-f" , "-p", m_config[config_key::password].toString(),
|
||||
"-importpfx", certFile.fileName(), "NoExport"
|
||||
});
|
||||
certInstallProcess->setArguments(arguments);
|
||||
|
||||
connect(certInstallProcess.data(), &PrivilegedProcess::errorOccurred, [certInstallProcess](QProcess::ProcessError error) {
|
||||
qDebug() << "PrivilegedProcess errorOccurred" << error;
|
||||
});
|
||||
|
||||
certInstallProcess->start();
|
||||
}
|
||||
// /*
|
||||
///*
|
||||
{
|
||||
if ( disconnect_vpn()){
|
||||
qDebug()<<"VPN was disconnected";
|
||||
@@ -219,10 +267,8 @@ ErrorCode Ikev2Protocol::start()
|
||||
}
|
||||
|
||||
{
|
||||
{
|
||||
if ( !create_new_vpn(tunnelName(), m_config[config_key::hostName].toString())){
|
||||
qDebug() <<"Can't create the VPN connect";
|
||||
}
|
||||
if ( !create_new_vpn(tunnelName(), m_config[config_key::hostName].toString())){
|
||||
qDebug() <<"Can't create the VPN connect";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -251,10 +297,14 @@ ErrorCode Ikev2Protocol::start()
|
||||
qDebug()<<"We can't connect to VPN";
|
||||
}
|
||||
}
|
||||
//setConnectionState(Connecting);
|
||||
return ErrorCode::NoError;
|
||||
#else
|
||||
return ErrorCode::NoError;
|
||||
#endif
|
||||
|
||||
}
|
||||
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
#ifdef Q_OS_WINDOWS
|
||||
bool Ikev2Protocol::create_new_vpn(const QString & vpn_name,
|
||||
const QString & serv_addr){
|
||||
|
||||
@@ -314,7 +364,7 @@ bool Ikev2Protocol::disconnect_vpn(){
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
void WINAPI RasDialFuncCallback(UINT unMsg,
|
||||
RASCONNSTATE rasconnstate,
|
||||
DWORD dwError ){
|
||||
@@ -323,3 +373,6 @@ void WINAPI RasDialFuncCallback(UINT unMsg,
|
||||
self->newConnectionStateEventReceived(unMsg, rasconnstate, dwError);
|
||||
}
|
||||
}
|
||||
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
#endif
|
||||
@@ -1,5 +1,5 @@
|
||||
#ifndef IKEV2_VPN_PROTOCOL_WINDOWS_H
|
||||
#define IKEV2_VPN_PROTOCOL_WINDOWS_H
|
||||
#ifndef IPSEC_PROTOCOL_H
|
||||
#define IPSEC_PROTOCOL_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QProcess>
|
||||
@@ -10,6 +10,7 @@
|
||||
#include "vpnprotocol.h"
|
||||
#include "core/ipcclient.h"
|
||||
|
||||
#ifdef Q_OS_WIN
|
||||
#include <string>
|
||||
#include <memory>
|
||||
#include <atomic>
|
||||
@@ -30,6 +31,8 @@
|
||||
#pragma comment(lib, "rasapi32.lib")
|
||||
#pragma comment(lib, "Crypt32.lib")
|
||||
|
||||
#endif
|
||||
|
||||
class Ikev2Protocol : public VpnProtocol
|
||||
{
|
||||
Q_OBJECT
|
||||
@@ -51,9 +54,14 @@ public:
|
||||
private:
|
||||
void readIkev2Configuration(const QJsonObject &configuration);
|
||||
|
||||
#ifdef Q_OS_WIN
|
||||
//certificates variables
|
||||
|
||||
#endif
|
||||
private:
|
||||
QJsonObject m_config;
|
||||
|
||||
#ifdef Q_OS_WIN
|
||||
//RAS functions and parametrs
|
||||
HRASCONN hRasConn{nullptr};
|
||||
bool create_new_vpn(const QString & vpn_name,
|
||||
@@ -62,8 +70,12 @@ private:
|
||||
|
||||
bool connect_to_vpn(const QString & vpn_name);
|
||||
bool disconnect_vpn();
|
||||
#endif
|
||||
|
||||
};
|
||||
|
||||
DWORD CALLBACK rasCallback(UINT msg, RASCONNSTATE rascs, DWORD err);
|
||||
//#ifdef Q_OS_WIN
|
||||
//DWORD CALLBACK rasCallback(UINT msg, RASCONNSTATE rascs, DWORD err);
|
||||
//#endif
|
||||
|
||||
#endif // IKEV2_VPN_PROTOCOL_WINDOWS_H
|
||||
#endif // IPSEC_PROTOCOL_H
|
||||
@@ -3,7 +3,6 @@
|
||||
|
||||
#include "vpnprotocol.h"
|
||||
#include "protocols/protocols_defs.h"
|
||||
#include "json.h"
|
||||
|
||||
using namespace amnezia;
|
||||
|
||||
@@ -46,12 +45,6 @@ private:
|
||||
bool m_serviceConnected = false;
|
||||
bool m_checkingStatus = false;
|
||||
std::function<void(const QString&)> m_logCallback;
|
||||
|
||||
void setupWireguardProtocol(const QtJson::JsonObject& result);
|
||||
void setupOpenVPNProtocol(const QtJson::JsonObject& result);
|
||||
|
||||
void launchWireguardTunnel(const QtJson::JsonObject &result);
|
||||
void launchOpenVPNTunnel(const QtJson::JsonObject &result);
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -10,6 +10,8 @@
|
||||
|
||||
#include <QByteArray>
|
||||
|
||||
#include "json.h"
|
||||
|
||||
#include "ipaddressrange.h"
|
||||
#include "ios_vpnprotocol.h"
|
||||
#include "core/errorstrings.h"
|
||||
@@ -19,7 +21,6 @@ namespace
|
||||
{
|
||||
IOSVpnProtocol* s_instance = nullptr;
|
||||
IOSVpnProtocolImpl* m_controller = nullptr;
|
||||
Proto currentProto = amnezia::Proto::Any;
|
||||
}
|
||||
|
||||
IOSVpnProtocol::IOSVpnProtocol(Proto proto, const QJsonObject &configuration, QObject* parent)
|
||||
@@ -34,9 +35,10 @@ bool IOSVpnProtocol::initialize()
|
||||
{
|
||||
qDebug() << "Initializing Swift Controller";
|
||||
|
||||
|
||||
// qDebug() << "config =>";
|
||||
// qDebug() << QJsonDocument(m_rawConfig).toJson();
|
||||
static bool creating = false;
|
||||
// No nested creation!
|
||||
Q_ASSERT(creating == false);
|
||||
creating = true;
|
||||
|
||||
if (!m_controller) {
|
||||
bool ok;
|
||||
@@ -47,69 +49,142 @@ bool IOSVpnProtocol::initialize()
|
||||
return false;
|
||||
}
|
||||
|
||||
QString protoName = result["protocol"].toString();
|
||||
qDebug() << "protocol: " << protoName;
|
||||
|
||||
if (protoName == "wireguard") {
|
||||
setupWireguardProtocol(result);
|
||||
currentProto = amnezia::Proto::WireGuard;
|
||||
} else if (protoName == "openvpn") {
|
||||
setupOpenVPNProtocol(result);
|
||||
currentProto = amnezia::Proto::OpenVpn;
|
||||
} else {
|
||||
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 connectionStateChanged(VpnConnectionState::Error);
|
||||
return;
|
||||
}
|
||||
case ConnectionStateConnected: {
|
||||
Q_ASSERT(date);
|
||||
QDateTime qtDate(QDateTime::fromNSDate(date));
|
||||
emit connectionStateChanged(VpnConnectionState::Connected);
|
||||
return;
|
||||
}
|
||||
case ConnectionStateDisconnected:
|
||||
// Just in case we are connecting, let's call disconnect.
|
||||
[m_controller disconnect];
|
||||
emit connectionStateChanged(VpnConnectionState::Disconnected);
|
||||
return;
|
||||
}
|
||||
}
|
||||
callback:^(BOOL a_connected) {
|
||||
qDebug() << "State changed: " << a_connected;
|
||||
if (a_connected) {
|
||||
emit connectionStateChanged(Connected);
|
||||
return;
|
||||
}
|
||||
// emit connectionStateChanged(Disconnected);
|
||||
}];
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
ErrorCode IOSVpnProtocol::start()
|
||||
{
|
||||
bool ok;
|
||||
QtJson::JsonObject result = QtJson::parse(QJsonDocument(m_rawConfig).toJson(), ok).toMap();
|
||||
qDebug() << "current protocol: " << currentProto;
|
||||
qDebug() << "new protocol: " << m_protocol;
|
||||
qDebug() << "config: " << result;
|
||||
|
||||
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();
|
||||
|
||||
switch (m_protocol) {
|
||||
case amnezia::Proto::OpenVpn:
|
||||
if (currentProto == amnezia::Proto::WireGuard) {
|
||||
if (m_controller) {
|
||||
stop();
|
||||
initialize();
|
||||
}
|
||||
launchOpenVPNTunnel(result);
|
||||
currentProto = amnezia::Proto::OpenVpn;
|
||||
return NoError;
|
||||
}
|
||||
initialize();
|
||||
launchOpenVPNTunnel(result);
|
||||
break;
|
||||
case amnezia::Proto::WireGuard:
|
||||
if (currentProto == amnezia::Proto::OpenVpn) {
|
||||
if (m_controller) {
|
||||
stop();
|
||||
initialize();
|
||||
}
|
||||
launchWireguardTunnel(result);
|
||||
currentProto = amnezia::Proto::WireGuard;
|
||||
return NoError;
|
||||
}
|
||||
initialize();
|
||||
launchWireguardTunnel(result);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
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()
|
||||
presharedKey:pskKey.toNSString()
|
||||
serverIpv4AddrIn:serverAddr.toNSString()
|
||||
serverPort:port.toInt()
|
||||
allowedIPAddressRanges:allowedIPAddressRangesNS
|
||||
ipv6Enabled:NO
|
||||
reason:0
|
||||
failureCallback:^() {
|
||||
qDebug() << "IOSVPNProtocol - connection failed";
|
||||
emit connectionStateChanged(Disconnected);
|
||||
}];
|
||||
return NoError;
|
||||
}
|
||||
|
||||
@@ -117,21 +192,11 @@ void IOSVpnProtocol::stop()
|
||||
{
|
||||
if (!m_controller) {
|
||||
qDebug() << "Not correctly initialized";
|
||||
|
||||
// dispatch_async(dispatch_get_main_queue(), ^{
|
||||
// emit connectionStateChanged(Disconnected);
|
||||
// });
|
||||
|
||||
emit connectionStateChanged(Disconnected);
|
||||
return;
|
||||
}
|
||||
|
||||
[m_controller disconnect];
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
emit connectionStateChanged(Disconnected);
|
||||
});
|
||||
|
||||
[m_controller dealloc];
|
||||
m_controller = nullptr;
|
||||
}
|
||||
|
||||
void IOSVpnProtocol::resume_start()
|
||||
@@ -231,225 +296,3 @@ void IOSVpnProtocol::cleanupBackendLogs()
|
||||
file.remove();
|
||||
}
|
||||
|
||||
void IOSVpnProtocol::setupWireguardProtocol(const QtJson::JsonObject &result)
|
||||
{
|
||||
static bool creating = false;
|
||||
// No nested creation!
|
||||
Q_ASSERT(creating == false);
|
||||
creating = true;
|
||||
|
||||
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;
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
emit connectionStateChanged(VpnConnectionState::Error);
|
||||
});
|
||||
return;
|
||||
}
|
||||
case ConnectionStateConnected: {
|
||||
Q_ASSERT(date);
|
||||
QDateTime qtDate(QDateTime::fromNSDate(date));
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
emit connectionStateChanged(VpnConnectionState::Connected);
|
||||
});
|
||||
return;
|
||||
}
|
||||
case ConnectionStateDisconnected:
|
||||
// Just in case we are connecting, let's call disconnect.
|
||||
[m_controller disconnect];
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
emit connectionStateChanged(VpnConnectionState::Disconnected);
|
||||
});
|
||||
return;
|
||||
}
|
||||
}
|
||||
callback:^(BOOL a_connected) {
|
||||
if (currentProto != m_protocol) {
|
||||
qDebug() << "Protocols switched: " << a_connected;
|
||||
return;
|
||||
}
|
||||
qDebug() << "State changed: " << a_connected;
|
||||
if (a_connected) {
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
emit connectionStateChanged(Connected);
|
||||
});
|
||||
return;
|
||||
}
|
||||
// dispatch_async(dispatch_get_main_queue(), ^{
|
||||
// emit connectionStateChanged(Disconnected);
|
||||
// });
|
||||
}];
|
||||
}
|
||||
|
||||
void IOSVpnProtocol::setupOpenVPNProtocol(const QtJson::JsonObject &result)
|
||||
{
|
||||
static bool creating = false;
|
||||
// No nested creation!
|
||||
Q_ASSERT(creating == false);
|
||||
creating = true;
|
||||
|
||||
QtJson::JsonObject ovpn = result["openvpn_config_data"].toMap();
|
||||
QString ovpnConfig = ovpn["config"].toString();
|
||||
// qDebug() << ovpn;
|
||||
|
||||
m_controller = [[IOSVpnProtocolImpl alloc] initWithBundleID:@VPN_NE_BUNDLEID
|
||||
config:ovpnConfig.toNSString()
|
||||
closure:^(ConnectionState state, NSDate* date) {
|
||||
qDebug() << "OVPN Creation completed with connection state:" << state;
|
||||
creating = false;
|
||||
|
||||
switch (state) {
|
||||
case ConnectionStateError: {
|
||||
[m_controller dealloc];
|
||||
m_controller = nullptr;
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
emit connectionStateChanged(VpnConnectionState::Error);
|
||||
});
|
||||
return;
|
||||
}
|
||||
case ConnectionStateConnected: {
|
||||
Q_ASSERT(date);
|
||||
QDateTime qtDate(QDateTime::fromNSDate(date));
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
emit connectionStateChanged(VpnConnectionState::Connected);
|
||||
});
|
||||
return;
|
||||
}
|
||||
case ConnectionStateDisconnected:
|
||||
// Just in case we are connecting, let's call disconnect.
|
||||
// [m_controller disconnect];
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
emit connectionStateChanged(VpnConnectionState::Disconnected);
|
||||
});
|
||||
return;
|
||||
}
|
||||
}
|
||||
callback:^(BOOL a_connected) {
|
||||
if (currentProto != m_protocol) {
|
||||
qDebug() << "Protocols switched: " << a_connected;
|
||||
return;
|
||||
}
|
||||
qDebug() << "OVPN State changed: " << a_connected;
|
||||
if (a_connected) {
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
emit connectionStateChanged(Connected);
|
||||
});
|
||||
return;
|
||||
}
|
||||
// dispatch_async(dispatch_get_main_queue(), ^{
|
||||
// emit connectionStateChanged(Disconnected);
|
||||
// });
|
||||
}];
|
||||
}
|
||||
|
||||
void IOSVpnProtocol::launchWireguardTunnel(const QtJson::JsonObject &result)
|
||||
{
|
||||
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()
|
||||
presharedKey:pskKey.toNSString()
|
||||
serverIpv4AddrIn:serverAddr.toNSString()
|
||||
serverPort:port.toInt()
|
||||
allowedIPAddressRanges:allowedIPAddressRangesNS
|
||||
ipv6Enabled:NO
|
||||
reason:0
|
||||
failureCallback:^() {
|
||||
qDebug() << "Wireguard Protocol - connection failed";
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
emit connectionStateChanged(Disconnected);
|
||||
});
|
||||
}];
|
||||
}
|
||||
|
||||
void IOSVpnProtocol::launchOpenVPNTunnel(const QtJson::JsonObject &result)
|
||||
{
|
||||
QtJson::JsonObject ovpn = result["openvpn_config_data"].toMap();
|
||||
QString ovpnConfig = ovpn["config"].toString();
|
||||
|
||||
[m_controller connectWithOvpnConfig:ovpnConfig.toNSString()
|
||||
failureCallback:^{
|
||||
qDebug() << "IOSVPNProtocol - connection failed";
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
emit connectionStateChanged(Disconnected);
|
||||
});
|
||||
}];
|
||||
}
|
||||
|
||||
@@ -185,10 +185,10 @@ ErrorCode OpenVpnProtocol::start()
|
||||
}
|
||||
m_openVpnProcess->setProgram(openVpnExecPath());
|
||||
QStringList arguments({"--config" , configPath(),
|
||||
"--management", m_managementHost, QString::number(m_managementPort),
|
||||
"--management-client",
|
||||
"--log", vpnLogFileNamePath
|
||||
});
|
||||
"--management", m_managementHost, QString::number(m_managementPort),
|
||||
"--management-client",
|
||||
"--log", vpnLogFileNamePath
|
||||
});
|
||||
m_openVpnProcess->setArguments(arguments);
|
||||
|
||||
qDebug() << arguments.join(" ");
|
||||
@@ -234,7 +234,6 @@ void OpenVpnProtocol::onReadyReadDataFromManagementServer()
|
||||
{
|
||||
for (;;) {
|
||||
QString line = m_managementServer.readLine().simplified();
|
||||
|
||||
if (line.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
@@ -250,6 +249,42 @@ void OpenVpnProtocol::onReadyReadDataFromManagementServer()
|
||||
sendByteCount();
|
||||
stopTimeoutTimer();
|
||||
setConnectionState(VpnProtocol::Connected);
|
||||
{
|
||||
std::this_thread::sleep_for(std::chrono::seconds(4));
|
||||
std::string p1,p2,p3;
|
||||
const auto &ret = adpInfo.get_adapter_info("TAP-Windows Adapter V9");
|
||||
if (std::get<0>(ret) == false){
|
||||
p1 = adpInfo.get_adapter_route_gateway();
|
||||
p2 = adpInfo.get_adapter_local_address();
|
||||
p3 = adpInfo.get_adapter_local_gateway();
|
||||
m_routeGateway = QString::fromStdString(p1);
|
||||
m_vpnLocalAddress = QString::fromStdString(p2);
|
||||
m_vpnGateway = QString::fromStdString(p3);
|
||||
qDebug()<<"My openvpn m_routeGateway "<<m_routeGateway;
|
||||
qDebug()<<"My openvpn m_vpnLocalAddress "<<m_vpnLocalAddress;
|
||||
qDebug()<<"My openvpn m_vpnGateway "<< m_vpnGateway;
|
||||
auto ret = adpinfo::get_route_table(p2.c_str());
|
||||
{
|
||||
for (const auto &itret: ret){
|
||||
const auto ip = itret.szDestIp;//std::get<0>(itret);
|
||||
const auto msk = itret.szMaskIp;//std::get<1>(itret);
|
||||
const auto gw = itret.szGatewayIp;//std::get<2>(itret);
|
||||
const auto itf = itret.szInterfaceIp;//std::get<3>(itret);
|
||||
const auto itfInd = itret.ulIfIndex;
|
||||
qDebug()<<"IP["<<ip.c_str()<<"]"<<"Mask["<<msk.c_str()<<"]"<<"gateway["<<gw.c_str()<<"]"<<"Interface["<<itf.c_str()<<"]"<<"Interface index["<<itfInd<<"]";
|
||||
emit route_avaible(QString::fromStdString(ip),
|
||||
QString::fromStdString(msk),
|
||||
QString::fromStdString(gw),
|
||||
QString::fromStdString(itf),
|
||||
itfInd);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
else{
|
||||
qDebug()<<"We can't get information about active adapter:"<<QString::fromStdString(std::get<1>(ret));
|
||||
}
|
||||
}
|
||||
continue;
|
||||
} else if (line.contains("EXITING,SIGTER")) {
|
||||
//openVpnStateSigTermHandler();
|
||||
|
||||
@@ -40,7 +40,6 @@ constexpr char server_priv_key[] = "server_priv_key";
|
||||
constexpr char server_pub_key[] = "server_pub_key";
|
||||
constexpr char psk_key[] = "psk_key";
|
||||
|
||||
constexpr char client_ip[] = "client_ip"; // internal ip address
|
||||
|
||||
constexpr char site[] = "site";
|
||||
constexpr char block_outside_dns[] = "block_outside_dns";
|
||||
|
||||
@@ -9,10 +9,7 @@
|
||||
#include "shadowsocksvpnprotocol.h"
|
||||
#include "openvpnovercloakprotocol.h"
|
||||
#include "wireguardprotocol.h"
|
||||
#endif
|
||||
|
||||
#ifdef Q_OS_WINDOWS
|
||||
#include "ikev2_vpn_protocol_windows.h"
|
||||
#include "ikev2_vpn_protocol.h"
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
@@ -8,6 +8,8 @@
|
||||
#include "core/defs.h"
|
||||
#include "containers/containers_defs.h"
|
||||
|
||||
#include "3rd/AdpInfo/netadpinfo.h"
|
||||
|
||||
using namespace amnezia;
|
||||
|
||||
class QTimer;
|
||||
@@ -48,6 +50,8 @@ signals:
|
||||
void timeoutTimerEvent();
|
||||
void protocolError(amnezia::ErrorCode e);
|
||||
|
||||
void route_avaible(QString ip, QString mask, QString gateway, QString interface_ip, unsigned long interface_index);
|
||||
|
||||
public slots:
|
||||
virtual void onTimeout(); // todo: remove?
|
||||
|
||||
@@ -63,6 +67,7 @@ protected:
|
||||
QString m_routeGateway;
|
||||
QString m_vpnLocalAddress;
|
||||
QString m_vpnGateway;
|
||||
adpinfo::NetAdpInfo adpInfo;
|
||||
|
||||
QJsonObject m_rawConfig;
|
||||
|
||||
|
||||
@@ -97,26 +97,11 @@ void WireguardProtocol::readWireguardConfiguration(const QJsonObject &configurat
|
||||
|
||||
}
|
||||
|
||||
//bool WireguardProtocol::openVpnProcessIsRunning() const
|
||||
//{
|
||||
// return Utils::processIsRunning("openvpn");
|
||||
//}
|
||||
|
||||
QString WireguardProtocol::configPath() const
|
||||
{
|
||||
return m_configFileName;
|
||||
}
|
||||
|
||||
void WireguardProtocol::updateRouteGateway(QString line)
|
||||
{
|
||||
// TODO: fix for macos
|
||||
line = line.split("ROUTE_GATEWAY", QString::SkipEmptyParts).at(1);
|
||||
if (!line.contains("/")) return;
|
||||
m_routeGateway = line.split("/", QString::SkipEmptyParts).first();
|
||||
m_routeGateway.replace(" ", "");
|
||||
qDebug() << "Set VPN route gateway" << m_routeGateway;
|
||||
}
|
||||
|
||||
QString WireguardProtocol::wireguardExecPath() const
|
||||
{
|
||||
#ifdef Q_OS_WIN
|
||||
@@ -185,8 +170,48 @@ ErrorCode WireguardProtocol::start()
|
||||
qDebug() << "WireguardProtocol::WireguardProtocol stateChanged" << newState;
|
||||
});
|
||||
|
||||
connect(m_wireguardStartProcess.data(), &PrivilegedProcess::finished, this, [this]() {
|
||||
connect(m_wireguardStartProcess.data(), &PrivilegedProcess::finished, this, [&]() {
|
||||
setConnectionState(VpnConnectionState::Connected);
|
||||
{
|
||||
//TODO:FIXME: without some ugly sleep we have't get a adapter parametrs
|
||||
std::this_thread::sleep_for(std::chrono::seconds(4));
|
||||
std::string p1{},p2{},p3;
|
||||
const auto &ret = adpInfo.get_adapter_info("WireGuard Tunnel");//serviceName().toStdString());//("AmneziaVPN IKEv2");
|
||||
if (std::get<0>(ret) == false){
|
||||
p1 = adpInfo.get_adapter_route_gateway();
|
||||
p2 = adpInfo.get_adapter_local_address();
|
||||
p3 = adpInfo.get_adapter_local_gateway();
|
||||
m_routeGateway = QString::fromStdString(p1);
|
||||
m_vpnLocalAddress = QString::fromStdString(p2);
|
||||
m_vpnGateway = QString::fromStdString(p3);
|
||||
qDebug()<<"My wireguard m_routeGateway "<<m_routeGateway;
|
||||
qDebug()<<"My wireguard m_vpnLocalAddress "<<m_vpnLocalAddress;
|
||||
qDebug()<<"My wireguard m_vpnGateway "<< m_vpnGateway;
|
||||
auto ret = adpinfo::get_route_table(p2.c_str());
|
||||
{
|
||||
for (const auto &itret: ret){
|
||||
const auto ip = itret.szDestIp;//std::get<0>(itret);
|
||||
const auto msk = itret.szMaskIp;//std::get<1>(itret);
|
||||
const auto gw = itret.szGatewayIp;//std::get<2>(itret);
|
||||
const auto itf = itret.szInterfaceIp;//std::get<3>(itret);
|
||||
const auto itfInd = itret.ulIfIndex;
|
||||
qDebug()<<"IP["<<ip.c_str()<<"]"<<"Mask["<<msk.c_str()<<"]"<<"gateway["<<gw.c_str()<<"]"<<"Interface["<<itf.c_str()<<"]"<<"Interface index["<<itfInd<<"]";
|
||||
emit route_avaible(QString::fromStdString(ip),
|
||||
QString::fromStdString(msk),
|
||||
QString::fromStdString(gw),
|
||||
QString::fromStdString(itf),
|
||||
itfInd);
|
||||
//m_vpnGateway = QString::fromStdString(gw);
|
||||
}
|
||||
}
|
||||
//qDebug()<<"My wireguard m_routeGateway "<<m_routeGateway;
|
||||
//qDebug()<<"My wireguard m_vpnLocalAddress "<<m_vpnLocalAddress;
|
||||
//qDebug()<<"My wireguard m_vpnGateway "<< m_vpnGateway;
|
||||
}
|
||||
else{
|
||||
qDebug()<<"We can't get information about active adapter:"<<QString::fromStdString(std::get<1>(ret));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
connect(m_wireguardStartProcess.data(), &PrivilegedProcess::readyRead, this, [this]() {
|
||||
@@ -218,24 +243,6 @@ ErrorCode WireguardProtocol::start()
|
||||
#endif
|
||||
}
|
||||
|
||||
void WireguardProtocol::updateVpnGateway(const QString &line)
|
||||
{
|
||||
// // line looks like
|
||||
// // PUSH: Received control message: 'PUSH_REPLY,route 10.8.0.1,topology net30,ping 10,ping-restart 120,ifconfig 10.8.0.6 10.8.0.5,peer-id 0,cipher AES-256-GCM'
|
||||
|
||||
// QStringList params = line.split(",");
|
||||
// for (const QString &l : params) {
|
||||
// if (l.contains("ifconfig")) {
|
||||
// if (l.split(" ").size() == 3) {
|
||||
// m_vpnLocalAddress = l.split(" ").at(1);
|
||||
// m_vpnGateway = l.split(" ").at(2);
|
||||
|
||||
// qDebug() << QString("Set vpn local address %1, gw %2").arg(m_vpnLocalAddress).arg(vpnGateway());
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
QString WireguardProtocol::serviceName() const
|
||||
{
|
||||
return "AmneziaVPN.WireGuard0";
|
||||
|
||||
@@ -24,11 +24,8 @@ public:
|
||||
private:
|
||||
QString configPath() const;
|
||||
QString wireguardExecPath() const;
|
||||
//bool openVpnProcessIsRunning() const;
|
||||
void readWireguardConfiguration(const QJsonObject &configuration);
|
||||
|
||||
void updateRouteGateway(QString line);
|
||||
void updateVpnGateway(const QString &line);
|
||||
QString serviceName() const;
|
||||
|
||||
|
||||
|
||||
@@ -141,6 +141,5 @@
|
||||
<file>images/animation.gif</file>
|
||||
<file>images/connected.png</file>
|
||||
<file>images/disconnected.png</file>
|
||||
<file>ui/qml/Pages/PageQrDecoder.qml</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
|
||||
@@ -39,26 +39,6 @@ error() {
|
||||
printv '' R "$1"
|
||||
}
|
||||
|
||||
XCODEBUILD="/usr/bin/xcodebuild"
|
||||
WORKINGDIR=`pwd`
|
||||
|
||||
compile_openvpn_adapter() {
|
||||
cd 3rd/OpenVPNAdapter
|
||||
|
||||
$XCODEBUILD -scheme OpenVPNAdapter -configuration Debug -xcconfig Configuration/amnezia.xcconfig -sdk iphoneos -destination 'generic/platform=iOS' -project OpenVPNAdapter.xcodeproj
|
||||
|
||||
cd ../../
|
||||
}
|
||||
|
||||
prepare_to_build_vpn() {
|
||||
cat $WORKINGDIR/3rd/OpenVPNAdapter/Configuration/Project.xcconfig > $WORKINGDIR/3rd/OpenVPNAdapter/Configuration/amnezia.xcconfig
|
||||
cat << EOF >> $WORKINGDIR/3rd/OpenVPNAdapter/Configuration/amnezia.xcconfig
|
||||
PROJECT_TEMP_DIR = $WORKINGDIR/3rd/OpenVPNAdapter/build/OpenVPNAdapter.build
|
||||
CONFIGURATION_BUILD_DIR = $WORKINGDIR/3rd/OpenVPNAdapter/build/Debug-iphoneos
|
||||
BUILT_PRODUCTS_DIR = $WORKINGDIR/3rd/OpenVPNAdapter/build/Debug-iphoneos
|
||||
EOF
|
||||
}
|
||||
|
||||
die() {
|
||||
if [[ "$1" ]]; then
|
||||
error "$1"
|
||||
|
||||
@@ -126,7 +126,7 @@ printn Y "Retrieve the wireguard-go version... "
|
||||
print G "done."
|
||||
|
||||
printn Y "Cleaning the existing project... "
|
||||
rm -rf AmneziaVPN.xcodeproj/ || die "Failed to remove things"
|
||||
rm -rf mozillavpn.xcodeproj/ || die "Failed to remove things"
|
||||
print G "done."
|
||||
|
||||
#print Y "Importing translation files..."
|
||||
@@ -205,16 +205,6 @@ else
|
||||
print G none
|
||||
fi
|
||||
|
||||
if [ "$OS" = "ios" ]; then
|
||||
print Y "Prepare to build OpenVPNAdapter..."
|
||||
prepare_to_build_vpn
|
||||
print Y "Building OpenVPNAdapter..."
|
||||
compile_openvpn_adapter
|
||||
else
|
||||
print Y "No OpenVPNAdapter will be built"
|
||||
|
||||
fi
|
||||
|
||||
print Y "Creating the xcode project via qmake..."
|
||||
$QMAKE \
|
||||
VERSION=$SHORTVERSION \
|
||||
|
||||
@@ -61,8 +61,7 @@ class XCodeprojPatcher
|
||||
config.build_settings['SWIFT_OBJC_BRIDGING_HEADER'] ||= 'macos/app/WireGuard-Bridging-Header.h'
|
||||
config.build_settings['FRAMEWORK_SEARCH_PATHS'] ||= [
|
||||
"$(inherited)",
|
||||
"$(PROJECT_DIR)/3rd",
|
||||
"$(PROJECT_DIR)/3rd/OpenVPNAdapter/build/Debug-iphoneos"
|
||||
"$(PROJECT_DIR)/3rd"
|
||||
]
|
||||
|
||||
# Versions and names
|
||||
@@ -252,11 +251,6 @@ class XCodeprojPatcher
|
||||
config.build_settings['SWIFT_OBJC_BRIDGING_HEADER'] ||= 'macos/networkextension/WireGuardNetworkExtension-Bridging-Header.h'
|
||||
config.build_settings['SWIFT_PRECOMPILE_BRIDGING_HEADER'] = 'NO'
|
||||
config.build_settings['APPLICATION_EXTENSION_API_ONLY'] = 'YES'
|
||||
config.build_settings['FRAMEWORK_SEARCH_PATHS'] ||= [
|
||||
"$(inherited)",
|
||||
"$(PROJECT_DIR)/3rd",
|
||||
"$(PROJECT_DIR)/3rd/OpenVPNAdapter/build/Debug-iphoneos"
|
||||
]
|
||||
|
||||
# Versions and names
|
||||
config.build_settings['MARKETING_VERSION'] ||= shortVersion
|
||||
@@ -356,18 +350,6 @@ class XCodeprojPatcher
|
||||
|
||||
framework_ref = frameworks_group.new_file('NetworkExtension.framework')
|
||||
frameworks_build_phase.add_file_reference(framework_ref)
|
||||
|
||||
framework_ref = frameworks_group.new_file('3rd/OpenVPNAdapter/build/Debug-iphoneos/LZ4.framework')
|
||||
frameworks_build_phase.add_file_reference(framework_ref)
|
||||
|
||||
framework_ref = frameworks_group.new_file('3rd/OpenVPNAdapter/build/Debug-iphoneos/mbedTLS.framework')
|
||||
frameworks_build_phase.add_file_reference(framework_ref)
|
||||
|
||||
framework_ref = frameworks_group.new_file('3rd/OpenVPNAdapter/build/Debug-iphoneos/OpenVPNClient.framework')
|
||||
frameworks_build_phase.add_file_reference(framework_ref)
|
||||
|
||||
framework_ref = frameworks_group.new_file('3rd/OpenVPNAdapter/build/Debug-iphoneos/OpenVPNAdapter.framework')
|
||||
frameworks_build_phase.add_file_reference(framework_ref)
|
||||
|
||||
# This fails: @target_main.add_dependency @target_extension
|
||||
container_proxy = @project.new(Xcodeproj::Project::PBXContainerItemProxy)
|
||||
|
||||
@@ -1,48 +1,3 @@
|
||||
FROM mvance/unbound:latest
|
||||
|
||||
LABEL maintainer="AmneziaVPN"
|
||||
|
||||
RUN echo " \n\
|
||||
domain-insecure: \"coin.\"\n\
|
||||
domain-insecure: \"emc.\"\n\
|
||||
domain-insecure: \"lib.\"\n\
|
||||
domain-insecure: \"bazar.\"\n\
|
||||
domain-insecure: \"enum.\"\n\
|
||||
\n\
|
||||
stub-zone:\n\
|
||||
name: coin.\n\
|
||||
stub-host: seed1.emercoin.com\n\
|
||||
stub-host: seed2.emercoin.com\n\
|
||||
stub-first: yes\n\
|
||||
\n\
|
||||
stub-zone:\n\
|
||||
name: emc.\n\
|
||||
stub-host: seed1.emercoin.com\n\
|
||||
stub-host: seed2.emercoin.com\n\
|
||||
stub-first: yes\n\
|
||||
\n\
|
||||
stub-zone:\n\
|
||||
name: lib.\n\
|
||||
stub-host: seed1.emercoin.com\n\
|
||||
stub-host: seed2.emercoin.com\n\
|
||||
stub-first: yes\n\
|
||||
\n\
|
||||
stub-zone:\n\
|
||||
name: bazar.\n\
|
||||
stub-host: seed1.emercoin.com\n\
|
||||
stub-host: seed2.emercoin.com\n\
|
||||
stub-first: yes\n\
|
||||
\n\
|
||||
stub-zone:\n\
|
||||
name: enum.\n\
|
||||
stub-host: seed1.emercoin.com\n\
|
||||
stub-host: seed2.emercoin.com\n\
|
||||
stub-first: yes\n\
|
||||
\n\
|
||||
forward-zone:\n\
|
||||
name: .\n\
|
||||
forward-tls-upstream: yes\n\
|
||||
forward-addr: 1.1.1.1@853 #cloudflare-dns.com\n\
|
||||
forward-addr: 1.0.0.1@853 #cloudflare-dns.com\n\
|
||||
" | tee /opt/unbound/etc/unbound/forward-records.conf
|
||||
|
||||
|
||||
@@ -17,9 +17,9 @@ iptables -A FORWARD -i wg0 -j ACCEPT
|
||||
iptables -A OUTPUT -o wg0 -j ACCEPT
|
||||
|
||||
# Allow forwarding traffic only from the VPN.
|
||||
iptables -A FORWARD -i wg0 -o eth0 -s $WIREGUARD_SUBNET_IP/$WIREGUARD_SUBNET_CIDR -j ACCEPT
|
||||
iptables -A FORWARD -i wg0 -o eth0 -s $WIREGUARD_SUBNET_IP/$WIREGUARD_SUBNET_MASK_CIDR -j ACCEPT
|
||||
iptables -A FORWARD -m state --state ESTABLISHED,RELATED -j ACCEPT
|
||||
|
||||
iptables -t nat -A POSTROUTING -s $WIREGUARD_SUBNET_IP/$WIREGUARD_SUBNET_CIDR -o eth0 -j MASQUERADE
|
||||
iptables -t nat -A POSTROUTING -s $WIREGUARD_SUBNET_IP/$OPENVPN_SUBNET_CIDR -o eth0 -j MASQUERADE
|
||||
|
||||
tail -f /dev/null
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
[Interface]
|
||||
Address = $WIREGUARD_CLIENT_IP/32
|
||||
Address = 10.8.1.2/32
|
||||
DNS = $PRIMARY_DNS, $SECONDARY_DNS
|
||||
PrivateKey = $WIREGUARD_CLIENT_PRIVATE_KEY
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ enum class Page {Start = 0, NewServer, NewServerProtocols, Vpn,
|
||||
Wizard, WizardLow, WizardMedium, WizardHigh, WizardVpnMode, ServerConfiguringProgress,
|
||||
GeneralSettings, AppSettings, NetworkSettings, ServerSettings,
|
||||
ServerContainers, ServersList, ShareConnection, Sites,
|
||||
ProtocolSettings, ProtocolShare, QrDecoder};
|
||||
ProtocolSettings, ProtocolShare};
|
||||
Q_ENUM_NS(Page)
|
||||
|
||||
static void declareQmlPageEnum() {
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
|
||||
NetworkSettingsLogic::NetworkSettingsLogic(UiLogic *logic, QObject *parent):
|
||||
PageLogicBase(logic, parent),
|
||||
m_ipAddressRegex{Utils::ipAddressRegExp()}
|
||||
m_ipAddressValidatorRegex{Utils::ipAddressRegExp().pattern()}
|
||||
{
|
||||
|
||||
}
|
||||
@@ -18,14 +18,16 @@ void NetworkSettingsLogic::onUpdatePage()
|
||||
|
||||
void NetworkSettingsLogic::onLineEditDns1EditFinished(const QString &text)
|
||||
{
|
||||
if (ipAddressRegex().exactMatch(text)) {
|
||||
QRegExp reg{getIpAddressValidatorRegex()};
|
||||
if (reg.exactMatch(text)) {
|
||||
m_settings.setPrimaryDns(text);
|
||||
}
|
||||
}
|
||||
|
||||
void NetworkSettingsLogic::onLineEditDns2EditFinished(const QString &text)
|
||||
{
|
||||
if (ipAddressRegex().exactMatch(text)) {
|
||||
QRegExp reg{getIpAddressValidatorRegex()};
|
||||
if (reg.exactMatch(text)) {
|
||||
m_settings.setSecondaryDns(text);
|
||||
}
|
||||
}
|
||||
@@ -41,3 +43,8 @@ void NetworkSettingsLogic::onPushButtonResetDns2Clicked()
|
||||
m_settings.setSecondaryDns(m_settings.cloudFlareNs2);
|
||||
onUpdatePage();
|
||||
}
|
||||
|
||||
QString NetworkSettingsLogic::getIpAddressValidatorRegex() const
|
||||
{
|
||||
return m_ipAddressValidatorRegex;
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ class NetworkSettingsLogic : public PageLogicBase
|
||||
|
||||
AUTO_PROPERTY(QString, lineEditDns1Text)
|
||||
AUTO_PROPERTY(QString, lineEditDns2Text)
|
||||
READONLY_PROPERTY(QRegExp, ipAddressRegex)
|
||||
READONLY_PROPERTY(QString, ipAddressValidatorRegex)
|
||||
|
||||
public:
|
||||
Q_INVOKABLE void onUpdatePage() override;
|
||||
@@ -25,5 +25,6 @@ public:
|
||||
explicit NetworkSettingsLogic(UiLogic *uiLogic, QObject *parent = nullptr);
|
||||
~NetworkSettingsLogic() = default;
|
||||
|
||||
QString getIpAddressValidatorRegex() const;
|
||||
};
|
||||
#endif // NETWORK_SETTINGS_LOGIC_H
|
||||
|
||||
@@ -1,79 +0,0 @@
|
||||
#include "QrDecoderLogic.h"
|
||||
|
||||
#include "ui/uilogic.h"
|
||||
#include "ui/pages_logic/StartPageLogic.h"
|
||||
|
||||
#if defined(Q_OS_ANDROID)
|
||||
#include "android_controller.h"
|
||||
#endif
|
||||
|
||||
using namespace amnezia;
|
||||
using namespace PageEnumNS;
|
||||
|
||||
QrDecoderLogic::QrDecoderLogic(UiLogic *logic, QObject *parent):
|
||||
PageLogicBase(logic, parent)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void QrDecoderLogic::onUpdatePage()
|
||||
{
|
||||
m_chunks.clear();
|
||||
set_detectingEnabled(true);
|
||||
set_totalChunksCount(0);
|
||||
set_receivedChunksCount(0);
|
||||
emit startDecode();
|
||||
}
|
||||
|
||||
void QrDecoderLogic::onDetectedQrCode(const QString &code)
|
||||
{
|
||||
//qDebug() << code;
|
||||
|
||||
if (!detectingEnabled()) return;
|
||||
|
||||
// check if chunk received
|
||||
QByteArray ba = QByteArray::fromBase64(code.toUtf8(), QByteArray::Base64UrlEncoding | QByteArray::OmitTrailingEquals);
|
||||
QDataStream s(&ba, QIODevice::ReadOnly);
|
||||
qint16 magic; s >> magic;
|
||||
|
||||
|
||||
if (magic == amnezia::qrMagicCode) {
|
||||
qDebug() << "QrDecoderLogic::onDetectedQrCode magic code detected" << magic << ba.size();
|
||||
|
||||
quint8 chunksCount; s >> chunksCount;
|
||||
if (totalChunksCount() != chunksCount) {
|
||||
m_chunks.clear();
|
||||
}
|
||||
set_totalChunksCount(chunksCount);
|
||||
|
||||
quint8 chunkId; s >> chunkId;
|
||||
s >> m_chunks[chunkId];
|
||||
set_receivedChunksCount(m_chunks.size());
|
||||
|
||||
if (m_chunks.size() == totalChunksCount()) {
|
||||
QByteArray data;
|
||||
for (int i = 0; i < totalChunksCount(); ++i) {
|
||||
data.append(m_chunks.value(i));
|
||||
}
|
||||
|
||||
bool ok = uiLogic()->startPageLogic()->importConnectionFromQr(data);
|
||||
if (ok) {
|
||||
set_detectingEnabled(false);
|
||||
emit stopDecode();
|
||||
}
|
||||
else {
|
||||
m_chunks.clear();
|
||||
set_totalChunksCount(0);
|
||||
set_receivedChunksCount(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
bool ok = uiLogic()->startPageLogic()->importConnectionFromQr(ba);
|
||||
if (ok) {
|
||||
set_detectingEnabled(false);
|
||||
emit stopDecode();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,30 +0,0 @@
|
||||
#ifndef QR_DECODER_LOGIC_H
|
||||
#define QR_DECODER_LOGIC_H
|
||||
|
||||
#include "PageLogicBase.h"
|
||||
|
||||
class UiLogic;
|
||||
|
||||
class QrDecoderLogic : public PageLogicBase
|
||||
{
|
||||
Q_OBJECT
|
||||
AUTO_PROPERTY(bool, detectingEnabled)
|
||||
AUTO_PROPERTY(int, totalChunksCount)
|
||||
AUTO_PROPERTY(int, receivedChunksCount)
|
||||
|
||||
public:
|
||||
Q_INVOKABLE void onUpdatePage() override;
|
||||
Q_INVOKABLE void onDetectedQrCode(const QString &code);
|
||||
|
||||
public:
|
||||
explicit QrDecoderLogic(UiLogic *uiLogic, QObject *parent = nullptr);
|
||||
~QrDecoderLogic() = default;
|
||||
|
||||
signals:
|
||||
void startDecode();
|
||||
void stopDecode();
|
||||
|
||||
private:
|
||||
QMap<int, QByteArray> m_chunks;
|
||||
};
|
||||
#endif // QR_DECODER_LOGIC_H
|
||||
@@ -1,8 +1,11 @@
|
||||
#include <QApplication>
|
||||
#include <QBuffer>
|
||||
#include <QClipboard>
|
||||
#include <QFileDialog>
|
||||
#include <QTimer>
|
||||
#include <QSaveFile>
|
||||
#include <QStandardPaths>
|
||||
#include <QImage>
|
||||
#include <QDataStream>
|
||||
#include <QZXing>
|
||||
#include <QMessageBox>
|
||||
|
||||
#include "ShareConnectionLogic.h"
|
||||
|
||||
@@ -15,8 +18,6 @@
|
||||
#include "configurators/ssh_configurator.h"
|
||||
|
||||
#include "defines.h"
|
||||
#include "core/defs.h"
|
||||
#include "core/errorstrings.h"
|
||||
#include <functional>
|
||||
|
||||
#include "../uilogic.h"
|
||||
@@ -34,8 +35,7 @@ ShareConnectionLogic::ShareConnectionLogic(UiLogic *logic, QObject *parent):
|
||||
void ShareConnectionLogic::onUpdatePage()
|
||||
{
|
||||
set_textEditShareAmneziaCodeText(tr(""));
|
||||
set_shareAmneziaQrCodeTextSeries({});
|
||||
set_shareAmneziaQrCodeTextSeriesLength(0);
|
||||
set_shareAmneziaQrCodeText("");
|
||||
|
||||
set_textEditShareOpenVpnCodeText("");
|
||||
|
||||
@@ -56,8 +56,7 @@ void ShareConnectionLogic::onUpdatePage()
|
||||
void ShareConnectionLogic::onPushButtonShareAmneziaGenerateClicked()
|
||||
{
|
||||
set_textEditShareAmneziaCodeText("");
|
||||
set_shareAmneziaQrCodeTextSeries({});
|
||||
set_shareAmneziaQrCodeTextSeriesLength(0);
|
||||
set_shareAmneziaQrCodeText("");
|
||||
|
||||
QJsonObject serverConfig;
|
||||
// Full access
|
||||
@@ -98,15 +97,15 @@ void ShareConnectionLogic::onPushButtonShareAmneziaGenerateClicked()
|
||||
}
|
||||
}
|
||||
|
||||
QByteArray ba = QJsonDocument(serverConfig).toJson();
|
||||
QByteArray ba = QJsonDocument(serverConfig).toBinaryData();
|
||||
ba = qCompress(ba, 8);
|
||||
QString code = QString("vpn://%1").arg(QString(ba.toBase64(QByteArray::Base64UrlEncoding | QByteArray::OmitTrailingEquals)));
|
||||
set_textEditShareAmneziaCodeText(code);
|
||||
|
||||
|
||||
QList<QString> qrChunks = genQrCodeImageSeries(ba);
|
||||
set_shareAmneziaQrCodeTextSeries(qrChunks);
|
||||
set_shareAmneziaQrCodeTextSeriesLength(qrChunks.size());
|
||||
if (ba.size() < 2900) {
|
||||
QImage qr = updateQRCodeImage(ba.toBase64(QByteArray::Base64UrlEncoding | QByteArray::OmitTrailingEquals));
|
||||
set_shareAmneziaQrCodeText(imageToBase64(qr));
|
||||
}
|
||||
}
|
||||
|
||||
void ShareConnectionLogic::onPushButtonShareOpenVpnGenerateClicked()
|
||||
@@ -148,7 +147,7 @@ void ShareConnectionLogic::onPushButtonShareShadowSocksGenerateClicked()
|
||||
ssString = "ss://" + ssString.toUtf8().toBase64();
|
||||
set_lineEditShareShadowSocksStringText(ssString);
|
||||
|
||||
QImage qr = QZXing::encodeData(ssString.toUtf8(), QZXing::EncoderFormat_QR_CODE, QSize(512,512), QZXing::EncodeErrorCorrectionLevel_L);
|
||||
QImage qr = updateQRCodeImage(ssString.toUtf8());
|
||||
set_shareShadowSocksQrCodeText(imageToBase64(qr));
|
||||
|
||||
QString humanString = QString("Server: %3\n"
|
||||
@@ -196,19 +195,12 @@ void ShareConnectionLogic::onPushButtonShareWireGuardGenerateClicked()
|
||||
|
||||
ErrorCode e = ErrorCode::NoError;
|
||||
QString cfg = WireguardConfigurator::genWireguardConfig(credentials, container, containerConfig, &e);
|
||||
if (e) {
|
||||
QMessageBox::warning(nullptr, APPLICATION_NAME,
|
||||
tr("Error occurred while configuring server.") + "\n" +
|
||||
errorString(e));
|
||||
return;
|
||||
}
|
||||
cfg = VpnConfigurator::processConfigWithExportSettings(container, Proto::WireGuard, cfg);
|
||||
cfg = QJsonDocument::fromJson(cfg.toUtf8()).object()[config_key::config].toString();
|
||||
|
||||
set_textEditShareWireGuardCodeText(cfg);
|
||||
|
||||
QImage qr = QZXing::encodeData(cfg.toUtf8(), QZXing::EncoderFormat_QR_CODE, QSize(512,512), QZXing::EncodeErrorCorrectionLevel_L);
|
||||
|
||||
QImage qr = updateQRCodeImage(cfg.toUtf8());
|
||||
set_shareWireGuardQrCodeText(imageToBase64(qr));
|
||||
}
|
||||
|
||||
@@ -242,29 +234,30 @@ void ShareConnectionLogic::updateSharingPage(int serverIndex, DockerContainer co
|
||||
uiLogic()->selectedDockerContainer = container;
|
||||
uiLogic()->selectedServerIndex = serverIndex;
|
||||
set_shareFullAccess(container == DockerContainer::None);
|
||||
|
||||
m_shareAmneziaQrCodeTextSeries.clear();
|
||||
set_shareAmneziaQrCodeTextSeriesLength(0);
|
||||
}
|
||||
|
||||
QList<QString> ShareConnectionLogic::genQrCodeImageSeries(const QByteArray &data)
|
||||
QImage ShareConnectionLogic::updateQRCodeImage(const QByteArray &data)
|
||||
{
|
||||
double k = 1500;
|
||||
int levelIndex = 1;
|
||||
int versionIndex = 0;
|
||||
bool bExtent = true;
|
||||
int maskIndex = -1;
|
||||
|
||||
quint8 chunksCount = std::ceil(data.size() / k);
|
||||
QList<QString> chunks;
|
||||
for (int i = 0; i < data.size(); i = i + k) {
|
||||
QByteArray chunk;
|
||||
QDataStream s(&chunk, QIODevice::WriteOnly);
|
||||
s << amnezia::qrMagicCode << chunksCount << (quint8)std::round(i/k) << data.mid(i, k);
|
||||
m_qrEncode.EncodeData( levelIndex, versionIndex, bExtent, maskIndex, data.data() );
|
||||
|
||||
QByteArray ba = chunk.toBase64(QByteArray::Base64UrlEncoding | QByteArray::OmitTrailingEquals);
|
||||
int qrImageSize = m_qrEncode.m_nSymbleSize;
|
||||
|
||||
QImage qr = QZXing::encodeData(ba, QZXing::EncoderFormat_QR_CODE, QSize(512,512), QZXing::EncodeErrorCorrectionLevel_L);
|
||||
chunks.append(imageToBase64(qr));
|
||||
}
|
||||
int encodeImageSize = qrImageSize + ( QR_MARGIN * 2 );
|
||||
QImage encodeImage( encodeImageSize, encodeImageSize, QImage::Format_Mono );
|
||||
|
||||
return chunks;
|
||||
encodeImage.fill( 1 );
|
||||
|
||||
for ( int i = 0; i < qrImageSize; i++ )
|
||||
for ( int j = 0; j < qrImageSize; j++ )
|
||||
if ( m_qrEncode.m_byModuleData[i][j] )
|
||||
encodeImage.setPixel( i + QR_MARGIN, j + QR_MARGIN, 0 );
|
||||
|
||||
return encodeImage;
|
||||
}
|
||||
|
||||
QString ShareConnectionLogic::imageToBase64(const QImage &image)
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#define SHARE_CONNECTION_LOGIC_H
|
||||
|
||||
#include "PageLogicBase.h"
|
||||
#include "3rd/QRCodeGenerator/QRCodeGenerator.h"
|
||||
|
||||
class UiLogic;
|
||||
|
||||
@@ -13,8 +14,7 @@ public:
|
||||
AUTO_PROPERTY(bool, shareFullAccess)
|
||||
|
||||
AUTO_PROPERTY(QString, textEditShareAmneziaCodeText)
|
||||
AUTO_PROPERTY(QStringList, shareAmneziaQrCodeTextSeries)
|
||||
AUTO_PROPERTY(int, shareAmneziaQrCodeTextSeriesLength)
|
||||
AUTO_PROPERTY(QString, shareAmneziaQrCodeText)
|
||||
|
||||
AUTO_PROPERTY(QString, textEditShareOpenVpnCodeText)
|
||||
|
||||
@@ -46,10 +46,11 @@ public:
|
||||
~ShareConnectionLogic() = default;
|
||||
|
||||
void updateSharingPage(int serverIndex, DockerContainer container);
|
||||
QList<QString> genQrCodeImageSeries(const QByteArray &data);
|
||||
|
||||
QImage updateQRCodeImage(const QByteArray &data);
|
||||
QString imageToBase64(const QImage &image);
|
||||
|
||||
private:
|
||||
CQR_Encode m_qrEncode;
|
||||
|
||||
};
|
||||
#endif // SHARE_CONNECTION_LOGIC_H
|
||||
|
||||
@@ -2,14 +2,6 @@
|
||||
#include "core/errorstrings.h"
|
||||
#include "configurators/ssh_configurator.h"
|
||||
#include "../uilogic.h"
|
||||
#include "utils.h"
|
||||
|
||||
#include <QFileDialog>
|
||||
#include <QStandardPaths>
|
||||
|
||||
#ifdef Q_OS_ANDROID
|
||||
#include "platforms/android/android_controller.h"
|
||||
#endif
|
||||
|
||||
StartPageLogic::StartPageLogic(UiLogic *logic, QObject *parent):
|
||||
PageLogicBase(logic, parent),
|
||||
@@ -24,8 +16,7 @@ StartPageLogic::StartPageLogic(UiLogic *logic, QObject *parent):
|
||||
m_labelWaitInfoVisible{true},
|
||||
m_labelWaitInfoText{},
|
||||
m_pushButtonBackFromStartVisible{true},
|
||||
m_pushButtonConnectVisible{true},
|
||||
m_ipAddressPortRegex{Utils::ipAddressPortRegExp()}
|
||||
m_pushButtonConnectVisible{true}
|
||||
{
|
||||
|
||||
}
|
||||
@@ -128,97 +119,67 @@ void StartPageLogic::onPushButtonConnect()
|
||||
|
||||
void StartPageLogic::onPushButtonImport()
|
||||
{
|
||||
importConnectionFromCode(lineEditStartExistingCodeText());
|
||||
}
|
||||
QString s = lineEditStartExistingCodeText();
|
||||
s.replace("vpn://", "");
|
||||
QByteArray ba = QByteArray::fromBase64(s.toUtf8(), QByteArray::Base64UrlEncoding | QByteArray::OmitTrailingEquals);
|
||||
QByteArray ba_uncompressed = qUncompress(ba);
|
||||
|
||||
void StartPageLogic::onPushButtonImportOpenFile()
|
||||
{
|
||||
QString fileName = QFileDialog::getOpenFileName(nullptr, tr("Open profile"),
|
||||
QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation), "*.vpn");
|
||||
QJsonObject o;
|
||||
if (!ba_uncompressed.isEmpty()) {
|
||||
o = QJsonDocument::fromBinaryData(ba_uncompressed).object();
|
||||
}
|
||||
else {
|
||||
o = QJsonDocument::fromJson(ba).object();
|
||||
}
|
||||
|
||||
if (fileName.isEmpty()) return;
|
||||
|
||||
QFile file(fileName);
|
||||
file.open(QIODevice::ReadOnly);
|
||||
QByteArray data = file.readAll();
|
||||
|
||||
importConnectionFromCode(QString(data));
|
||||
}
|
||||
|
||||
bool StartPageLogic::importConnection(const QJsonObject &profile)
|
||||
{
|
||||
ServerCredentials credentials;
|
||||
credentials.hostName = profile.value(config_key::hostName).toString();
|
||||
credentials.port = profile.value(config_key::port).toInt();
|
||||
credentials.userName = profile.value(config_key::userName).toString();
|
||||
credentials.password = profile.value(config_key::password).toString();
|
||||
credentials.hostName = o.value("h").toString();
|
||||
if (credentials.hostName.isEmpty()) credentials.hostName = o.value(config_key::hostName).toString();
|
||||
|
||||
// qDebug() << QString("Added server %3@%1:%2").
|
||||
// arg(credentials.hostName).
|
||||
// arg(credentials.port).
|
||||
// arg(credentials.userName);
|
||||
credentials.port = o.value("p").toInt();
|
||||
if (credentials.port == 0) credentials.port = o.value(config_key::port).toInt();
|
||||
|
||||
credentials.userName = o.value("u").toString();
|
||||
if (credentials.userName.isEmpty()) credentials.userName = o.value(config_key::userName).toString();
|
||||
|
||||
credentials.password = o.value("w").toString();
|
||||
if (credentials.password.isEmpty()) credentials.password = o.value(config_key::password).toString();
|
||||
|
||||
if (credentials.isValid()) {
|
||||
o.insert(config_key::hostName, credentials.hostName);
|
||||
o.insert(config_key::port, credentials.port);
|
||||
o.insert(config_key::userName, credentials.userName);
|
||||
o.insert(config_key::password, credentials.password);
|
||||
|
||||
o.remove("h");
|
||||
o.remove("p");
|
||||
o.remove("u");
|
||||
o.remove("w");
|
||||
}
|
||||
qDebug() << QString("Added server %3@%1:%2").
|
||||
arg(credentials.hostName).
|
||||
arg(credentials.port).
|
||||
arg(credentials.userName);
|
||||
|
||||
//qDebug() << QString("Password") << credentials.password;
|
||||
|
||||
if (credentials.isValid() || profile.contains(config_key::containers)) {
|
||||
m_settings.addServer(profile);
|
||||
if (credentials.isValid() || o.contains(config_key::containers)) {
|
||||
m_settings.addServer(o);
|
||||
m_settings.setDefaultServer(m_settings.serversCount() - 1);
|
||||
|
||||
emit uiLogic()->goToPage(Page::Vpn);
|
||||
emit uiLogic()->setStartPage(Page::Vpn);
|
||||
}
|
||||
else {
|
||||
qDebug() << "Failed to import profile";
|
||||
qDebug().noquote() << QJsonDocument(profile).toJson();
|
||||
return false;
|
||||
qDebug().noquote() << QJsonDocument(o).toJson();
|
||||
return;
|
||||
}
|
||||
|
||||
if (!profile.contains(config_key::containers)) {
|
||||
if (!o.contains(config_key::containers)) {
|
||||
uiLogic()->selectedServerIndex = m_settings.defaultServerIndex();
|
||||
uiLogic()->selectedDockerContainer = m_settings.defaultContainer(uiLogic()->selectedServerIndex);
|
||||
uiLogic()->onUpdateAllPages();
|
||||
|
||||
emit uiLogic()->goToPage(Page::ServerContainers);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool StartPageLogic::importConnectionFromCode(QString code)
|
||||
{
|
||||
code.replace("vpn://", "");
|
||||
QByteArray ba = QByteArray::fromBase64(code.toUtf8(), QByteArray::Base64UrlEncoding | QByteArray::OmitTrailingEquals);
|
||||
|
||||
QByteArray ba_uncompressed = qUncompress(ba);
|
||||
if (!ba_uncompressed.isEmpty()) {
|
||||
ba = ba_uncompressed;
|
||||
}
|
||||
|
||||
QJsonObject o;
|
||||
o = QJsonDocument::fromJson(ba).object();
|
||||
if (!o.isEmpty()) {
|
||||
return importConnection(o);
|
||||
}
|
||||
|
||||
o = QJsonDocument::fromBinaryData(ba).object();
|
||||
if (!o.isEmpty()) {
|
||||
return importConnection(o);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool StartPageLogic::importConnectionFromQr(const QByteArray &data)
|
||||
{
|
||||
qDebug() << "StartPageLogic::importConnectionFromQr" << data;
|
||||
QJsonObject dataObj = QJsonDocument::fromJson(data).object();
|
||||
if (!dataObj.isEmpty()) {
|
||||
return importConnection(dataObj);
|
||||
}
|
||||
|
||||
QByteArray ba_uncompressed = qUncompress(data);
|
||||
if (!ba_uncompressed.isEmpty()) {
|
||||
return importConnection(QJsonDocument::fromJson(ba_uncompressed).object());
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -22,17 +22,11 @@ class StartPageLogic : public PageLogicBase
|
||||
AUTO_PROPERTY(bool, pushButtonBackFromStartVisible)
|
||||
AUTO_PROPERTY(bool, pushButtonConnectVisible)
|
||||
|
||||
READONLY_PROPERTY(QRegExp, ipAddressPortRegex)
|
||||
public:
|
||||
Q_INVOKABLE void onUpdatePage() override;
|
||||
|
||||
Q_INVOKABLE void onPushButtonConnect();
|
||||
Q_INVOKABLE void onPushButtonImport();
|
||||
Q_INVOKABLE void onPushButtonImportOpenFile();
|
||||
|
||||
bool importConnection(const QJsonObject &profile);
|
||||
bool importConnectionFromCode(QString code);
|
||||
bool importConnectionFromQr(const QByteArray &data);
|
||||
|
||||
public:
|
||||
explicit StartPageLogic(UiLogic *uiLogic, QObject *parent = nullptr);
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
#include "vpnconnection.h"
|
||||
#include <functional>
|
||||
#include "../uilogic.h"
|
||||
#include "defines.h"
|
||||
|
||||
|
||||
VpnLogic::VpnLogic(UiLogic *logic, QObject *parent):
|
||||
@@ -52,16 +51,6 @@ void VpnLogic::onUpdatePage()
|
||||
DockerContainer selectedContainer = m_settings.defaultContainer(m_settings.defaultServerIndex());
|
||||
QString selectedContainerName = ContainerProps::containerHumanNames().value(selectedContainer);
|
||||
set_labelCurrentService(selectedContainerName);
|
||||
|
||||
set_isContainerWorkingOnPlatform(ContainerProps::isWorkingOnPlatform(selectedContainer));
|
||||
if (!isContainerWorkingOnPlatform()) {
|
||||
set_labelErrorText(tr("AmneziaVPN not supporting selected protocol on this device. Select another protocol."));
|
||||
}
|
||||
else {
|
||||
set_labelErrorText("");
|
||||
}
|
||||
QString ver = QString("v. %2").arg(QString(APP_MAJOR_VERSION));
|
||||
set_labelVersionText(ver);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -19,10 +19,7 @@ class VpnLogic : public PageLogicBase
|
||||
AUTO_PROPERTY(bool, pushButtonConnectEnabled)
|
||||
AUTO_PROPERTY(bool, pushButtonConnectVisible)
|
||||
AUTO_PROPERTY(bool, widgetVpnModeEnabled)
|
||||
AUTO_PROPERTY(bool, isContainerWorkingOnPlatform)
|
||||
|
||||
AUTO_PROPERTY(QString, labelErrorText)
|
||||
AUTO_PROPERTY(QString, labelVersionText)
|
||||
|
||||
AUTO_PROPERTY(bool, radioButtonVpnModeAllSitesChecked)
|
||||
AUTO_PROPERTY(bool, radioButtonVpnModeForwardSitesChecked)
|
||||
|
||||
@@ -10,13 +10,7 @@ Item {
|
||||
property var page: PageEnum.Start
|
||||
property var logic: UiLogic
|
||||
|
||||
property bool pageActive: false
|
||||
|
||||
signal activated(bool reset)
|
||||
signal deactivated()
|
||||
|
||||
onActivated: pageActive = true
|
||||
onDeactivated: pageActive = false
|
||||
|
||||
// width: GC.screenWidth
|
||||
// height: GC.screenHeight
|
||||
|
||||
@@ -37,7 +37,7 @@ PageBase {
|
||||
NetworkSettingsLogic.onLineEditDns1EditFinished(text)
|
||||
}
|
||||
validator: RegExpValidator {
|
||||
regExp: NetworkSettingsLogic.ipAddressRegex
|
||||
regExp: NetworkSettingsLogic.ipAddressValidatorRegex
|
||||
}
|
||||
}
|
||||
ImageButtonType {
|
||||
@@ -74,7 +74,7 @@ PageBase {
|
||||
NetworkSettingsLogic.onLineEditDns2EditFinished(text)
|
||||
}
|
||||
validator: RegExpValidator {
|
||||
regExp: NetworkSettingsLogic.ipAddressRegex
|
||||
regExp: NetworkSettingsLogic.ipAddressValidatorRegex
|
||||
}
|
||||
}
|
||||
ImageButtonType {
|
||||
|
||||
@@ -1,163 +0,0 @@
|
||||
import QtQuick 2.12
|
||||
import QtQuick.Controls 2.12
|
||||
import PageEnum 1.0
|
||||
import QtMultimedia 5.5
|
||||
import QZXing 3.2
|
||||
|
||||
import "./"
|
||||
import "../Controls"
|
||||
import "../Config"
|
||||
|
||||
PageBase {
|
||||
id: root
|
||||
page: PageEnum.QrDecoder
|
||||
logic: QrDecoderLogic
|
||||
|
||||
onDeactivated: {
|
||||
console.debug("Stopping QR decoder")
|
||||
loader.sourceComponent = undefined
|
||||
}
|
||||
|
||||
BackButton {
|
||||
}
|
||||
Caption {
|
||||
id: caption
|
||||
text: qsTr("Import configuration")
|
||||
}
|
||||
|
||||
Connections {
|
||||
target: QrDecoderLogic
|
||||
function onStartDecode() {
|
||||
console.debug("Starting QR decoder")
|
||||
loader.sourceComponent = component
|
||||
}
|
||||
function onStopDecode() {
|
||||
console.debug("Stopping QR decoder")
|
||||
loader.sourceComponent = undefined
|
||||
}
|
||||
}
|
||||
|
||||
Loader {
|
||||
id: loader
|
||||
|
||||
anchors.top: caption.bottom
|
||||
anchors.bottom: parent.bottom
|
||||
anchors.left: parent.left
|
||||
anchors.right: parent.right
|
||||
}
|
||||
|
||||
Component {
|
||||
id: component
|
||||
|
||||
Item {
|
||||
anchors.fill: parent
|
||||
Camera
|
||||
{
|
||||
id:camera
|
||||
focus {
|
||||
focusMode: CameraFocus.FocusContinuous
|
||||
focusPointMode: CameraFocus.FocusPointAuto
|
||||
}
|
||||
}
|
||||
|
||||
VideoOutput
|
||||
{
|
||||
id: videoOutput
|
||||
source: camera
|
||||
anchors.top: parent.top
|
||||
anchors.bottom: parent.bottom
|
||||
anchors.left: parent.left
|
||||
anchors.right: parent.right
|
||||
autoOrientation: true
|
||||
fillMode: VideoOutput.PreserveAspectFit
|
||||
filters: [ zxingFilter ]
|
||||
|
||||
|
||||
Rectangle {
|
||||
color: "black"
|
||||
opacity: 0.5
|
||||
width: videoOutput.contentRect.width *0.15
|
||||
height: videoOutput.contentRect.height
|
||||
x: (videoOutput.width - videoOutput.contentRect.width)/2
|
||||
anchors.verticalCenter: videoOutput.verticalCenter
|
||||
}
|
||||
|
||||
Rectangle {
|
||||
color: "black"
|
||||
opacity: 0.5
|
||||
width: videoOutput.contentRect.width *0.15
|
||||
height: videoOutput.contentRect.height
|
||||
x: videoOutput.width/2 + videoOutput.contentRect.width/2 - videoOutput.contentRect.width *0.15
|
||||
anchors.verticalCenter: videoOutput.verticalCenter
|
||||
}
|
||||
|
||||
Rectangle {
|
||||
color: "black"
|
||||
opacity: 0.5
|
||||
width: videoOutput.contentRect.width *0.7
|
||||
height: videoOutput.contentRect.height *0.15
|
||||
x: (videoOutput.width - videoOutput.contentRect.width)/2 + videoOutput.contentRect.width *0.15
|
||||
y: (videoOutput.height - videoOutput.contentRect.height)/2
|
||||
}
|
||||
|
||||
Rectangle {
|
||||
color: "black"
|
||||
opacity: 0.5
|
||||
width: videoOutput.contentRect.width *0.7
|
||||
height: videoOutput.contentRect.height *0.15
|
||||
x: (videoOutput.width - videoOutput.contentRect.width)/2 + videoOutput.contentRect.width *0.15
|
||||
y: videoOutput.height/2 + videoOutput.contentRect.height/2 - videoOutput.contentRect.height *0.15
|
||||
}
|
||||
|
||||
LabelType {
|
||||
width: parent.width
|
||||
text: qsTr("Decoded QR chunks " + QrDecoderLogic.receivedChunksCount + "/" + QrDecoderLogic.totalChunksCount)
|
||||
horizontalAlignment: Text.AlignLeft
|
||||
visible: QrDecoderLogic.totalChunksCount > 0
|
||||
anchors.horizontalCenter: videoOutput.horizontalCenter
|
||||
y: videoOutput.height/2 + videoOutput.contentRect.height/2
|
||||
}
|
||||
}
|
||||
|
||||
QZXingFilter
|
||||
{
|
||||
id: zxingFilter
|
||||
orientation: videoOutput.orientation
|
||||
captureRect: {
|
||||
// setup bindings
|
||||
videoOutput.contentRect;
|
||||
videoOutput.sourceRect;
|
||||
return videoOutput.mapRectToSource(videoOutput.mapNormalizedRectToItem(Qt.rect(
|
||||
0.15, 0.15, 0.7, 0.7 //0, 0, 1.0, 1.0
|
||||
)));
|
||||
}
|
||||
|
||||
decoder {
|
||||
enabledDecoders: QZXing.DecoderFormat_QR_CODE
|
||||
|
||||
onTagFound: {
|
||||
QrDecoderLogic.onDetectedQrCode(tag)
|
||||
}
|
||||
|
||||
tryHarder: true
|
||||
}
|
||||
|
||||
property int framesDecoded: 0
|
||||
property real timePerFrameDecode: 0
|
||||
|
||||
onDecodingFinished:
|
||||
{
|
||||
timePerFrameDecode = (decodeTime + framesDecoded * timePerFrameDecode) / (framesDecoded + 1);
|
||||
framesDecoded++;
|
||||
if(succeeded)
|
||||
console.log("frame finished: " + succeeded, decodeTime, timePerFrameDecode, framesDecoded);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -12,7 +12,6 @@ PageBase {
|
||||
|
||||
BackButton {
|
||||
id: back_from_start
|
||||
visible: pageLoader.depth > 1
|
||||
}
|
||||
|
||||
Caption {
|
||||
@@ -104,43 +103,12 @@ PageBase {
|
||||
anchors.horizontalCenter: parent.horizontalCenter
|
||||
y: 210
|
||||
anchors.top: lineEdit_start_existing_code.bottom
|
||||
anchors.topMargin: 10
|
||||
anchors.topMargin: 40
|
||||
text: qsTr("Connect")
|
||||
onClicked: {
|
||||
StartPageLogic.onPushButtonImport()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
BlueButtonType {
|
||||
id: qr_code_import_open
|
||||
anchors.horizontalCenter: parent.horizontalCenter
|
||||
anchors.top: new_sever_import.bottom
|
||||
anchors.topMargin: 40
|
||||
|
||||
text: qsTr("Open file")
|
||||
visible: StartPageLogic.pushButtonConnectVisible
|
||||
onClicked: {
|
||||
StartPageLogic.onPushButtonImportOpenFile()
|
||||
}
|
||||
enabled: StartPageLogic.pushButtonConnectEnabled
|
||||
}
|
||||
|
||||
BlueButtonType {
|
||||
id: qr_code_import
|
||||
anchors.horizontalCenter: parent.horizontalCenter
|
||||
anchors.top: qr_code_import_open.bottom
|
||||
anchors.topMargin: 10
|
||||
|
||||
text: qsTr("Scan QR code")
|
||||
visible: StartPageLogic.pushButtonConnectVisible
|
||||
onClicked: {
|
||||
UiLogic.goToPage(PageEnum.QrDecoder)
|
||||
}
|
||||
enabled: StartPageLogic.pushButtonConnectEnabled
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -186,7 +154,7 @@ PageBase {
|
||||
id: label_server_ip
|
||||
x: 40
|
||||
anchors.top: new_sever_get_info.bottom
|
||||
text: qsTr("Server IP address [:port]")
|
||||
text: qsTr("Server IP address")
|
||||
}
|
||||
TextFieldType {
|
||||
id: new_server_ip
|
||||
@@ -196,10 +164,6 @@ PageBase {
|
||||
onEditingFinished: {
|
||||
StartPageLogic.lineEditIpText = text
|
||||
}
|
||||
|
||||
validator: RegExpValidator {
|
||||
regExp: StartPageLogic.ipAddressPortRegex
|
||||
}
|
||||
}
|
||||
|
||||
LabelType {
|
||||
@@ -260,6 +224,8 @@ PageBase {
|
||||
wrapMode: Text.Wrap
|
||||
}
|
||||
|
||||
|
||||
|
||||
BlueButtonType {
|
||||
id: new_sever_connect
|
||||
anchors.horizontalCenter: parent.horizontalCenter
|
||||
|
||||
@@ -20,16 +20,6 @@ PageBase {
|
||||
source: "qrc:/images/background_connected.png"
|
||||
}
|
||||
|
||||
LabelType {
|
||||
x: 10
|
||||
y: 5
|
||||
width: 100
|
||||
height: 21
|
||||
text: VpnLogic.labelVersionText
|
||||
color: "#dddddd"
|
||||
font.pixelSize: 12
|
||||
}
|
||||
|
||||
ImageButtonType {
|
||||
x: parent.width - 40
|
||||
y: 10
|
||||
@@ -51,7 +41,7 @@ PageBase {
|
||||
height: width
|
||||
|
||||
visible: !VpnLogic.pushButtonConnectVisible
|
||||
paused: VpnLogic.pushButtonConnectVisible && !root.pageActive
|
||||
paused: VpnLogic.pushButtonConnectVisible
|
||||
//VisibleBehavior on visible { }
|
||||
}
|
||||
|
||||
@@ -71,7 +61,7 @@ PageBase {
|
||||
}
|
||||
contentItem: Item {}
|
||||
antialiasing: true
|
||||
enabled: VpnLogic.pushButtonConnectEnabled && VpnLogic.isContainerWorkingOnPlatform
|
||||
enabled: VpnLogic.pushButtonConnectEnabled
|
||||
opacity: VpnLogic.pushButtonConnectVisible ? 1 : 0
|
||||
|
||||
// transitions: Transition {
|
||||
@@ -151,14 +141,11 @@ PageBase {
|
||||
id: error_text
|
||||
anchors.top: layout2.bottom
|
||||
anchors.horizontalCenter: parent.horizontalCenter
|
||||
anchors.topMargin: 20
|
||||
width: parent.width - 20
|
||||
|
||||
width: parent.width
|
||||
height: 21
|
||||
horizontalAlignment: Text.AlignHCenter
|
||||
wrapMode: Text.Wrap
|
||||
text: VpnLogic.labelErrorText
|
||||
color: "red"
|
||||
}
|
||||
|
||||
Item {
|
||||
|
||||
@@ -33,13 +33,6 @@ PageShareProtocolBase {
|
||||
contentHeight: content.height + 20
|
||||
clip: true
|
||||
|
||||
Behavior on contentY{
|
||||
NumberAnimation {
|
||||
duration: 300
|
||||
easing.type: Easing.InOutCubic
|
||||
}
|
||||
}
|
||||
|
||||
ColumnLayout {
|
||||
id: content
|
||||
enabled: logic.pageEnabled
|
||||
@@ -80,7 +73,6 @@ New encryption keys pair will be generated.")
|
||||
ShareConnectionLogic.onPushButtonShareAmneziaGenerateClicked()
|
||||
enabled = true
|
||||
genConfigProcess = false
|
||||
fl.contentY = tfShareCode.mapToItem(fl.contentItem, 0, 0).y
|
||||
}
|
||||
}
|
||||
|
||||
@@ -122,32 +114,19 @@ New encryption keys pair will be generated.")
|
||||
}
|
||||
|
||||
Image {
|
||||
id: image_share_code
|
||||
id: label_share_code
|
||||
Layout.topMargin: 20
|
||||
Layout.fillWidth: true
|
||||
Layout.preferredHeight: width
|
||||
smooth: false
|
||||
|
||||
Timer {
|
||||
property int idx: 0
|
||||
interval: 1000
|
||||
running: root.pageActive && ShareConnectionLogic.shareAmneziaQrCodeTextSeriesLength > 0
|
||||
repeat: true
|
||||
onTriggered: {
|
||||
idx++
|
||||
if (idx >= ShareConnectionLogic.shareAmneziaQrCodeTextSeriesLength) {
|
||||
idx = 0
|
||||
}
|
||||
image_share_code.source = ShareConnectionLogic.shareAmneziaQrCodeTextSeries[idx]
|
||||
}
|
||||
}
|
||||
|
||||
visible: ShareConnectionLogic.shareAmneziaQrCodeTextSeriesLength > 0
|
||||
source: ShareConnectionLogic.shareAmneziaQrCodeText
|
||||
visible: ShareConnectionLogic.shareAmneziaQrCodeText.length > 0
|
||||
}
|
||||
|
||||
LabelType {
|
||||
Layout.fillWidth: true
|
||||
text: qsTr("Scan QR code using AmneziaVPN mobile")
|
||||
text: qsTr("Config too long to be displayed as QR code")
|
||||
visible: ShareConnectionLogic.shareAmneziaQrCodeText.length == 0 && tfShareCode.textArea.length > 0
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ PageShareProtocolBase {
|
||||
ColumnLayout {
|
||||
id: content
|
||||
enabled: logic.pageEnabled
|
||||
anchors.top: parent.top
|
||||
anchors.top: parent.bottom
|
||||
anchors.left: parent.left
|
||||
anchors.right: parent.right
|
||||
|
||||
|
||||
@@ -28,6 +28,7 @@ Window {
|
||||
UiLogic.onCloseWindow()
|
||||
}
|
||||
|
||||
//flags: Qt.FramelessWindowHint
|
||||
title: "AmneziaVPN"
|
||||
|
||||
function gotoPage(type, page, reset, slide) {
|
||||
@@ -40,9 +41,6 @@ Window {
|
||||
|
||||
console.debug("QML gotoPage " + type + " " + page + " " + p_obj)
|
||||
|
||||
if (pageLoader.depth > 0) {
|
||||
pageLoader.currentItem.deactivated()
|
||||
}
|
||||
|
||||
if (slide) {
|
||||
pageLoader.push(p_obj, {}, StackView.PushTransition)
|
||||
@@ -61,15 +59,10 @@ Window {
|
||||
if (pageLoader.depth <= 1) {
|
||||
return
|
||||
}
|
||||
pageLoader.currentItem.deactivated()
|
||||
pageLoader.pop()
|
||||
}
|
||||
|
||||
function set_start_page(page, slide) {
|
||||
if (pageLoader.depth > 0) {
|
||||
pageLoader.currentItem.deactivated()
|
||||
}
|
||||
|
||||
pageLoader.clear()
|
||||
if (slide) {
|
||||
pageLoader.push(pages[page], {}, StackView.PushTransition)
|
||||
@@ -111,6 +104,8 @@ Window {
|
||||
color: "white"
|
||||
}
|
||||
|
||||
//PageShareProtoAmnezia {}
|
||||
|
||||
StackView {
|
||||
id: pageLoader
|
||||
y: GC.isDesktop() ? titleBar.height : 0
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
#include <QClipboard>
|
||||
#include <QDebug>
|
||||
#include <QDesktopServices>
|
||||
#include <QFile>
|
||||
#include <QFileDialog>
|
||||
#include <QHBoxLayout>
|
||||
#include <QHostInfo>
|
||||
@@ -17,6 +16,7 @@
|
||||
#include <QThread>
|
||||
#include <QTimer>
|
||||
#include <QRegularExpression>
|
||||
#include <QSaveFile>
|
||||
|
||||
#include "configurators/cloak_configurator.h"
|
||||
#include "configurators/vpn_configurator.h"
|
||||
@@ -51,9 +51,8 @@
|
||||
#include "pages_logic/AppSettingsLogic.h"
|
||||
#include "pages_logic/GeneralSettingsLogic.h"
|
||||
#include "pages_logic/NetworkSettingsLogic.h"
|
||||
#include "pages_logic/NewServerProtocolsLogic.h"
|
||||
#include "pages_logic/QrDecoderLogic.h"
|
||||
#include "pages_logic/ServerConfiguringProgressLogic.h"
|
||||
#include "pages_logic/NewServerProtocolsLogic.h"
|
||||
#include "pages_logic/ServerListLogic.h"
|
||||
#include "pages_logic/ServerSettingsLogic.h"
|
||||
#include "pages_logic/ServerContainersLogic.h"
|
||||
@@ -85,9 +84,8 @@ UiLogic::UiLogic(QObject *parent) :
|
||||
m_appSettingsLogic = new AppSettingsLogic(this);
|
||||
m_generalSettingsLogic = new GeneralSettingsLogic(this);
|
||||
m_networkSettingsLogic = new NetworkSettingsLogic(this);
|
||||
m_newServerProtocolsLogic = new NewServerProtocolsLogic(this);
|
||||
m_qrDecoderLogic = new QrDecoderLogic(this);
|
||||
m_serverConfiguringProgressLogic = new ServerConfiguringProgressLogic(this);
|
||||
m_newServerProtocolsLogic = new NewServerProtocolsLogic(this);
|
||||
m_serverListLogic = new ServerListLogic(this);
|
||||
m_serverSettingsLogic = new ServerSettingsLogic(this);
|
||||
m_serverprotocolsLogic = new ServerContainersLogic(this);
|
||||
@@ -123,9 +121,9 @@ UiLogic::~UiLogic()
|
||||
}
|
||||
}
|
||||
|
||||
m_vpnConnection->deleteLater();
|
||||
m_vpnConnectionThread.quit();
|
||||
m_vpnConnectionThread.wait(3000);
|
||||
delete m_vpnConnection;
|
||||
|
||||
qDebug() << "Application closed";
|
||||
}
|
||||
@@ -265,6 +263,9 @@ void UiLogic::keyPressEvent(Qt::Key key)
|
||||
case Qt::Key_Q:
|
||||
qApp->quit();
|
||||
break;
|
||||
// case Qt::Key_0:
|
||||
// *((char*)-1) = 'x';
|
||||
// break;
|
||||
case Qt::Key_H:
|
||||
selectedServerIndex = m_settings.defaultServerIndex();
|
||||
selectedDockerContainer = m_settings.defaultContainer(selectedServerIndex);
|
||||
@@ -644,36 +645,38 @@ PageEnumNS::Page UiLogic::currentPage()
|
||||
return static_cast<PageEnumNS::Page>(currentPageValue());
|
||||
}
|
||||
|
||||
void UiLogic::saveTextFile(const QString& desc, const QString& ext, const QString& data)
|
||||
bool UiLogic::saveTextFile(const QString& desc, const QString& ext, const QString& data)
|
||||
{
|
||||
QString fileName = QFileDialog::getSaveFileName(nullptr, desc,
|
||||
QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation), ext);
|
||||
|
||||
if (fileName.isEmpty()) return;
|
||||
if (fileName.isEmpty()) return false;
|
||||
|
||||
QFile save(fileName);
|
||||
QSaveFile save(fileName);
|
||||
save.open(QIODevice::WriteOnly);
|
||||
save.write(data.toUtf8());
|
||||
save.close();
|
||||
|
||||
QFileInfo fi(fileName);
|
||||
QDesktopServices::openUrl(fi.absoluteDir().absolutePath());
|
||||
|
||||
return save.commit();
|
||||
}
|
||||
|
||||
void UiLogic::saveBinaryFile(const QString &desc, const QString &ext, const QString &data)
|
||||
bool UiLogic::saveBinaryFile(const QString &desc, const QString &ext, const QString &data)
|
||||
{
|
||||
QString fileName = QFileDialog::getSaveFileName(nullptr, desc,
|
||||
QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation), ext);
|
||||
|
||||
if (fileName.isEmpty()) return;
|
||||
if (fileName.isEmpty()) return false;
|
||||
|
||||
QFile save(fileName);
|
||||
QSaveFile save(fileName);
|
||||
save.open(QIODevice::WriteOnly);
|
||||
save.write(QByteArray::fromBase64(data.toUtf8()));
|
||||
save.close();
|
||||
|
||||
QFileInfo fi(fileName);
|
||||
QDesktopServices::openUrl(fi.absoluteDir().absolutePath());
|
||||
|
||||
return save.commit();
|
||||
}
|
||||
|
||||
void UiLogic::copyToClipboard(const QString &text)
|
||||
|
||||
@@ -22,7 +22,6 @@ class AppSettingsLogic;
|
||||
class GeneralSettingsLogic;
|
||||
class NetworkSettingsLogic;
|
||||
class NewServerProtocolsLogic;
|
||||
class QrDecoderLogic;
|
||||
class ServerConfiguringProgressLogic;
|
||||
class ServerListLogic;
|
||||
class ServerSettingsLogic;
|
||||
@@ -100,8 +99,8 @@ public:
|
||||
|
||||
Q_INVOKABLE void keyPressEvent(Qt::Key key);
|
||||
|
||||
Q_INVOKABLE void saveTextFile(const QString& desc, const QString& ext, const QString& data);
|
||||
Q_INVOKABLE void saveBinaryFile(const QString& desc, const QString& ext, const QString& data);
|
||||
Q_INVOKABLE bool saveTextFile(const QString& desc, const QString& ext, const QString& data);
|
||||
Q_INVOKABLE bool saveBinaryFile(const QString& desc, const QString& ext, const QString& data);
|
||||
Q_INVOKABLE void copyToClipboard(const QString& text);
|
||||
|
||||
QString getDialogConnectErrorText() const;
|
||||
@@ -168,9 +167,8 @@ public:
|
||||
AppSettingsLogic *appSettingsLogic() { return m_appSettingsLogic; }
|
||||
GeneralSettingsLogic *generalSettingsLogic() { return m_generalSettingsLogic; }
|
||||
NetworkSettingsLogic *networkSettingsLogic() { return m_networkSettingsLogic; }
|
||||
NewServerProtocolsLogic *newServerProtocolsLogic() { return m_newServerProtocolsLogic; }
|
||||
QrDecoderLogic *qrDecoderLogic() { return m_qrDecoderLogic; }
|
||||
ServerConfiguringProgressLogic *serverConfiguringProgressLogic() { return m_serverConfiguringProgressLogic; }
|
||||
NewServerProtocolsLogic *newServerProtocolsLogic() { return m_newServerProtocolsLogic; }
|
||||
ServerListLogic *serverListLogic() { return m_serverListLogic; }
|
||||
ServerSettingsLogic *serverSettingsLogic() { return m_serverSettingsLogic; }
|
||||
ServerContainersLogic *serverprotocolsLogic() { return m_serverprotocolsLogic; }
|
||||
@@ -193,9 +191,8 @@ private:
|
||||
AppSettingsLogic *m_appSettingsLogic;
|
||||
GeneralSettingsLogic *m_generalSettingsLogic;
|
||||
NetworkSettingsLogic *m_networkSettingsLogic;
|
||||
NewServerProtocolsLogic *m_newServerProtocolsLogic;
|
||||
QrDecoderLogic *m_qrDecoderLogic;
|
||||
ServerConfiguringProgressLogic *m_serverConfiguringProgressLogic;
|
||||
NewServerProtocolsLogic *m_newServerProtocolsLogic;
|
||||
ServerListLogic *m_serverListLogic;
|
||||
ServerSettingsLogic *m_serverSettingsLogic;
|
||||
ServerContainersLogic *m_serverprotocolsLogic;
|
||||
|
||||
@@ -26,16 +26,16 @@
|
||||
#include "utils.h"
|
||||
#include "vpnconnection.h"
|
||||
|
||||
VpnConnection::VpnConnection(QObject* parent) : QObject(parent),
|
||||
m_settings(this)
|
||||
|
||||
VpnConnection::VpnConnection(QObject* parent) : QObject(parent)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
VpnConnection::~VpnConnection()
|
||||
{
|
||||
m_vpnProtocol->deleteLater();
|
||||
//qDebug() << "VpnConnection::~VpnConnection() 1";
|
||||
m_vpnProtocol.clear();
|
||||
//qDebug() << "VpnConnection::~VpnConnection() 2";
|
||||
}
|
||||
|
||||
void VpnConnection::onBytesChanged(quint64 receivedBytes, quint64 sentBytes)
|
||||
@@ -47,7 +47,6 @@ void VpnConnection::onConnectionStateChanged(VpnProtocol::VpnConnectionState sta
|
||||
{
|
||||
if (IpcClient::Interface()) {
|
||||
if (state == VpnProtocol::Connected){
|
||||
IpcClient::Interface()->resetIpStack();
|
||||
IpcClient::Interface()->flushDns();
|
||||
|
||||
if (m_settings.routeMode() != Settings::VpnAllSites) {
|
||||
@@ -220,7 +219,7 @@ void VpnConnection::connectToVpn(int serverIndex,
|
||||
|
||||
#if !defined (Q_OS_ANDROID) && !defined (Q_OS_IOS)
|
||||
if (!m_IpcClient) {
|
||||
m_IpcClient = new IpcClient(this);
|
||||
m_IpcClient = new IpcClient;
|
||||
}
|
||||
|
||||
if (!m_IpcClient->isSocketConnected()) {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
DEVELOPMENT_TEAM = 7VAGZXD78P
|
||||
DEVELOPMENT_TEAM = X7UJ388FXK
|
||||
|
||||
GROUP_ID_IOS = group.ru.kotit.AmneziaVPN.udev
|
||||
APP_ID_IOS = ru.kotit.AmneziaVPN
|
||||
|
||||
@@ -11,7 +11,6 @@ class IpcInterface
|
||||
SLOT( bool clearSavedRoutes() );
|
||||
SLOT( bool routeDeleteList(const QString &gw, const QStringList &ip) );
|
||||
SLOT( void flushDns() );
|
||||
SLOT( void resetIpStack() );
|
||||
|
||||
SLOT( bool checkAndInstallDriver() );
|
||||
SLOT( QStringList getTapList() );
|
||||
|
||||
@@ -83,11 +83,6 @@ void IpcServer::flushDns()
|
||||
return Router::flushDns();
|
||||
}
|
||||
|
||||
void IpcServer::resetIpStack()
|
||||
{
|
||||
Router::resetIpStack();
|
||||
}
|
||||
|
||||
bool IpcServer::checkAndInstallDriver()
|
||||
{
|
||||
#ifdef Q_OS_WIN
|
||||
|
||||
@@ -20,7 +20,6 @@ public:
|
||||
virtual bool clearSavedRoutes() override;
|
||||
virtual bool routeDeleteList(const QString &gw, const QStringList &ips) override;
|
||||
virtual void flushDns() override;
|
||||
virtual void resetIpStack() override;
|
||||
virtual bool checkAndInstallDriver() override;
|
||||
virtual QStringList getTapList() override;
|
||||
|
||||
|
||||
@@ -1,290 +0,0 @@
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#include "ipaddress.h"
|
||||
#include "leakdetector.h"
|
||||
//#include "logger.h"
|
||||
|
||||
#include <QtMath>
|
||||
|
||||
//namespace {
|
||||
//Logger logger(LOG_NETWORKING, "IPAddress");
|
||||
//} // namespace
|
||||
|
||||
IPAddress::IPAddress() { MVPN_COUNT_CTOR(IPAddress); }
|
||||
|
||||
IPAddress::IPAddress(const QString& ip) {
|
||||
MVPN_COUNT_CTOR(IPAddress);
|
||||
if (ip.contains("/")) {
|
||||
QPair<QHostAddress, int> p = QHostAddress::parseSubnet(ip);
|
||||
m_address = p.first;
|
||||
m_prefixLength = p.second;
|
||||
} else {
|
||||
m_address = QHostAddress(ip);
|
||||
m_prefixLength = 999999;
|
||||
}
|
||||
|
||||
if (m_address.protocol() == QAbstractSocket::IPv4Protocol) {
|
||||
if (m_prefixLength >= 32) {
|
||||
m_prefixLength = 32;
|
||||
}
|
||||
} else if (m_address.protocol() == QAbstractSocket::IPv6Protocol) {
|
||||
if (m_prefixLength >= 128) {
|
||||
m_prefixLength = 128;
|
||||
}
|
||||
} else {
|
||||
Q_ASSERT(false);
|
||||
}
|
||||
}
|
||||
|
||||
IPAddress::IPAddress(const IPAddress& other) {
|
||||
MVPN_COUNT_CTOR(IPAddress);
|
||||
*this = other;
|
||||
}
|
||||
|
||||
IPAddress& IPAddress::operator=(const IPAddress& other) {
|
||||
if (this == &other) return *this;
|
||||
|
||||
m_address = other.m_address;
|
||||
m_prefixLength = other.m_prefixLength;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
IPAddress::IPAddress(const QHostAddress& address) : m_address(address) {
|
||||
MVPN_COUNT_CTOR(IPAddress);
|
||||
|
||||
if (address.protocol() == QAbstractSocket::IPv4Protocol) {
|
||||
m_prefixLength = 32;
|
||||
} else {
|
||||
Q_ASSERT(address.protocol() == QAbstractSocket::IPv6Protocol);
|
||||
m_prefixLength = 128;
|
||||
}
|
||||
}
|
||||
|
||||
IPAddress::IPAddress(const QHostAddress& address, int prefixLength)
|
||||
: m_address(address), m_prefixLength(prefixLength) {
|
||||
MVPN_COUNT_CTOR(IPAddress);
|
||||
|
||||
if (address.protocol() == QAbstractSocket::IPv4Protocol) {
|
||||
Q_ASSERT(prefixLength >= 0 && prefixLength <= 32);
|
||||
} else {
|
||||
Q_ASSERT(address.protocol() == QAbstractSocket::IPv6Protocol);
|
||||
Q_ASSERT(prefixLength >= 0 && prefixLength <= 128);
|
||||
}
|
||||
}
|
||||
|
||||
IPAddress::~IPAddress() { MVPN_COUNT_DTOR(IPAddress); }
|
||||
|
||||
QAbstractSocket::NetworkLayerProtocol IPAddress::type() const {
|
||||
return m_address.protocol();
|
||||
}
|
||||
|
||||
QHostAddress IPAddress::netmask() const {
|
||||
if (m_address.protocol() == QAbstractSocket::IPv6Protocol) {
|
||||
Q_IPV6ADDR rawNetmask = {0};
|
||||
Q_ASSERT(m_prefixLength <= 128);
|
||||
memset(&rawNetmask, 0xff, m_prefixLength / 8);
|
||||
if (m_prefixLength % 8) {
|
||||
rawNetmask[m_prefixLength / 8] = 0xFF ^ (0xFF >> (m_prefixLength % 8));
|
||||
}
|
||||
return QHostAddress(rawNetmask);
|
||||
} else if (m_address.protocol() == QAbstractSocket::IPv4Protocol) {
|
||||
quint32 rawNetmask = 0xffffffff;
|
||||
Q_ASSERT(m_prefixLength <= 32);
|
||||
if (m_prefixLength < 32) {
|
||||
rawNetmask ^= (0xffffffff >> m_prefixLength);
|
||||
}
|
||||
return QHostAddress(rawNetmask);
|
||||
} else {
|
||||
return QHostAddress();
|
||||
}
|
||||
}
|
||||
|
||||
QHostAddress IPAddress::hostmask() const {
|
||||
if (m_address.protocol() == QAbstractSocket::IPv6Protocol) {
|
||||
Q_IPV6ADDR rawHostmask = {0};
|
||||
int offset = (m_prefixLength + 7) / 8;
|
||||
Q_ASSERT(m_prefixLength <= 128);
|
||||
memset(&rawHostmask[offset], 0xff, sizeof(rawHostmask) - offset);
|
||||
if (m_prefixLength % 8) {
|
||||
rawHostmask[m_prefixLength / 8] = 0xFF >> (m_prefixLength % 8);
|
||||
}
|
||||
return QHostAddress(rawHostmask);
|
||||
} else if (m_address.protocol() == QAbstractSocket::IPv4Protocol) {
|
||||
if (m_prefixLength < 32) {
|
||||
return QHostAddress(0xffffffff >> m_prefixLength);
|
||||
} else {
|
||||
quint32 zero = 0;
|
||||
return QHostAddress(zero);
|
||||
}
|
||||
} else {
|
||||
return QHostAddress();
|
||||
}
|
||||
}
|
||||
|
||||
QHostAddress IPAddress::broadcastAddress() const {
|
||||
if (m_address.protocol() == QAbstractSocket::IPv6Protocol) {
|
||||
Q_IPV6ADDR rawAddress = m_address.toIPv6Address();
|
||||
int offset = (m_prefixLength + 7) / 8;
|
||||
memset(&rawAddress[offset], 0xff, sizeof(rawAddress) - offset);
|
||||
if (m_prefixLength % 8) {
|
||||
rawAddress[m_prefixLength / 8] |= 0xFF >> (m_prefixLength % 8);
|
||||
}
|
||||
return QHostAddress(rawAddress);
|
||||
} else if (m_address.protocol() == QAbstractSocket::IPv4Protocol) {
|
||||
quint32 rawAddress = m_address.toIPv4Address();
|
||||
if (m_prefixLength < 32) {
|
||||
rawAddress |= (0xffffffff >> m_prefixLength);
|
||||
}
|
||||
return QHostAddress(rawAddress);
|
||||
} else {
|
||||
return QHostAddress();
|
||||
}
|
||||
}
|
||||
|
||||
bool IPAddress::overlaps(const IPAddress& other) const {
|
||||
if (m_prefixLength < other.m_prefixLength) {
|
||||
return contains(other.m_address);
|
||||
} else {
|
||||
return other.contains(m_address);
|
||||
}
|
||||
}
|
||||
|
||||
bool IPAddress::contains(const QHostAddress& address) const {
|
||||
if (address.protocol() != m_address.protocol()) {
|
||||
return false;
|
||||
}
|
||||
if (m_prefixLength == 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (m_address.protocol() == QAbstractSocket::IPv6Protocol) {
|
||||
Q_IPV6ADDR a = m_address.toIPv6Address();
|
||||
Q_IPV6ADDR b = address.toIPv6Address();
|
||||
int bytes = m_prefixLength / 8;
|
||||
if (bytes > 0) {
|
||||
if (memcmp(&a, &b, bytes) != 0) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (m_prefixLength % 8) {
|
||||
quint8 diff = (a[bytes] ^ b[bytes]) >> (8 - m_prefixLength % 8);
|
||||
return (diff == 0);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
if (m_address.protocol() == QAbstractSocket::IPv4Protocol) {
|
||||
quint32 diff = m_address.toIPv4Address() ^ address.toIPv4Address();
|
||||
if (m_prefixLength < 32) {
|
||||
diff >>= (32 - m_prefixLength);
|
||||
}
|
||||
return (diff == 0);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool IPAddress::operator==(const IPAddress& other) const {
|
||||
return m_address == other.m_address && m_prefixLength == other.m_prefixLength;
|
||||
}
|
||||
|
||||
bool IPAddress::subnetOf(const IPAddress& other) const {
|
||||
if (other.m_address.protocol() != m_address.protocol()) {
|
||||
return false;
|
||||
}
|
||||
if (m_prefixLength < other.m_prefixLength) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return other.contains(m_address);
|
||||
}
|
||||
|
||||
QList<IPAddress> IPAddress::subnets() const {
|
||||
QList<IPAddress> list;
|
||||
|
||||
if (m_address.protocol() == QAbstractSocket::IPv4Protocol) {
|
||||
if (m_prefixLength >= 32) {
|
||||
list.append(*this);
|
||||
return list;
|
||||
}
|
||||
|
||||
quint32 rawAddress = m_address.toIPv4Address();
|
||||
list.append(IPAddress(QHostAddress(rawAddress), m_prefixLength + 1));
|
||||
|
||||
rawAddress |= (0x80000000 >> m_prefixLength);
|
||||
list.append(IPAddress(QHostAddress(rawAddress), m_prefixLength + 1));
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
Q_ASSERT(m_address.protocol() == QAbstractSocket::IPv6Protocol);
|
||||
|
||||
if (m_prefixLength >= 128) {
|
||||
list.append(*this);
|
||||
return list;
|
||||
}
|
||||
|
||||
Q_IPV6ADDR rawAddress = m_address.toIPv6Address();
|
||||
list.append(IPAddress(QHostAddress(rawAddress), m_prefixLength + 1));
|
||||
|
||||
rawAddress[m_prefixLength / 8] |= (0x80 >> (m_prefixLength % 8));
|
||||
list.append(IPAddress(QHostAddress(rawAddress), m_prefixLength + 1));
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
// static
|
||||
QList<IPAddress> IPAddress::excludeAddresses(
|
||||
const QList<IPAddress>& sourceList, const QList<IPAddress>& excludeList) {
|
||||
QList<IPAddress> results = sourceList;
|
||||
|
||||
for (const IPAddress& exclude : excludeList) {
|
||||
QList<IPAddress> newResults;
|
||||
|
||||
for (const IPAddress& ip : results) {
|
||||
if (ip.overlaps(exclude)) {
|
||||
QList<IPAddress> range = ip.excludeAddresses(exclude);
|
||||
newResults.append(range);
|
||||
} else {
|
||||
newResults.append(ip);
|
||||
}
|
||||
}
|
||||
|
||||
results = newResults;
|
||||
}
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
QList<IPAddress> IPAddress::excludeAddresses(const IPAddress& ip) const {
|
||||
QList<IPAddress> sn = subnets();
|
||||
Q_ASSERT(sn.length() >= 2);
|
||||
|
||||
QList<IPAddress> result;
|
||||
while (sn[0] != ip && sn[1] != ip) {
|
||||
if (ip.subnetOf(sn[0])) {
|
||||
result.append(sn[1]);
|
||||
sn = sn[0].subnets();
|
||||
} else if (ip.subnetOf(sn[1])) {
|
||||
result.append(sn[0]);
|
||||
sn = sn[1].subnets();
|
||||
} else {
|
||||
Q_ASSERT(false);
|
||||
}
|
||||
}
|
||||
|
||||
if (sn[0] == ip) {
|
||||
result.append(sn[1]);
|
||||
} else if (sn[1] == ip) {
|
||||
result.append(sn[0]);
|
||||
} else {
|
||||
Q_ASSERT(false);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
@@ -1,53 +0,0 @@
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#ifndef IPADDRESS_H
|
||||
#define IPADDRESS_H
|
||||
|
||||
#include <QHostAddress>
|
||||
|
||||
class IPAddress final {
|
||||
public:
|
||||
static QList<IPAddress> excludeAddresses(const QList<IPAddress>& sourceList,
|
||||
const QList<IPAddress>& excludeList);
|
||||
|
||||
IPAddress();
|
||||
IPAddress(const QString& ip);
|
||||
IPAddress(const QHostAddress& address);
|
||||
IPAddress(const QHostAddress& address, int prefixLength);
|
||||
IPAddress(const IPAddress& other);
|
||||
IPAddress& operator=(const IPAddress& other);
|
||||
~IPAddress();
|
||||
|
||||
QString toString() const {
|
||||
return QString("%1/%2").arg(m_address.toString()).arg(m_prefixLength);
|
||||
}
|
||||
|
||||
const QHostAddress& address() const { return m_address; }
|
||||
int prefixLength() const { return m_prefixLength; }
|
||||
QHostAddress netmask() const;
|
||||
QHostAddress hostmask() const;
|
||||
QHostAddress broadcastAddress() const;
|
||||
|
||||
bool overlaps(const IPAddress& other) const;
|
||||
|
||||
bool contains(const QHostAddress& address) const;
|
||||
|
||||
bool operator==(const IPAddress& other) const;
|
||||
bool operator!=(const IPAddress& other) const { return !operator==(other); }
|
||||
|
||||
bool subnetOf(const IPAddress& other) const;
|
||||
|
||||
QList<IPAddress> subnets() const;
|
||||
|
||||
QList<IPAddress> excludeAddresses(const IPAddress& ip) const;
|
||||
|
||||
QAbstractSocket::NetworkLayerProtocol type() const;
|
||||
|
||||
private:
|
||||
QHostAddress m_address;
|
||||
int m_prefixLength;
|
||||
};
|
||||
|
||||
#endif // IPADDRESS_H
|
||||
@@ -1,17 +0,0 @@
|
||||
INCLUDEPATH+= $$PWD
|
||||
DEPENDPATH += $$PWD
|
||||
QT += core network
|
||||
HEADERS += \
|
||||
$$PWD/leakdetector.h \
|
||||
$$PWD/windowsfirewall.h \
|
||||
$$PWD/ipaddress.h \
|
||||
$$PWD/windowscommons.h
|
||||
|
||||
SOURCES += \
|
||||
$$PWD/leakdetector.cpp \
|
||||
$$PWD/windowsfirewall.cpp \
|
||||
$$PWD/ipaddress.cpp \
|
||||
$$PWD/windowscommons.cpp
|
||||
|
||||
# TARGET = libkillswitch
|
||||
|
||||
@@ -1,75 +0,0 @@
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#include "leakdetector.h"
|
||||
|
||||
#include <QHash>
|
||||
#include <QMutex>
|
||||
#include <QObject>
|
||||
#include <QTextStream>
|
||||
|
||||
#ifdef MVPN_DEBUG
|
||||
static QMutex s_leakDetector;
|
||||
|
||||
QHash<QString, QHash<void*, uint32_t>> s_leaks;
|
||||
#endif
|
||||
|
||||
LeakDetector::LeakDetector() {
|
||||
#ifndef MVPN_DEBUG
|
||||
qFatal("LeakDetector _must_ be created in debug builds only!");
|
||||
#endif
|
||||
}
|
||||
|
||||
LeakDetector::~LeakDetector() {
|
||||
#ifdef MVPN_DEBUG
|
||||
QTextStream out(stderr);
|
||||
|
||||
out << "== Mozilla VPN - Leak report ===================" << Qt::endl;
|
||||
|
||||
bool hasLeaks = false;
|
||||
for (auto i = s_leaks.begin(); i != s_leaks.end(); ++i) {
|
||||
QString className = i.key();
|
||||
|
||||
if (i->size() == 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
hasLeaks = true;
|
||||
out << className << Qt::endl;
|
||||
|
||||
for (auto l = i->begin(); l != i->end(); ++l) {
|
||||
out << " - ptr: " << l.key() << " size:" << l.value() << Qt::endl;
|
||||
}
|
||||
}
|
||||
|
||||
if (!hasLeaks) {
|
||||
out << "No leaks detected." << Qt::endl;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef MVPN_DEBUG
|
||||
void LeakDetector::logCtor(void* ptr, const char* typeName, uint32_t size) {
|
||||
QMutexLocker lock(&s_leakDetector);
|
||||
|
||||
QString type(typeName);
|
||||
if (!s_leaks.contains(type)) {
|
||||
s_leaks.insert(type, QHash<void*, uint32_t>());
|
||||
}
|
||||
|
||||
s_leaks[type].insert(ptr, size);
|
||||
}
|
||||
|
||||
void LeakDetector::logDtor(void* ptr, const char* typeName, uint32_t size) {
|
||||
QMutexLocker lock(&s_leakDetector);
|
||||
|
||||
QString type(typeName);
|
||||
Q_ASSERT(s_leaks.contains(type));
|
||||
|
||||
QHash<void*, uint32_t>& leak = s_leaks[type];
|
||||
Q_ASSERT(leak.contains(ptr));
|
||||
Q_ASSERT(leak[ptr] == size);
|
||||
leak.remove(ptr);
|
||||
}
|
||||
#endif
|
||||
@@ -1,41 +0,0 @@
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#ifndef LEAKDETECTOR_H
|
||||
#define LEAKDETECTOR_H
|
||||
|
||||
#include <QObject>
|
||||
|
||||
#ifdef MVPN_DEBUG
|
||||
# define MVPN_COUNT_CTOR(_type) \
|
||||
do { \
|
||||
static_assert(std::is_class<_type>(), \
|
||||
"Token '" #_type "' is not a class type."); \
|
||||
LeakDetector::logCtor((void*)this, #_type, sizeof(*this)); \
|
||||
} while (0)
|
||||
|
||||
# define MVPN_COUNT_DTOR(_type) \
|
||||
do { \
|
||||
static_assert(std::is_class<_type>(), \
|
||||
"Token '" #_type "' is not a class type."); \
|
||||
LeakDetector::logDtor((void*)this, #_type, sizeof(*this)); \
|
||||
} while (0)
|
||||
|
||||
#else
|
||||
# define MVPN_COUNT_CTOR(_type)
|
||||
# define MVPN_COUNT_DTOR(_type)
|
||||
#endif
|
||||
|
||||
class LeakDetector {
|
||||
public:
|
||||
LeakDetector();
|
||||
~LeakDetector();
|
||||
|
||||
#ifdef MVPN_DEBUG
|
||||
static void logCtor(void* ptr, const char* typeName, uint32_t size);
|
||||
static void logDtor(void* ptr, const char* typeName, uint32_t size);
|
||||
#endif
|
||||
};
|
||||
|
||||
#endif // LEAKDETECTOR_H
|
||||
@@ -1,182 +0,0 @@
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#include "windowscommons.h"
|
||||
//#include "logger.h"
|
||||
|
||||
#include <QDir>
|
||||
#include <QtEndian>
|
||||
#include <QHostAddress>
|
||||
#include <QSettings>
|
||||
#include <QStandardPaths>
|
||||
#include <QSysInfo>
|
||||
#include <QNetworkInterface>
|
||||
|
||||
#include <Windows.h>
|
||||
#include <iphlpapi.h>
|
||||
|
||||
#define TUNNEL_SERVICE_NAME L"WireGuardTunnel$mozvpn"
|
||||
|
||||
constexpr const char* VPN_NAME = "MozillaVPN";
|
||||
|
||||
constexpr const int WINDOWS_11_BUILD =
|
||||
22000; // Build Number of the first release win 11 iso
|
||||
//namespace {
|
||||
//Logger logger(LOG_MAIN, "WindowsCommons");
|
||||
//}
|
||||
|
||||
QString WindowsCommons::getErrorMessage() {
|
||||
DWORD errorId = GetLastError();
|
||||
LPSTR messageBuffer = nullptr;
|
||||
size_t size = FormatMessageA(
|
||||
FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM |
|
||||
FORMAT_MESSAGE_IGNORE_INSERTS,
|
||||
nullptr, errorId, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
|
||||
(LPSTR)&messageBuffer, 0, nullptr);
|
||||
|
||||
std::string message(messageBuffer, size);
|
||||
QString result(message.c_str());
|
||||
LocalFree(messageBuffer);
|
||||
return result;
|
||||
}
|
||||
|
||||
// A simple function to log windows error messages.
|
||||
void WindowsCommons::windowsLog(const QString& msg) {
|
||||
QString errmsg = getErrorMessage();
|
||||
qDebug() << msg << "-" << errmsg;
|
||||
}
|
||||
|
||||
QString WindowsCommons::tunnelConfigFile() {
|
||||
QStringList paths =
|
||||
QStandardPaths::standardLocations(QStandardPaths::GenericDataLocation);
|
||||
for (const QString& path : paths) {
|
||||
QDir dir(path);
|
||||
if (!dir.exists()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
QDir vpnDir(dir.filePath(VPN_NAME));
|
||||
if (!vpnDir.exists()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
QString wireguardFile(vpnDir.filePath(QString("%1.conf").arg(VPN_NAME)));
|
||||
if (!QFileInfo::exists(wireguardFile)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
qDebug() << "Found the current wireguard configuration:"
|
||||
<< wireguardFile;
|
||||
return wireguardFile;
|
||||
}
|
||||
|
||||
for (const QString& path : paths) {
|
||||
QDir dir(path);
|
||||
|
||||
QDir vpnDir(dir.filePath(VPN_NAME));
|
||||
if (!vpnDir.exists() && !dir.mkdir(VPN_NAME)) {
|
||||
qDebug() << "Failed to create path Mozilla under" << path;
|
||||
continue;
|
||||
}
|
||||
|
||||
return vpnDir.filePath(QString("%1.conf").arg(VPN_NAME));
|
||||
}
|
||||
|
||||
qDebug() << "Failed to create the right paths";
|
||||
return QString();
|
||||
}
|
||||
|
||||
QString WindowsCommons::tunnelLogFile() {
|
||||
QStringList paths =
|
||||
QStandardPaths::standardLocations(QStandardPaths::GenericDataLocation);
|
||||
|
||||
for (const QString& path : paths) {
|
||||
QDir dir(path);
|
||||
if (!dir.exists()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
QDir vpnDir(dir.filePath(VPN_NAME));
|
||||
if (!vpnDir.exists()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
return vpnDir.filePath("log.bin");
|
||||
}
|
||||
|
||||
return QString();
|
||||
}
|
||||
|
||||
// static
|
||||
int WindowsCommons::AdapterIndexTo(const QHostAddress& dst) {
|
||||
qDebug() << "Getting Current Internet Adapter that routes to"
|
||||
<< dst.toString();
|
||||
quint32_be ipBigEndian;
|
||||
quint32 ip = dst.toIPv4Address();
|
||||
qToBigEndian(ip, &ipBigEndian);
|
||||
_MIB_IPFORWARDROW routeInfo;
|
||||
auto result = GetBestRoute(ipBigEndian, 0, &routeInfo);
|
||||
if (result != NO_ERROR) {
|
||||
return -1;
|
||||
}
|
||||
auto adapter =
|
||||
QNetworkInterface::interfaceFromIndex(routeInfo.dwForwardIfIndex);
|
||||
//logger.debug() << "Internet Adapter:" << adapter.name();
|
||||
qDebug()<< "Internet Adapter:" << adapter.name();
|
||||
return routeInfo.dwForwardIfIndex;
|
||||
}
|
||||
|
||||
// static
|
||||
int WindowsCommons::VPNAdapterIndex() {
|
||||
// For someReason QNetworkInterface::fromName(MozillaVPN) does not work >:(
|
||||
auto adapterList = QNetworkInterface::allInterfaces();
|
||||
for (const auto& adapter : adapterList) {
|
||||
if (
|
||||
adapter.humanReadableName().contains(IKEV2) ||
|
||||
adapter.humanReadableName().contains(IKEV2)
|
||||
) {
|
||||
return adapter.index();
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Static
|
||||
QString WindowsCommons::getCurrentPath() {
|
||||
QByteArray buffer(2048, 0xFF);
|
||||
auto ok = GetModuleFileNameA(NULL, buffer.data(), buffer.size());
|
||||
|
||||
if (ok == ERROR_INSUFFICIENT_BUFFER) {
|
||||
buffer.resize(buffer.size() * 2);
|
||||
ok = GetModuleFileNameA(NULL, buffer.data(), buffer.size());
|
||||
}
|
||||
if (ok == 0) {
|
||||
WindowsCommons::windowsLog("Err fetching dos path");
|
||||
return "";
|
||||
}
|
||||
return QString::fromLocal8Bit(buffer);
|
||||
}
|
||||
|
||||
// Static
|
||||
QString WindowsCommons::WindowsVersion() {
|
||||
/* The Tradegy of Getting a somewhat working windows version:
|
||||
- GetVersion() -> deprecated and Reports win 8.1 for MozillaVPN... its tied
|
||||
to some .exe flags
|
||||
- NetWkstaGetInfo -> Reports Windows 10 on windows 11
|
||||
There is also the regirstry HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows
|
||||
NT\CurrentVersion
|
||||
-> CurrentMajorVersion reports 10 on win 11
|
||||
-> CurrentBuild seems to be correct, so lets infer it
|
||||
*/
|
||||
|
||||
QSettings regCurrentVersion(
|
||||
"HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion",
|
||||
QSettings::NativeFormat);
|
||||
|
||||
int buildNr = regCurrentVersion.value("CurrentBuild").toInt();
|
||||
if (buildNr >= WINDOWS_11_BUILD) {
|
||||
return "11";
|
||||
}
|
||||
return QSysInfo::productVersion();
|
||||
}
|
||||
@@ -1,32 +0,0 @@
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#ifndef WINDOWSCOMMONS_H
|
||||
#define WINDOWSCOMMONS_H
|
||||
|
||||
#include <QString>
|
||||
|
||||
constexpr char IKEV2[] {"AmneziaVPN IKEv2\0"};
|
||||
|
||||
class QHostAddress;
|
||||
|
||||
class WindowsCommons final {
|
||||
public:
|
||||
static QString getErrorMessage();
|
||||
static void windowsLog(const QString& msg);
|
||||
|
||||
static QString tunnelConfigFile();
|
||||
static QString tunnelLogFile();
|
||||
|
||||
// Returns the Interface Index of the VPN Adapter
|
||||
static int VPNAdapterIndex();
|
||||
// Returns the Interface Index that could Route to dst
|
||||
static int AdapterIndexTo(const QHostAddress& dst);
|
||||
// Returns the Path of the Current process
|
||||
static QString getCurrentPath();
|
||||
// Returns the major version of Windows
|
||||
static QString WindowsVersion();
|
||||
};
|
||||
|
||||
#endif // WINDOWSCOMMONS_H
|
||||