Skip to content

Commit

Permalink
Qt 6 support
Browse files Browse the repository at this point in the history
IB-7156

Signed-off-by: Raul Metsma <raul@metsma.ee>
  • Loading branch information
metsma committed Apr 22, 2022
1 parent 2b7fff1 commit a00bb25
Show file tree
Hide file tree
Showing 47 changed files with 494 additions and 271 deletions.
23 changes: 18 additions & 5 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
run: |
QT_DIR=$(ls -d /Library/Developer/Qt-*-OpenSSL | tail -n 1)
cmake \
-DQt5_DIR=${QT_DIR}/lib/cmake/Qt5 \
-DCMAKE_PREFIX_PATH=${QT_DIR} \
-DOPENSSL_ROOT_DIR=/Library/Developer/OpenSSL \
-DLDAP_ROOT=/Library/Developer/OpenLDAP \
-DCMAKE_OSX_ARCHITECTURES="x86_64;arm64" -B build -S .
Expand Down Expand Up @@ -133,10 +133,9 @@ jobs:
strategy:
matrix:
vcver: [141, 142, 143]
arch: [x86, x64]
arch: [x64]
qtver: [5.12.12]
include:
- arch: x86
qt: win32_msvc2017
- arch: x64
qt: win64_msvc2017_64
- vcver: 141
Expand All @@ -148,6 +147,19 @@ jobs:
- vcver: 143
image: windows-2022
toolset: 14.31
- vcver: 142
arch: x86
qtver: 5.12.12
qt: win32_msvc2017
image: windows-2019
toolset: 14.29
- vcver: 142
arch: x64
qtver: 6.3.0
qtmodules: qt5compat
qt: win64_msvc2019_64
image: windows-2019
toolset: 14.29
env:
VER_SUFFIX: .VS${{ matrix.vcver }}
steps:
Expand Down Expand Up @@ -176,8 +188,9 @@ jobs:
- name: Install Qt
uses: jurplel/install-qt-action@v2
with:
version: '5.12.12'
version: ${{ matrix.qtver }}
arch: ${{ matrix.qt }}
modules: ${{ matrix.qtmodules }}
- name: Setup dev env
uses: ilammy/msvc-dev-cmd@v1
with:
Expand Down
5 changes: 3 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ if(POLICY CMP0074)
endif()
project(qdigidoc4 VERSION 4.2.12)

set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/modules")
set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/modules)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOMOC ON)

Expand All @@ -14,7 +14,8 @@ include( VersionInfo )
find_package( PKCS11 )
find_package( LibDigiDocpp 3.14.8 REQUIRED )
find_package( LDAP REQUIRED )
find_package( Qt5 5.9.0 REQUIRED COMPONENTS Core Widgets Network PrintSupport Svg LinguistTools )
find_package(QT NAMES Qt6 Qt5 COMPONENTS Core REQUIRED)
find_package(Qt${QT_VERSION_MAJOR} 5.9.0 REQUIRED COMPONENTS Core Widgets Network PrintSupport Svg LinguistTools)

set_env( TSL_URL "https://ec.europa.eu/tools/lotl/eu-lotl.xml" CACHE STRING "TSL trust list primary URL" )
set_env( TSL_INCLUDE "EE" CACHE STRING "TSL list include in binary" )
Expand Down
17 changes: 9 additions & 8 deletions client/Application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,14 @@ class MacMenuBar {};

#include <qtsingleapplication/src/qtlocalpeer.h>

