Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SSH Agent: Fix attachment data not updating before apply #4549

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/gui/entry/EditEntryWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -673,7 +673,11 @@ bool EditEntryWidget::getOpenSSHKey(OpenSSHKey& key, bool decrypt)
return false;
}

if (!settings.toOpenSSHKey(m_entry, key, decrypt)) {
if (!settings.toOpenSSHKey(m_mainUi->usernameComboBox->lineEdit()->text(),
m_mainUi->passwordEdit->text(),
m_advancedUi->attachmentsWidget->entryAttachments(),
key,
decrypt)) {
showMessage(settings.errorString(), MessageWidget::Error);
return false;
}
Expand Down
33 changes: 30 additions & 3 deletions src/sshagent/KeeAgentSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -364,13 +364,40 @@ bool KeeAgentSettings::keyConfigured() const
* @return true if key was properly opened
*/
bool KeeAgentSettings::toOpenSSHKey(const Entry* entry, OpenSSHKey& key, bool decrypt)
{
return toOpenSSHKey(entry->username(), entry->password(), entry->attachments(), key, decrypt);
}

/**
* Read a SSH key based on settings to key.
*
* Sets error string on error.
*
* @param username username to set on key if empty
* @param password password to decrypt key if needed
* @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)
* @return true if key was properly opened
*/
bool KeeAgentSettings::toOpenSSHKey(const QString& username,
const QString& password,
const EntryAttachments* attachments,
OpenSSHKey& key,
bool decrypt)
{
QString fileName;
QByteArray privateKeyData;

if (m_selectedType == "attachment") {
if (!attachments) {
m_error = QCoreApplication::translate("KeeAgentSettings",
"Private key is an attachment but no attachments provided.");
return false;
}

fileName = m_attachmentName;
privateKeyData = entry->attachments()->value(fileName);
privateKeyData = attachments->value(fileName);
} else {
QFile localFile(fileNameEnvSubst());
QFileInfo localFileInfo(localFile);
Expand Down Expand Up @@ -405,14 +432,14 @@ bool KeeAgentSettings::toOpenSSHKey(const Entry* entry, OpenSSHKey& key, bool de
}

if (key.encrypted() && (decrypt || key.publicParts().isEmpty())) {
if (!key.openKey(entry->password())) {
if (!key.openKey(password)) {
m_error = key.errorString();
return false;
}
}

if (key.comment().isEmpty()) {
key.setComment(entry->username());
key.setComment(username);
}

if (key.comment().isEmpty()) {
Expand Down
6 changes: 6 additions & 0 deletions src/sshagent/KeeAgentSettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#define KEEAGENTSETTINGS_H

#include "core/Entry.h"
#include "core/EntryAttachments.h"
#include "crypto/ssh/OpenSSHKey.h"
#include <QXmlStreamReader>
#include <QtCore>
Expand All @@ -39,6 +40,11 @@ class KeeAgentSettings
void toEntry(Entry* entry) const;
bool keyConfigured() const;
bool toOpenSSHKey(const Entry* entry, OpenSSHKey& key, bool decrypt);
bool toOpenSSHKey(const QString& username,
const QString& password,
const EntryAttachments* attachments,
OpenSSHKey& key,
bool decrypt);

const QString errorString() const;

Expand Down