aboutsummaryrefslogtreecommitdiff
path: root/CA_store.cpp
blob: 3bf7be3e1280208b630f6a75b7892327b1c7bd49 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
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;
}