Mercurial > trustbridge
diff common/certhelp.c @ 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 | 17e1c8f37d72 |
children |
line wrap: on
line diff
--- a/common/certhelp.c Mon Sep 29 13:02:41 2014 +0200 +++ b/common/certhelp.c Mon Sep 29 13:12:58 2014 +0200 @@ -50,3 +50,42 @@ } return str; } + +#ifdef WIN32 +PCCERT_CONTEXT +b64_to_cert_context(char *b64_data, size_t b64_size) +{ + size_t buf_size = 0; + char *buf = NULL; + PCCERT_CONTEXT pCert = NULL; + int ret = -1; + + ret = str_base64_decode (&buf, &buf_size, b64_data, b64_size); + + if (ret != 0) + { + ERRORPRINTF ("decoding certificate failed\n"); + return NULL; + } + + pCert = CertCreateContext (CERT_STORE_CERTIFICATE_CONTEXT, + X509_ASN_ENCODING | PKCS_7_ASN_ENCODING, + (const PBYTE) buf, + (DWORD) buf_size, + 0, + NULL); + free (buf); /* Windows has a copy */ + + if (pCert == NULL) + { + char *error = getLastErrorMsg(); + if (error) + { + ERRORPRINTF ("Failed to create cert context: %s \n", error); + free (error); + } + return NULL; + } + return pCert; +} +#endif