Skip to content

Commit 695b550

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

File tree

3 files changed

+26
-5
lines changed

3 files changed

+26
-5
lines changed

share/translations/keepassxc_en.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2332,10 +2332,6 @@ removed from the database.</source>
23322332
<source>Download failed with error: %1</source>
23332333
<translation type="unfinished"></translation>
23342334
</message>
2335-
<message>
2336-
<source>Download finished, but file %1 could not be found.</source>
2337-
<translation type="unfinished"></translation>
2338-
</message>
23392335
<message>
23402336
<source>Download successful.</source>
23412337
<translation type="unfinished"></translation>
@@ -2368,6 +2364,14 @@ The command has to exit. In case of `sftp` as last command `exit` has to be sent
23682364
</source>
23692365
<translation type="unfinished"></translation>
23702366
</message>
2367+
<message>
2368+
<source>Command finished, but downloaded file does not exist.</source>
2369+
<translation type="unfinished"></translation>
2370+
</message>
2371+
<message>
2372+
<source>Download finished, but file failed KeePass header check. File is not a KeePass file or it&apos;s an unsupported version</source>
2373+
<translation type="unfinished"></translation>
2374+
</message>
23712375
</context>
23722376
<context>
23732377
<name>DatabaseTabWidget</name>

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."),
196+
MessageWidget::Error);
197+
return;
198+
}
199+
200+
if (!hasValidPublicHeaders(result.filePath)) {
201+
m_ui->messageWidget->showMessage(tr("Download finished, but file failed KeePass header check. File is not a "
202+
"KeePass file or it's an unsupported version"),
195203
MessageWidget::Error);
196204
return;
197205
}
198206

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)