Skip to content

Commit

Permalink
Source code changes
Browse files Browse the repository at this point in the history
  • Loading branch information
yaroslavyaroslav committed Feb 12, 2025
1 parent 613a133 commit e58c594
Show file tree
Hide file tree
Showing 34 changed files with 372 additions and 235 deletions.
10 changes: 6 additions & 4 deletions client/amnezia_application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

#include "protocols/qml_register_protocols.h"

#if defined(Q_OS_IOS)
#if defined(Q_OS_IOS) || defined(MACOS_NE)
#include "platforms/ios/ios_controller.h"
#include <AmneziaVPN-Swift.h>
#endif
Expand Down Expand Up @@ -121,7 +121,8 @@ void AmneziaApplication::init()
m_engine->addImageProvider(QLatin1String("installedAppImage"), new InstalledAppsImageProvider);
#endif

#ifdef Q_OS_IOS
#if defined(Q_OS_IOS)
#if defined(MACOS_NE)
IosController::Instance()->initialize();
connect(IosController::Instance(), &IosController::importConfigFromOutside, this, [this](QString data) {
emit m_pageController->goToPageHome();
Expand All @@ -134,6 +135,7 @@ void AmneziaApplication::init()
m_pageController->goToPageSettingsBackup();
emit m_settingsController->importBackupFromOutside(filePath);
});
#endif

QTimer::singleShot(0, this, [this]() { AmneziaVPN::toggleScreenshots(m_settings->isScreenshotsEnabled()); });

Expand Down Expand Up @@ -269,7 +271,7 @@ bool AmneziaApplication::parseCommands()

QCommandLineOption c_cleanup { { "c", "cleanup" }, "Cleanup logs" };
m_parser.addOption(c_cleanup);

m_parser.process(*this);

if (m_parser.isSet(c_cleanup)) {
Expand All @@ -281,7 +283,7 @@ bool AmneziaApplication::parseCommands()
return true;
}

