What changed, and why it matters
This change hardens how the Monero GUI opens a printable PDF seed template. Previously, the app copied a bundled PDF to a predictable temporary path and opened it without checking whether the file had been tampered with. Now it creates a private temporary directory, verifies the PDF against a known SHA-256 hash before opening, and reports an error to the user if the check fails. The patch also adds a test that reminds developers to update the hash whenever the template PDF changes.
No immediate action required; this is a hardening patch. Users and downstream packagers should ensure the bundled wizard/template.pdf matches the hard-coded SHA-256 in src/main/oshelper.h, otherwise the print-template feature will fail. Developers should keep the new regression test passing after any PDF update.
Security signals we found
Local file integrity verification added (SHA-256) before opening an embedded PDF
Predictable temporary file path replaced with QTemporaryDir unique directory
Return-value handling added so QML can surface verification failures to the user
New regression test ties embedded resource hash to code constant
Evidence from the diff
The commit modifies OSHelper::openSeedTemplate() to: (1) use QTemporaryDir with a unique suffix instead of a fixed QDir::tempPath()/seed_template.pdf path; (2) copy the bundled :/wizard/template.pdf only if not already present; (3) compute SHA-256 of the copied file and compare it to a compile-time constant seedTemplateHash; (4) return an int status (0 success, -1 integrity failure, -2 file/open failure) instead of void. The QML caller in WizardCreateWallet2.qml now checks the return value and shows a status message on failure. A new QML test verifies that the bundled resource still matches the hard-coded hash. This is a defense-in-depth integrity check for a local, user-triggered file-open flow.
Changed components
src/main/oshelper.cppsrc/main/oshelper.hwizard/WizardCreateWallet2.qmltests/qml/QmlTestHarness.cpptests/qml/tst_Utils.qmlInspect captured patch +58 / −5
### src/main/oshelper.cpp
@@ -32,10 +32,12 @@
#include <unordered_set>
#include <QCoreApplication>
+#include <QCryptographicHash>
#include <QGuiApplication>
#include <QFileDialog>
#include <QScreen>
#include <QStandardPaths>
+#include <QTemporaryDir>
#include <QWindow>
#include <QDir>
#include <QDebug>
@@ -313,8 +315,35 @@ quint8 OSHelper::getNetworkTypeFromFile(const QString &keysPath, quint8 fallback
return networkTypeAndAddress.second.isEmpty() ? fallbackNetworkType : networkTypeAndAddress.first;
}
-void OSHelper::openSeedTemplate() const
+int OSHelper::openSeedTemplate() const
{
- QFile::copy(":/wizard/template.pdf", QDir::tempPath() + "/seed_template.pdf");
- openFile(QDir::tempPath() + "/seed_template.pdf");
+ static const QTemporaryDir directory(QDir::tempPath() + "/monero-seed-template-XXXXXX");
+ if (!directory.isValid())
+ {
+ qWarning() << "Failed to create seed template directory" << directory.errorString();
+ return -2;
+ }
+
+ const QString path = directory.filePath("seed_template.pdf");
+ if (!QFile::exists(path) && !QFile::copy(":/wizard/template.pdf", path))
+ {
+ qWarning() << "Failed to copy seed template";
+ return -2;
+ }
+
+ QFile file(path);
+ QCryptographicHash hash(QCryptographicHash::Sha256);
+ if (!file.open(QIODevice::ReadOnly) || !hash.addData(&file))
+ {
+ qWarning() << "Failed to read seed template" << file.errorString();
+ return -2;
+ }
+ if (hash.result().toHex() != seedTemplateHash)
+ {
+ qWarning() << "Seed template integrity check failed";
+ return -1;
+ }
+ file.close();
+
+ return openFile(path) ? 0 : -2;
}
### src/main/oshelper.h
@@ -41,6 +41,8 @@ class OSHelper : public QObject
Q_PROPERTY(bool installed READ installed CONSTANT);
public:
+ static constexpr char seedTemplateHash[] = "bcca2abd0ecff56423b4b04e81b2506c6b22bc5f5ef568251d2fbabc966755ef";
+
explicit OSHelper(QObject *parent = 0);
Q_INVOKABLE void createDesktopEntry() const;
@@ -54,7 +56,8 @@ class OSHelper : public QObject
Q_INVOKABLE QString randomPassword(int numBytes = 32) const;
Q_INVOKABLE bool isCapsLock() const;
Q_INVOKABLE quint8 getNetworkTypeFromFile(const QString &keysPath, quint8 fallbackNetworkType) const;
- Q_INVOKABLE void openSeedTemplate() const;
+ // 0: success, -1: integrity failure, -2: file/open failure.
+ Q_INVOKABLE int openSeedTemplate() const;
bool installed() const;
static std::pair<quint8, QString> getNetworkTypeAndAddressFromFile(const QString &wallet);
### tests/qml/QmlTestHarness.cpp
@@ -29,6 +29,7 @@
#include "QmlTestHarness.h"
#include <QCoreApplication>
+#include <QCryptographicHash>
#include <QDir>
#include <QFile>
#include <QQmlContext>
@@ -111,6 +112,14 @@ class QmlTestSetup : public QObject
return url.toLocalFile();
}
+ Q_INVOKABLE bool seedTemplateHashMatchesResource()
+ {
+ QFile file(":/wizard/template.pdf");
+ QCryptographicHash hash(QCryptographicHash::Sha256);
+ return file.open(QIODevice::ReadOnly) && hash.addData(&file) &&
+ hash.result().toHex() == OSHelper::seedTemplateHash;
+ }
+
public slots:
void qmlEngineAvailable(QQmlEngine *engine)
{
### tests/qml/tst_Utils.qml
@@ -47,6 +47,11 @@ Item {
TestCase {
name: "Utils"
+ function test_bundled_template_hash() {
+ verify(settingsTestHelper.seedTemplateHashMatchesResource(),
+ "Update OSHelper::seedTemplateHash to match wizard/template.pdf")
+ }
+
function test_restore_height_stays_a_height() {
compare(Utils.parseDateStringOrRestoreHeightAsInteger("0"), 0)
compare(Utils.parseDateStringOrRestoreHeightAsInteger("1234567"), 1234567)
### wizard/WizardCreateWallet2.qml
@@ -320,7 +320,14 @@ Rectangle {
text: qsTr("Print a template") + translationManager.emptyString
tooltip: qsTr("Print a template to write down your seed") + translationManager.emptyString
onClicked: {
- oshelper.openSeedTemplate();
+ var result = oshelper.openSeedTemplate();
+ if (result === 0)
+ return;
+
+ var message = (result === -1
+ ? qsTr("Unable to open the seed template because the file could not be verified.")
+ : qsTr("Unable to open the seed template.")) + translationManager.emptyString;
+ appWindow.showStatusMessage(message, 5);
}
Accessible.role: Accessible.Button
Accessible.name: qsTr("Print a template to write down your seed") + translationManager.emptyStringWhy this scored 44/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.