diff ui/createcertlistdialog.cpp @ 679:75cd2fbf9ac6

(Issue 9) Log key's sha256 fingerprint
author Andre Heinecke <andre.heinecke@intevation.de>
date Mon, 30 Jun 2014 17:21:44 +0200
parents ccdc4c6b97ce
children bd2cb6bdb1c5
line wrap: on
line diff
--- a/ui/createcertlistdialog.cpp	Mon Jun 30 15:41:13 2014 +0200
+++ b/ui/createcertlistdialog.cpp	Mon Jun 30 17:21:44 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();
 }

http://wald.intevation.org/projects/trustbridge/