diff --git a/src/gui/entry/EditEntryWidget.cpp b/src/gui/entry/EditEntryWidget.cpp index db9f5760f..c50d1e0a1 100644 --- a/src/gui/entry/EditEntryWidget.cpp +++ b/src/gui/entry/EditEntryWidget.cpp @@ -412,7 +412,11 @@ void EditEntryWidget::updateSSHAgentKeyInfo() } if (!key.fingerprint().isEmpty()) { - m_sshAgentUi->fingerprintTextLabel->setText(key.fingerprint()); + m_sshAgentUi->fingerprintTextLabel->setText( + key.fingerprint(QCryptographicHash::Md5) + + "\n" + + key.fingerprint(QCryptographicHash::Sha256) + ); } else { m_sshAgentUi->fingerprintTextLabel->setText(tr("(encrypted)")); } @@ -596,7 +600,11 @@ void EditEntryWidget::decryptPrivateKey() m_sshAgentUi->commentTextLabel->setText(tr("n/a")); } - m_sshAgentUi->fingerprintTextLabel->setText(key.fingerprint()); + m_sshAgentUi->fingerprintTextLabel->setText( + key.fingerprint(QCryptographicHash::Md5) + + "\n" + + key.fingerprint(QCryptographicHash::Sha256) + ); m_sshAgentUi->publicKeyEdit->document()->setPlainText(key.publicKey()); m_sshAgentUi->copyToClipboardButton->setEnabled(true); } diff --git a/src/sshagent/OpenSSHKey.cpp b/src/sshagent/OpenSSHKey.cpp index c75a41a12..c2f410137 100644 --- a/src/sshagent/OpenSSHKey.cpp +++ b/src/sshagent/OpenSSHKey.cpp @@ -90,7 +90,7 @@ int OpenSSHKey::keyLength() const return 0; } -const QString OpenSSHKey::fingerprint() const +const QString OpenSSHKey::fingerprint(QCryptographicHash::Algorithm algo) const { if (m_publicData.isEmpty()) { return {}; @@ -105,9 +105,20 @@ const QString OpenSSHKey::fingerprint() const stream.writeString(ba); } - QByteArray rawHash = QCryptographicHash::hash(publicKey, QCryptographicHash::Sha256); + QByteArray rawHash = QCryptographicHash::hash(publicKey, algo); - return "SHA256:" + QString::fromLatin1(rawHash.toBase64(QByteArray::OmitTrailingEquals)); + if (algo == QCryptographicHash::Md5) { + QString md5Hash = QString::fromLatin1(rawHash.toHex()); + QStringList md5HashParts; + for (int i = 0; i < md5Hash.length(); i += 2) { + md5HashParts.append(md5Hash.mid(i, 2)); + } + return "MD5:" + md5HashParts.join(':'); + } else if (algo == QCryptographicHash::Sha256) { + return "SHA256:" + QString::fromLatin1(rawHash.toBase64(QByteArray::OmitTrailingEquals)); + } + + return "HASH:" + QString::fromLatin1(rawHash.toHex()); } const QString OpenSSHKey::comment() const diff --git a/src/sshagent/OpenSSHKey.h b/src/sshagent/OpenSSHKey.h index cd162796d..406f390ea 100644 --- a/src/sshagent/OpenSSHKey.h +++ b/src/sshagent/OpenSSHKey.h @@ -37,7 +37,7 @@ public: const QString cipherName() const; const QString type() const; int keyLength() const; - const QString fingerprint() const; + const QString fingerprint(QCryptographicHash::Algorithm algo = QCryptographicHash::Sha256) const; const QString comment() const; const QString publicKey() const; const QString errorString() const; diff --git a/tests/TestOpenSSHKey.cpp b/tests/TestOpenSSHKey.cpp index a8e0c3580..74ea665c1 100644 --- a/tests/TestOpenSSHKey.cpp +++ b/tests/TestOpenSSHKey.cpp @@ -49,6 +49,7 @@ void TestOpenSSHKey::testParse() QCOMPARE(key.type(), QString("ssh-ed25519")); QCOMPARE(key.comment(), QString("opensshkey-test-parse@keepassxc")); QCOMPARE(key.fingerprint(), QString("SHA256:D1fVmA15YXzaJ5sdO9dXxo5coHL/pnNaIfCvokHzTA4")); + QCOMPARE(key.fingerprint(QCryptographicHash::Md5), QString("MD5:2d:e8:04:09:13:b4:2b:73:5e:87:43:cf:4e:6f:62:f1")); QByteArray publicKey, privateKey; BinaryStream publicStream(&publicKey), privateStream(&privateKey); @@ -173,6 +174,7 @@ void TestOpenSSHKey::testParseRSA() QCOMPARE(key.type(), QString("ssh-rsa")); QCOMPARE(key.comment(), QString("")); QCOMPARE(key.fingerprint(), QString("SHA256:DYdaZciYNxCejr+/8x+OKYxeTU1D5UsuIFUG4PWRFkk")); + QCOMPARE(key.fingerprint(QCryptographicHash::Md5), QString("MD5:c2:26:5b:3d:62:19:56:b0:c3:67:99:7a:a6:4c:66:06")); } void TestOpenSSHKey::testDecryptOpenSSHAES256CBC()