Page MenuHome GnuPG

D625.id1668.diff
No OneTemporary

D625.id1668.diff

diff --git a/client/draft/draftmanager.cpp b/client/draft/draftmanager.cpp
--- a/client/draft/draftmanager.cpp
+++ b/client/draft/draftmanager.cpp
@@ -8,6 +8,7 @@
#include <QStandardPaths>
#include "editor_debug.h"
+#include "../../common/paths.h"
DraftManager::DraftManager(bool testMode)
: m_testMode(testMode)
@@ -28,10 +29,10 @@
QString DraftManager::draftDirectory(bool testMode)
{
if (testMode) {
- static const QString path = QStandardPaths::writableLocation(QStandardPaths::TempLocation) + QLatin1String("/gpgol-server/draft/");
+ static const QString path = QStandardPaths::writableLocation(QStandardPaths::TempLocation) + QLatin1String("/draft/");
return path;
} else {
- static const QString path = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QLatin1String("/gpgol-server/draft/");
+ static const QString path = CommonPaths::writeablePath() + QLatin1String("/draft/");
return path;
}
}
@@ -39,10 +40,10 @@
QString DraftManager::autosaveDirectory(bool testMode)
{
if (testMode) {
- static const QString path = QStandardPaths::writableLocation(QStandardPaths::TempLocation) + QLatin1String("/gpgol-server/autosave/");
+ static const QString path = QStandardPaths::writableLocation(QStandardPaths::TempLocation) + QLatin1String("/autosave/");
return path;
} else {
- static const QString path = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QLatin1String("/gpgol-server/autosave/");
+ static const QString path = CommonPaths::writeablePath() + QLatin1String("/autosave/");
return path;
}
}
diff --git a/client/editor/composerviewbase.cpp b/client/editor/composerviewbase.cpp
--- a/client/editor/composerviewbase.cpp
+++ b/client/editor/composerviewbase.cpp
@@ -50,7 +50,6 @@
#include <QDir>
#include <QSaveFile>
-#include <QStandardPaths>
#include <QTemporaryDir>
#include <QTimer>
#include <QUuid>
diff --git a/client/firsttimedialog.cpp b/client/firsttimedialog.cpp
--- a/client/firsttimedialog.cpp
+++ b/client/firsttimedialog.cpp
@@ -3,6 +3,7 @@
// SPDX-License-Identifier: GPL-2.0-or-later
#include "firsttimedialog.h"
+#include "../common/paths.h"
#include "config.h"
#include "gpgolweb_version.h"
#include "rootcagenerator/controller.h"
@@ -20,7 +21,6 @@
#include <QFile>
#include <QMargins>
#include <QSaveFile>
-#include <QStandardPaths>
#include <QStatusBar>
#include <QStyle>
#include <QTemporaryDir>
@@ -308,7 +308,7 @@
manifest.replace("%HOST%", serverDomain().toUtf8());
manifest.replace("%VERSION%", GPGOLWEB_VERSION_STRING);
- const auto saveFilePath = QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation) + u"/gpgol-web-manifest.xml"_s;
+ const auto saveFilePath = CommonPaths::writeablePath() + u"/gpgol-web-manifest.xml"_s;
QSaveFile saveFile(saveFilePath);
if (!saveFile.open(QIODeviceBase::WriteOnly)) {
diff --git a/client/identity/identitydialog.cpp b/client/identity/identitydialog.cpp
--- a/client/identity/identitydialog.cpp
+++ b/client/identity/identitydialog.cpp
@@ -65,7 +65,6 @@
#include <QIcon>
#include <QLabel>
#include <QPushButton>
-#include <QStandardPaths>
#include <QTabWidget>
#include <QToolButton>
#include <QVBoxLayout>
diff --git a/client/identity/signatureconfigurator.cpp b/client/identity/signatureconfigurator.cpp
--- a/client/identity/signatureconfigurator.cpp
+++ b/client/identity/signatureconfigurator.cpp
@@ -27,8 +27,6 @@
#include <QHBoxLayout>
#include <QVBoxLayout>
-#include <QStandardPaths>
-
using namespace KIdentityManagementWidgets;
namespace KIdentityManagementWidgets
diff --git a/client/rootcagenerator/CMakeLists.txt b/client/rootcagenerator/CMakeLists.txt
--- a/client/rootcagenerator/CMakeLists.txt
+++ b/client/rootcagenerator/CMakeLists.txt
@@ -29,7 +29,4 @@
target_link_libraries(rootcagenerator PUBLIC KPim6::Libkleo KF6::I18n KF6::CoreAddons)
-add_executable(gpgol-cert-generator main.cpp)
-target_link_libraries(gpgol-cert-generator PUBLIC rootcagenerator)
-install(TARGETS gpgol-cert-generator ${KDE_INSTALL_TARGETS_DEFAULT_ARGS})
diff --git a/client/rootcagenerator/controller.cpp b/client/rootcagenerator/controller.cpp
--- a/client/rootcagenerator/controller.cpp
+++ b/client/rootcagenerator/controller.cpp
@@ -5,13 +5,14 @@
#include "controller.h"
#include "truststore.h"
+#include "../gpgol_client_debug.h"
+#include "../../common/paths.h"
#include "../utils/formatter.h"
#include <QDate>
#include <QDir>
#include <QProcess>
#include <QSaveFile>
-#include <QStandardPaths>
#include <QTemporaryDir>
#include <QGpgME/ExportJob>
@@ -93,9 +94,28 @@
bool Controller::certificateAlreadyGenerated()
{
- auto certPath = QStandardPaths::locate(QStandardPaths::AppLocalDataLocation, QStringLiteral("certificate.pem"));
+ if (!(CommonPaths::locateFile(u"certificate.pem"_s).isEmpty())) {
+ return true;
+ }
+
+ // Copy from legacy path, if installed, there.
+ // TODO: remove this after grace period
+ // NOTE: copy certiface.pem last: Only if all three files were copied successfully, we shall return true below
+ const QStringList files{ u"certificate-key.pem"_s, u"root-ca.pem"_s, u"certificate.pem"_s };
+ const auto modern_path = CommonPaths::writeablePath();
+ QDir().mkpath(modern_path);
+ for (const auto & file : files) {
+ const auto legacy_path = CommonPaths::locateFileInLegacyPath(file);
+ if (!legacy_path.isEmpty() && QFile::exists(legacy_path)) {
+ qCWarning(GPGOL_CLIENT_LOG) << "Copying from legacy path:" << legacy_path;
+ if (!QFile::copy(legacy_path, QString(modern_path + u"/"_s + file))) {
+ qCWarning(GPGOL_CLIENT_LOG) << "Copying from legacy path failed";
+ return false;
+ }
+ }
+ }
- return !certPath.isEmpty();
+ return !(CommonPaths::locateFile(u"certificate.pem"_s).isEmpty());
}
void Controller::setHomeDirForJob(QGpgME::Job *job)
@@ -312,11 +332,9 @@
void Controller::install()
{
- auto keyPath = QStandardPaths::locate(QStandardPaths::AppLocalDataLocation, QStringLiteral("certificate-key.pem"));
-
- // Install for gpgol-client
+ // Install
{
- auto certPath = QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation);
+ auto certPath = CommonPaths::writeablePath();
Q_EMIT debutOutput(i18nc("Debug message, %1 is a path", "Installing certificate for gpgol-client in %1", certPath));
QDir dir;
@@ -350,54 +368,20 @@
emitResult();
return;
}
- }
-
- // Install for gpgol-server
- {
- auto certPath = QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation).chopped(QStringLiteral(u"gpgol-client").length()).append(u"gpgol-server");
- Q_EMIT debutOutput(i18nc("Debug message. %1 is a path", "Installing certificate for gpgol-server in %1", certPath));
-
- QDir dir;
- if (!dir.mkpath(certPath)) {
- Q_EMIT debutOutput(i18nc("Debug message. %1 is a path", "Unable to create the following path: %1", certPath));
- setError(UserDefinedError);
- emitResult();
- return;
- }
-
- QSaveFile localhostPub(certPath + u"/certificate.pem"_s);
- if (localhostPub.open(QIODeviceBase::WriteOnly)) {
- localhostPub.write(m_publicTLS);
- localhostPub.commit();
- } else {
- Q_EMIT debutOutput(
- i18nc("Debug message, %1 is a filename. %2 is a path", "No permission to write: %1 in %2", localhostPub.fileName(), dir.absolutePath()));
- setError(UserDefinedError);
- emitResult();
- return;
- }
- QSaveFile localhostKey(certPath + u"/certificate-key.pem"_s);
- if (localhostKey.open(QIODeviceBase::WriteOnly)) {
- localhostKey.write(m_secretTLS);
- localhostKey.commit();
- } else {
- Q_EMIT debutOutput(
- i18nc("Debug message. %1 is a filename. %2 is a path.", "No permission to write: %1 in %2", localhostKey.fileName(), dir.absolutePath()));
- setError(UserDefinedError);
- emitResult();
- return;
- }
- QSaveFile rootCaPub(certPath + u"/root-ca.pem"_s);
- if (rootCaPub.open(QIODeviceBase::WriteOnly)) {
- rootCaPub.write(m_publicCA);
- rootCaPub.commit();
- } else {
- Q_EMIT debutOutput(
- i18nc("Debug message. %1 is a filename. %2 is a path", "No permission to write: %1 in %2", rootCaPub.fileName(), dir.absolutePath()));
- setError(UserDefinedError);
- emitResult();
- return;
+ // This one needed for the server, only
+ {
+ QSaveFile localhostKey(certPath + u"/certificate-key.pem"_s);
+ if (localhostKey.open(QIODeviceBase::WriteOnly)) {
+ localhostKey.write(m_secretTLS);
+ localhostKey.commit();
+ } else {
+ Q_EMIT debutOutput(
+ i18nc("Debug message. %1 is a filename. %2 is a path.", "No permission to write: %1 in %2", localhostKey.fileName(), dir.absolutePath()));
+ setError(UserDefinedError);
+ emitResult();
+ return;
+ }
}
}
diff --git a/client/rootcagenerator/main.cpp b/client/rootcagenerator/main.cpp
deleted file mode 100644
--- a/client/rootcagenerator/main.cpp
+++ /dev/null
@@ -1,63 +0,0 @@
-// SPDX-FileCopyrightText: 2023 g10 code GmbH
-// SPDX-Contributor: Carl Schwan <carl.schwan@gnupg.com>
-// SPDX-License-Identifier: GPL-2.0-or-later
-
-#include <QCommandLineParser>
-#include <QCoreApplication>
-#include <QTemporaryDir>
-
-#include <KLocalizedString>
-
-#include "controller.h"
-#include <iostream>
-
-#ifdef Q_OS_WINDOWS
-#include <windows.h>
-#endif
-
-using namespace Qt::StringLiterals;
-
-int main(int argc, char *argv[])
-{
- QCoreApplication app(argc, argv);
- app.setApplicationName(QStringLiteral("GpgOL/Web cert generator"));
- app.setApplicationVersion(QStringLiteral("0.0.1"));
- app.setOrganizationName(QStringLiteral("g10code"));
- app.setOrganizationDomain(QStringLiteral("gnupg.com"));
- KLocalizedString::setApplicationDomain(QByteArrayLiteral("gpgol"));
- QCommandLineParser parser;
-
- auto helpOpt = parser.addHelpOption();
- parser.setApplicationDescription(i18n("Helper application to generate certificates for GgpOL/Web\nWithout any arguments, a certificate set is generated"));
-
- parser.process(app);
- if (parser.isSet(helpOpt)) {
- std::cout << qPrintable(parser.helpText());
- return 0;
- }
- QTemporaryDir tempDir;
- tempDir.setAutoRemove(false);
-
-#ifdef Q_OS_WINDOWS
- if (AttachConsole(ATTACH_PARENT_PROCESS)) {
- freopen("CONOUT$", "w", stdout);
- freopen("CONOUT$", "w", stderr);
- }
-#endif
-
- qWarning() << tempDir.path();
-
- qputenv("GNUPGHOME", tempDir.path().toUtf8());
-
- auto controller = new Controller;
- QObject::connect(controller, &KJob::finished, &app, [&app](KJob *job) {
- if (job->error()) {
- app.exit(1);
- } else {
- app.exit(0);
- }
- });
- controller->start();
-
- return app.exec();
-}
\ No newline at end of file
diff --git a/client/websocketclient.cpp b/client/websocketclient.cpp
--- a/client/websocketclient.cpp
+++ b/client/websocketclient.cpp
@@ -10,7 +10,6 @@
#include <QJsonArray>
#include <QJsonDocument>
#include <QJsonObject>
-#include <QStandardPaths>
#include <QTimer>
#include <QUuid>
@@ -30,6 +29,7 @@
#include <gpgme++/key.h>
#include <gpgme++/keylistresult.h>
+#include "../common/paths.h"
#include "config.h"
#include "draft/draftmanager.h"
#include "editor/composerwindow.h"
@@ -85,7 +85,7 @@
});
QSslConfiguration sslConfiguration;
- auto certPath = QStandardPaths::locate(QStandardPaths::AppLocalDataLocation, QStringLiteral("certificate.pem"));
+ auto certPath = CommonPaths::locateFile(u"certificate.pem"_s);
Q_ASSERT(!certPath.isEmpty());
QFile certFile(certPath);
diff --git a/common/CMakeLists.txt b/common/CMakeLists.txt
--- a/common/CMakeLists.txt
+++ b/common/CMakeLists.txt
@@ -5,6 +5,8 @@
add_library(common STATIC
log.cpp
log.h
+ paths.cpp
+ paths.h
protocol.cpp
protocol.h
utils.cpp
diff --git a/common/paths.h b/common/paths.h
new file mode 100644
--- /dev/null
+++ b/common/paths.h
@@ -0,0 +1,12 @@
+// SPDX-FileCopyrightText: 2025 g10 code GmbH
+// SPDX-Contributor: Thomas Friedrichsmeier <thomas.friedrichsmeier@gnupg.com>
+// SPDX-License-Identifier: GPL-2.0-or-later
+
+#include <QString>
+
+namespace CommonPaths
+{
+QString locateFile(const QString &file);
+QString locateFileInLegacyPath(const QString &file);
+QString writeablePath();
+}
diff --git a/common/paths.cpp b/common/paths.cpp
new file mode 100644
--- /dev/null
+++ b/common/paths.cpp
@@ -0,0 +1,21 @@
+// SPDX-FileCopyrightText: 2025 g10 code GmbH
+// SPDX-Contributor: Thomas Friedrichsmeier <thomas.friedrichsmeier@gnupg.com>
+// SPDX-License-Identifier: GPL-2.0-or-later
+
+#include <QStandardPaths>
+
+#include "paths.h"
+// replacement for QStandardsPaths::locate(), look up file in the data path shared between client and server
+QString CommonPaths::locateFile(const QString &file) {
+ return QStandardPaths::locate(QStandardPaths::GenericDataLocation, u"gpgol-web/" + file);
+}
+
+QString CommonPaths::writeablePath() {
+ return QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + u"/gpgol-web";
+}
+
+QString CommonPaths::locateFileInLegacyPath(const QString &file) {
+ const auto ret = QStandardPaths::locate(QStandardPaths::GenericDataLocation, u"gpgol-client/" + file);
+ if (!ret.isEmpty()) return ret;
+ return QStandardPaths::locate(QStandardPaths::GenericDataLocation, u"gpgol-server/" + file);
+}
diff --git a/server/controllers/staticcontroller.cpp b/server/controllers/staticcontroller.cpp
--- a/server/controllers/staticcontroller.cpp
+++ b/server/controllers/staticcontroller.cpp
@@ -13,8 +13,7 @@
QHttpServerResponse StaticController::homeAction(const QHttpServerRequest &)
{
- const auto basePath = QStandardPaths::locate(QStandardPaths::GenericDataLocation, u"gpgol-web/"_s, QStandardPaths::LocateDirectory);
- QFile file(basePath + u"index.html"_s);
+ QFile file(QStandardPaths::locate(QStandardPaths::GenericDataLocation, u"gpgol-web/index.html"_s));
if (!file.open(QIODeviceBase::ReadOnly)) {
qCWarning(HTTP_LOG) << file.errorString() << file.fileName();
return QHttpServerResponse(QHttpServerResponder::StatusCode::NotFound);
diff --git a/server/webserver.cpp b/server/webserver.cpp
--- a/server/webserver.cpp
+++ b/server/webserver.cpp
@@ -14,13 +14,13 @@
#include <QSslCertificate>
#include <QSslKey>
#include <QSslServer>
-#include <QStandardPaths>
#include <QWebSocket>
#include <QWebSocketCorsAuthenticator>
#include <QWebSocketServer>
#include <protocol.h>
#include "controllers/staticcontroller.h"
+#include "../common/paths.h"
#include "http_debug.h"
#include "websocket_debug.h"
@@ -39,9 +39,9 @@
bool WebServer::run()
{
- auto keyPath = QStandardPaths::locate(QStandardPaths::AppLocalDataLocation, QStringLiteral("certificate-key.pem"));
- auto certPath = QStandardPaths::locate(QStandardPaths::AppLocalDataLocation, QStringLiteral("certificate.pem"));
- auto rootCertPath = QStandardPaths::locate(QStandardPaths::AppLocalDataLocation, QStringLiteral("root-ca.pem"));
+ auto keyPath = CommonPaths::locateFile(u"certificate-key.pem"_s);
+ auto certPath = CommonPaths::locateFile(u"certificate.pem"_s);
+ auto rootCertPath = CommonPaths::locateFile(u"root-ca.pem"_s);
Q_ASSERT(!keyPath.isEmpty());
Q_ASSERT(!certPath.isEmpty());

File Metadata

Mime Type
text/plain
Expires
Mon, Jan 19, 6:50 AM (2 h, 12 m)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
d1/bf/681ae875cae277c2ed333449f75c

Event Timeline