mirror of
https://github.com/amnezia-vpn/amnezia-client.git
synced 2026-07-03 14:07:39 +02:00
Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 204e4ee7c2 | |||
| 4efaf20a1c | |||
| bfd232a707 |
@@ -217,7 +217,11 @@ jobs:
|
||||
export QT_BIN_DIR="${{ runner.temp }}/Qt/${{ env.QT_VERSION }}/ios/bin"
|
||||
export QT_MACOS_ROOT_DIR="${{ runner.temp }}/Qt/${{ env.QT_VERSION }}/macos"
|
||||
export PATH=$PATH:~/go/bin
|
||||
sh deploy/build_ios.sh
|
||||
sh deploy/build_ios.sh | \
|
||||
sed -e '/-Xcc -DPROD_AGW_PUBLIC_KEY/,/-Xcc/ { /-Xcc/!d; }' -e '/-Xcc -DPROD_AGW_PUBLIC_KEY/d' | \
|
||||
sed -e '/-Xcc -DDEV_AGW_PUBLIC_KEY/,/-Xcc/ { /-Xcc/!d; }' -e '/-Xcc -DDEV_AGW_PUBLIC_KEY/d' | \
|
||||
sed -e '/-DPROD_AGW_PUBLIC_KEY/,/-D/ { /-D/!d; }' -e '/-DPROD_AGW_PUBLIC_KEY/d' | \
|
||||
sed -e '/-DDEV_AGW_PUBLIC_KEY/,/-D/ { /-D/!d; }' -e '/-DDEV_AGW_PUBLIC_KEY/d'
|
||||
env:
|
||||
IOS_TRUST_CERT_BASE64: ${{ secrets.IOS_TRUST_CERT_BASE64 }}
|
||||
IOS_SIGNING_CERT_BASE64: ${{ secrets.IOS_SIGNING_CERT_BASE64 }}
|
||||
|
||||
@@ -50,6 +50,8 @@ namespace
|
||||
constexpr char authData[] = "auth_data";
|
||||
}
|
||||
|
||||
const int requestTimeoutMsecs = 12 * 1000; // 12 secs
|
||||
|
||||
ErrorCode checkErrors(const QList<QSslError> &sslErrors, QNetworkReply *reply)
|
||||
{
|
||||
if (!sslErrors.empty()) {
|
||||
@@ -177,7 +179,7 @@ void ApiController::fillServerConfig(const QString &protocol, const ApiControlle
|
||||
QStringList ApiController::getProxyUrls()
|
||||
{
|
||||
QNetworkRequest request;
|
||||
request.setTransferTimeout(7000);
|
||||
request.setTransferTimeout(requestTimeoutMsecs);
|
||||
request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json");
|
||||
|
||||
QEventLoop wait;
|
||||
@@ -280,7 +282,7 @@ void ApiController::updateServerConfigFromApi(const QString &installationUuid, c
|
||||
|
||||
if (serverConfig.value(config_key::configVersion).toInt()) {
|
||||
QNetworkRequest request;
|
||||
request.setTransferTimeout(7000);
|
||||
request.setTransferTimeout(requestTimeoutMsecs);
|
||||
request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json");
|
||||
request.setRawHeader("Authorization", "Api-Key " + serverConfig.value(configKey::accessToken).toString().toUtf8());
|
||||
QString endpoint = serverConfig.value(configKey::apiEdnpoint).toString();
|
||||
@@ -336,7 +338,7 @@ ErrorCode ApiController::getServicesList(QByteArray &responseBody)
|
||||
#endif
|
||||
|
||||
QNetworkRequest request;
|
||||
request.setTransferTimeout(7000);
|
||||
request.setTransferTimeout(requestTimeoutMsecs);
|
||||
request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json");
|
||||
|
||||
request.setUrl(QString("%1v1/services").arg(m_gatewayEndpoint));
|
||||
@@ -390,7 +392,7 @@ ErrorCode ApiController::getConfigForService(const QString &installationUuid, co
|
||||
#endif
|
||||
|
||||
QNetworkRequest request;
|
||||
request.setTransferTimeout(7000);
|
||||
request.setTransferTimeout(requestTimeoutMsecs);
|
||||
request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json");
|
||||
|
||||
request.setUrl(QString("%1v1/config").arg(m_gatewayEndpoint));
|
||||
|
||||
@@ -111,20 +111,10 @@ extension PacketTunnelProvider {
|
||||
settingsDictionary[pair[0]] = pair[1]
|
||||
}
|
||||
}
|
||||
|
||||
let lastHandshakeString = settingsDictionary["last_handshake_time_sec"]
|
||||
let lastHandshake: Int64
|
||||
|
||||
if let lastHandshakeValue = lastHandshakeString, let handshakeValue = Int64(lastHandshakeValue) {
|
||||
lastHandshake = handshakeValue
|
||||
} else {
|
||||
lastHandshake = -2
|
||||
}
|
||||
|
||||
let response: [String: Any] = [
|
||||
"rx_bytes": settingsDictionary["rx_bytes"] ?? "0",
|
||||
"tx_bytes": settingsDictionary["tx_bytes"] ?? "0",
|
||||
"last_handshake_time_sec": lastHandshake
|
||||
"tx_bytes": settingsDictionary["tx_bytes"] ?? "0"
|
||||
]
|
||||
|
||||
completionHandler(try? JSONSerialization.data(withJSONObject: response, options: []))
|
||||
|
||||
@@ -55,9 +55,6 @@ public:
|
||||
QString openFile();
|
||||
|
||||
void requestInetAccess();
|
||||
|
||||
void stopForHandshake();
|
||||
void waitForHandshake();
|
||||
signals:
|
||||
void connectionStateChanged(Vpn::ConnectionState state);
|
||||
void bytesChanged(quint64 receivedBytes, quint64 sentBytes);
|
||||
@@ -65,6 +62,7 @@ signals:
|
||||
void importBackupFromOutside(const QString);
|
||||
|
||||
void finished();
|
||||
|
||||
protected slots:
|
||||
|
||||
private:
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
#include <QJsonObject>
|
||||
#include <QThread>
|
||||
#include <QEventLoop>
|
||||
#include <QTimer>
|
||||
|
||||
#include "../protocols/vpnprotocol.h"
|
||||
#import "ios_controller_wrapper.h"
|
||||
|
||||
@@ -58,7 +58,6 @@ Vpn::ConnectionState iosStatusToState(NEVPNStatus status) {
|
||||
|
||||
namespace {
|
||||
IosController* s_instance = nullptr;
|
||||
QTimer *m_handshakeTimer = nullptr;
|
||||
}
|
||||
|
||||
IosController::IosController() : QObject()
|
||||
@@ -238,6 +237,7 @@ void IosController::disconnectVpn()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void IosController::checkStatus()
|
||||
{
|
||||
NSString *actionKey = [NSString stringWithUTF8String:MessageKey::action];
|
||||
@@ -258,15 +258,10 @@ void IosController::checkStatus()
|
||||
void IosController::vpnStatusDidChange(void *pNotification)
|
||||
{
|
||||
NETunnelProviderSession *session = (NETunnelProviderSession *)pNotification;
|
||||
NETunnelProviderProtocol *tunnelProtocol = (NETunnelProviderProtocol *)m_currentTunnel.protocolConfiguration;
|
||||
|
||||
if (session /* && session == TunnelManager.session */ ) {
|
||||
qDebug() << "IosController::vpnStatusDidChange" << iosStatusToState(session.status) << session;
|
||||
if (tunnelProtocol.providerConfiguration[@"wireguard"] != nil &&
|
||||
(session.status == NEVPNStatusConnected || session.status == NEVPNStatusConnecting))
|
||||
{
|
||||
// use last_handshake_time for check status connected for WireGuard
|
||||
return;
|
||||
}
|
||||
|
||||
if (session.status == NEVPNStatusDisconnected) {
|
||||
if (@available(iOS 16.0, *)) {
|
||||
[session fetchLastDisconnectErrorWithCompletionHandler:^(NSError * _Nullable error) {
|
||||
@@ -361,7 +356,6 @@ void IosController::vpnStatusDidChange(void *pNotification)
|
||||
} else {
|
||||
qDebug() << "Disconnect error is unavailable on iOS < 16.0";
|
||||
}
|
||||
stopForHandshake();
|
||||
}
|
||||
|
||||
emit connectionStateChanged(iosStatusToState(session.status));
|
||||
@@ -647,7 +641,6 @@ bool IosController::startWireGuard(const QString &config)
|
||||
|
||||
m_currentTunnel.protocolConfiguration = tunnelProtocol;
|
||||
|
||||
waitForHandshake();
|
||||
startTunnel();
|
||||
}
|
||||
|
||||
@@ -674,8 +667,6 @@ void IosController::startTunnel()
|
||||
protocolName = @"WireGuard";
|
||||
} else if (tunnelProtocol.providerConfiguration[@"ovpn"] != nil) {
|
||||
protocolName = @"OpenVPN";
|
||||
} else if (tunnelProtocol.providerConfiguration[@"xray"] != nil) {
|
||||
protocolName = @"XRay";
|
||||
}
|
||||
|
||||
m_rxBytes = 0;
|
||||
@@ -872,83 +863,3 @@ void IosController::requestInetAccess() {
|
||||
}];
|
||||
[task resume];
|
||||
}
|
||||
|
||||
void IosController::stopForHandshake() {
|
||||
if (m_handshakeTimer) {
|
||||
if (QThread::currentThread() != m_handshakeTimer->thread()) {
|
||||
QMetaObject::invokeMethod(m_handshakeTimer, "stop", Qt::QueuedConnection);
|
||||
QMetaObject::invokeMethod(m_handshakeTimer, "deleteLater", Qt::QueuedConnection);
|
||||
m_handshakeTimer = nullptr;
|
||||
return;
|
||||
}
|
||||
if (m_handshakeTimer->isActive()) {
|
||||
m_handshakeTimer->stop();
|
||||
}
|
||||
m_handshakeTimer->deleteLater();
|
||||
m_handshakeTimer = nullptr;
|
||||
|
||||
qDebug() << "Handshake monitoring stopped.";
|
||||
} else {
|
||||
qDebug() << "No active handshake monitoring to stop.";
|
||||
}
|
||||
}
|
||||
|
||||
void IosController::waitForHandshake() {
|
||||
qDebug() << "Waiting for last_handshake_time_sec to be greater than 0...";
|
||||
|
||||
// Initialize the timer if it's null
|
||||
if (!m_handshakeTimer) {
|
||||
m_handshakeTimer = new QTimer(this);
|
||||
|
||||
// Connect the timer's timeout signal to perform handshake checking
|
||||
connect(m_handshakeTimer, &QTimer::timeout, this, [this]() {
|
||||
// Prepare the message to check status
|
||||
NSString *actionKey = [NSString stringWithUTF8String:MessageKey::action];
|
||||
NSString *actionValue = [NSString stringWithUTF8String:Action::getStatus];
|
||||
NSString *tunnelIdKey = [NSString stringWithUTF8String:MessageKey::tunnelId];
|
||||
NSString *tunnelIdValue = !m_tunnelId.isEmpty() ? m_tunnelId.toNSString() : @"";
|
||||
|
||||
NSDictionary *message = @{actionKey: actionValue, tunnelIdKey: tunnelIdValue};
|
||||
|
||||
// Lambda to handle the response
|
||||
auto checkHandshake = [this](NSDictionary *response) {
|
||||
uint64_t last_handshake_time_sec = 0;
|
||||
if (response && response[@"last_handshake_time_sec"] &&
|
||||
![response[@"last_handshake_time_sec"] isKindOfClass:[NSNull class]]) {
|
||||
last_handshake_time_sec = [response[@"last_handshake_time_sec"] unsignedLongLongValue];
|
||||
}
|
||||
|
||||
qDebug() << "last_handshake_time_sec:" << last_handshake_time_sec;
|
||||
|
||||
if (last_handshake_time_sec > 0) {
|
||||
// Handshake successful, update state
|
||||
qDebug() << "Handshake detected, updating state to CONNECTED.";
|
||||
emit connectionStateChanged(Vpn::ConnectionState::Connected);
|
||||
stopForHandshake();
|
||||
return;
|
||||
} else {
|
||||
if (last_handshake_time_sec == 0) {
|
||||
// Keep retrying
|
||||
emit connectionStateChanged(Vpn::ConnectionState::Connecting);
|
||||
} else {
|
||||
// Handle handshake failure and stop monitoring
|
||||
emit connectionStateChanged(Vpn::ConnectionState::Disconnected);
|
||||
stopForHandshake();
|
||||
return;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// Send the message to the VPN extension
|
||||
sendVpnExtensionMessage(message, checkHandshake);
|
||||
});
|
||||
|
||||
qDebug() << "Handshake timer initialized.";
|
||||
}
|
||||
|
||||
// Start the timer only if it's not already active
|
||||
if (m_handshakeTimer && !m_handshakeTimer->isActive()) {
|
||||
m_handshakeTimer->start(1000); // Retry every 1 second
|
||||
qDebug() << "Handshake timer Retry every 1 second";
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user