Compare commits

...

5 Commits

Author SHA1 Message Date
vladimir.kuznetsov 54e69c4fe4 now extract config after stop qr decoding 2024-07-08 21:58:12 +02:00
vladimir.kuznetsov f97c84c7f9 Merge branch 'dev' of github.com:amnezia-vpn/amnezia-client into feature/awg-wg-qr 2024-07-08 09:43:54 +02:00
vladimir.kuznetsov ae5ac16611 stopDecodingQr before extract config 2024-07-05 14:21:25 +02:00
vladimir.kuznetsov 6b6f5802bf Merge branch 'dev' of github.com:amnezia-vpn/amnezia-client into feature/awg-wg-qr 2024-07-05 12:58:46 +02:00
vladimir.kuznetsov a14e8ec0aa added processing of native qr codes for wg/awg 2024-05-15 23:02:21 +02:00
5 changed files with 30 additions and 26 deletions
+1
View File
@@ -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,
+1
View File
@@ -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;
+19 -25
View File
@@ -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;
} }
} }
+5 -1
View File
@@ -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