Add KeePass header check for testing remote download (#10910)

This commit is contained in:
Stefan Forstenlechner 2024-06-17 23:41:56 +02:00
parent 4d7eae34c2
commit c908081421
3 changed files with 26 additions and 5 deletions

View File

@ -2409,10 +2409,6 @@ removed from the database.</source>
<source>Download failed with error: %1</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Download finished, but file %1 could not be found.</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Download successful.</source>
<translation type="unfinished"></translation>
@ -2445,6 +2441,14 @@ The command has to exit. In case of `sftp` as last command `exit` has to be sent
</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Command finished, but downloaded file does not exist.</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Download finished, but file failed KeePass header check. File is not a KeePass file or it&apos;s an unsupported version</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Timeout:</source>
<translation type="unfinished"></translation>

View File

@ -18,6 +18,7 @@
#include "DatabaseSettingsWidgetRemote.h"
#include "ui_DatabaseSettingsWidgetRemote.h"
#include "core/Database.h"
#include "core/Global.h"
#include "core/Metadata.h"
@ -200,10 +201,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);
}

View File

@ -56,6 +56,8 @@ private:
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;