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

Fix SSH Agent broken decrypt button #10638

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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 8 additions & 4 deletions share/translations/keepassxc_en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2556,10 +2556,6 @@ Disable safe saves and try again?</source>
<source>n/a</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>(encrypted)</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Select private key</source>
<translation type="unfinished"></translation>
Expand Down Expand Up @@ -2669,6 +2665,10 @@ Would you like to correct it?</source>
<numerusform></numerusform>
</translation>
</message>
<message>
<source>Failed to decrypt SSH key, ensure password is correct.</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>EditEntryWidgetAdvanced</name>
Expand Down Expand Up @@ -6204,6 +6204,10 @@ We recommend you use the AppImage available on our downloads page.</source>
<source>Unexpected EOF when writing private key</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>(encrypted)</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>OpenSSHKeyGenDialog</name>
Expand Down
14 changes: 5 additions & 9 deletions src/gui/entry/EditEntryWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -661,23 +661,17 @@ void EditEntryWidget::updateSSHAgentKeyInfo()
if (!key.fingerprint().isEmpty()) {
m_sshAgentUi->fingerprintTextLabel->setText(key.fingerprint(QCryptographicHash::Md5) + "\n"
+ key.fingerprint(QCryptographicHash::Sha256));
} else {
m_sshAgentUi->fingerprintTextLabel->setText(tr("(encrypted)"));
}

if (!key.comment().isEmpty() || !key.encrypted()) {
if (!key.comment().isEmpty()) {
m_sshAgentUi->commentTextLabel->setText(key.comment());
} else {
m_sshAgentUi->commentTextLabel->setText(tr("(encrypted)"));
m_sshAgentUi->decryptButton->setEnabled(true);
}

m_sshAgentUi->decryptButton->setEnabled(key.encrypted());

if (!key.publicKey().isEmpty()) {
m_sshAgentUi->publicKeyEdit->document()->setPlainText(key.publicKey());
m_sshAgentUi->copyToClipboardButton->setEnabled(true);
} else {
m_sshAgentUi->publicKeyEdit->document()->setPlainText(tr("(encrypted)"));
m_sshAgentUi->copyToClipboardButton->setDisabled(true);
}

// enable agent buttons only if we have an agent running
Expand Down Expand Up @@ -791,6 +785,7 @@ void EditEntryWidget::decryptPrivateKey()
OpenSSHKey key;

if (!getOpenSSHKey(key, true)) {
showMessage(tr("Failed to decrypt SSH key, ensure password is correct."), MessageWidget::Error);
return;
}

Expand All @@ -804,6 +799,7 @@ void EditEntryWidget::decryptPrivateKey()
+ key.fingerprint(QCryptographicHash::Sha256));
m_sshAgentUi->publicKeyEdit->document()->setPlainText(key.publicKey());
m_sshAgentUi->copyToClipboardButton->setEnabled(true);
m_sshAgentUi->decryptButton->setEnabled(false);
}

void EditEntryWidget::copyPublicKey()
Expand Down
6 changes: 1 addition & 5 deletions src/sshagent/KeeAgentSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -490,11 +490,7 @@ bool KeeAgentSettings::toOpenSSHKey(const QString& username,
}

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

if (key.comment().isEmpty()) {
key.setComment(fileName);
key.setComment(QString("%1@%2").arg(username, fileName));
}

return true;
Expand Down
4 changes: 3 additions & 1 deletion src/sshagent/OpenSSHKey.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ const QString OpenSSHKey::type() const
const QString OpenSSHKey::fingerprint(QCryptographicHash::Algorithm algo) const
{
if (m_rawPublicData.isEmpty()) {
return {};
return tr("(encrypted)");
}

QByteArray publicKey;
Expand Down Expand Up @@ -351,6 +351,8 @@ bool OpenSSHKey::parsePKCS1PEM(const QByteArray& in)
// load private if no encryption
if (!encrypted()) {
return openKey();
} else {
m_comment = tr("(encrypted)");
}

return true;
Expand Down