#endif /* HAVE_XKEY_PROVIDER */
+static char *
+get_cert_name(const CERT_CONTEXT *cc, struct gc_arena *gc)
+{
+ DWORD len = CertGetNameStringW(cc, CERT_NAME_FRIENDLY_DISPLAY_TYPE, 0, NULL, NULL, 0);
+ char *name = NULL;
+ if (len)
+ {
+ wchar_t *wname = gc_malloc(len*sizeof(wchar_t), false, gc);
+ if (!wname
+ || CertGetNameStringW(cc, CERT_NAME_FRIENDLY_DISPLAY_TYPE, 0, NULL, wname, len) == 0)
+ {
+ return NULL;
+ }
+ name = utf16to8(wname, gc);
+ }
+ return name;
+}
+
int
SSL_CTX_use_CryptoAPI_certificate(SSL_CTX *ssl_ctx, const char *cert_prop)
{
HCERTSTORE cs;
X509 *cert = NULL;
CAPI_DATA *cd = calloc(1, sizeof(*cd));
+ struct gc_arena gc = gc_new();
if (cd == NULL)
{
}
}
+ /* try to log the "name" of the selected certificate */
+ char *cert_name = get_cert_name(cd->cert_context, &gc);
+ if (cert_name)
+ {
+ msg(D_LOW, "cryptapicert: using certificate with name <%s>", cert_name);
+ }
+
/* cert_context->pbCertEncoded is the cert X509 DER encoded. */
cert = d2i_X509(NULL, (const unsigned char **) &cd->cert_context->pbCertEncoded,
cd->cert_context->cbCertEncoded);
EVP_PKEY *privkey = xkey_load_generic_key(tls_libctx, cd, pkey,
xkey_cng_sign, (XKEY_PRIVKEY_FREE_fn *) CAPI_DATA_free);
SSL_CTX_use_PrivateKey(ssl_ctx, privkey);
+ gc_free(&gc);
return 1; /* do not free cd -- its kept by xkey provider */
#else /* ifdef HAVE_XKEY_PROVIDER */
goto err;
}
CAPI_DATA_free(cd); /* this will do a ref_count-- */
+ gc_free(gc);
return 1;
#endif /* HAVE_XKEY_PROVIDER */
err:
CAPI_DATA_free(cd);
+ gc_free(&gc);
return 0;
}
#endif /* _WIN32 */
return ucs16;
}
+char *
+utf16to8(const wchar_t *utf16, struct gc_arena *gc)
+{
+ char *utf8 = NULL;
+ int n = WideCharToMultiByte(CP_UTF8, 0, utf16, -1, NULL, 0, NULL, NULL);
+ if (n > 0)
+ {
+ utf8 = gc_malloc(n, true, gc);
+ if (utf8)
+ {
+ WideCharToMultiByte(CP_UTF8, 0, utf16, -1, utf8, n, NULL, NULL);
+ }
+ }
+ return utf8;
+}
/*
* Return true if filename is safe to be used on Windows,
/* Convert a string from UTF-8 to UCS-2 */
WCHAR *wide_string(const char *utf8, struct gc_arena *gc);
+/* Convert a string from UTF-16 to UTF-8 */
+char *utf16to8(const wchar_t *utf16, struct gc_arena *gc);
+
/* return true if filename is safe to be used on Windows */
bool win_safe_filename(const char *fn);