Skip to content

Commit

Permalink
Use libxml2/xmsec1 for XAdES signature parsing and validation (#1280)
Browse files Browse the repository at this point in the history
IB-7948

Signed-off-by: Raul Metsma <raul@metsma.ee>
  • Loading branch information
metsma authored Aug 6, 2024
1 parent a857685 commit 5212d87
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 62 deletions.
8 changes: 2 additions & 6 deletions client/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,9 @@ if( APPLE )
COMMAND rm $<TARGET_BUNDLE_CONTENT_DIR:${PROJECT_NAME}>/Frameworks/digidocpp.framework/Resources/digidoc-tool
COMMAND find $<TARGET_BUNDLE_CONTENT_DIR:${PROJECT_NAME}>/Frameworks -name Headers | xargs rm -rf
COMMAND install_name_tool -delete_rpath /Library/Frameworks $<TARGET_FILE:${PROJECT_NAME}>
COMMAND ln -sf digidocpp.framework/Libraries/libcrypto.dylib
COMMAND ln -sf digidocpp.framework/Libraries/libcrypto.3.dylib
$<TARGET_BUNDLE_CONTENT_DIR:${PROJECT_NAME}>/Frameworks/libcrypto.3.dylib
COMMAND ln -sf digidocpp.framework/Libraries/libssl.dylib
COMMAND ln -sf digidocpp.framework/Libraries/libssl.3.dylib
$<TARGET_BUNDLE_CONTENT_DIR:${PROJECT_NAME}>/Frameworks/libssl.3.dylib
)

Expand Down Expand Up @@ -267,10 +267,6 @@ elseif(WIN32)
COMMAND ${CMAKE_COMMAND} -E copy ${LIBS_PATH}/libcrypto-3${OPENSSL_SUFFIX}.dll appx
COMMAND ${CMAKE_COMMAND} -E copy ${LIBS_PATH}/libssl-3${OPENSSL_SUFFIX}.dll appx
COMMAND ${CMAKE_COMMAND} -E copy ${LIBS_PATH}/zlib1.dll appx
COMMAND ${CMAKE_COMMAND} -E copy ${LIBS_PATH}/xerces-c_3_2.dll appx
COMMAND ${CMAKE_COMMAND} -E copy ${LIBS_PATH}/XalanMessages_1_12.dll appx
COMMAND ${CMAKE_COMMAND} -E copy ${LIBS_PATH}/Xalan-C_1_12.dll appx
COMMAND ${CMAKE_COMMAND} -E copy ${LIBS_PATH}/xsec_2_0.dll appx
COMMAND ${CMAKE_COMMAND} -E copy ${LIBS_PATH}/libxml2.dll appx
COMMAND ${CMAKE_COMMAND} -E copy ${LIBS_PATH}/libxmlsec1.dll appx
COMMAND ${CMAKE_COMMAND} -E copy ${LIBS_PATH}/libxmlsec1-openssl.dll appx
Expand Down
15 changes: 7 additions & 8 deletions client/Diagnostics_unix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@
#include <QtNetwork/QSslSocket>

#include <sys/utsname.h>
#ifdef Q_OS_MAC
#ifdef Q_OS_DARWIN
#include <CoreFoundation/CFBundle.h>
#endif

