From 8cd45f57b7ae24e4ee9cde05628117fe8731d948 Mon Sep 17 00:00:00 2001 From: Alexandre Petit <62973006+AlexpFr@users.noreply.github.com> Date: Mon, 27 May 2024 20:48:33 +0200 Subject: [PATCH] Fix SSH Agent broken decrypt button (#10638) * SSH Agent: Fix broken decrypt button (Fixes #10637) --------- Co-authored-by: Jonathan White --- share/translations/keepassxc_en.ts | 12 ++++++++---- src/gui/entry/EditEntryWidget.cpp | 14 +++++--------- src/sshagent/KeeAgentSettings.cpp | 6 +----- src/sshagent/OpenSSHKey.cpp | 4 +++- 4 files changed, 17 insertions(+), 19 deletions(-) diff --git a/share/translations/keepassxc_en.ts b/share/translations/keepassxc_en.ts index 126deb41b..48e3d45e7 100644 --- a/share/translations/keepassxc_en.ts +++ b/share/translations/keepassxc_en.ts @@ -2556,10 +2556,6 @@ Disable safe saves and try again? n/a - - (encrypted) - - Select private key @@ -2669,6 +2665,10 @@ Would you like to correct it? + + Failed to decrypt SSH key, ensure password is correct. + + EditEntryWidgetAdvanced @@ -6204,6 +6204,10 @@ We recommend you use the AppImage available on our downloads page. Unexpected EOF when writing private key + + (encrypted) + + OpenSSHKeyGenDialog diff --git a/src/gui/entry/EditEntryWidget.cpp b/src/gui/entry/EditEntryWidget.cpp index 6620b0807..3ead0af0e 100644 --- a/src/gui/entry/EditEntryWidget.cpp +++ b/src/gui/entry/EditEntryWidget.cpp @@ -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 @@ -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; } @@ -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() diff --git a/src/sshagent/KeeAgentSettings.cpp b/src/sshagent/KeeAgentSettings.cpp index 272fb7edf..a794eac93 100644 --- a/src/sshagent/KeeAgentSettings.cpp +++ b/src/sshagent/KeeAgentSettings.cpp @@ -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; diff --git a/src/sshagent/OpenSSHKey.cpp b/src/sshagent/OpenSSHKey.cpp index cdcc25701..ff127191a 100644 --- a/src/sshagent/OpenSSHKey.cpp +++ b/src/sshagent/OpenSSHKey.cpp @@ -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; @@ -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;