Skip to content

Commit

Permalink
Move QPCSC to digidoc
Browse files Browse the repository at this point in the history
IB-7927

Signed-off-by: Raul Metsma <[email protected]>
  • Loading branch information
metsma committed Oct 17, 2024
1 parent d59f384 commit e438768
Show file tree
Hide file tree
Showing 19 changed files with 872 additions and 35 deletions.
4 changes: 3 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.16)
if(NOT EXISTS ${CMAKE_SOURCE_DIR}/cmake/modules/VersionInfo.cmake)
message(FATAL_ERROR "cmake submodule directory empty, did you 'git clone --recursive'?")
endif()
project(qdigidoc4 VERSION 4.6.0)
project(qdigidoc4 VERSION 4.7.0)

set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/modules)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
Expand All @@ -25,6 +25,8 @@ set_env(CDOC2_GET_URL "https://cdoc2-keyserver-get" CACHE STRING "CDoc 2.0 Key S
set_env(CDOC2_POST_URL "https://cdoc2-keyserver-post" CACHE STRING "CDoc 2.0 Key Server post URL")
set_env( MOBILEID_URL "https://dd-mid.ria.ee/mid-api" CACHE STRING "URL for Mobile-ID" )
set_env( SMARTID_URL "https://dd-sid.ria.ee/v1" CACHE STRING "URL for Smart-ID" )
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED YES)
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION YES)
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION_DEBUG NO)
if(CMAKE_CXX_COMPILER_ID MATCHES "AppleClang")
Expand Down
67 changes: 58 additions & 9 deletions client/Application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@

#include "Application.h"

#include "Common.h"
#include "Configuration.h"
#include "MainWindow.h"
#include "QSigner.h"
#include "QSmartCard.h"
Expand All @@ -40,7 +42,6 @@ class MacMenuBar {};
#include "dialogs/WarningDialog.h"
#include "effects/Overlay.h"

#include <common/Configuration.h>
#include <optional>

#include <digidocpp/Container.h>
Expand Down Expand Up @@ -308,13 +309,35 @@ class Application::Private
};

Application::Application( int &argc, char **argv )
#ifdef Q_OS_MAC
: Common(argc, argv, QStringLiteral("qdigidoc4"), QStringLiteral(":/images/Icon.svg"))
#else
: Common(argc, argv, QStringLiteral("qdigidoc4"), QStringLiteral(":/images/digidoc_128.png"))
#endif
: BaseApplication(argc, argv)
, d(new Private)
{
setApplicationName(QStringLiteral("qdigidoc4"));
setApplicationVersion(QStringLiteral("%1.%2.%3.%4")
.arg( MAJOR_VER ).arg( MINOR_VER ).arg( RELEASE_VER ).arg( BUILD_VER ) );
setOrganizationDomain(QStringLiteral("ria.ee"));
setOrganizationName(QStringLiteral("RIA"));
setWindowIcon(QIcon(QStringLiteral(":/images/Icon.svg")));
if(QFile::exists(QStringLiteral("%1/%2.log").arg(QDir::tempPath(), applicationName())))
qInstallMessageHandler(msgHandler);

Q_INIT_RESOURCE(common_tr);
#if defined(Q_OS_WIN)
AllowSetForegroundWindow( ASFW_ANY );
#ifdef NDEBUG
setLibraryPaths({ applicationDirPath() });
#endif
#elif defined(Q_OS_MAC)
qputenv("OPENSSL_CONF", applicationDirPath().toUtf8() + "../Resources/openssl.cnf");
#ifdef NDEBUG
setLibraryPaths({ applicationDirPath() + "/../PlugIns" });
#endif
#endif
setStyleSheet(QStringLiteral(
"QDialogButtonBox { dialogbuttonbox-buttons-have-icons: 0; }\n"));

QNetworkProxyFactory::setUseSystemConfiguration(true);

QStringList args = arguments();
args.removeFirst();
#ifndef Q_OS_MAC
Expand Down Expand Up @@ -432,7 +455,7 @@ Application::Application( int &argc, char **argv )
updateTSLCache(QDateTime::currentDateTimeUtc().addDays(-7));

digidoc::initialize(applicationName().toUtf8().constData(), QStringLiteral("%1/%2 (%3)")
.arg(applicationName(), applicationVersion(), applicationOs()).toUtf8().constData(),
.arg(applicationName(), applicationVersion(), Common::applicationOs()).toUtf8().constData(),
[](const digidoc::Exception *ex) {
qDebug() << "TSL loading finished";
Q_EMIT qApp->TSLLoadingFinished();
Expand Down Expand Up @@ -627,9 +650,9 @@ bool Application::event(QEvent *event)
// Load here because cocoa NSApplication overides events
case QEvent::ApplicationActivate:
initMacEvents();
return Common::event(event);
return BaseApplication::event(event);
#endif
default: return Common::event(event);
default: return BaseApplication::event(event);
}
}

Expand Down Expand Up @@ -756,6 +779,32 @@ QWidget* Application::mainWindow()
return nullptr;
}