#include <QAction>
#include <QtCore/QFileInfo>
#include <QtCore/QJsonArray>
#include <QtCore/QJsonDocument>
#include <QtCore/QJsonObject>
#include <QtCore/QProcess>
#include <QtCore/QSettings>
#include <QtCore/QStandardPaths>
#include <QtCore/QTimer>
#include <QtCore/QTranslator>
#include <QtCore/QUrl>
Expand All @@ -61,7 +63,6 @@ class MacMenuBar {};
#include <QtNetwork/QNetworkProxy>
#include <QtNetwork/QSslCertificate>
#include <QtNetwork/QSslConfiguration>
#include <QtWidgets/QAction>
#include <QtWidgets/QMessageBox>
#include <QtWidgets/QProgressBar>
#include <QtWidgets/QProgressDialog>
Expand Down Expand Up @@ -163,7 +164,7 @@ class DigidocConf: public digidoc::XmlConfCurrent
bool PKCS12Disable() const override
{ return s.value(QStringLiteral("PKCS12Disable"), digidoc::XmlConfCurrent::PKCS12Disable()).toBool(); }
std::string TSLCache() const override
{ return QStandardPaths::writableLocation(QStandardPaths::DataLocation).toStdString(); }
{ return QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation).toStdString(); }
bool TSLOnlineDigest() const override
{ return s.value(QStringLiteral("TSLOnlineDigest"), digidoc::XmlConfCurrent::TSLOnlineDigest()).toBool(); }

Expand Down Expand Up @@ -649,9 +650,9 @@ void Application::loadTranslation( const QString &lang )
else if(lang == QStringLiteral("ru")) QLocale::setDefault(QLocale( QLocale::Russian, QLocale::RussianFederation));
else QLocale::setDefault(QLocale(QLocale::Estonian, QLocale::Estonia));

