diff ui/certificate.cpp @ 1288:265583011f24

(issue123) Add possibility to open native certificate dialog This is currently only implemented for windows.
author Andre Heinecke <andre.heinecke@intevation.de>
date Mon, 29 Sep 2014 13:12:58 +0200
parents 2a1206932f53
children c2fd36cd4093
line wrap: on
line diff
--- a/ui/certificate.cpp	Mon Sep 29 13:02:41 2014 +0200
+++ b/ui/certificate.cpp	Mon Sep 29 13:12:58 2014 +0200
@@ -16,6 +16,10 @@
 #include "certhelp.h"
 #include "listutil.h"
 
+#ifdef WIN32
+#include <cryptuiapi.h>
+#endif
+
 /* Qt wrapper around certhelp functions. */
 QString getX509Value(x509_name *namebuf, unsigned char *oid) {
     QString retval;
@@ -196,3 +200,64 @@
         mBaseLine.replace(0, 1, "R");
     }
 }
+
+#ifdef WIN32
+bool Certificate::showNativeUI(void *parent)
+{
+    /* Cut of the first two chars (e.g. I: and decode) */
+    bool retval = false;
+    QByteArray pemData = QByteArray(
+            mBaseLine.right(mBaseLine.size() - 2).toLatin1());
+    PCCERT_CONTEXT pCert = b64_to_cert_context (pemData.data(), pemData.size());
+    typedef BOOL (CALLBACK* LPFNVIEWDLG)(DWORD,const void *,HWND,LPCWSTR,DWORD,void *);
+    LPFNVIEWDLG funcPtr;
+
+    /* CryptUIDlgViewContext is not part of mingw 3.1.0
+     * so we workaround this by geting the process address dynamically. */
+    HMODULE hmod = LoadLibraryW(L"cryptui");
+
+    if (!hmod) {
+        qDebug() << "Failed to open Cryptui.dll";
+        goto done;
+    }
+
+    funcPtr = (LPFNVIEWDLG) GetProcAddress (hmod, "CryptUIDlgViewContext");
+    if (!funcPtr) {
+        qDebug() << "Failed to find Address of CryptUIDlgViewContext";
+        goto done;
+    }
+
+    if (pCert == NULL) {
+        qDebug() << "Failed to parse certificate.";
+        goto done;
+    }
+
+    if (!funcPtr(CERT_STORE_CERTIFICATE_CONTEXT,
+                 pCert,
+                 (HWND) parent,
+                 NULL, // Default Title
+                 0,
+                 NULL)) {
+        qDebug() << "Failed to view certificate.";
+        retval = false;
+        goto done;
+    }
+
+    retval = true;
+done:
+
+    if (pCert) {
+        CertFreeCertificateContext(pCert);
+    }
+    if (hmod) {
+        FreeLibrary(hmod);
+    }
+    return retval;
+}
+#else
+bool Certificate::showNativeUI(void *parent)
+{
+    qDebug() << "Not implemented.";
+    return false;
+}
+#endif

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