void Application::msgHandler(QtMsgType type, const QMessageLogContext &ctx, const QString &msg)
{
QFile f(QStringLiteral("%1/%2.log").arg(QDir::tempPath(), applicationName()));
if(!f.open( QFile::Append ))
return;
f.write(QDateTime::currentDateTime().toString(QStringLiteral("yyyy-MM-dd hh:mm:ss ")).toUtf8());
switch(type)
{
case QtDebugMsg: f.write("D"); break;
case QtWarningMsg: f.write("W"); break;
case QtCriticalMsg: f.write("C"); break;
case QtFatalMsg: f.write("F"); break;
default: f.write("I"); break;
}
f.write(QStringLiteral(" %1 ").arg(QLatin1String(ctx.category)).toUtf8());
if(ctx.line > 0)
{
f.write(QStringLiteral("%1:%2 \"%3\" ")
.arg(QFileInfo(QString::fromLatin1(ctx.file)).fileName())
.arg(ctx.line)
.arg(QLatin1String(ctx.function)).toUtf8());
}
f.write(msg.toUtf8());
f.write("\n");
}

bool Application::notify(QObject *object, QEvent *event)
{
try
Expand Down
18 changes: 12 additions & 6 deletions client/Application.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,15 @@

#pragma once

#include <common/Common.h>
#include <QtCore/QtGlobal>

#include <QtCore/QStringList>
#include <QtCore/QVariant>
#ifdef Q_OS_MAC
#include <QtWidgets/QApplication>
using BaseApplication = QApplication;
#else
#include "qtsingleapplication/src/QtSingleApplication"
using BaseApplication = QtSingleApplication;
#endif

#if defined(qApp)
#undef qApp
Expand All @@ -33,12 +38,12 @@ namespace digidoc { class Exception; }
class Configuration;
class QAction;
class QSigner;
class Application final: public Common
class Application final: public BaseApplication
{
Q_OBJECT

public:
enum ConfParameter
enum ConfParameter : quint8
{
SiVaUrl,
ProxyHost,
Expand Down Expand Up @@ -86,6 +91,7 @@ private Q_SLOTS:
private:
bool event(QEvent *event) final;
static void closeWindow();
static void msgHandler(QtMsgType type, const QMessageLogContext &ctx, const QString &msg);
static void parseArgs(const QString &msg = {});
static void parseArgs(QStringList args);
static void showWarning(const QString &msg, const digidoc::Exception &e);
Expand All @@ -102,7 +108,7 @@ private Q_SLOTS:
class REOpenEvent: public QEvent
{
public:
enum { Type = QEvent::User + 1 };
enum : quint16 { Type = QEvent::User + 1 };
REOpenEvent(): QEvent( QEvent::Type(Type) ) {}
};

Expand Down
6 changes: 4 additions & 2 deletions client/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ add_executable(${PROJECT_NAME} WIN32 MACOSX_BUNDLE
QCardLock.h
QCryptoBackend.cpp
QCryptoBackend.h
QPCSC.cpp
QPCSC_p.h
QPCSC.h
QPKCS11.cpp
QPKCS11.h
QSigner.cpp
Expand Down Expand Up @@ -118,7 +121,7 @@ set_target_properties(${PROJECT_NAME} PROPERTIES
MACOSX_BUNDLE_BUNDLE_NAME ${PROJECT_NAME}
MACOSX_BUNDLE_GUI_IDENTIFIER "ee.ria.${PROJECT_NAME}"
)
target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_SOURCE_DIR} ${LIBDIGIDOCPP_INCLUDE_DIR})
target_include_directories(${PROJECT_NAME} PRIVATE ${LIBDIGIDOCPP_INCLUDE_DIR})
target_compile_definitions(${PROJECT_NAME} PRIVATE
CDOC2_GET_URL="${CDOC2_GET_URL}"
CDOC2_POST_URL="${CDOC2_POST_URL}"
Expand Down Expand Up @@ -229,7 +232,6 @@ elseif(WIN32)
-ext WixToolset.UI.wixext
-bv WixUIDialogBmp=${CMAKE_SOURCE_DIR}/cmake/modules/dlgbmp.bmp
-bv WixUIBannerBmp=${CMAKE_SOURCE_DIR}/cmake/modules/banner.bmp
-d MSI_VERSION=${VERSION}
-d ico_path=${CMAKE_CURRENT_SOURCE_DIR}/images/digidoc.ico
-d libs_path=${LIBS_PATH}
-d client_path=$<TARGET_FILE:${PROJECT_NAME}>
Expand Down
5 changes: 4 additions & 1 deletion client/CheckConnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "CheckConnection.h"

#include "Application.h"
#include "Common.h"

#include <QtCore/QCoreApplication>
#include <QtCore/QEventLoop>
Expand Down Expand Up @@ -106,8 +107,10 @@ QSslConfiguration CheckConnection::sslConfiguration(const QByteArray &add)
{
QSslConfiguration ssl = QSslConfiguration::defaultConfiguration();
#ifdef CONFIG_URL
const auto list = Application::confValue(QLatin1String("CERT-BUNDLE")).toArray();
QList<QSslCertificate> trusted;
for(const auto &cert: Application::confValue(QLatin1String("CERT-BUNDLE")).toArray())
trusted.reserve(list.size());
for(const auto &cert: list)
trusted.append(QSslCertificate(QByteArray::fromBase64(cert.toString().toLatin1()), QSsl::Der));
if(!add.isEmpty())
trusted.append(QSslCertificate(QByteArray::fromBase64(add), QSsl::Der));
Expand Down
3 changes: 2 additions & 1 deletion client/Diagnostics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "Diagnostics.h"

#include "Application.h"
#include "Common.h"
#include "QPCSC.h"
#include "Settings.h"

Expand Down Expand Up @@ -142,6 +143,6 @@ void Diagnostics::generalInfo(QTextStream &s)
}

#ifdef Q_OS_WIN
s << "<b>" << tr("Smart Card reader drivers") << ":</b><br />" << QPCSC::instance().drivers().join(QLatin1String("<br />"));
s << "<b>" << tr("Smart Card reader drivers") << ":</b><br />" << Common::drivers().join(QLatin1String("<br />"));
#endif
}
1 change: 1 addition & 0 deletions client/Diagnostics_unix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

#include "Common.h"

#include <QtCore/QCoreApplication>
#include <QtCore/QFile>
#include <QtCore/QRegularExpression>
#include <QtCore/QTextStream>
Expand Down
7 changes: 4 additions & 3 deletions client/Diagnostics_win.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@

#include "Diagnostics.h"

#include "Common.h"
#include "Configuration.h"

#include <QtCore/QCoreApplication>
#include <QtCore/QProcess>
#include <QtCore/QRegularExpression>
#include <QtCore/QSettings>
Expand Down Expand Up @@ -131,7 +132,7 @@ void Diagnostics::run()
emit update( info );
info.clear();

s << "<b>" << tr("OS:") << "</b> " << Common::applicationOs() << "<br /><br /";
s << "<b>" << tr("OS:") << "</b> " << Configuration::applicationOs() << "<br /><br /";
emit update( info );
info.clear();

Expand All @@ -145,7 +146,7 @@ void Diagnostics::run()
+ ";C:\\Program Files\\Open-EID"
+ ";C:\\Program Files\\EstIDMinidriver Minidriver"
+ ";C:\\Program Files (x86)\\EstIDMinidriver Minidriver");
SetDllDirectory(LPCWSTR(qApp->applicationDirPath().utf16()));
SetDllDirectory(LPCWSTR(QCoreApplication::applicationDirPath().utf16()));
static const QStringList dlls{
"digidocpp", "qdigidoc4.exe", "EsteidShellExtension", "id-updater.exe",
"EstIDMinidriver", "EstIDMinidriver64", "web-eid.exe",
Expand Down
3 changes: 1 addition & 2 deletions client/QCNG.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,10 @@

#include "QCNG.h"

#include "QPCSC.h"
#include "SslCertificate.h"
#include "TokenData.h"

#include <common/QPCSC.h>

#include <QtCore/QDebug>
#include <QtNetwork/QSslKey>

Expand Down
Loading

0 comments on commit e438768

Please sign in to comment.