QStringList Diagnostics::packages(const QStringList &names, bool withName)
{
QStringList packages;
#ifdef Q_OS_MAC
#ifdef Q_OS_DARWIN
Q_UNUSED(withName);
for (const QString &name: names) {
CFStringRef id = QStringLiteral("ee.ria.%1").arg(name).toCFString();
Expand Down Expand Up @@ -88,7 +88,7 @@ void Diagnostics::run()
emit update( info );
info.clear();

#ifndef Q_OS_MAC
#ifndef Q_OS_DARWIN
QStringList package = packages({"open-eid"}, false);
if( !package.isEmpty() )
s << "<b>" << tr("Base version:") << "</b> " << package.first() << "<br />";
Expand All @@ -98,7 +98,7 @@ void Diagnostics::run()
info.clear();

s << "<b>" << tr("OS:") << "</b> " << Common::applicationOs() << "<br />";
#ifndef Q_OS_MAC
#ifndef Q_OS_DARWIN
s << "<b>" << tr("CPU:") << "</b> ";
QFile f( "/proc/cpuinfo" );
if( f.open( QFile::ReadOnly ) )
Expand All @@ -124,12 +124,11 @@ void Diagnostics::run()
<< "OpenSSL build (" << QSslSocket::sslLibraryBuildVersionString() << ")<br />"
<< "OpenSSL current (" << QSslSocket::sslLibraryVersionString() << ")<br />"
<< packages({
#ifdef Q_OS_MAC
#ifdef Q_OS_DARWIN
"digidocpp"
#else
"libdigidocpp1", "qdigidoc4", "firefox-pkcs11-loader", "chrome-token-signing", "web-eid",
"libxerces-c3.2", "libxml-security-c20", "libxalan-c111", "libxalan-c112",
"openssl", "libpcsclite1", "pcsc-lite", "opensc", "awp"
"libxml2", "libxmlsec1", "libpcsclite1", "pcsc-lite", "opensc"
#endif
}).join(QStringLiteral("<br />")) << "<br /><br />";
emit update( info );
Expand All @@ -139,7 +138,7 @@ void Diagnostics::run()
emit update( info );
info.clear();

#ifndef Q_OS_MAC
#ifndef Q_OS_DARWIN
QStringList browsers = packages({"chromium-browser", "firefox", "MozillaFirefox", "google-chrome-stable"});
if( !browsers.isEmpty() )
s << "<br /><br /><b>" << tr("Browsers:") << "</b><br />" << browsers.join(QStringLiteral("<br />")) << "<br /><br />";
Expand Down
66 changes: 22 additions & 44 deletions client/Diagnostics_win.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@

#include <qt_windows.h>

using namespace Qt::StringLiterals;

static QString getUserRights()
{
HANDLE hToken {};
Expand Down Expand Up @@ -76,25 +78,24 @@ static QString getUserRights()
QStringList Diagnostics::packages(const QStringList &names, bool withName)
{
QStringList packages;
for(const QString &group: {QStringLiteral("HKEY_LOCAL_MACHINE"), QStringLiteral("HKEY_CURRENT_USER")})
for(const QString &group: {u"HKEY_LOCAL_MACHINE"_s, u"HKEY_CURRENT_USER"_s})
{
QString path = QStringLiteral("%1\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall").arg(group);
static const QVector<QSettings::Format> formats = []() -> QVector<QSettings::Format> {
if(QSysInfo::currentCpuArchitecture().contains(QStringLiteral("64")))
if(QSysInfo::currentCpuArchitecture().contains("64"_L1))
return {QSettings::Registry32Format, QSettings::Registry64Format};
return {QSettings::Registry32Format};
}();
for(QSettings::Format format: formats)
{
QSettings s(path, format);
QSettings s(u"%1\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall"_s.arg(group), format);
for(const QString &key: s.childGroups())
{
s.beginGroup(key);
QString name = s.value(QStringLiteral("/DisplayName")).toString();
QString version = s.value(QStringLiteral("/DisplayVersion")).toString();
QString type = s.value(QStringLiteral("/ReleaseType")).toString();
if(!type.contains(QStringLiteral("Update"), Qt::CaseInsensitive) &&
!name.contains(QStringLiteral("Update"), Qt::CaseInsensitive) &&
QString name = s.value("/DisplayName"_L1).toString();
QString version = s.value("/DisplayVersion"_L1).toString();
QString type = s.value("/ReleaseType"_L1).toString();
if(!type.contains("Update"_L1, Qt::CaseInsensitive) &&
!name.contains("Update"_L1, Qt::CaseInsensitive) &&
name.contains(QRegularExpression(names.join('|').prepend('^'), QRegularExpression::CaseInsensitiveOption)))
packages.append(packageName(name, version, withName));
s.endGroup();
Expand Down Expand Up @@ -142,19 +143,14 @@ void Diagnostics::run()
QByteArray path = qgetenv("PATH");
qputenv("PATH", path
+ ";C:\\Program Files\\Open-EID"
+ ";C:\\Program Files\\TeRa Client"
+ ";C:\\Program Files\\EstIDMinidriver Minidriver"
+ ";C:\\Program Files (x86)\\Open-EID"
+ ";C:\\Program Files (x86)\\TeRa Client"
+ ";C:\\Program Files (x86)\\EstIDMinidriver Minidriver");
SetDllDirectory(LPCWSTR(qApp->applicationDirPath().utf16()));
static const QStringList dlls{
"digidoc", "digidocpp", "qdigidoc4.exe", "qdigidocclient.exe", "qesteidutil.exe", "id-updater.exe", "qdigidoc_tera_gui.exe",
"esteidcm", "esteidcm64", "EstIDMinidriver", "EstIDMinidriver64", "onepin-opensc-pkcs11", "EsteidShellExtension",
"esteid-plugin-ie", "esteid-plugin-ie64", "chrome-token-signing.exe", "web-eid.exe",
"libcrypto-3", "libssl-3", "libcrypto-3-x64", "libssl-3-x64", "libcrypto-1_1", "libssl-1_1", "libcrypto-1_1-x64", "libssl-1_1-x64",
"zlib1", "xerces-c_3_1", "xerces-c_3_2", "xalan-c_1_12", "xalanmessages_1_12", "xsec_1_7", "xsec_2_0", "libxml2",
"advapi32", "crypt32", "winscard"};
"digidocpp", "qdigidoc4.exe", "EsteidShellExtension", "id-updater.exe",
"EstIDMinidriver", "EstIDMinidriver64", "web-eid.exe",
"zlib1", "libxml2", "libxmlsec1", "libxmlsec1-openssl"};
for(const QString &lib: dlls)
{
DWORD infoHandle {};
Expand All @@ -168,7 +164,7 @@ void Diagnostics::run()
UINT len {};
if( !VerQueryValueW( data.constData(), L"\\", (LPVOID*)&info, &len ) )
continue;
s << QStringLiteral("%1 (%2.%3.%4.%5)").arg(lib)
s << u"%1 (%2.%3.%4.%5)"_s.arg(lib)
.arg( HIWORD(info->dwFileVersionMS) )
.arg( LOWORD(info->dwFileVersionMS) )
.arg( HIWORD(info->dwFileVersionLS) )
Expand All @@ -181,53 +177,35 @@ void Diagnostics::run()
emit update( info );
info.clear();

enum {
Running,
Stopped,
NotFound
} atrfiltr = NotFound, certprop = NotFound;
QString atrfiltr = tr("Not found");
QString certprop = tr("Not found");
if(SC_HANDLE h = OpenSCManager(nullptr, nullptr, SC_MANAGER_CONNECT))
{
if( SC_HANDLE s = OpenService( h, L"atrfiltr", SERVICE_QUERY_STATUS ) )
{
SERVICE_STATUS status {};
QueryServiceStatus( s, &status );
atrfiltr = (status.dwCurrentState == SERVICE_RUNNING) ? Running : Stopped;
atrfiltr = status.dwCurrentState == SERVICE_RUNNING ? tr("Running") : tr("Not running");
CloseServiceHandle( s );
}
if( SC_HANDLE s = OpenService( h, L"CertPropSvc", SERVICE_QUERY_STATUS ))
{
SERVICE_STATUS status {};
QueryServiceStatus( s, &status );
certprop = (status.dwCurrentState == SERVICE_RUNNING) ? Running : Stopped;
certprop = status.dwCurrentState == SERVICE_RUNNING ? tr("Running") : tr("Not running");
CloseServiceHandle( s );
}
CloseServiceHandle( h );
}
s << "<br /><b>" << tr("ATRfiltr service status: ") << "</b>" << " ";
switch( atrfiltr )
{
case NotFound: s << tr("Not found"); break;
case Stopped: s << tr("Not running"); break;
case Running: s << tr("Running"); break;
}
s << "<br /><b>" << tr("Certificate Propagation service status: ") << "</b>" << " ";
switch( certprop )
{
case NotFound: s << tr("Not found"); break;
case Stopped: s << tr("Not running"); break;
case Running: s << tr("Running"); break;
}
s << "<br />";
s << "<br /><b>" << tr("ATRfiltr service status: ") << "</b " << atrfiltr
<< "<br /><b>" << tr("Certificate Propagation service status: ") << "</b> " << certprop << "<br />";

generalInfo( s );
emit update( info );
info.clear();

QStringList browsers = packages({"Mozilla Firefox", "Google Chrome", "Microsoft EDGE"});
QSettings reg(QStringLiteral("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Internet Explorer"), QSettings::NativeFormat);
browsers << QStringLiteral("Internet Explorer (%1)").arg(reg.value("svcVersion", reg.value("Version")).toString());
s << "<br /><br /><b>" << tr("Browsers:") << "</b><br />" << browsers.join(QStringLiteral("<br />")) << "<br /><br />";
s << "<br /><br /><b>" << tr("Browsers:") << "</b><br />"
<< packages({"Mozilla Firefox", "Google Chrome", "Microsoft EDGE"}).join("<br />"_L1) << "<br /><br />";
emit update( info );
info.clear();
}
4 changes: 0 additions & 4 deletions qdigidoc4.wxs
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,6 @@
</ProgId>
</Component>
<File Name="zlib$(var.qt_suffix)1.dll" />
<File Name="xerces-c_3_2$(var.qt_suffix).dll" />
<File Name="XalanMessages_1_12$(var.qt_suffix).dll" />
<File Name="Xalan-C_1_12$(var.qt_suffix).dll" />
<File Name="xsec_2_0$(var.qt_suffix).dll" />
<File Name="libxml2.dll" />
<File Name="libxmlsec1.dll" />
<File Name="libxmlsec1-openssl.dll" />
Expand Down

0 comments on commit 5212d87

Please sign in to comment.