comparison 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
comparison
equal deleted inserted replaced
1287:d3d66d43365f 1288:265583011f24
13 13
14 #include <polarssl/sha1.h> 14 #include <polarssl/sha1.h>
15 15
16 #include "certhelp.h" 16 #include "certhelp.h"
17 #include "listutil.h" 17 #include "listutil.h"
18
19 #ifdef WIN32
20 #include <cryptuiapi.h>
21 #endif
18 22
19 /* Qt wrapper around certhelp functions. */ 23 /* Qt wrapper around certhelp functions. */
20 QString getX509Value(x509_name *namebuf, unsigned char *oid) { 24 QString getX509Value(x509_name *namebuf, unsigned char *oid) {
21 QString retval; 25 QString retval;
22 char * buf = get_oid_valstr(namebuf, oid); 26 char * buf = get_oid_valstr(namebuf, oid);
194 } 198 }
195 else if (!install && mBaseLine.startsWith("I:")) { 199 else if (!install && mBaseLine.startsWith("I:")) {
196 mBaseLine.replace(0, 1, "R"); 200 mBaseLine.replace(0, 1, "R");
197 } 201 }
198 } 202 }
203
204 #ifdef WIN32
205 bool Certificate::showNativeUI(void *parent)
206 {
207 /* Cut of the first two chars (e.g. I: and decode) */
208 bool retval = false;
209 QByteArray pemData = QByteArray(
210 mBaseLine.right(mBaseLine.size() - 2).toLatin1());
211 PCCERT_CONTEXT pCert = b64_to_cert_context (pemData.data(), pemData.size());
212 typedef BOOL (CALLBACK* LPFNVIEWDLG)(DWORD,const void *,HWND,LPCWSTR,DWORD,void *);
213 LPFNVIEWDLG funcPtr;
214
215 /* CryptUIDlgViewContext is not part of mingw 3.1.0
216 * so we workaround this by geting the process address dynamically. */
217 HMODULE hmod = LoadLibraryW(L"cryptui");
218
219 if (!hmod) {
220 qDebug() << "Failed to open Cryptui.dll";
221 goto done;
222 }
223
224 funcPtr = (LPFNVIEWDLG) GetProcAddress (hmod, "CryptUIDlgViewContext");
225 if (!funcPtr) {
226 qDebug() << "Failed to find Address of CryptUIDlgViewContext";
227 goto done;
228 }
229
230 if (pCert == NULL) {
231 qDebug() << "Failed to parse certificate.";
232 goto done;
233 }
234
235 if (!funcPtr(CERT_STORE_CERTIFICATE_CONTEXT,
236 pCert,
237 (HWND) parent,
238 NULL, // Default Title
239 0,
240 NULL)) {
241 qDebug() << "Failed to view certificate.";
242 retval = false;
243 goto done;
244 }
245
246 retval = true;
247 done:
248
249 if (pCert) {
250 CertFreeCertificateContext(pCert);
251 }
252 if (hmod) {
253 FreeLibrary(hmod);
254 }
255 return retval;
256 }
257 #else
258 bool Certificate::showNativeUI(void *parent)
259 {
260 qDebug() << "Not implemented.";
261 return false;
262 }
263 #endif

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