Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added processing of native qr codes for wg/awg #815

Draft
wants to merge 5 commits into
base: dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions client/core/defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ namespace amnezia

// import and install errors
ImportInvalidConfigError = 900,
ImportQrDecodingError = 901,

// Android errors
AndroidError = 1000,
Expand Down
1 change: 1 addition & 0 deletions client/core/errorstrings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
44 changes: 19 additions & 25 deletions client/ui/controllers/importController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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();
}

Expand Down Expand Up @@ -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;
}
}
Expand Down
6 changes: 5 additions & 1 deletion client/ui/controllers/importController.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ public slots:

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);
Expand All @@ -69,7 +73,7 @@ public slots:
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;
Expand Down
4 changes: 4 additions & 0 deletions client/ui/qml/Pages2/PageSetupWizardConfigSource.qml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ PageType {
PageController.closePage()
PageController.goToPage(PageEnum.PageSetupWizardViewConfig)
}

function onQrDecodingError() {
PageController.closePage()
}
}

defaultActiveFocusItem: focusItem
Expand Down
Loading