Skip to content

Commit

Permalink
Implement read_system_root_certs on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
borrrden committed Aug 29, 2019
1 parent c0dcf53 commit 529d61b
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions src/mbedtls_context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
#include <mbedtls/ssl.h>
#include <mutex>
#include <chrono>
#include <cassert>

#ifdef __APPLE__
#include <TargetConditionals.h>
Expand All @@ -59,7 +60,11 @@
#include <sstream>
#include <sys/stat.h>
#else
// TODO: Add Windows #includes here
#include <wincrypt.h>
#include <sstream>

#pragma comment (lib, "crypt32.lib")
#pragma comment (lib, "cryptui.lib")
#endif


Expand Down Expand Up @@ -554,9 +559,20 @@ namespace sockpp {
}

#else
// TODO: Windows support
static string read_system_root_certs() {
return "";
PCCERT_CONTEXT pContext = nullptr;
HCERTSTORE hStore = CertOpenSystemStore(NULL, "ROOT");
if(hStore == nullptr) {
return "";
}

stringstream certs;
while ((pContext = CertEnumCertificatesInStore(hStore, pContext))) {
certs.write((const char*)pContext->pbCertEncoded, pContext->cbCertEncoded);
}

CertCloseStore(hStore, CERT_CLOSE_STORE_FORCE_FLAG);
return certs.str();
}
#endif

Expand Down

0 comments on commit 529d61b

Please sign in to comment.