diff ui/certificate.cpp @ 378:31079bd54036

Add fingerprint to certificate
author Andre Heinecke <andre.heinecke@intevation.de>
date Tue, 15 Apr 2014 12:36:22 +0200
parents 67b471c4d1fc
children 2ddc685cba33
line wrap: on
line diff
--- a/ui/certificate.cpp	Tue Apr 15 12:34:04 2014 +0200
+++ b/ui/certificate.cpp	Tue Apr 15 12:36:22 2014 +0200
@@ -4,6 +4,8 @@
 #include <QStringList>
 #include <QObject>
 
+#include <polarssl/sha1.h>
+
 #include "certhelp.h"
 #include "listutil.h"
 
@@ -47,6 +49,17 @@
     mSubjectOU = getX509Value(&(chain.subject), CERT_OID_OU);
     mSubjectO = getX509Value(&(chain.subject), CERT_OID_O);
     mSubjectSN = getX509Value(&(chain.subject), CERT_OID_SN);
+
+    /* Calculate sha1 fingerprint */
+    unsigned char sha1sum[20];
+    sha1(chain.raw.p, chain.raw.len, sha1sum);
+    for (int i=0; i < 20; i++) {
+        mFingerprint += QString("%1").arg(sha1sum[i], 0, 16);
+        if (i != 19) {
+            mFingerprint += ":";
+        }
+    }
+
     x509_crt_free(&chain);
 
     mDetails = QObject::tr("Certificate:\n"
@@ -62,6 +75,7 @@
             .arg(mSubjectSN)
             .arg(QLocale::system().toString(mValidFrom))
             .arg(QLocale::system().toString(mValidTo));
+
 }
 
 Certificate::Certificate(const QByteArray& derData) :

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