changeset 378:31079bd54036

Add fingerprint to certificate
author Andre Heinecke <andre.heinecke@intevation.de>
date Tue, 15 Apr 2014 12:36:22 +0200
parents e3f825a7257e
children 2ddc685cba33
files ui/certificate.cpp ui/certificate.h ui/certificatetablemodel.cpp
diffstat 3 files changed, 21 insertions(+), 3 deletions(-) [+]
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) :
--- a/ui/certificate.h	Tue Apr 15 12:34:04 2014 +0200
+++ b/ui/certificate.h	Tue Apr 15 12:36:22 2014 +0200
@@ -107,6 +107,9 @@
     /** @brief get the date the certificate expires */
     QDateTime validTo() const {return mValidTo;}
 
+    /** @brief get sha1 sum of the certificate */
+    QString fingerprint() const {return mFingerprint;}
+
     /** @brief construct certificate objects from a file
      *
      *  Constructs a new Certificate Object from a file containing either
@@ -132,7 +135,8 @@
             mSubjectO,
             mSubjectSN,
             mDetails,
-            mBaseLine;
+            mBaseLine,
+            mFingerprint;
 
     QDateTime mValidFrom,
               mValidTo;
--- a/ui/certificatetablemodel.cpp	Tue Apr 15 12:34:04 2014 +0200
+++ b/ui/certificatetablemodel.cpp	Tue Apr 15 12:36:22 2014 +0200
@@ -7,7 +7,7 @@
     header.append(tr("CN"));
     header.append(tr("issued  on"));
     header.append(tr("expires on"));
-    header.append(tr("Fingerprint"));
+    header.append(tr("SHA1 Fingerprint"));
 
 }
 
@@ -51,7 +51,7 @@
         case 1: ret = cert.subjectCN(); break;
         case 2: ret = cert.validFrom(); break;
         case 3: ret = cert.validTo(); break;
-        case 4: ret = "Fingerprint"; break;
+        case 4: ret = cert.fingerprint(); break;
         default: ;
         }
         return ret;

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