d->appTranslator.load(QStringLiteral(":/translations/") + lang);
d->commonTranslator.load(QStringLiteral(":/translations/common_") + lang);
d->qtTranslator.load(QStringLiteral(":/translations/qt_") + lang);
void(d->appTranslator.load(QStringLiteral(":/translations/") + lang));
void(d->commonTranslator.load(QStringLiteral(":/translations/common_") + lang));
void(d->qtTranslator.load(QStringLiteral(":/translations/qt_") + lang));
if( d->closeAction ) d->closeAction->setText( tr("Close Window") );
if( d->newClientAction ) d->newClientAction->setText( tr("New Window") );
if( d->newCryptoAction ) d->newCryptoAction->setText( tr("New Crypto window") );
Expand All @@ -676,7 +677,7 @@ void Application::mailTo( const QUrl &url )
doc.lpszFileName = PWSTR(fileName.utf16());
MapiMessageW message = {};
message.lpszSubject = PWSTR(subject.utf16());
message.lpszNoteText = L"";
message.lpszNoteText = PWSTR(L"");
message.nFileCount = 1;
message.lpFiles = lpMapiFileDescW(&doc);
switch( mapi( NULL, 0, &message, MAPI_LOGON_UI|MAPI_DIALOG, 0 ) )
Expand All @@ -699,7 +700,7 @@ void Application::mailTo( const QUrl &url )
doc.lpszFileName = LPSTR(fileName.constData());
MapiMessage message = {};
message.lpszSubject = LPSTR(subject.constData());
message.lpszNoteText = "";
message.lpszNoteText = LPSTR("");
message.nFileCount = 1;
message.lpFiles = lpMapiFileDesc(&doc);
switch( mapi( NULL, 0, &message, MAPI_LOGON_UI|MAPI_DIALOG, 0 ) )
Expand Down Expand Up @@ -1000,7 +1001,7 @@ uint Application::readTSLVersion(const QString &path)
QXmlStreamReader r(&f);
while(!r.atEnd())
{
if(r.readNextStartElement() && r.name() == "TSLSequenceNumber")
if(r.readNextStartElement() && r.name() == QStringLiteral("TSLSequenceNumber"))
{
r.readNext();
return r.text().toUInt();
Expand Down
41 changes: 27 additions & 14 deletions client/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
set_app_name( PROGNAME qdigidoc4 )

add_executable( TSLDownload TSLDownload.cpp )
target_link_libraries( TSLDownload Qt5::Network )
target_link_libraries(TSLDownload Qt${QT_VERSION_MAJOR}::Network)
get_target_property(qtCore_install_prefix Qt${QT_VERSION_MAJOR}::qmake IMPORTED_LOCATION)
get_filename_component(qtCore_install_prefix ${qtCore_install_prefix} DIRECTORY)
add_custom_command(
OUTPUT TSL.qrc
DEPENDS TSLDownload
COMMAND $<TARGET_FILE:TSLDownload> "${CMAKE_CURRENT_BINARY_DIR}" ${TSL_URL} ${TSL_INCLUDE}
WORKING_DIRECTORY ${_qt5Core_install_prefix}/bin
WORKING_DIRECTORY ${qtCore_install_prefix}
)

configure_file( translations/tr.qrc tr.qrc COPYONLY )
qt5_add_translation( SOURCES translations/en.ts translations/et.ts translations/ru.ts )
qt_add_translation(SOURCES translations/en.ts translations/et.ts translations/ru.ts)

add_executable( ${PROGNAME} WIN32 MACOSX_BUNDLE
${PROGNAME}.rc
Expand All @@ -28,6 +30,7 @@ add_executable( ${PROGNAME} WIN32 MACOSX_BUNDLE
Diagnostics.cpp
DiagnosticsTask.cpp
DocumentModel.cpp
IKValidator.cpp
MainWindow.ui
MainWindow.cpp
MainWindow_MyEID.cpp
Expand Down Expand Up @@ -123,11 +126,21 @@ add_executable( ${PROGNAME} WIN32 MACOSX_BUNDLE

target_link_libraries( ${PROGNAME}
qdigidoccommon
Qt5::PrintSupport
Qt5::Svg
Qt${QT_VERSION_MAJOR}::PrintSupport
Qt${QT_VERSION_MAJOR}::Svg
${LIBDIGIDOCPP_LIBRARY}
${LDAP_LIBRARIES}
)

if(${QT_VERSION_MAJOR} STREQUAL "6")
find_package(Qt6 COMPONENTS Core5Compat SvgWidgets REQUIRED)
target_link_libraries(${PROGNAME} Qt6::Core5Compat Qt6::SvgWidgets)
elseif(WIN32)
find_package(Qt5 COMPONENTS WinExtras)
target_compile_definitions(${PROGNAME} PRIVATE QT_WIN_EXTRAS)
target_link_libraries(${PROGNAME} Qt5::WinExtras)
endif()

set_target_properties(${PROGNAME} PROPERTIES
AUTOUIC ON
AUTORCC ON
Expand Down Expand Up @@ -156,7 +169,7 @@ if( APPLE )
COMMAND cp -a $<TARGET_BUNDLE_DIR:DigiDocQL> $<TARGET_BUNDLE_CONTENT_DIR:${PROGNAME}>/Library/QuickLook
)
add_custom_target( macdeployqt DEPENDS ${PROGNAME}
COMMAND ${_qt5Core_install_prefix}/bin/macdeployqt $<TARGET_BUNDLE_DIR:${PROGNAME}>
COMMAND ${qtCore_install_prefix}/macdeployqt $<TARGET_BUNDLE_DIR:${PROGNAME}>
COMMAND rm -rf $<TARGET_BUNDLE_CONTENT_DIR:${PROGNAME}>/PlugIns/bearer
COMMAND cp -a /Library/Frameworks/digidocpp.framework $<TARGET_BUNDLE_CONTENT_DIR:${PROGNAME}>/Frameworks
COMMAND rm $<TARGET_BUNDLE_CONTENT_DIR:${PROGNAME}>/Frameworks/digidocpp.framework/Resources/digidoc-tool
Expand Down Expand Up @@ -197,8 +210,7 @@ elseif(WIN32)
target_sources( ${PROGNAME} PRIVATE QCSP.cpp QCNG.cpp QWin.cpp CertStore.cpp Diagnostics_win.cpp)
target_compile_options(${PROGNAME} PRIVATE "/guard:cf")
target_link_options(${PROGNAME} PRIVATE "/guard:cf" $<$<BOOL:${CROSSSIGNCERT}>:/INTEGRITYCHECK>)
find_package( Qt5 COMPONENTS WinExtras )
target_link_libraries( ${PROGNAME} Qt5::WinExtras NCrypt Crypt32 Cryptui )
target_link_libraries(${PROGNAME} NCrypt Crypt32 Cryptui)
get_filename_component(LIBS_PATH ${LIBDIGIDOCPP_LIBRARIES} DIRECTORY)
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
set(PLATFORM x64)
Expand All @@ -210,19 +222,20 @@ elseif(WIN32)
set(MSI_FILE "Digidoc4_Client-${VERSION}$ENV{VER_SUFFIX}.${PLATFORM}")
list(APPEND CANDLE_CMD "$ENV{WIX}bin\\candle.exe" -nologo -arch ${PLATFORM} -dMSI_VERSION=${VERSION} -dPlatform=${PLATFORM}
-dlibs_path="${LIBS_PATH}" -dclient_path=$<TARGET_FILE:${PROGNAME}> -dico_path=${CMAKE_CURRENT_SOURCE_DIR}/images/digidoc.ico
-dqtconf=${CMAKE_SOURCE_DIR}/qt.conf -dschemasLocation=${LIBS_PATH}/schema SchemasFragment.wxs ${CMAKE_SOURCE_DIR}/qdigidoc4.wxs
${CMAKE_MODULE_PATH}/WelcomeDlg2.wxs ${CMAKE_MODULE_PATH}/WixUI_Minimal2.wxs)
-dqtconf=${CMAKE_SOURCE_DIR}/qt.conf -dschemasLocation=${LIBS_PATH}/schema SchemasFragment.wxs
-dqt_ver_major=${QT_VERSION_MAJOR} -dqt_suffix=$<$<CONFIG:Debug>:d> ${CMAKE_SOURCE_DIR}/qdigidoc4.wxs
${CMAKE_SOURCE_DIR}/cmake/modules/WelcomeDlg2.wxs ${CMAKE_SOURCE_DIR}/cmake/modules/WixUI_Minimal2.wxs)
list(APPEND LIGHT_CMD "$ENV{WIX}bin\\light.exe" -nologo -ext WixUIExtension
qdigidoc4.wixobj SchemasFragment.wixobj WelcomeDlg2.wixobj WixUI_Minimal2.wixobj
-dWixUIDialogBmp=${CMAKE_MODULE_PATH}/dlgbmp.bmp
-dWixUIBannerBmp=${CMAKE_MODULE_PATH}/banner.bmp)
-dWixUIDialogBmp=${CMAKE_SOURCE_DIR}/cmake/modules/dlgbmp.bmp
-dWixUIBannerBmp=${CMAKE_SOURCE_DIR}/cmake/modules/banner.bmp)
add_custom_target(msi DEPENDS ${PROGNAME}
COMMAND "$ENV{WIX}bin\\heat.exe" dir ${LIBS_PATH}/schema -nologo -cg Schemas -gg -scom -sreg -sfrag -srd -dr SchemaFolder -var var.schemasLocation -out SchemasFragment.wxs
COMMAND ${CANDLE_CMD}
COMMAND ${LIGHT_CMD} -loc ${CMAKE_SOURCE_DIR}/qdigidoc4.en-US.wxl -cultures:en-US -o "${MSI_FILE}.en-US.msi"
COMMAND ${LIGHT_CMD} -loc ${CMAKE_SOURCE_DIR}/qdigidoc4.et-EE.wxl -cultures:et-EE -o "${MSI_FILE}.et-EE.msi"
#Build MSI with QT
COMMAND ${CANDLE_CMD} -dqt_path=${_qt5Core_install_prefix}
COMMAND ${CANDLE_CMD} -dqt_path=${qtCore_install_prefix}
COMMAND ${LIGHT_CMD} -loc ${CMAKE_SOURCE_DIR}/qdigidoc4.en-US.wxl -cultures:en-US -o "${MSI_FILE}.en-US.qt.msi"
COMMAND ${LIGHT_CMD} -loc ${CMAKE_SOURCE_DIR}/qdigidoc4.et-EE.wxl -cultures:et-EE -o "${MSI_FILE}.et-EE.qt.msi"
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
Expand Down Expand Up @@ -259,7 +272,7 @@ elseif(WIN32)
COMMAND ${CMAKE_COMMAND} -E copy ${LIBS_PATH}/digidocpp.conf appx
COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_SOURCE_DIR}/Assets appx/Assets
COMMAND ${CMAKE_COMMAND} -E copy_directory ${LIBS_PATH}/schema appx/schema
COMMAND ${_qt5Core_install_prefix}/bin/windeployqt --no-translations --no-compiler-runtime --no-patchqt appx
COMMAND ${qtCore_install_prefix}/windeployqt --no-translations --no-compiler-runtime --no-patchqt appx
COMMAND ${CMAKE_COMMAND} -E remove_directory appx/bearer
COMMAND makeappx.exe pack -d appx -p ${MSI_FILE}.appx
# https://msdn.microsoft.com/en-us/library/windows/desktop/jj835832(v=vs.85).aspx
Expand Down
53 changes: 40 additions & 13 deletions client/CryptoDoc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include <QtCore/QFileInfo>
#include <QtCore/QLoggingCategory>
#include <QtCore/QMimeData>
#include <QtCore/QRegularExpression>
#include <QtCore/QTemporaryFile>
#include <QtCore/QtEndian>
#include <QtCore/QThread>
Expand Down Expand Up @@ -82,7 +83,11 @@ class CryptoDoc::Private final: public QThread
QByteArray crypto(const EVP_CIPHER *cipher, const QByteArray &data, bool encrypt);

bool isEncryptedWarning();
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
QByteArray fromBase64(const QStringView &data);
#else
QByteArray fromBase64(const QStringRef &data);
#endif
static bool opensslError(bool err);
QByteArray readCDoc(QIODevice *cdoc, bool data);
void readDDoc(QIODevice *ddoc);
Expand Down Expand Up @@ -266,7 +271,11 @@ QByteArray CryptoDoc::Private::crypto(const EVP_CIPHER *cipher, const QByteArray
return result;
}

QByteArray CryptoDoc::Private::fromBase64( const QStringRef &data )
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
QByteArray CryptoDoc::Private::fromBase64(const QStringView &data)
#else
QByteArray CryptoDoc::Private::fromBase64(const QStringRef &data)
#endif
{
unsigned int buf = 0;
int nbits = 0;
Expand Down Expand Up @@ -480,10 +489,10 @@ QByteArray CryptoDoc::Private::readCDoc(QIODevice *cdoc, bool data)
if(data)
{
// EncryptedData/KeyInfo
if(xml.name() == "KeyInfo")
if(xml.name() == QStringLiteral("KeyInfo"))
xml.skipCurrentElement();
// EncryptedData/CipherData/CipherValue
else if(xml.name() == "CipherValue")
else if(xml.name() == QStringLiteral("CipherValue"))
{
xml.readNext();
return fromBase64(xml.text());
Expand All @@ -492,16 +501,16 @@ QByteArray CryptoDoc::Private::readCDoc(QIODevice *cdoc, bool data)
}

// EncryptedData
if( xml.name() == "EncryptedData")
if(xml.name() == QStringLiteral("EncryptedData"))
mime = xml.attributes().value(QStringLiteral("MimeType")).toString();
// EncryptedData/EncryptionProperties/EncryptionProperty
else if( xml.name() == "EncryptionProperty" )
else if(xml.name() == QStringLiteral("EncryptionProperty"))
{
for( const QXmlStreamAttribute &attr: xml.attributes() )
{
if( attr.name() != "Name" )
if(attr.name() != QStringLiteral("Name"))
continue;
if( attr.value() == "orig_file" )
if(attr.value() == QStringLiteral("orig_file"))
{
QStringList fileparts = xml.readElementText().split('|');
File file;
Expand All @@ -516,10 +525,10 @@ QByteArray CryptoDoc::Private::readCDoc(QIODevice *cdoc, bool data)
}
}
// EncryptedData/EncryptionMethod
else if( xml.name() == "EncryptionMethod" )
else if(xml.name() == QStringLiteral("EncryptionMethod"))
method = xml.attributes().value(QStringLiteral("Algorithm")).toString();
// EncryptedData/KeyInfo/EncryptedKey
else if( xml.name() == "EncryptedKey" )
else if(xml.name() == QStringLiteral("EncryptedKey"))
{
CKey key;
key.id = xml.attributes().value(QStringLiteral("Id")).toString();
Expand Down Expand Up @@ -718,7 +727,7 @@ void CryptoDoc::Private::writeCDoc(QIODevice *cdoc, const QByteArray &transportK
writeBase64Element(w, DENC, QStringLiteral("CipherValue"), encryptedData);
});
writeElement(w, DENC, QStringLiteral("EncryptionProperties"), [&]{
for(QHash<QString,QString>::const_iterator i = props.constBegin(); i != props.constEnd(); ++i)
for(QMultiHash<QString,QString>::const_iterator i = props.constBegin(); i != props.constEnd(); ++i)
writeElement(w, DENC, QStringLiteral("EncryptionProperty"), {{"Name", i.key()}}, [&]{ w.writeCharacters(i.value()); });
});
});
Expand All @@ -744,7 +753,7 @@ void CryptoDoc::Private::readDDoc(QIODevice *ddoc)
default: continue;
}

if(x.name() == "DataFile")
if(x.name() == QStringLiteral("DataFile"))
{
File file;
file.name = x.attributes().value(QStringLiteral("Filename")).toString().normalized(QString::NormalizationForm_C);
Expand All @@ -755,7 +764,7 @@ void CryptoDoc::Private::readDDoc(QIODevice *ddoc)
file.size = FileDialog::fileSize(quint64(file.data.size()));
files << file;
}
else if(x.name() == "Signature")
else if(x.name() == QStringLiteral("Signature"))
hasSignature = true;
}
qCDebug(CRYPTO) << "Container contains signature" << hasSignature;
Expand Down Expand Up @@ -934,7 +943,25 @@ QString CDocumentModel::save(int row, const QString &path) const
void CKey::setCert( const QSslCertificate &c )
{
cert = c;
recipient = SslCertificate(c).friendlyName();
recipient = [](const SslCertificate &c) {
QString cn = c.subjectInfo(QSslCertificate::CommonName);
QString o = c.subjectInfo(QSslCertificate::Organization);

QRegularExpression rx("ESTEID \\((.*)\\)");
QRegularExpressionMatch match = rx.match(o);
if(match.hasMatch())
return QStringLiteral("%1,%2").arg(cn, match.captured(1));
if(o == QStringLiteral("ESTEID"))
return QStringLiteral("%1,%2").arg(cn, CryptoDoc::tr("ID-CARD"));
int certType = c.type();
if(certType & SslCertificate::EResidentSubType)
return QStringLiteral("%1,%2").arg(cn, CryptoDoc::tr("Digi-ID E-RESIDENT"));
if(certType & SslCertificate::DigiIDType)
return QStringLiteral("%1,%2").arg(cn, CryptoDoc::tr("Digi-ID"));
if(certType & SslCertificate::EstEidType)
return QStringLiteral("%1,%2").arg(cn, CryptoDoc::tr("ID-CARD"));
return cn;
}(c);
}


Expand Down
1 change: 0 additions & 1 deletion client/DigiDoc.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
class DigiDoc;
class QDateTime;
class QSslCertificate;
class QStringList;

class DigiDocSignature
{
Expand Down
Loading

0 comments on commit a00bb25

Please sign in to comment.