SSH Agent: Show MD5 fingerprint of keys

Fixes #2050
This commit is contained in:
Toni Spets 2018-07-14 15:42:28 +03:00 committed by Jonathan White
parent 470a74ee24
commit 07efabed03
4 changed files with 27 additions and 6 deletions

View File

@ -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);
}

View File

@ -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

View File

@ -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;

View File

@ -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()