CppServer 1.0.6.0
C++ Server Library
Loading...
Searching...
No Matches
ssl_context.cpp
Go to the documentation of this file.
1
8
10
11#if defined(_WIN32) || defined(_WIN64)
12#include <wincrypt.h>
13#endif
14
15namespace CppServer {
16namespace Asio {
17
19{
20#if defined(_WIN32) || defined(_WIN64)
21 HCERTSTORE hStore = CertOpenSystemStore(0, "ROOT");
22 if (hStore == nullptr)
23 return;
24
25 X509_STORE* store = X509_STORE_new();
26 PCCERT_CONTEXT pContext = nullptr;
27 while ((pContext = CertEnumCertificatesInStore(hStore, pContext)) != nullptr)
28 {
29 // Convert from DER to internal format
30 X509* x509 = d2i_X509(nullptr, (const unsigned char**)&pContext->pbCertEncoded, pContext->cbCertEncoded);
31 if (x509 != nullptr)
32 {
33 X509_STORE_add_cert(store, x509);
34 X509_free(x509);
35 }
36 }
37
38 CertFreeCertificateContext(pContext);
39 CertCloseStore(hStore, 0);
40
41 // Attach X509_STORE to the current SSL context
42 SSL_CTX_set_cert_store(native_handle(), store);
43#endif
44}
45
46} // namespace Asio
47} // namespace CppServer
void set_root_certs()
Configures the context to use system root certificates.
Asio definitions.
C++ Server project definitions.
Definition asio.h:56
SSL context definition.