[Pkg-owncloud-commits] [owncloud-client] 07/103: SSL Button: Fix issues around printing Hash sums

Sandro Knauß hefee-guest at moszumanska.debian.org
Wed Apr 30 18:08:53 UTC 2014


This is an automated email from the git hooks/post-receive script.

hefee-guest pushed a commit to branch master
in repository owncloud-client.

commit 87010fbe1a9bee564e1e017f47f8e6960e63dfac
Author: Daniel Molkentin <danimo at owncloud.com>
Date:   Wed Apr 9 14:30:43 2014 +0200

    SSL Button: Fix issues around printing Hash sums
    
    - Use SHA 265 instead of obsolete MD5 where possible (Qt5)
    - Remove <tt> formatting: that simply looked ugly
    - Wrap SHA 265 hash
    - Use spaces as separators
    
    As usual, the default needs to remain ':' separation, because
    it's needed to pass valid hashes to csync.
---
 src/mirall/sslbutton.cpp | 33 +++++++++++++++++++--------------
 src/mirall/utility.cpp   |  6 ++++--
 src/mirall/utility.h     |  2 +-
 3 files changed, 24 insertions(+), 17 deletions(-)

diff --git a/src/mirall/sslbutton.cpp b/src/mirall/sslbutton.cpp
index 088e2d6..7bd2e3c 100644
--- a/src/mirall/sslbutton.cpp
+++ b/src/mirall/sslbutton.cpp
@@ -46,19 +46,12 @@ QString SslButton::protoToString(QSsl::SslProtocol proto)
     }
 }
 
-static QString addCertDetailsField(const QString &key, const QString &value, bool tt = false)
+static QString addCertDetailsField(const QString &key, const QString &value)
 {
     if (value.isEmpty())
         return QString();
 
-    QString row = QString::fromLatin1("<tr><td style=\"vertical-align: top;\"><b>%1</b></td><td style=\"vertical-align: bottom;\">%2</td></tr>").arg(key);
-
-    if (tt) {
-        row = row.arg(QString::fromLatin1("<tt style=\"font-size: small\">%1</tt>").arg(value));
-    } else {
-        row = row.arg(value);
-    }
-    return row;
+    return QString::fromLatin1("<tr><td style=\"vertical-align: top;\"><b>%1</b></td><td style=\"vertical-align: bottom;\">%2</td></tr>").arg(key).arg(value);
 }
 
 
@@ -80,8 +73,16 @@ QMenu* SslButton::buildCertMenu(QMenu *parent, const QSslCertificate& cert,
     QString issuer = QStringList(cert.issuerInfo(QSslCertificate::CommonName)).join(QChar(';'));
     if (issuer.isEmpty())
         issuer = QStringList(cert.issuerInfo(QSslCertificate::OrganizationalUnitName)).join(QChar(';'));
-    QString md5 = Utility::formatFingerprint(cert.digest(QCryptographicHash::Md5).toHex());
-    QString sha1 = Utility::formatFingerprint(cert.digest(QCryptographicHash::Sha1).toHex());
+    QString sha1 = Utility::formatFingerprint(cert.digest(QCryptographicHash::Sha1).toHex(), false);
+#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
+    QString md5 = Utility::formatFingerprint(cert.digest(QCryptographicHash::Md5).toHex(), false);
+#else
+    QByteArray sha265hash = cert.digest(QCryptographicHash::Sha256).toHex();
+    QString sha256escaped =
+            Utility::escape(Utility::formatFingerprint(sha265hash.left(sha265hash.length()/2), false)) +
+            QLatin1String("<br/>") +
+            Utility::escape(Utility::formatFingerprint(sha265hash.mid(sha265hash.length()/2), false));
+#endif
     QString serial = QString::fromUtf8(cert.serialNumber(), true);
     QString effectiveDate = cert.effectiveDate().date().toString();
     QString expiryDate = cert.expiryDate().date().toString();
@@ -102,7 +103,7 @@ QMenu* SslButton::buildCertMenu(QMenu *parent, const QSslCertificate& cert,
     stream << addCertDetailsField(tr("Organizational Unit (OU):"), Utility::escape(ou));
     stream << addCertDetailsField(tr("State/Province:"), Utility::escape(state));
     stream << addCertDetailsField(tr("Country:"), Utility::escape(country));
-    stream << addCertDetailsField(tr("Serial:"), Utility::escape(serial), true);
+    stream << addCertDetailsField(tr("Serial:"), Utility::escape(serial));
     stream << QLatin1String("</table>");
 
     stream << tr("<h3>Issuer</h3>");
@@ -116,8 +117,12 @@ QMenu* SslButton::buildCertMenu(QMenu *parent, const QSslCertificate& cert,
     stream << tr("<h3>Fingerprints</h3>");
 
     stream << QLatin1String("<table>");
-    stream << addCertDetailsField(tr("MD 5:"), Utility::escape(md5), true);
-    stream << addCertDetailsField(tr("SHA-1:"), Utility::escape(sha1), true);
+#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
+    stream << addCertDetailsField(tr("MD 5:"), Utility::escape(md5));
+#else
+    stream << addCertDetailsField(tr("SHA-256:"), sha256escaped);
+#endif
+    stream << addCertDetailsField(tr("SHA-1:"), Utility::escape(sha1));
     stream << QLatin1String("</table>");
 
     if (userApproved.contains(cert)) {
diff --git a/src/mirall/utility.cpp b/src/mirall/utility.cpp
index d00392b..115b9b5 100644
--- a/src/mirall/utility.cpp
+++ b/src/mirall/utility.cpp
@@ -80,7 +80,7 @@ bool Utility::writeRandomFile( const QString& fname, int size )
 
 }
 
-QString Utility::formatFingerprint( const QByteArray& fmhash )
+QString Utility::formatFingerprint( const QByteArray& fmhash, bool colonSeparated )
 {
     QByteArray hash;
     int steps = fmhash.length()/2;
@@ -91,7 +91,9 @@ QString Utility::formatFingerprint( const QByteArray& fmhash )
     }
 
     QString fp = QString::fromLatin1( hash.trimmed() );
-    fp.replace(QChar(' '), QChar(':'));
+    if (colonSeparated) {
+        fp.replace(QChar(' '), QChar(':'));
+    }
 
     return fp;
 }
diff --git a/src/mirall/utility.h b/src/mirall/utility.h
index efbd57c..0dfc53a 100644
--- a/src/mirall/utility.h
+++ b/src/mirall/utility.h
@@ -29,7 +29,7 @@ namespace Utility
 {
     void sleep(int sec);
     void usleep(int usec);
-    QString formatFingerprint( const QByteArray& );
+    QString formatFingerprint( const QByteArray&, bool colonSeparated = true );
     void setupFavLink( const QString &folder );
     bool writeRandomFile( const QString& fname, int size = -1);
     QString octetsToString( qint64 octets );

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/owncloud-client.git



More information about the Pkg-owncloud-commits mailing list