···1616 | _ ->
1717 Error
1818 (`Msg
1919- ("ca-certs: no trust anchor file found, looked into " ^ path ^ ".\n"
2020- ^ issue))
1919+ ("ca-certs: no trust anchor file found, looked into " ^ path ^ ".\n"
2020+ ^ issue))
21212222let detect_list paths =
2323 let rec one = function
2424 | [] ->
2525 Error
2626 (`Msg
2727- ("ca-certs: no trust anchor file found, looked into "
2828- ^ String.concat ", " paths ^ ".\n" ^ issue))
2727+ ("ca-certs: no trust anchor file found, looked into "
2828+ ^ String.concat ", " paths ^ ".\n" ^ issue))
2929 | path :: paths -> (
3030 match detect_one path with Ok data -> Ok data | Error _ -> one paths)
3131 in
···62626363let ( let* ) = Result.bind
64646565-(** Load certificates from Windows' ["ROOT"] system certificate store.
6666- The C API returns a list of DER-encoded certificates. These are decoded and
6767- reencoded as a single PEM certificate. *)
6565+(** Load certificates from Windows' ["ROOT"] system certificate store. The C API
6666+ returns a list of DER-encoded certificates. These are decoded and reencoded
6767+ as a single PEM certificate. *)
6868let windows_trust_anchors () =
6969 let* anchors = get_anchors () in
7070- let cert_list =
7070+ let cert_list, err_count =
7171 List.fold_left
7272- (fun acc cert ->
7272+ (fun (acc, err_count) cert ->
7373 match X509.Certificate.decode_der cert with
7474- | Ok cert -> cert :: acc
7474+ | Ok cert -> (cert :: acc, err_count)
7575 | Error (`Msg msg) ->
7676- Log.warn (fun m -> m "Ignoring undecodable trust anchor: %s." msg);
7676+ Log.debug (fun m -> m "Ignoring undecodable trust anchor: %s." msg);
7777 Log.debug (fun m ->
7878 m "Full certificate:@.%a" (Ohex.pp_hexdump ()) cert);
7979- acc)
8080- [] anchors
7979+ (acc, err_count + 1))
8080+ ([], 0) anchors
8181 in
8282+ if err_count > 0 then
8383+ Log.warn (fun m -> m "Ignored %u trust anchors." err_count);
8284 Ok (X509.Certificate.encode_pem_multiple cert_list)
83858486let system_trust_anchors () =
···8991 (Sys.getenv_opt "SSL_CERT_FILE", Sys.getenv_opt "NIX_SSL_CERT_FILE")
9092 with
9193 | Some x, _ ->
9292- Log.info (fun m -> m "using %s (from SSL_CERT_FILE)" x);
9494+ Log.debug (fun m -> m "using %s (from SSL_CERT_FILE)" x);
9395 detect_one x
9496 | _, Some x ->
9595- Log.info (fun m -> m "using %s (from NIX_SSL_CERT_FILE)" x);
9797+ Log.debug (fun m -> m "using %s (from NIX_SSL_CERT_FILE)" x);
9698 detect_one x
9799 | None, None -> (
98100 let cmd = Bos.Cmd.(v "uname" % "-s") in
···156158 Ok cas
157159158160let decode_pem_multiple data =
159159- X509.Certificate.fold_decode_pem_multiple
160160- (fun acc -> function
161161- | Ok t -> t :: acc
162162- | Error (`Msg msg) ->
163163- Log.warn (fun m -> m "Ignoring undecodable trust anchor: %s." msg);
164164- acc)
165165- [] data
161161+ let tas, err_count =
162162+ X509.Certificate.fold_decode_pem_multiple
163163+ (fun (acc, err_count) -> function
164164+ | Ok t -> (t :: acc, err_count)
165165+ | Error (`Msg msg) ->
166166+ Log.debug (fun m -> m "Ignoring undecodable trust anchor: %s." msg);
167167+ (acc, err_count + 1))
168168+ ([], 0) data
169169+ in
170170+ if err_count > 0 then
171171+ Log.warn (fun m -> m "Ignored %u trust anchors." err_count);
172172+ tas
166173167174let authenticator ?crls ?allowed_hashes () =
168175 let* data = trust_anchors () in
+3-3
lib/ca_certs.mli
···77 anchors) in the operating system's trust store using {!trust_anchors}. It
88 constructs an authenticator with the current timestamp {!Ptime_clock.now},
99 and the provided [~crls] and [~allowed_hashes] arguments. The resulting
1010- authenticator can be used for {!Tls.Config.client}.
1111- Returns [Error `Msg msg] if detection did not succeed. *)
1010+ authenticator can be used for {!Tls.Config.client}. Returns [Error `Msg msg]
1111+ if detection did not succeed. *)
12121313val trust_anchors : unit -> (string, [> `Msg of string ]) result
1414(** [trust_anchors ()] detects the root CAs (trust anchors) in the operating
···1717 pem-encoded X509 certificates.
18181919 On Unix systems, if the environment variable [SSL_CERT_FILE] is set, its
2020- value is used as path to the system trust anchors. Otherwise, if
2020+ value is used as path to the system trust anchors. Otherwise, if
2121 [NIX_SSL_CERT_FILE] is set, its value is used.
22222323 The successful result is a list of pem-encoded X509 certificates. *)