mirror of
https://github.com/amnezia-vpn/amnezia-client.git
synced 2026-06-02 08:33:38 +02:00
Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 54e69c4fe4 | |||
| f97c84c7f9 | |||
| ae5ac16611 | |||
| 6b6f5802bf | |||
| a14e8ec0aa |
@@ -96,6 +96,7 @@ namespace amnezia
|
||||
|
||||
// import and install errors
|
||||
ImportInvalidConfigError = 900,
|
||||
ImportQrDecodingError = 901,
|
||||
|
||||
// Android errors
|
||||
AndroidError = 1000,
|
||||
|
||||
@@ -50,6 +50,7 @@ QString errorString(ErrorCode code) {
|
||||
case (ErrorCode::AddressPoolError): errorMessage = QObject::tr("VPN pool error: no available addresses"); break;
|
||||
|
||||
case (ErrorCode::ImportInvalidConfigError): errorMessage = QObject::tr("The config does not contain any containers and credentials for connecting to the server"); break;
|
||||
case (ErrorCode::ImportQrDecodingError): errorMessage = QObject::tr("Failed to decode qr-code"); break;
|
||||
|
||||
// Android errors
|
||||
case (ErrorCode::AndroidError): errorMessage = QObject::tr("VPN connection error"); break;
|
||||
|
||||
@@ -197,19 +197,7 @@ bool ImportController::extractConfigFromData(QString data)
|
||||
|
||||
bool ImportController::extractConfigFromQr(const QByteArray &data)
|
||||
{
|
||||
QJsonObject dataObj = QJsonDocument::fromJson(data).object();
|
||||
if (!dataObj.isEmpty()) {
|
||||
m_config = dataObj;
|
||||
return true;
|
||||
}
|
||||
|
||||
QByteArray ba_uncompressed = qUncompress(data);
|
||||
if (!ba_uncompressed.isEmpty()) {
|
||||
m_config = QJsonDocument::fromJson(ba_uncompressed).object();
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
return extractConfigFromData(data.toBase64(QByteArray::Base64UrlEncoding | QByteArray::OmitTrailingEquals));
|
||||
}
|
||||
|
||||
QString ImportController::getConfig()
|
||||
@@ -533,8 +521,12 @@ void ImportController::startDecodingQr()
|
||||
#endif
|
||||
}
|
||||
|
||||
void ImportController::stopDecodingQr()
|
||||
void ImportController::stopDecodingQr(const QByteArray &data)
|
||||
{
|
||||
if (!extractConfigFromQr(data)) {
|
||||
emit qrDecodingError(ErrorCode::ImportQrDecodingError);
|
||||
return;
|
||||
}
|
||||
emit qrDecodingFinished();
|
||||
}
|
||||
|
||||
@@ -571,25 +563,27 @@ bool ImportController::parseQrCodeChunk(const QString &code)
|
||||
data.append(m_qrCodeChunks.value(i));
|
||||
}
|
||||
|
||||
bool ok = extractConfigFromQr(data);
|
||||
if (ok) {
|
||||
m_isQrCodeProcessed = false;
|
||||
qDebug() << "stopDecodingQr";
|
||||
stopDecodingQr();
|
||||
return true;
|
||||
} else {
|
||||
data = qUncompress(data);
|
||||
auto format = checkConfigFormat(data);
|
||||
if (format == ConfigTypes::Invalid) {
|
||||
qDebug() << "error while extracting data from qr";
|
||||
m_qrCodeChunks.clear();
|
||||
m_totalQrCodeChunksCount = 0;
|
||||
m_receivedQrCodeChunksCount = 0;
|
||||
} else {
|
||||
qDebug() << "stopDecodingQr";
|
||||
m_isQrCodeProcessed = false;
|
||||
stopDecodingQr(data);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
bool ok = extractConfigFromQr(ba);
|
||||
if (ok) {
|
||||
m_isQrCodeProcessed = false;
|
||||
auto data = code.toUtf8();
|
||||
auto format = checkConfigFormat(data);
|
||||
if (format != ConfigTypes::Invalid) {
|
||||
qDebug() << "stopDecodingQr";
|
||||
stopDecodingQr();
|
||||
m_isQrCodeProcessed = false;
|
||||
stopDecodingQr(data);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -61,6 +61,10 @@ signals:
|
||||
|
||||
void restoreAppConfig(const QByteArray &data);
|
||||
|
||||
#if defined Q_OS_ANDROID || defined Q_OS_IOS
|
||||
void qrDecodingError(ErrorCode errorCode);
|
||||
#endif
|
||||
|
||||
private:
|
||||
QJsonObject extractOpenVpnConfig(const QString &data);
|
||||
QJsonObject extractWireGuardConfig(const QString &data);
|
||||
@@ -69,7 +73,7 @@ private:
|
||||
void checkForMaliciousStrings(const QJsonObject &protocolConfig);
|
||||
|
||||
#if defined Q_OS_ANDROID || defined Q_OS_IOS
|
||||
void stopDecodingQr();
|
||||
void stopDecodingQr(const QByteArray &data);
|
||||
#endif
|
||||
|
||||
QSharedPointer<ServersModel> m_serversModel;
|
||||
|
||||
@@ -20,6 +20,10 @@ PageType {
|
||||
PageController.closePage()
|
||||
PageController.goToPage(PageEnum.PageSetupWizardViewConfig)
|
||||
}
|
||||
|
||||
function onQrDecodingError() {
|
||||
PageController.closePage()
|
||||
}
|
||||
}
|
||||
|
||||
defaultActiveFocusItem: focusItem
|
||||
|
||||
Reference in New Issue
Block a user