-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14 from emillon/windows
Windows support
- Loading branch information
Showing
3 changed files
with
101 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
#include "caml/alloc.h" | ||
#include "caml/callback.h" | ||
#include "caml/fail.h" | ||
#include "caml/memory.h" | ||
|
||
#ifdef _WIN32 | ||
|
||
#include <windows.h> | ||
|
||
value ca_certs_iter_on_anchors(value v_f) | ||
{ | ||
CAMLparam1(v_f); | ||
CAMLlocal1(v_encoded_cert); | ||
|
||
HCERTSTORE hCertStore = CertOpenSystemStore(0, "ROOT"); | ||
if (!hCertStore) | ||
{ | ||
caml_failwith("ca_certs_iter_on_anchors: CertOpenSystemStore returned NULL"); | ||
} | ||
|
||
PCCERT_CONTEXT pCertContext = NULL; | ||
while ((pCertContext = CertEnumCertificatesInStore(hCertStore, pCertContext)) != NULL) | ||
{ | ||
if (!(pCertContext->dwCertEncodingType & X509_ASN_ENCODING)) | ||
{ | ||
caml_failwith("ca_certs_iter_on_anchors: certificate does not have expected encoding"); | ||
} | ||
v_encoded_cert = caml_alloc_initialized_string( | ||
pCertContext->cbCertEncoded, | ||
pCertContext->pbCertEncoded); | ||
caml_callback(v_f, v_encoded_cert); | ||
} | ||
|
||
if (!CertCloseStore(hCertStore, 0)) | ||
{ | ||
caml_failwith("ca_certs_iter_on_anchors: CertCloseStore returned an error"); | ||
} | ||
|
||
CAMLreturn(Val_unit); | ||
} | ||
|
||
#else | ||
|
||
value ca_certs_iter_on_anchors(value v_unit) | ||
{ | ||
caml_failwith("ca_certs_iter_on_anchors: only implemented on Windows"); | ||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,27 @@ | ||
(library | ||
(name ca_certs) | ||
(public_name ca-certs) | ||
(libraries mirage-crypto x509 astring bos rresult fpath logs ptime.clock.os)) | ||
(libraries mirage-crypto x509 astring bos rresult fpath logs ptime.clock.os) | ||
(foreign_stubs | ||
(language c) | ||
(names ca_certs_stubs)) | ||
(c_library_flags | ||
(:include flags.sexp))) | ||
|
||
(rule | ||
(target flags.sexp) | ||
(enabled_if | ||
(= %{os_type} Win32)) | ||
(action | ||
(with-stdout-to | ||
%{target} | ||
(echo "(:standard -lcrypt32)")))) | ||
|
||
(rule | ||
(target flags.sexp) | ||
(enabled_if | ||
(<> %{os_type} Win32)) | ||
(action | ||
(with-stdout-to | ||
%{target} | ||
(echo :standard)))) |