[PATCH 2 of 2] Merged

Wald Commits scm-commit at wald.intevation.org
Mon Jun 30 18:36:19 CEST 2014


# HG changeset patch
# User Sascha Wilde <wilde at intevation.de>
# Date 1404146122 -7200
# Node ID 5e25159d702504d74a3e6808796c5cc80b090da3
# Parent  a5a709c6ce93eb146d04c908d8cbfe560042522b
# Parent  75cd2fbf9ac6fa190845acfee18d67fddf4fa749
Merged

diff -r a5a709c6ce93 -r 5e25159d7025 ui/administratorwindow.cpp
--- a/ui/administratorwindow.cpp	Mon Jun 30 18:33:26 2014 +0200
+++ b/ui/administratorwindow.cpp	Mon Jun 30 18:35:22 2014 +0200
@@ -224,7 +224,7 @@
     }
 }
 
-void AdministratorWindow::logChanges(const QString &currentCerts)
+void AdministratorWindow::logChanges(const QString &currentCerts, const QString& keyFingerprint)
 {
     QDir logDir(QStandardPaths::writableLocation(QStandardPaths::DataLocation));
     QString logFilePath = logDir.filePath("log.txt");
@@ -239,7 +239,7 @@
 
     CertificateList newCertList;
     newCertList.readList(currentCerts.toLocal8Bit());
-    QByteArray entries = createLogEntries(newCertList);
+    QByteArray entries = createLogEntries(newCertList, keyFingerprint);
     if(logFile.write(entries) != entries.size()) {
         QMessageBox::warning(this, tr("Error!"), tr("Failed to write log file: ") +
                 logFilePath + tr(" Changes are not logged!"));
@@ -248,7 +248,7 @@
     logFile.close();
 }
 
-QByteArray AdministratorWindow::createLogEntries(const CertificateList &list)
+QByteArray AdministratorWindow::createLogEntries(const CertificateList &list, const QString& keyFingerprint)
 {
     QByteArray entries;
     QByteArray removeListEntries;
@@ -265,7 +265,9 @@
         listDate.toString(Qt::ISODate) +
         "#####\r\n");
     entries.append(tr("signing certificate: \r\n"));
-    entries.append(tr("new certificates:\r\n"));
+    entries.append(keyFingerprint);
+
+    entries.append(tr("\r\nnew certificates:\r\n"));
 
     foreach (const Certificate& cert, list.getCertificates()) {
         if (!mCertList.getCertificates().contains(cert)) {
diff -r a5a709c6ce93 -r 5e25159d7025 ui/administratorwindow.h
--- a/ui/administratorwindow.h	Mon Jun 30 18:33:26 2014 +0200
+++ b/ui/administratorwindow.h	Mon Jun 30 18:35:22 2014 +0200
@@ -48,8 +48,9 @@
      * saved as current.
      *
      * @param currentCerts  Path to the current certificate list file.
+     * @param certFingerprint The fingerprint of the signing key used.
      */
-    void logChanges(const QString &currentCerts);
+    void logChanges(const QString &currentCerts, const QString &keyFingerprint);
 
     /** @brief get the currently changed certificates.
      * @return a list of certificates.
@@ -71,7 +72,7 @@
     void createContent();
     void loadCertificateTable();
     void addToCertificateTable(const QList<Certificate> &certs);
-    QByteArray createLogEntries(const CertificateList &list);
+    QByteArray createLogEntries(const CertificateList &list, const QString &keyFingerprint);
 
     QSettings mSettings;
 
diff -r a5a709c6ce93 -r 5e25159d7025 ui/createcertlistdialog.cpp
--- a/ui/createcertlistdialog.cpp	Mon Jun 30 18:33:26 2014 +0200
+++ b/ui/createcertlistdialog.cpp	Mon Jun 30 18:35:22 2014 +0200
@@ -272,7 +272,33 @@
         return;
     }
 
+
+    QString keyFingerprint;
+
+    {
+        /* Calculate sha256 sum of the der key */
+        unsigned char output_buf[16000]; /* Buf size taken from examples */
+        int ret;
+        ret = pk_write_key_der (mPk, output_buf, 16000);
+        if (ret <= 0) {
+            showErrorMessage(tr("Failed to calculate key hash."));
+            return;
+        }
+        QByteArray derKey((const char*)output_buf, ret);
+        QByteArray fp = sha256sum(derKey);
+
+        for (int i=0; i < fp.size(); i++) {
+            keyFingerprint += QString("%1").arg(
+                    (unsigned char)(fp[i]), 0, 16).rightJustified(2, '0');
+            if (i != fp.size() - 1) {
+                keyFingerprint += ":";
+            }
+        }
+        keyFingerprint = keyFingerprint.toUpper();
+    }
+
+    mAdminWindow->logChanges(curCerts, keyFingerprint);
+
     QMessageBox::information(this, "", tr("Saved certificate list:\n%1").arg(fileName));
-    mAdminWindow->logChanges(curCerts);
     close();
 }


More information about the Trustbridge-commits mailing list