20 boost::asio::ssl::context& ctx,
21 boost::system::error_code& ec,
25 auto certStoreDelete = [](
void* h) {
30 CertOpenSystemStore(0,
"ROOT"), certStoreDelete};
34 ec = boost::system::error_code(
35 GetLastError(), boost::system::system_category());
42 X509_STORE_new(), X509_STORE_free};
46 ec = boost::system::error_code(
47 static_cast<int>(::ERR_get_error()),
48 boost::asio::error::get_ssl_category());
55 ::ERR_error_string_n(ec.value(), buf,
sizeof(buf));
56 JLOG(j.
warn()) << mesg <<
" " << buf;
60 PCCERT_CONTEXT pContext = NULL;
61 while ((pContext = CertEnumCertificatesInStore(hStore.get(), pContext)) !=
64 unsigned char const* pbCertEncoded = pContext->pbCertEncoded;
66 d2i_X509(NULL, &pbCertEncoded, pContext->cbCertEncoded), X509_free};
69 warn(
"Error decoding certificate");
73 if (X509_STORE_add_cert(store.get(), x509.get()) != 1)
75 warn(
"Error adding certificate");
85 SSL_CTX_set_cert_store(ctx.native_handle(), store.release());
88 ctx.set_default_verify_paths(ec);