Skip to content
Open
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
9 changes: 9 additions & 0 deletions src/controller/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,15 @@ Application::Application(int& argc, char** argv, const QString& name) :
installTranslator(translator);
loadTranslations();

auto list = QUrl::idnWhitelist();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, removing the .com fromPunycode() hack is a big improvement! Should we move the IDN whitelist initialization to a separate function initializeIdnWhitelist() with a comment that clarifies why this is needed and how this works? Perhaps also link to https://doc.qt.io/qt-6/qurl.html#setIdnWhitelist and https://github.com/qt/qtbase/blob/dev/src/corelib/io/qurlidna.cpp#L281-L318 in the comment. Note that "fi", "lt", "lv" already exist in https://github.com/qt/qtbase/blob/dev/src/corelib/io/qurlidna.cpp#L281-L318.

Also, see the discussion at https://qt-project.atlassian.net/browse/QTBUG-95597.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the goal is to show same url as in browse.
Right now we are depending on Qt behavior and as you can see it is always not the same as in browser.
I think extension should send URL in format that is show in browser.

list.append({
QStringLiteral("fi"),
QStringLiteral("ee"),
QStringLiteral("lt"),
QStringLiteral("lv"),
});
QUrl::setIdnWhitelist(list);

for (const QString& font : QDir(QStringLiteral(":/fonts")).entryList()) {
QFontDatabase::addApplicationFont(QStringLiteral(":/fonts/%1").arg(font));
}
Expand Down
1 change: 0 additions & 1 deletion src/ui/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
add_library(ui STATIC
certificatewidget.cpp
certificatewidget.hpp
punycode.hpp
ui.cpp
webeiddialog.cpp
webeiddialog.hpp
Expand Down
6 changes: 6 additions & 0 deletions src/ui/dialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,9 @@ border-radius: 4px;</string>
<property name="focusPolicy">
<enum>Qt::TabFocus</enum>
</property>
<property name="textFormat">
<enum>Qt::PlainText</enum>
</property>
</widget>
</item>
</layout>
Expand Down Expand Up @@ -586,6 +589,9 @@ border-radius: 4px;</string>
<property name="focusPolicy">
<enum>Qt::TabFocus</enum>
</property>
<property name="textFormat">
<enum>Qt::PlainText</enum>
</property>
</widget>
</item>
</layout>
Expand Down
39 changes: 0 additions & 39 deletions src/ui/punycode.hpp

This file was deleted.

20 changes: 13 additions & 7 deletions src/ui/webeiddialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@

#include "webeiddialog.hpp"
#include "application.hpp"
#include "punycode.hpp"

#include "ui_dialog.h"

Expand All @@ -43,8 +42,6 @@
#include <unistd.h>
#endif

#include <unordered_map>

#if QT_VERSION < QT_VERSION_CHECK(6, 4, 0)
constexpr inline QLatin1String operator"" _L1(const char* str, size_t size) noexcept
{
Expand Down Expand Up @@ -171,7 +168,8 @@ WebEidDialog::WebEidDialog(QWidget* parent) : WebEidUI(parent), ui(new Private)
if (auto* button =
qobject_cast<CertificateButton*>(ui->selectionGroup->checkedButton())) {
ui->lockedWarning->setHidden(button->certificateInfo().cardActive);
ui->okButton->setEnabled(currentCommand == CommandType::AUTHENTICATE || button->certificateInfo().cardActive);
ui->okButton->setEnabled(currentCommand == CommandType::AUTHENTICATE
|| button->certificateInfo().cardActive);
}
ui->okButton->setFocus();
});
Expand Down Expand Up @@ -336,7 +334,7 @@ void WebEidDialog::onSmartCardStatusUpdate(const RetriableError status)
void WebEidDialog::onMultipleCertificatesReady(
const QUrl& origin, const std::vector<EidCertificateAndPinInfo>& certAndPinInfos)
{
ui->selectCertificateOriginLabel->setText(fromPunycode(origin));
setupOrigin(origin);
setupCertificateAndPinInfo(certAndPinInfos);

switch (currentCommand) {
Expand Down Expand Up @@ -390,7 +388,7 @@ void WebEidDialog::onMultipleCertificatesReady(
void WebEidDialog::onSingleCertificateReady(const QUrl& origin,
const EidCertificateAndPinInfo& certAndPinInfo)
{
ui->selectCertificateOriginLabel->setText(fromPunycode(origin));
setupOrigin(origin);
ui->pinInputOriginLabel->setText(ui->selectCertificateOriginLabel->text());
const bool useExternalPinDialog = certAndPinInfo.eid->providesExternalPinDialog();

Expand Down Expand Up @@ -611,6 +609,13 @@ void WebEidDialog::setupCertificateAndPinInfo(
}
}

void WebEidDialog::setupOrigin(const QUrl& origin)
{
const auto host = origin.host(QUrl::PrettyDecoded);
ui->selectCertificateOriginLabel->setText(QStringLiteral("%2%3").arg(
host, origin.port() == -1 ? QString() : QStringLiteral(":%1").arg(origin.port())));
}

void WebEidDialog::setupPinPrompt(PinInfo pinInfo, bool cardActive)
{
ui->okButton->setHidden(pinInfo.readerHasPinPad || !cardActive);
Expand Down Expand Up @@ -666,7 +671,8 @@ void WebEidDialog::setupPinPadProgressBarAndEmitWait(const EidCertificateAndPinI
void WebEidDialog::setupPinInput(const EidCertificateAndPinInfo& certAndPinInfo)
{
ui->lockedWarning->setHidden(certAndPinInfo.cardActive);
setupPinPrompt(certAndPinInfo.pinInfo, currentCommand == CommandType::AUTHENTICATE || certAndPinInfo.cardActive);
setupPinPrompt(certAndPinInfo.pinInfo,
currentCommand == CommandType::AUTHENTICATE || certAndPinInfo.cardActive);
// The allowed character ranges are from the SafeNet eToken guide:
// 1. English uppercase letters (ASCII 0x41...0x5A).
// 2. English lowercase letters (ASCII 0x61...0x7A).
Expand Down
1 change: 1 addition & 0 deletions src/ui/webeiddialog.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ class WebEidDialog final : public WebEidUI
void setTrText(QWidget* label, Text text) const;
void
setupCertificateAndPinInfo(const std::vector<EidCertificateAndPinInfo>& cardCertAndPinInfos);
void setupOrigin(const QUrl& origin);
void setupPinPrompt(PinInfo pinInfo, bool cardActive);
void setupPinPadProgressBarAndEmitWait(const EidCertificateAndPinInfo& certAndPinInfo);
void setupPinInput(const EidCertificateAndPinInfo& certAndPinInfo);
Expand Down
10 changes: 0 additions & 10 deletions tests/tests/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@
#include "controller.hpp"
#include "command-handlers/getcertificate.hpp"

#include "../ui/punycode.hpp"

#include "mock-ui.hpp"
#include "getcommandhandler-mock.hpp"

Expand Down Expand Up @@ -72,8 +70,6 @@ private slots:

void authenticate_validArgumentsResultInValidToken();

void fromPunycode_decodesEeDomain();

void quit_exits();

private:
Expand Down Expand Up @@ -201,12 +197,6 @@ void WebEidTests::authenticate_validArgumentsResultInValidToken()
QStringLiteral("MIIEAzCCA2WgAwIBAgIQOWkBW"));
}

void WebEidTests::fromPunycode_decodesEeDomain()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should keep the test to verify that "https://xn--igusnunik-p7af.ee" is shown as "\u00F5igusn\u00F5unik.ee", use URL + QUrl::PrettyDecoded directly.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

again, extension should send correctly formated url

{
QCOMPARE(fromPunycode(QUrl(QStringLiteral("https://xn--igusnunik-p7af.ee"))),
QStringLiteral("\u00F5igusn\u00F5unik.ee"));
}

void WebEidTests::quit_exits()
{
try {
Expand Down