#if !defined(Q_OS_ANDROID) && !defined(Q_OS_IOS)
#if !defined(Q_OS_ANDROID) && !defined(Q_OS_IOS) && !defined(MACOS_NE)
void AmneziaApplication::startLocalServer() {
const QString serverName("AmneziaVPNInstance");
QLocalServer::removeServer(serverName);
Expand Down
6 changes: 3 additions & 3 deletions client/amnezia_application.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include <QQmlApplicationEngine>
#include <QQmlContext>
#include <QThread>
#if defined(Q_OS_ANDROID) || defined(Q_OS_IOS)
#if defined(Q_OS_ANDROID) || defined(Q_OS_IOS) || defined(MACOS_NE)
#include <QGuiApplication>
#else
#include <QApplication>
Expand Down Expand Up @@ -51,7 +51,7 @@

#define amnApp (static_cast<AmneziaApplication *>(QCoreApplication::instance()))

#if defined(Q_OS_ANDROID) || defined(Q_OS_IOS)
#if defined(Q_OS_ANDROID) || defined(Q_OS_IOS) || defined(MACOS_NE)
#define AMNEZIA_BASE_CLASS QGuiApplication
#else
#define AMNEZIA_BASE_CLASS QApplication
Expand All @@ -71,7 +71,7 @@ class AmneziaApplication : public AMNEZIA_BASE_CLASS
void updateTranslator(const QLocale &locale);
bool parseCommands();

#if !defined(Q_OS_ANDROID) && !defined(Q_OS_IOS)
#if !defined(Q_OS_ANDROID) && !defined(Q_OS_IOS) && !defined(MACOS_NE)
void startLocalServer();
#endif

Expand Down
6 changes: 3 additions & 3 deletions client/configurators/openvpn_configurator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include <QString>
#include <QTemporaryDir>
#include <QTemporaryFile>
#if defined(Q_OS_ANDROID) || defined(Q_OS_IOS)
#if defined(Q_OS_ANDROID) || defined(Q_OS_IOS) || defined(MACOS_NE)
#include <QGuiApplication>
#else
#include <QApplication>
Expand Down Expand Up @@ -120,7 +120,7 @@ QString OpenVpnConfigurator::processConfigWithLocalSettings(const QPair<QString,
if (!m_settings->isSitesSplitTunnelingEnabled()) {
config.append("\nredirect-gateway def1 ipv6 bypass-dhcp\n");

#if !defined(Q_OS_ANDROID) && !defined(Q_OS_IOS)
#if !defined(Q_OS_ANDROID) && !defined(Q_OS_IOS) && !defined(MACOS_NE)
// Prevent ipv6 leak
config.append("ifconfig-ipv6 fd15:53b6:dead::2/64 fd15:53b6:dead::1\n");
#endif
Expand All @@ -129,7 +129,7 @@ QString OpenVpnConfigurator::processConfigWithLocalSettings(const QPair<QString,

// no redirect-gateway
} else if (m_settings->routeMode() == Settings::VpnAllExceptSites) {
#if !defined(Q_OS_ANDROID) && !defined(Q_OS_IOS)
#if !defined(Q_OS_ANDROID) && !defined(Q_OS_IOS) && !defined(MACOS_NE)
config.append("\nredirect-gateway ipv6 !ipv4 bypass-dhcp\n");
// Prevent ipv6 leak
config.append("ifconfig-ipv6 fd15:53b6:dead::2/64 fd15:53b6:dead::1\n");
Expand Down
9 changes: 5 additions & 4 deletions client/configurators/ssh_configurator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include <QTemporaryFile>
#include <QThread>
#include <qtimer.h>
#if defined(Q_OS_ANDROID) || defined(Q_OS_IOS)
#if defined(Q_OS_ANDROID) || defined(Q_OS_IOS) || defined(MACOS_NE)
#include <QGuiApplication>
#else
#include <QApplication>
Expand All @@ -24,7 +24,7 @@ SshConfigurator::SshConfigurator(std::shared_ptr<Settings> settings, const QShar

QString SshConfigurator::convertOpenSShKey(const QString &key)
{
#ifndef Q_OS_IOS
#if !defined(Q_OS_IOS) && !defined(MACOS_NE)
QProcess p;
p.setProcessChannelMode(QProcess::MergedChannels);

Expand Down Expand Up @@ -67,9 +67,10 @@ QString SshConfigurator::convertOpenSShKey(const QString &key)
#endif
}

// DEAD CODE.
void SshConfigurator::openSshTerminal(const ServerCredentials &credentials)
{
#ifndef Q_OS_IOS
#if !defined(Q_OS_IOS) && !defined(MACOS_NE)
QProcess *p = new QProcess();
p->setProcessChannelMode(QProcess::SeparateChannels);

Expand Down Expand Up @@ -101,7 +102,7 @@ QProcessEnvironment SshConfigurator::prepareEnv()
pathEnvVar.clear();
pathEnvVar.prepend(QDir::toNativeSeparators(QApplication::applicationDirPath()) + "\\cygwin;");
pathEnvVar.prepend(QDir::toNativeSeparators(QApplication::applicationDirPath()) + "\\openvpn;");
#elif defined(Q_OS_MACX)
#elif defined(Q_OS_MAC) && !defined(MACOS_NE)
pathEnvVar.prepend(QDir::toNativeSeparators(QApplication::applicationDirPath()) + "/Contents/MacOS");
#endif

Expand Down
2 changes: 1 addition & 1 deletion client/containers/containers_defs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ bool ContainerProps::isSupportedByCurrentPlatform(DockerContainer c)
#ifdef Q_OS_WINDOWS
return true;

#elif defined(Q_OS_IOS)
#elif defined(Q_OS_IOS) || defined(MACOS_NE)
switch (c) {
case DockerContainer::WireGuard: return true;
case DockerContainer::OpenVpn: return true;
Expand Down
6 changes: 3 additions & 3 deletions client/core/controllers/apiController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ QJsonObject ApiController::fillApiPayload(const QString &protocol, const ApiCont

void ApiController::updateServerConfigFromApi(const QString &installationUuid, const int serverIndex, QJsonObject serverConfig)
{
#ifdef Q_OS_IOS
#if defined(Q_OS_IOS) || defined(MACOS_NE)
IosController::Instance()->requestInetAccess();
QThread::msleep(10);
#endif
Expand Down Expand Up @@ -332,7 +332,7 @@ void ApiController::updateServerConfigFromApi(const QString &installationUuid, c

ErrorCode ApiController::getServicesList(QByteArray &responseBody)
{
#ifdef Q_OS_IOS
#if defined(Q_OS_IOS) || defined(MACOS_NE)
IosController::Instance()->requestInetAccess();
QThread::msleep(10);
#endif
Expand Down Expand Up @@ -393,7 +393,7 @@ ErrorCode ApiController::getConfigForService(const QString &installationUuid, co
const QString &protocol, const QString &serverCountryCode, const QJsonObject &authData,
QJsonObject &serverConfig)
{
#ifdef Q_OS_IOS
#if defined(Q_OS_IOS) || defined(MACOS_NE)
IosController::Instance()->requestInetAccess();
QThread::msleep(10);
#endif
Expand Down
2 changes: 1 addition & 1 deletion client/core/controllers/apiController.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

#include "configurators/openvpn_configurator.h"

#ifdef Q_OS_IOS
#if defined(Q_OS_IOS) || defined(MACOS_NE)
#include "platforms/ios/ios_controller.h"
#endif

Expand Down
4 changes: 2 additions & 2 deletions client/core/networkUtilities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#include <sys/socket.h>
#include <unistd.h>
#endif
#if defined(Q_OS_MAC) && !defined(Q_OS_IOS)
#if defined(Q_OS_MAC) && !defined(Q_OS_IOS) && !defined(MACOS_NE)
#include <sys/param.h>
#include <sys/sysctl.h>
#include <sys/socket.h>
Expand Down Expand Up @@ -378,7 +378,7 @@ QString NetworkUtilities::getGatewayAndIface()
close(sock);
return gateway_address;
#endif
#if defined(Q_OS_MAC) && !defined(Q_OS_IOS)
#if defined(Q_OS_MAC) && !defined(Q_OS_IOS) && !defined(MACOS_NE)
QString gateway;
int mib[] = {CTL_NET, PF_ROUTE, 0, 0, NET_RT_FLAGS, RTF_GATEWAY};
int afinet_type[] = {AF_INET, AF_INET6};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/* 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 "macos/gobridge/wireguard.h"

#include "wireguard-go-version.h"
#include "3rd/awg-apple/Sources/WireGuardKitC/WireGuardKitC.h"
#include "3rd/amneziawg-apple/Sources/WireGuardKitGo/wireguard.h"
#include "3rd/amneziawg-apple/Sources/WireGuardKitC/WireGuardKitC.h"

#include <stdbool.h>
#include <stdint.h>
Expand All @@ -23,3 +23,8 @@ bool key_from_hex(uint8_t key[WG_KEY_LEN], const char* hex);
bool key_eq(const uint8_t key1[WG_KEY_LEN], const uint8_t key2[WG_KEY_LEN]);

void write_msg_to_log(const char* tag, const char* msg);

// init function definition in C
void hev_socks5_tunnel_quit(void);
// Updated function definition in C
int hev_socks5_tunnel_main(const char* configFile, int fd);
3 changes: 3 additions & 0 deletions client/macos/networkextension/wireguard-go-version.h.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#ifndef WIREGUARD_GO_VERSION
#define WIREGUARD_GO_VERSION "@WG_VERSION_STRING@"
#endif // WIREGUARD_GO_VERSION
6 changes: 3 additions & 3 deletions client/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@
#include "Windows.h"
#endif

#if defined(Q_OS_IOS)
#if defined(Q_OS_IOS) || defined(MACOS_NE)
#include "platforms/ios/QtAppDelegate-C-Interface.h"
#endif

#if !defined(Q_OS_ANDROID) && !defined(Q_OS_IOS)
#if !defined(Q_OS_ANDROID) && !defined(Q_OS_IOS) && !defined(MACOS_NE)
bool isAnotherInstanceRunning()
{
QLocalSocket socket;
Expand Down Expand Up @@ -45,7 +45,7 @@ int main(int argc, char *argv[])

AmneziaApplication app(argc, argv);

#if !defined(Q_OS_ANDROID) && !defined(Q_OS_IOS)
#if !defined(Q_OS_ANDROID) && !defined(Q_OS_IOS) && !defined(MACOS_NE)
if (isAnotherInstanceRunning()) {
QTimer::singleShot(1000, &app, [&]() { app.quit(); });
return app.exec();
Expand Down
2 changes: 1 addition & 1 deletion client/platforms/ios/PacketTunnelProvider+OpenVPN.swift
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ extension PacketTunnelProvider {
startHandler = completionHandler
ovpnAdapter?.connect(using: packetFlow)
}

func handleOpenVPNStatusMessage(_ messageData: Data, completionHandler: ((Data?) -> Void)? = nil) {
guard let completionHandler = completionHandler else { return }
let bytesin = ovpnAdapter?.transportStatistics.bytesIn
Expand Down
12 changes: 11 additions & 1 deletion client/platforms/ios/PacketTunnelProvider+WireGuard.swift
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,19 @@ extension PacketTunnelProvider {
}
}

let lastHandshakeString = settingsDictionary["last_handshake_time_sec"]
let lastHandshake: Int64

if let lastHandshakeValue = lastHandshakeString, let handshakeValue = Int64(lastHandshakeValue) {
lastHandshake = handshakeValue
} else {
lastHandshake = -2 // Return an error if there is no value for `last_handshake_time_sec`
}

let response: [String: Any] = [
"rx_bytes": settingsDictionary["rx_bytes"] ?? "0",
"tx_bytes": settingsDictionary["tx_bytes"] ?? "0"
"tx_bytes": settingsDictionary["tx_bytes"] ?? "0",
"last_handshake_time_sec": lastHandshake
]

completionHandler(try? JSONSerialization.data(withJSONObject: response, options: []))
Expand Down
17 changes: 17 additions & 0 deletions client/platforms/ios/QRCodeReaderBase.mm
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#if !MACOS_NE
#include "QRCodeReaderBase.h"

#import <UIKit/UIKit.h>
Expand Down Expand Up @@ -108,3 +109,19 @@ - (void)captureOutput:(AVCaptureOutput *)output didOutputMetadataObjects:(NSArra
void QRCodeReader::stopReading() {
[m_qrCodeReader stopReading];
}
#else
#include "QRCodeReaderBase.h"

QRCodeReader::QRCodeReader()
{

}

QRect QRCodeReader::cameraSize() {
return QRect();
}

void QRCodeReader::startReading() {}
void QRCodeReader::stopReading() {}
void QRCodeReader::setCameraSize(QRect) {}
#endif
3 changes: 2 additions & 1 deletion client/platforms/ios/QtAppDelegate.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#if !MACOS_NE
#import <UIKit/UIKit.h>

#endif
@interface QIOSApplicationDelegate
@end

Expand Down
4 changes: 2 additions & 2 deletions client/platforms/ios/QtAppDelegate.mm
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@


@implementation QIOSApplicationDelegate (AmneziaVPNDelegate)

#if !MACOS_NE
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[application setMinimumBackgroundFetchInterval: UIApplicationBackgroundFetchIntervalMinimum];
Expand Down Expand Up @@ -57,5 +57,5 @@ - (BOOL)application:(UIApplication *)app
}
return NO;
}

#endif
@end
11 changes: 11 additions & 0 deletions client/platforms/ios/ScreenProtection.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
#if MACOS_NE
public func toggleScreenshots(_ isEnabled: Bool) {

}

class ScreenProtection {


}
#else
import UIKit

public func toggleScreenshots(_ isEnabled: Bool) {
Expand Down Expand Up @@ -85,3 +95,4 @@ struct ProtectionPair {
textField.removeFromSuperview()
}
}
#endif
1 change: 1 addition & 0 deletions client/platforms/ios/ios_controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class IosController : public QObject
void disconnectVpn();

void vpnStatusDidChange(void *pNotification);

void vpnConfigurationDidChange(void *pNotification);

void getBackendLogs(std::function<void(const QString &)> &&callback);
Expand Down
Loading

0 comments on commit e58c594

Please sign in to comment.