mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2024-10-01 01:26:01 -04:00
SSH Agent: Use database location to resolve relative key file path
Closes #5225
This commit is contained in:
parent
ed0ece304d
commit
9b8feed3ed
@ -701,6 +701,7 @@ bool EditEntryWidget::getOpenSSHKey(OpenSSHKey& key, bool decrypt)
|
||||
|
||||
if (!settings.toOpenSSHKey(m_mainUi->usernameComboBox->lineEdit()->text(),
|
||||
m_mainUi->passwordEdit->text(),
|
||||
m_db->filePath(),
|
||||
m_advancedUi->attachmentsWidget->entryAttachments(),
|
||||
key,
|
||||
decrypt)) {
|
||||
|
@ -17,6 +17,7 @@
|
||||
*/
|
||||
|
||||
#include "KeeAgentSettings.h"
|
||||
#include "core/Database.h"
|
||||
#include "core/Tools.h"
|
||||
|
||||
KeeAgentSettings::KeeAgentSettings()
|
||||
@ -389,7 +390,8 @@ bool KeeAgentSettings::keyConfigured() const
|
||||
*/
|
||||
bool KeeAgentSettings::toOpenSSHKey(const Entry* entry, OpenSSHKey& key, bool decrypt)
|
||||
{
|
||||
return toOpenSSHKey(entry->username(), entry->password(), entry->attachments(), key, decrypt);
|
||||
return toOpenSSHKey(
|
||||
entry->username(), entry->password(), entry->database()->filePath(), entry->attachments(), key, decrypt);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -399,6 +401,7 @@ bool KeeAgentSettings::toOpenSSHKey(const Entry* entry, OpenSSHKey& key, bool de
|
||||
*
|
||||
* @param username username to set on key if empty
|
||||
* @param password password to decrypt key if needed
|
||||
* @param databasePath path to database file this key is loaded from
|
||||
* @param attachments attachments to read an attachment key from
|
||||
* @param key output key object
|
||||
* @param decrypt avoid private key decryption if possible (old RSA keys are always decrypted)
|
||||
@ -406,6 +409,7 @@ bool KeeAgentSettings::toOpenSSHKey(const Entry* entry, OpenSSHKey& key, bool de
|
||||
*/
|
||||
bool KeeAgentSettings::toOpenSSHKey(const QString& username,
|
||||
const QString& password,
|
||||
const QString& databasePath,
|
||||
const EntryAttachments* attachments,
|
||||
OpenSSHKey& key,
|
||||
bool decrypt)
|
||||
@ -423,10 +427,19 @@ bool KeeAgentSettings::toOpenSSHKey(const QString& username,
|
||||
fileName = m_attachmentName;
|
||||
privateKeyData = attachments->value(fileName);
|
||||
} else {
|
||||
QFile localFile(fileNameEnvSubst());
|
||||
QFileInfo localFileInfo(localFile);
|
||||
QString fileNameSubst = fileNameEnvSubst();
|
||||
QFileInfo localFileInfo(fileNameSubst);
|
||||
|
||||
// resolve relative private key path from database location
|
||||
if (localFileInfo.isRelative()) {
|
||||
QFileInfo databaseFileInfo(databasePath);
|
||||
localFileInfo = QFileInfo(databaseFileInfo.absolutePath() + QDir::separator() + fileNameSubst);
|
||||
}
|
||||
|
||||
fileName = localFileInfo.fileName();
|
||||
|
||||
QFile localFile(localFileInfo.absoluteFilePath());
|
||||
|
||||
if (localFile.fileName().isEmpty()) {
|
||||
m_error = QCoreApplication::translate("KeeAgentSettings", "Private key is empty");
|
||||
return false;
|
||||
|
@ -44,6 +44,7 @@ public:
|
||||
bool toOpenSSHKey(const Entry* entry, OpenSSHKey& key, bool decrypt);
|
||||
bool toOpenSSHKey(const QString& username,
|
||||
const QString& password,
|
||||
const QString& databasePath,
|
||||
const EntryAttachments* attachments,
|
||||
OpenSSHKey& key,
|
||||
bool decrypt);
|
||||
|
Loading…
Reference in New Issue
Block a user