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.

Copy link
Member

Choose a reason for hiding this comment

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

Yes, that is the goal and this is a good suggestion, but the problem is that there is no API for getting the displayed URL. WebExtensions can read the actual URL, not the address bar’s rendered string. Internationalized domain name or punycode display is a browser UI decision, so we can’t match what the browser shows without reimplementing browser UI logic.

We only have access to MessageSender.url: https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/runtime/MessageSender#url

Here's how the origin URL is constructed at the moment: https://github.com/web-eid/web-eid-webextension/blob/main/src/background/actions/authenticate.ts#L58

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
Expand Up @@ -4,7 +4,6 @@ add_library(ui STATIC
languageselect.cpp
languageselect.hpp
languageselect.ui
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 @@ -496,6 +496,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 @@ -569,6 +572,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.

12 changes: 9 additions & 3 deletions src/ui/webeiddialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
#include "webeiddialog.hpp"
#include "application.hpp"
#include "languageselect.hpp"
#include "punycode.hpp"

#include "ui_dialog.h"

Expand Down Expand Up @@ -280,7 +279,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 @@ -334,7 +333,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 @@ -552,6 +551,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
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