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