From efa8d7670cd2605adc5ee114cfd5e5783d481817 Mon Sep 17 00:00:00 2001 From: Daniel Molkentin Date: Wed, 24 Oct 2012 01:42:25 +0200 Subject: [PATCH] Show hashes of unknown certs --- src/mirall/sslerrordialog.cpp | 34 +++++++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/src/mirall/sslerrordialog.cpp b/src/mirall/sslerrordialog.cpp index 95b8ef9671..5c9cdf7a48 100644 --- a/src/mirall/sslerrordialog.cpp +++ b/src/mirall/sslerrordialog.cpp @@ -51,6 +51,7 @@ QString SslErrorDialog::styleSheet() const "#ca_error p { margin-top: 2px; margin-bottom:2px; }" "#ccert { margin-left: 5px; }" "#issuer { margin-left: 5px; }" + "tt { font-size: small; }" ); return style; @@ -118,6 +119,18 @@ bool SslErrorDialog::setErrorList( QList errors ) return false; } +static QByteArray formatHash(const QByteArray &fmhash) +{ + QByteArray hash; + int steps = fmhash.length()/2; + for (int i = 0; i < steps; i++) { + hash.append(fmhash[i]); + hash.append(fmhash[i+1]); + hash.append(' '); + } + return hash; +} + QString SslErrorDialog::certDiv( QSslCertificate cert ) const { QString msg; @@ -126,12 +139,27 @@ QString SslErrorDialog::certDiv( QSslCertificate cert ) const msg += QL("
"); QStringList li; - li << tr("Organization: %1").arg( cert.subjectInfo( QSslCertificate::Organization) ); - li << tr("Unit: %1").arg( cert.subjectInfo( QSslCertificate::OrganizationalUnitName) ); - li << tr("Country: %1").arg(cert.subjectInfo( QSslCertificate::CountryName)); + + QString org = cert.subjectInfo( QSslCertificate::Organization); + QString unit = cert.subjectInfo( QSslCertificate::OrganizationalUnitName); + QString country = cert.subjectInfo( QSslCertificate::CountryName); + if (unit.isEmpty()) unit = tr("<not specified>"); + if (org.isEmpty()) org = tr("<not specified>"); + if (country.isEmpty()) country = tr("<not specified>"); + li << tr("Organization: %1").arg(org); + li << tr("Unit: %1").arg(unit); + li << tr("Country: %1").arg(country); msg += QL("

") + li.join(QL("
")) + QL("

"); msg += QL("

"); + + QString md5sum = QString::fromAscii(formatHash(cert.digest(QCryptographicHash::Md5).toHex())); + QString sha1sum = QString::fromAscii(formatHash(cert.digest(QCryptographicHash::Sha1).toHex())); + if (!md5sum.isEmpty()) + msg += tr("Fingerprint (MD5): %1").arg(md5sum) + QL("
"); + if (!sha1sum.isEmpty()) + msg += tr("Fingerprint (SHA1): %1").arg(sha1sum) + QL("
"); + msg += QL("
"); msg += tr("Effective Date: %1").arg( cert.effectiveDate().toString()) + QL("
"); msg += tr("Expiry Date: %1").arg( cert.expiryDate().toString()) + QL("

");