Skip to content

Commit

Permalink
debug
Browse files Browse the repository at this point in the history
  • Loading branch information
hannesm committed Aug 5, 2024
1 parent 090040a commit a246660
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 6 deletions.
7 changes: 6 additions & 1 deletion lib/ca_certs.ml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,10 @@ external iter_on_anchors : (string -> unit) -> unit = "ca_certs_iter_on_anchors"

let get_anchors () =
let der_list = ref [] in
match iter_on_anchors (fun der_cert -> der_list := (String.of_bytes (Bytes.of_string der_cert)) :: !der_list) with
match iter_on_anchors (fun der_cert ->
Logs.debug (fun m -> m "cert: %a" (Ohex.pp_hexdump ()) der_cert);
der_list := der_cert :: !der_list)
with
| () -> Ok !der_list
| exception Failure msg -> Error (`Msg msg)

Expand All @@ -72,7 +75,9 @@ let rec map_m f l =
reencoded as a single PEM certificate. *)
let windows_trust_anchors () =
let* anchors = get_anchors () in
Logs.info (fun m -> m "found %u anchors" (List.length anchors));
let* cert_list = map_m X509.Certificate.decode_der anchors in
Logs.info (fun m -> m "cert list is %u" (List.length cert_list));
Ok (X509.Certificate.encode_pem_multiple cert_list)

let trust_anchors () =
Expand Down
2 changes: 1 addition & 1 deletion lib/dune
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
(library
(name ca_certs)
(public_name ca-certs)
(libraries mirage-crypto x509 bos fpath logs ptime.clock.os digestif)
(libraries mirage-crypto x509 bos fpath logs ptime.clock.os digestif ohex)
(foreign_stubs
(language c)
(names ca_certs_stubs))
Expand Down
2 changes: 1 addition & 1 deletion test/dune
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
(test
(name tests)
(libraries ca-certs fmt alcotest))
(libraries ca-certs fmt alcotest logs.fmt))
12 changes: 9 additions & 3 deletions test/tests.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1016,6 +1016,12 @@ let ta () =
Ok (List.rev cas))

let () =
let tas = Result.get_ok (ta ()) in
Alcotest.run "verification tests"
[ ("X509 certificate validation", tests tas) ]
Logs.set_reporter (Logs_fmt.reporter ());
Logs.set_level ~all:true (Some Logs.Debug);
match ta () with
| Ok tas ->
Alcotest.run "verification tests"
[ ("X509 certificate validation", tests tas) ]
| Error `Msg msg ->
Logs.err (fun m -> m "error %s in ta()" msg);
exit 2

0 comments on commit a246660

Please sign in to comment.