Skip to content

Commit

Permalink
Add KeePass header check for testing remote download (#10910)
Browse files Browse the repository at this point in the history
  • Loading branch information
t-h-e committed Jun 17, 2024
1 parent a6ea307 commit e209465
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/gui/remote/DatabaseSettingsWidgetRemote.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "DatabaseSettingsWidgetRemote.h"
#include "ui_DatabaseSettingsWidgetRemote.h"

#include "core/Database.h"
#include "core/Global.h"
#include "core/Metadata.h"

Expand Down Expand Up @@ -191,10 +192,24 @@ void DatabaseSettingsWidgetRemote::testDownload()
}

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

if (!hasValidPublicHeaders(result.filePath)) {
m_ui->messageWidget->showMessage(tr("Download finished, but file failed KeePass header check. File is not a "
"KeePass file or it's an unsupported version"),
MessageWidget::Error);
return;
}

m_ui->messageWidget->showMessage(tr("Download successful."), MessageWidget::Positive);
}

bool DatabaseSettingsWidgetRemote::hasValidPublicHeaders(QString& filePath) {
// Read public headers
QString error;
QScopedPointer<Database> db(new Database());
return db->open(filePath, nullptr, &error);
}
2 changes: 2 additions & 0 deletions src/gui/remote/DatabaseSettingsWidgetRemote.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ private slots:
QListWidgetItem* findItemByName(const QString& name);
void clearFields();

bool hasValidPublicHeaders(QString& filePath);

QScopedPointer<RemoteSettings> m_remoteSettings;
const QScopedPointer<Ui::DatabaseSettingsWidgetRemote> m_ui;
bool m_modified = false;
Expand Down

0 comments on commit e209465

Please sign in to comment.