Skip to content

Commit 6baf5c5

Browse files
committed
Add KeePass header check for testing remote download (#10910)
1 parent a6ea307 commit 6baf5c5

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

src/gui/remote/DatabaseSettingsWidgetRemote.cpp

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "DatabaseSettingsWidgetRemote.h"
1919
#include "ui_DatabaseSettingsWidgetRemote.h"
2020

21+
#include "core/Database.h"
2122
#include "core/Global.h"
2223
#include "core/Metadata.h"
2324

@@ -191,10 +192,24 @@ void DatabaseSettingsWidgetRemote::testDownload()
191192
}
192193

193194
if (!QFile::exists(result.filePath)) {
194-
m_ui->messageWidget->showMessage(tr("Download finished, but file %1 could not be found.").arg(result.filePath),
195+
m_ui->messageWidget->showMessage(tr("Command finished, but downloaded file does not exist."),
195196
MessageWidget::Error);
196197
return;
197198
}
198199

200+
if (!hasValidPublicHeaders(result.filePath)) {
201+
m_ui->messageWidget->showMessage(
202+
tr("Download finished, but file failed KeePass header check. File is not a KeePass file or it's an unsupported version"),
203+
MessageWidget::Error);
204+
return;
205+
}
206+
199207
m_ui->messageWidget->showMessage(tr("Download successful."), MessageWidget::Positive);
208+
}
209+
210+
bool DatabaseSettingsWidgetRemote::hasValidPublicHeaders(QString &filePath) {
211+
// Read public headers
212+
QString error;
213+
QScopedPointer<Database> db(new Database());
214+
return db->open(filePath, nullptr, &error);
200215
}

src/gui/remote/DatabaseSettingsWidgetRemote.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ private slots:
5656
QListWidgetItem* findItemByName(const QString& name);
5757
void clearFields();
5858

59+
bool hasValidPublicHeaders(QString &filePath);
60+
5961
QScopedPointer<RemoteSettings> m_remoteSettings;
6062
const QScopedPointer<Ui::DatabaseSettingsWidgetRemote> m_ui;
6163
bool m_modified = false;

0 commit comments

Comments
 (0)