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
8 changes: 6 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,11 @@ jobs:
DEBIAN_FRONTEND: noninteractive
steps:
- name: Install dependencies
run: apt update -qq && apt install --no-install-recommends -y git ca-certificates build-essential pkg-config cmake libpcsclite-dev libssl-dev libgl-dev qt6-tools-dev qt6-tools-dev-tools qt6-l10n-tools
run: |
for f in /etc/apt/sources.list /etc/apt/sources.list.d/*.list /etc/apt/sources.list.d/*.sources; do
[ -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"
done
apt update -qq && apt install --no-install-recommends -y ca-certificates build-essential pkg-config cmake libpcsclite-dev libssl-dev qt6-base-dev
- name: Checkout
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
Expand All @@ -65,7 +69,7 @@ jobs:
cache: true
aqtsource: git+https://github.com/miurahr/aqtinstall.git@16db45a70b5905ad596941b223469bc86a56901e
- name: Cache vcpkg
uses: actions/cache@caa296126883cff596d87d8935842f9db880ef25 # v5.1.0
uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
with:
path: ${{ github.workspace }}/vcpkg_cache
key: vcpkg-windows
Expand Down
21 changes: 11 additions & 10 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,37 @@
# SPDX-License-Identifier: LGPL-2.1-or-later

cmake_minimum_required(VERSION 3.22)
project(qdigidoccommon VERSION 1.0.0)
project(qdigidoccommon LANGUAGES CXX)
if(NOT COMMAND SET_ENV)
macro(set_env)
set(${ARGN})
endmacro()
endif()
set_env( CONFIG_URL "https://id.eesti.ee/config.json" CACHE STRING "Set Config URL" )
set(CMAKE_CXX_STANDARD 23)
find_package(OpenSSL 3.0.0 REQUIRED)
find_package(Qt6 6.2.0 REQUIRED COMPONENTS Widgets Network)
find_package(Qt6 6.2.0 REQUIRED COMPONENTS Network)

add_library(qdigidoccommon STATIC ${SOURCES} Common.cpp)
add_library(qdigidoccommon STATIC Common.cpp)
target_compile_features(qdigidoccommon PUBLIC cxx_std_23)
target_include_directories(qdigidoccommon PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
target_compile_definitions(qdigidoccommon PUBLIC QT_WARN_DEPRECATED_UP_TO=060200)
target_link_libraries(qdigidoccommon PUBLIC Qt6::Network Qt6::Widgets OpenSSL::SSL)
target_link_libraries(qdigidoccommon PUBLIC Qt6::Network)

if(WIN32)
target_compile_definitions(qdigidoccommon PUBLIC UNICODE WIN32_LEAN_AND_MEAN NOMINMAX)
target_link_libraries(qdigidoccommon PRIVATE Version SetupApi)
target_link_libraries(qdigidoccommon PRIVATE SetupApi)
elseif(APPLE)
target_link_libraries(qdigidoccommon PRIVATE "-framework PCSC")
target_link_libraries(qdigidoccommon PRIVATE $<LINK_LIBRARY:FRAMEWORK,PCSC>)
else()
find_package(PkgConfig REQUIRED)
pkg_check_modules(PCSCLITE REQUIRED libpcsclite IMPORTED_TARGET)
target_link_libraries(qdigidoccommon PUBLIC PkgConfig::PCSCLITE)
endif()

if( CONFIG_URL )
set_env( LAST_CHECK_DAYS 4 CACHE STRING "How often check configuration changes" )
find_package(OpenSSL 3.0.0 REQUIRED)
set_env(LAST_CHECK_DAYS 1 CACHE STRING "Days between configuration update checks")
if( LAST_CHECK_DAYS )
set_source_files_properties(Configuration.cpp PROPERTIES COMPILE_DEFINITIONS LAST_CHECK_DAYS=${LAST_CHECK_DAYS})
target_compile_definitions(qdigidoccommon PRIVATE LAST_CHECK_DAYS=${LAST_CHECK_DAYS})
endif()
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/config.json AND
EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/config.ecc AND
Expand Down Expand Up @@ -79,4 +79,5 @@ if( CONFIG_URL )
)
target_compile_definitions(qdigidoccommon PUBLIC CONFIG_URL="${CONFIG_URL}")
target_sources(qdigidoccommon PRIVATE Configuration.cpp)
target_link_libraries(qdigidoccommon PRIVATE OpenSSL::Crypto)
endif()
31 changes: 13 additions & 18 deletions Configuration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
#include <QtCore/QCoreApplication>
#include <QtCore/QDir>
#include <QtCore/QFile>
#include <QtCore/QFileInfo>
#include <QtCore/QJsonArray>
#include <QtCore/QJsonDocument>
#include <QtCore/QJsonObject>
#include <QtCore/QSettings>
#include <QtCore/QStandardPaths>
#include <QtCore/QTimer>
#include <QtCore/QTimeZone>
#include <QtCore/QVersionNumber>
#include <QtNetwork/QNetworkAccessManager>
#include <QtNetwork/QNetworkReply>
Expand All @@ -30,7 +30,7 @@ struct free_deleter
constexpr void operator()(T *t) const noexcept { D(t); }
};

static QVariant headerValue(const QJsonObject &obj, QLatin1String key) {
static QJsonValue headerValue(const QJsonObject &obj, QLatin1String key) {
return obj.value(QLatin1String("META-INF")).toObject().value(key);
}

Expand Down Expand Up @@ -155,7 +155,9 @@ bool Configuration::Private::validate(const QByteArray &data, const QByteArray &
return false;

QString date = headerValue(toObject(data), QLatin1String("DATE")).toString();
return QDateTime::currentDateTimeUtc() > QDateTime::fromString(date, QStringLiteral("yyyyMMddHHmmss'Z'"));
QDateTime notBefore = QDateTime::fromString(date, QStringLiteral("yyyyMMddHHmmss'Z'"));
notBefore.setTimeZone(QTimeZone::utc());
return QDateTime::currentDateTimeUtc() > notBefore;
}


Expand All @@ -167,9 +169,7 @@ Configuration::Configuration(QObject *parent)
#ifndef NO_CACHE
QDir().mkpath(d->cache);
#endif
d->eccurl = QStringLiteral("%1%2.ecc").arg(
d->url.adjusted(QUrl::RemoveFilename).toString(),
QFileInfo(d->url.fileName()).baseName());
d->eccurl = d->url.toString().replace(QLatin1String(".json"), QLatin1String(".ecc"));
d->req.setRawHeader("User-Agent", QStringLiteral("%1/%2 (%3) Lang: %4 Devices: %5")
.arg(QCoreApplication::applicationName(), QCoreApplication::applicationVersion(),
Common::applicationOs(), QLocale().uiLanguages().first(), Common::drivers().join('/')).toUtf8());
Expand All @@ -180,7 +180,7 @@ Configuration::Configuration(QObject *parent)
reply->ignoreSslErrors(errors);
});
connect(d->net, &QNetworkAccessManager::finished, this, [this](QNetworkReply *reply){
QScopedPointer<QNetworkReply, QScopedPointerDeleteLater> replyScoped(reply);
reply->deleteLater();
if(reply->error() != QNetworkReply::NoError)
{
Q_EMIT finished(false, reply->errorString());
Expand Down Expand Up @@ -240,13 +240,8 @@ Configuration::Configuration(QObject *parent)

QByteArray key = readFile(QStringLiteral(":/config.ecpub"));
std::unique_ptr<BIO,free_deleter<BIO_free>> bio(BIO_new_mem_buf(key.constData(), int(key.size())));
if(!bio)
{
qWarning() << "Failed to parse public key";
return;
}

d->publicKey.reset(PEM_read_bio_PUBKEY(bio.get(), nullptr, nullptr, nullptr));
if(bio)
d->publicKey.reset(PEM_read_bio_PUBKEY(bio.get(), nullptr, nullptr, nullptr));
if(!d->publicKey)
{
qWarning() << "Failed to parse public key";
Expand All @@ -256,19 +251,19 @@ Configuration::Configuration(QObject *parent)
d->initCache(false);
auto readSerials = [this]() -> std::tuple<int, int> {
int serial = headerValue(object(), QLatin1String("SERIAL")).toInt();
qDebug() << "Chache configuration serial:" << serial;
qDebug() << "Cache configuration serial:" << serial;
int bundledSerial = headerValue(toObject(readFile(QStringLiteral(":/config.json"))), QLatin1String("SERIAL")).toInt();
qDebug() << "Bundled configuration serial:" << bundledSerial;
return {serial, bundledSerial};
};
if(!d->validate(d->data, d->signature))
{
qWarning() << "Config siganture is invalid, clearing cache";
qWarning() << "Config signature is invalid, clearing cache";
update(true);
}
else if(auto [serial, bundledSerial] = readSerials(); serial < bundledSerial)
{
qWarning() << "Bundled configuration is recent than cache, resetting cache";
qWarning() << "Bundled configuration is more recent than cache, resetting cache";
update(true);
}
#ifdef LAST_CHECK_DAYS
Expand All @@ -279,7 +274,7 @@ Configuration::Configuration(QObject *parent)
update();
}
// Scheduled update or DigiDoc4 updated
else if(lastCheck < QDate::currentDate().addDays(-LAST_CHECK_DAYS) ||
else if(lastCheck.daysTo(QDate::currentDate()) >= LAST_CHECK_DAYS ||
QVersionNumber::fromString(QSettings().value(QStringLiteral("LastVersion")).toString()) <
QVersionNumber::fromString(QCoreApplication::applicationVersion()))
update();
Expand Down
6 changes: 4 additions & 2 deletions Configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@

#include <QObject>

class QNetworkReply;
#include <memory>

class QJsonObject;

class Configuration final : public QObject
{
Expand All @@ -21,7 +23,7 @@ class Configuration final : public QObject
void finished(bool changed, const QString &error);

private:
Q_DISABLE_COPY(Configuration)
Q_DISABLE_COPY_MOVE(Configuration)

class Private;
std::unique_ptr<Private> d;
Expand Down
Loading