Skip to content

Commit

Permalink
Remove Qt 5 support
Browse files Browse the repository at this point in the history
IB-8335

Signed-off-by: Raul Metsma <[email protected]>
  • Loading branch information
metsma committed Jan 24, 2025
1 parent f470100 commit 9e9c3d4
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 96 deletions.
18 changes: 4 additions & 14 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v4
with:
submodules: recursive
- name: Install libraries
run: brew install qt@6
- name: Build
Expand All @@ -27,20 +25,14 @@ jobs:
container: ubuntu:${{ matrix.container }}
strategy:
matrix:
container: ['20.04', '22.04', '24.04']
container: ['22.04', '24.04', '24.10']
env:
DEBIAN_FRONTEND: noninteractive
steps:
- name: Install dependencies
if: matrix.container == '20.04'
run: apt update -qq && apt install --no-install-recommends -y git ca-certificates build-essential pkg-config cmake libpcsclite-dev libssl-dev qttools5-dev-tools qttools5-dev
- name: Install dependencies
if: matrix.container != '20.04'
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
- name: Checkout
uses: actions/checkout@v4
with:
submodules: recursive
- name: Build packages
run: |
cmake -B build -S .
Expand All @@ -51,19 +43,17 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v4
with:
submodules: recursive
- name: Prepare vcpkg
uses: lukka/run-vcpkg@v7
with:
vcpkgArguments: openssl
vcpkgGitCommitId: 18b028fe785e707265fa0e35590b7537ae1d12ea
vcpkgGitCommitId: e4644bd15436d406bba71928d086c809e5c9ca45
vcpkgTriplet: x64-windows
- name: Install Qt
uses: jurplel/install-qt-action@v4
with:
version: 6.7.1
arch: win64_msvc2019_64
version: 6.8.1
arch: win64_msvc2022_64
- name: Build
run: |
cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo `
Expand Down
28 changes: 6 additions & 22 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,38 +1,22 @@
cmake_minimum_required(VERSION 3.10)
cmake_minimum_required(VERSION 3.22)
project(qdigidoccommon VERSION 1.0.0)
if(NOT VERSION)
if(NOT DEFINED set_env)
macro(set_env)
set(${ARGN})
endmacro()
add_compile_definitions(
MAJOR_VER=${PROJECT_VERSION_MAJOR}
MINOR_VER=${PROJECT_VERSION_MINOR}
RELEASE_VER=${PROJECT_VERSION_PATCH}
BUILD_VER=$<IF:$<BOOL:$ENV{BUILD_NUMBER}>,$ENV{BUILD_NUMBER},0>
)
endif()
set_env( CONFIG_URL "https://id.eesti.ee/config.json" CACHE STRING "Set Config URL" )
find_package(OpenSSL 1.1.1 REQUIRED)
find_package(QT NAMES Qt6 Qt5 COMPONENTS Core REQUIRED)
find_package(Qt${QT_VERSION_MAJOR} 5.12.0 REQUIRED COMPONENTS Widgets Network LinguistTools)

if(${QT_VERSION} VERSION_LESS "5.15.0")
macro(qt_add_translation)
qt5_add_translation(${ARGN})
endmacro()
macro(qt_add_resources)
qt5_add_resources(${ARGN})
endmacro()
endif()
find_package(OpenSSL 3.0.0 REQUIRED)
find_package(Qt6 6.2.0 REQUIRED COMPONENTS Widgets Network LinguistTools)

configure_file( translations/common_tr.qrc common_tr.qrc COPYONLY )
qt_add_translation(SOURCES translations/qtbase_et.ts translations/qtbase_ru.ts
translations/common_en.ts translations/common_et.ts translations/common_ru.ts)
qt_add_resources(SOURCES ${CMAKE_CURRENT_BINARY_DIR}/common_tr.qrc)
add_library(qdigidoccommon STATIC ${SOURCES} Common.cpp)
target_include_directories(qdigidoccommon PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
target_compile_definitions(qdigidoccommon PUBLIC QT_DEPRECATED_WARNINGS_SINCE=051200)
target_link_libraries(qdigidoccommon PUBLIC Qt${QT_VERSION_MAJOR}::Network Qt${QT_VERSION_MAJOR}::Widgets OpenSSL::SSL)
target_compile_definitions(qdigidoccommon PUBLIC QT_DEPRECATED_WARNINGS_SINCE=060200)
target_link_libraries(qdigidoccommon PUBLIC Qt6::Network Qt6::Widgets OpenSSL::SSL)

if(WIN32)
target_compile_definitions(qdigidoccommon PUBLIC UNICODE WIN32_LEAN_AND_MEAN)
Expand Down
82 changes: 25 additions & 57 deletions Configuration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,14 @@
#include <openssl/evp.h>
#include <openssl/pem.h>

#include <memory>
#include <array>

template<auto D>
struct free_deleter
{
template<typename T>
constexpr void operator()(T *t) const noexcept { D(t); }
};

static QVariant headerValue(const QJsonObject &obj, QLatin1String key) {
return obj.value(QLatin1String("META-INF")).toObject().value(key);
Expand Down Expand Up @@ -70,7 +77,7 @@ class Configuration::Private
QByteArray data, signature;
QJsonObject dataobject;
QUrl rsaurl, url = QUrl(QStringLiteral(CONFIG_URL));
EVP_PKEY *publicKey = nullptr;
std::unique_ptr<EVP_PKEY,free_deleter<EVP_PKEY_free>> publicKey;
QNetworkRequest req;
QNetworkAccessManager *net = nullptr;
#ifdef LAST_CHECK_DAYS
Expand Down Expand Up @@ -105,11 +112,7 @@ void Configuration::Private::setData(const QByteArray &_data, const QByteArray &
data = _data;
signature = _signature;
dataobject = toObject(data);
#if QT_VERSION >= QT_VERSION_CHECK(5, 13, 0)
QSettings system(QSettings::SystemScope);
#else
QSettings system(QSettings::SystemScope, QCoreApplication::organizationName(), QCoreApplication::applicationName());
#endif
for(const QString &key: system.childKeys())
{
if(!dataobject.contains(key))
Expand All @@ -133,23 +136,24 @@ bool Configuration::Private::validate(const QByteArray &data, const QByteArray &

QByteArray sig = QByteArray::fromBase64(signature);
size_t size = 0;
auto ctx = std::unique_ptr<EVP_PKEY_CTX,decltype(&EVP_PKEY_CTX_free)>(EVP_PKEY_CTX_new(publicKey, nullptr), EVP_PKEY_CTX_free);
auto ctx = std::unique_ptr<EVP_PKEY_CTX,free_deleter<EVP_PKEY_CTX_free>>(EVP_PKEY_CTX_new(publicKey.get(), nullptr));
if(!ctx || EVP_PKEY_verify_recover_init(ctx.get()) < 1 ||
EVP_PKEY_verify_recover(ctx.get(), nullptr, &size,
(const unsigned char*)sig.constData(), size_t(sig.size())) < 1)
return false;
QByteArray digest(int(size), '\0');
QByteArray digest(qsizetype(size), '\0');
if(EVP_PKEY_verify_recover(ctx.get(), (unsigned char*)digest.data(), &size,
(const unsigned char*)sig.constData(), size_t(sig.size())) < 1)
return false;
digest.resize(int(size));
digest.resize(qsizetype(size));

static const std::map<QCryptographicHash::Algorithm,QByteArray> list {
{QCryptographicHash::Sha1, QByteArray::fromHex("3021300906052b0e03021a05000414")},
{QCryptographicHash::Sha224, QByteArray::fromHex("302d300d06096086480165030402040500041c")},
{QCryptographicHash::Sha256, QByteArray::fromHex("3031300d060960864801650304020105000420")},
{QCryptographicHash::Sha384, QByteArray::fromHex("3041300d060960864801650304020205000430")},
{QCryptographicHash::Sha512, QByteArray::fromHex("3051300d060960864801650304020305000440")},
using item = std::pair<QCryptographicHash::Algorithm,QByteArray>;
static const std::array list {
item{QCryptographicHash::Sha1, QByteArray::fromHex("3021300906052b0e03021a05000414")},
item{QCryptographicHash::Sha224, QByteArray::fromHex("302d300d06096086480165030402040500041c")},
item{QCryptographicHash::Sha256, QByteArray::fromHex("3031300d060960864801650304020105000420")},
item{QCryptographicHash::Sha384, QByteArray::fromHex("3041300d060960864801650304020205000430")},
item{QCryptographicHash::Sha512, QByteArray::fromHex("3051300d060960864801650304020305000440")},
};
if(std::none_of(list.cbegin(), list.cend(), [&](const auto &item) {
return digest == item.second + QCryptographicHash::hash(data, item.first);
Expand All @@ -176,9 +180,7 @@ Configuration::Configuration(QObject *parent)
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());
#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
d->req.setTransferTimeout();
#endif
d->net = new QNetworkAccessManager(this);
connect(d->net, &QNetworkAccessManager::sslErrors, this,
[](QNetworkReply *reply, const QList<QSslError> &errors){
Expand All @@ -203,7 +205,8 @@ Configuration::Configuration(QObject *parent)
return;
}
qDebug() << "Remote signature does not match, downloading new configuration";
sendRequest(d->url)->setProperty("signature", signature);
d->req.setUrl(d->url);
d->net->get(d->req)->setProperty("signature", signature);
}
else if(reply->url() == d->url)
{
Expand Down Expand Up @@ -250,14 +253,7 @@ Configuration::Configuration(QObject *parent)
return;
}

#if OPENSSL_VERSION_NUMBER < 0x30000000L
RSA *rsa = PEM_read_bio_RSAPublicKey(bio, nullptr, nullptr, nullptr);
d->publicKey = EVP_PKEY_new();
EVP_PKEY_set1_RSA(d->publicKey, rsa);
RSA_free(rsa);
#else
d->publicKey = PEM_read_bio_PUBKEY(bio, nullptr, nullptr, nullptr);
#endif
d->publicKey.reset(PEM_read_bio_PUBKEY(bio, nullptr, nullptr, nullptr));
BIO_free(bio);
if(!d->publicKey)
{
Expand Down Expand Up @@ -299,45 +295,17 @@ Configuration::Configuration(QObject *parent)
#endif
}

Configuration::~Configuration()
{
if(d->publicKey)
EVP_PKEY_free(d->publicKey);
delete d;
}
Configuration::~Configuration() = default;

QJsonObject Configuration::object() const
{
return d->dataobject;
}

QNetworkReply* Configuration::sendRequest(const QUrl &url)
{
d->req.setUrl(url);
QNetworkReply *reply = d->net->get(d->req);
#if QT_VERSION < QT_VERSION_CHECK(5, 15, 0)
if(!reply->isRunning())
return reply;
QTimer *timer = new QTimer(this);
timer->setSingleShot(true);
connect(reply, &QNetworkReply::finished, timer, [=]{
timer->stop();
timer->deleteLater();
});
connect(timer, &QTimer::timeout, this, [=]{
timer->deleteLater();
reply->abort();
qDebug() << "Request timed out";
Q_EMIT finished(false, tr("Request timed out"));
});
timer->start(30*1000);
#endif
return reply;
}

void Configuration::update(bool force)
{
d->initCache(force);
sendRequest(d->rsaurl);
d->req.setUrl(d->rsaurl);
d->net->get(d->req);
QSettings().setValue(QStringLiteral("LastVersion"), QCoreApplication::applicationVersion());
}
4 changes: 1 addition & 3 deletions Configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,8 @@ class Configuration final : public QObject
void finished(bool changed, const QString &error);

private:
QNetworkReply *sendRequest(const QUrl &url);

Q_DISABLE_COPY(Configuration)

class Private;
Private *d;
std::unique_ptr<Private> d;
};

0 comments on commit 9e9c3d4

Please sign in to comment.