diff options
author | Wojtek Kosior <wk@koszkonutek-tmp.pl.eu.org> | 2021-04-30 00:33:56 +0200 |
---|---|---|
committer | Wojtek Kosior <wk@koszkonutek-tmp.pl.eu.org> | 2021-04-30 00:33:56 +0200 |
commit | aa4d426b4d3527d7e166df1a05058c9a4a0f6683 (patch) | |
tree | 4ff17ce8b89a2321b9d0ed4bcfc37c447bcb6820 /CA_store.cpp | |
download | smtps-and-pop3s-console-program-master.tar.gz smtps-and-pop3s-console-program-master.zip |
Diffstat (limited to 'CA_store.cpp')
-rw-r--r-- | CA_store.cpp | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/CA_store.cpp b/CA_store.cpp new file mode 100644 index 0000000..3bf7be3 --- /dev/null +++ b/CA_store.cpp @@ -0,0 +1,40 @@ +#include <windows.h> +#include <wincrypt.h> + +#include "vmime/vmime.hpp" + +#include "utilities.h" + +using namespace vmime::security::cert; + +vmime::shared_ptr<defaultCertificateVerifier> +windows_root_certs_verifier(void) +{ + vmime::shared_ptr<defaultCertificateVerifier> vrf = + vmime::make_shared<defaultCertificateVerifier>(); + std::vector<vmime::shared_ptr<X509Certificate>> root_certs; + vmime::shared_ptr<vmime::security::cert::X509Certificate> cert; + HCERTSTORE store; + PCCERT_CONTEXT context; + + store = CertOpenSystemStore(0, "ROOT"); + if (store == NULL) + FAIL(MSG_NO_ROOT_CA_STORE); + + context = NULL; + while (true) { + context = CertEnumCertificatesInStore(store, context); + if (context == NULL) + break; + + cert = vmime::security::cert::X509Certificate::import + (context->pbCertEncoded, context->cbCertEncoded); + if (cert) + root_certs.push_back(cert); + } + + CertCloseStore(store, 0); + vrf->setX509RootCAs(root_certs); + + return vrf; +} |