Skip to content

Commit c3a9ae5

Browse files
committed
Add version parameter and cleanup
WE2-1204 Signed-off-by: Raul Metsma <raul@metsma.ee>
1 parent 3484c81 commit c3a9ae5

13 files changed

Lines changed: 96 additions & 77 deletions

File tree

.github/workflows/cmake-linux-fedora.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
container: fedora:${{ matrix.container }}
1515
strategy:
1616
matrix:
17-
container: [42, 43]
17+
container: [42, 43, 44]
1818

1919
steps:
2020
- name: Install Deps

.github/workflows/cmake-linux-ubuntu.yml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,19 @@ jobs:
1717
container: ubuntu:${{matrix.container}}
1818
strategy:
1919
matrix:
20-
container: ['22.04', '24.04', '25.04', '25.10']
20+
container: ['22.04', '24.04', '25.10', '26.04']
2121
arch: ['amd64', 'arm64']
2222

2323
steps:
2424
- name: Install dependencies
25-
run: apt update -qq && apt install --no-install-recommends -y git lsb-release fakeroot build-essential devscripts debhelper lintian pkg-config cmake libpcsclite-dev libssl-dev libgtest-dev libgl-dev libqt6svg6-dev qt6-tools-dev qt6-tools-dev-tools qt6-l10n-tools
25+
run: |
26+
for f in /etc/apt/sources.list /etc/apt/sources.list.d/*.list /etc/apt/sources.list.d/*.sources; do
27+
[ -f "$f" ] && sed -i 's|http://archive.ubuntu.com|http://azure.archive.ubuntu.com|g; s|http://security.ubuntu.com|http://azure.archive.ubuntu.com|g' "$f"
28+
done
29+
echo 'path-exclude=/usr/share/man/*' > /etc/dpkg/dpkg.cfg.d/99-nodocs
30+
echo 'path-exclude=/usr/share/doc/*' >> /etc/dpkg/dpkg.cfg.d/99-nodocs
31+
echo 'path-exclude=/usr/share/doc-base/*' >> /etc/dpkg/dpkg.cfg.d/99-nodocs
32+
apt update -qq && apt install --no-install-recommends -y git lsb-release fakeroot build-essential devscripts debhelper lintian pkg-config cmake libpcsclite-dev libssl-dev libgtest-dev libgl-dev libqt6svg6-dev qt6-tools-dev qt6-tools-dev-tools qt6-l10n-tools
2633
2734
- uses: actions/checkout@v6
2835
with:

src/controller/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ add_library(controller STATIC
3333
utils/erasedata.hpp
3434
utils/observer_ptr.hpp
3535
utils/qdisablecopymove.hpp
36+
utils/qt_comp.hpp
3637
utils/utils.hpp
3738
writeresponse.cpp
3839
writeresponse.hpp

src/controller/application.cpp

Lines changed: 40 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include "certandpininfo.hpp"
2525
#include "logging.hpp"
2626
#include "retriableerror.hpp"
27+
#include "utils/qt_comp.hpp"
2728

2829
#include <QCommandLineParser>
2930
#include <QDir>
@@ -36,6 +37,11 @@
3637
#include <QStyleHints>
3738
#include <QTranslator>
3839

40+
#include <algorithm>
41+
#include <array>
42+
43+
using namespace Qt::Literals::StringLiterals;
44+
3945
inline CommandWithArguments::second_type parseArgumentJson(const QString& argumentStr)
4046
{
4147
const auto argumentJson = QJsonDocument::fromJson(argumentStr.toUtf8());
@@ -51,26 +57,26 @@ Application::Application(int& argc, char** argv, const QString& name) :
5157
QApplication(argc, argv), translator(new QTranslator(this))
5258
{
5359
setApplicationName(name);
54-
setApplicationDisplayName(QStringLiteral("Web eID"));
60+
setApplicationDisplayName(u"Web eID"_s);
5561
setApplicationVersion(QStringLiteral(PROJECT_VERSION));
56-
setOrganizationDomain(QStringLiteral("web-eid.eu"));
57-
setOrganizationName(QStringLiteral("RIA"));
62+
setOrganizationDomain(u"web-eid.eu"_s);
63+
setOrganizationName(u"RIA"_s);
5864
setQuitOnLastWindowClosed(false);
5965

6066
installTranslator(translator);
6167
loadTranslations();
6268

6369
auto list = QUrl::idnWhitelist();
6470
list.append({
65-
QStringLiteral("fi"),
66-
QStringLiteral("ee"),
67-
QStringLiteral("lt"),
68-
QStringLiteral("lv"),
71+
u"fi"_s,
72+
u"ee"_s,
73+
u"lt"_s,
74+
u"lv"_s,
6975
});
7076
QUrl::setIdnWhitelist(list);
7177

72-
for (const QString& font : QDir(QStringLiteral(":/fonts")).entryList()) {
73-
QFontDatabase::addApplicationFont(QStringLiteral(":/fonts/%1").arg(font));
78+
for (const QString& font : QDir(u":/fonts"_s).entryList()) {
79+
QFontDatabase::addApplicationFont(u":/fonts/%1"_s.arg(font));
7480
}
7581

7682
registerMetatypes();
@@ -93,8 +99,7 @@ bool Application::isDarkTheme()
9399
// supported OS-s.
94100
static const bool isDarkTheme = [] {
95101
QProcess p;
96-
p.start(QStringLiteral("gsettings"),
97-
{"get", "org.gnome.desktop.interface", "color-scheme"});
102+
p.start(u"gsettings"_s, {u"get"_s, u"org.gnome.desktop.interface"_s, u"color-scheme"_s});
98103
if (p.waitForFinished()) {
99104
return p.readAllStandardOutput().contains("dark");
100105
}
@@ -108,56 +113,52 @@ bool Application::isDarkTheme()
108113

109114
void Application::loadTranslations(const QString& lang)
110115
{
111-
static const QStringList SUPPORTED_LANGS {
112-
QStringLiteral("en"), QStringLiteral("et"), QStringLiteral("fi"), QStringLiteral("hr"),
113-
QStringLiteral("ru"), QStringLiteral("de"), QStringLiteral("fr"), QStringLiteral("nl"),
114-
QStringLiteral("cs"), QStringLiteral("sk")};
116+
static constexpr auto SUPPORTED_LANGS = std::to_array<QStringView>(
117+
{u"en", u"et", u"fi", u"hr", u"ru", u"de", u"fr", u"nl", u"cs", u"sk"});
115118
QLocale locale;
116-
QString langSetting = QSettings().value(QStringLiteral("lang"), lang).toString();
117-
if (SUPPORTED_LANGS.contains(langSetting)) {
119+
QString langSetting = QSettings().value(u"lang"_s, lang).toString();
120+
if (std::ranges::find(SUPPORTED_LANGS, langSetting) != SUPPORTED_LANGS.cend()) {
118121
locale = QLocale(langSetting);
119122
}
120-
void(translator->load(locale, QStringLiteral(":/translations/")));
123+
void(translator->load(locale, u":/translations/"_s));
121124
}
122125

123126
CommandWithArguments Application::parseArgs()
124127
{
125128
// On Windows Chrome, the native messaging host is also passed a command line argument with a
126129
// handle to the calling Chrome native window: --parent-window=<decimal handle value>.
127130
// We don't use it, but need to support it to avoid unknown option errors.
128-
QCommandLineOption parentWindow(QStringLiteral("parent-window"),
129-
QStringLiteral("Parent window handle (unused)"),
130-
QStringLiteral("parent-window"));
131+
QCommandLineOption parentWindow(u"parent-window"_s, u"Parent window handle (unused)"_s,
132+
u"parent-window"_s);
131133

132-
QCommandLineOption aboutArgument(QStringLiteral("about"),
133-
QStringLiteral("Show Web-eID about window"));
134+
QCommandLineOption aboutArgument(u"about"_s, u"Show Web-eID about window"_s);
135+
QCommandLineOption commandLineMode(
136+
{u"c"_s, u"command-line-mode"_s},
137+
u"Command-line mode, read commands from command line arguments instead of "
138+
"standard input."_s);
134139

135140
QCommandLineParser parser;
136-
parser.setApplicationDescription(QStringLiteral(
137-
"Application that communicates with the Web eID browser extension via standard input and "
141+
parser.setApplicationDescription(
142+
u"Application that communicates with the Web eID browser extension via standard input and "
138143
"output, but also works standalone in command-line mode. Performs PKI cryptographic "
139-
"operations with eID smart cards for signing and authentication purposes."));
144+
"operations with eID smart cards for signing and authentication purposes."_s);
140145

141146
parser.addHelpOption();
142-
parser.addOptions({{{"c", "command-line-mode"},
143-
"Command-line mode, read commands from command line arguments instead of "
144-
"standard input."},
145-
aboutArgument,
146-
parentWindow});
147+
parser.addVersionOption();
148+
parser.addOptions({commandLineMode, aboutArgument, parentWindow});
147149

148-
static const auto COMMANDS = "'" + CMDLINE_GET_SIGNING_CERTIFICATE + "', '"
149-
+ CMDLINE_AUTHENTICATE + "', '" + CMDLINE_SIGN + "'.";
150+
static const auto COMMANDS = u"'%1', '%2', '%3'."_s.arg(CMDLINE_GET_SIGNING_CERTIFICATE,
151+
CMDLINE_AUTHENTICATE, CMDLINE_SIGN);
150152

151153
parser.addPositionalArgument(
152-
QStringLiteral("command"),
153-
QStringLiteral("The command to execute in command-line mode, any of ") + COMMANDS);
154-
parser.addPositionalArgument(
155-
QStringLiteral("arguments"),
156-
QStringLiteral("Arguments to the given command as a JSON-encoded string."));
154+
u"command"_s, u"The command to execute in command-line mode, any of "_s + COMMANDS,
155+
u"(%1|%2|%3)"_s.arg(CMDLINE_GET_SIGNING_CERTIFICATE, CMDLINE_AUTHENTICATE, CMDLINE_SIGN));
156+
parser.addPositionalArgument(u"arguments"_s,
157+
u"Arguments to the given command as a JSON-encoded string."_s);
157158

158159
parser.process(arguments());
159160

160-
if (parser.isSet(QStringLiteral("command-line-mode"))) {
161+
if (parser.isSet(commandLineMode)) {
161162
const auto args = parser.positionalArguments();
162163
if (args.size() != 2) {
163164
throw ArgumentError("Provide two positional arguments in command-line mode.");

src/controller/command-handlers/authenticate.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,12 @@ namespace
4444
// Use common base64-encoding defaults.
4545
constexpr auto BASE64_OPTIONS = QByteArray::Base64Encoding | QByteArray::KeepTrailingEquals;
4646

47-
QVariantMap createAuthenticationToken(const QString& signatureAlgorithm,
47+
QVariantMap createAuthenticationToken(std::string_view signatureAlgorithm,
4848
const QByteArray& certificateDer, const QByteArray& signature)
4949
{
5050
return QVariantMap {
5151
{"unverifiedCertificate", QString(certificateDer.toBase64(BASE64_OPTIONS))},
52-
{"algorithm", signatureAlgorithm},
52+
{"algorithm", QLatin1String(signatureAlgorithm.data(), signatureAlgorithm.size())},
5353
{"signature", QString(signature)},
5454
{"format", QStringLiteral("web-eid:1.0")},
5555
{"appVersion",
@@ -123,8 +123,6 @@ QVariantMap Authenticate::onConfirm(WebEidUI* window,
123123
const EidCertificateAndPinInfo& certAndPinInfo)
124124
{
125125
try {
126-
const auto signatureAlgorithm =
127-
QString::fromStdString(certAndPinInfo.eid->authSignatureAlgorithm());
128126
pcsc_cpp::byte_vector pin;
129127
// Reserve space for APDU overhead (5 bytes) + PIN padding (16 bytes) to prevent PIN memory
130128
// reallocation. The 16-byte limit comes from the max PIN length of 12 bytes across all card
@@ -133,8 +131,8 @@ QVariantMap Authenticate::onConfirm(WebEidUI* window,
133131
getPin(pin, *certAndPinInfo.eid, window);
134132
const auto signature =
135133
createSignature(origin.url(), challengeNonce, *certAndPinInfo.eid, std::move(pin));
136-
return createAuthenticationToken(signatureAlgorithm, certAndPinInfo.certificateBytesInDer,
137-
signature);
134+
return createAuthenticationToken(certAndPinInfo.eid->authSignatureAlgorithm(),
135+
certAndPinInfo.certificateBytesInDer, signature);
138136

139137
} catch (const VerifyPinFailed& failure) {
140138
switch (failure.status()) {

src/controller/commands.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,12 @@
2727
#include <stdexcept>
2828
#include <map>
2929

30-
const QString CMDLINE_GET_SIGNING_CERTIFICATE = QStringLiteral("get-signing-certificate");
31-
const QString CMDLINE_AUTHENTICATE = QStringLiteral("authenticate");
32-
const QString CMDLINE_SIGN = QStringLiteral("sign");
3330
// A special command for stdin mode for quitting the application after sending the version.
34-
const QString STDINMODE_QUIT = QStringLiteral("quit");
31+
constexpr QStringView STDINMODE_QUIT {u"quit"};
3532

3633
CommandType::CommandType(const QString& cmdName)
3734
{
38-
static const std::map<QString, CommandType> SUPPORTED_COMMANDS {
35+
static const std::map<QStringView, CommandType> SUPPORTED_COMMANDS {
3936
{CMDLINE_GET_SIGNING_CERTIFICATE, CommandType::GET_SIGNING_CERTIFICATE},
4037
{CMDLINE_AUTHENTICATE, CommandType::AUTHENTICATE},
4138
{CMDLINE_SIGN, CommandType::SIGN},

src/controller/commands.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ class CommandType
5252
CommandTypeEnum value;
5353
};
5454

55-
extern const QString CMDLINE_GET_SIGNING_CERTIFICATE;
56-
extern const QString CMDLINE_AUTHENTICATE;
57-
extern const QString CMDLINE_SIGN;
55+
constexpr QStringView CMDLINE_GET_SIGNING_CERTIFICATE {u"get-signing-certificate"};
56+
constexpr QStringView CMDLINE_AUTHENTICATE {u"authenticate"};
57+
constexpr QStringView CMDLINE_SIGN {u"sign"};
5858

5959
using CommandWithArguments = std::pair<CommandType, QVariantMap>;

src/controller/logging.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222

2323
#include "logging.hpp"
2424

25+
#include "utils/qt_comp.hpp"
26+
2527
#include <QCoreApplication>
2628
#include <QDateTime>
2729
#include <QDir>

src/controller/logging.hpp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,6 @@
2626

2727
void setupLogging();
2828

29-
#if QT_VERSION < QT_VERSION_CHECK(6, 5, 0)
30-
template <typename... Args>
31-
inline QDebug operator<<(QDebug out, const std::basic_string<char, Args...>& s)
32-
{
33-
return out << QUtf8StringView(s);
34-
}
35-
#endif
36-
3729
inline QDebug operator<<(QDebug out, const std::exception& e)
3830
{
3931
out << e.what();

0 commit comments

Comments
 (0)