···7878 in
7979 Ok (X509.Certificate.encode_pem_multiple cert_list)
80808181-let trust_anchors () =
8181+let system_trust_anchors () =
8282 if Sys.win32 then windows_trust_anchors ()
8383 else
8484 (* NixOS is special and sets "NIX_SSL_CERT_FILE" as location during builds *)
···107107 Bos.OS.Cmd.(run_out cmd |> out_string |> success)
108108 | s -> Error (`Msg ("ca-certs: unknown system " ^ s ^ ".\n" ^ issue)))
109109110110+let extra_trust_anchors () =
111111+ match Sys.getenv_opt "OCAML_EXTRA_CA_CERTS" with
112112+ | None -> Ok ""
113113+ | Some x ->
114114+ Log.info (fun m -> m "using %s (from OCAML_EXTRA_CA_CERTS)" x);
115115+ detect_one x
116116+117117+let trust_anchors () =
118118+ let* cas = system_trust_anchors () in
119119+ match extra_trust_anchors () with
120120+ | Ok "" -> Ok cas
121121+ | Ok extra_cas -> Ok (cas ^ "\n" ^ extra_cas)
122122+ | Error (`Msg msg) ->
123123+ Log.warn (fun m -> m "Ignoring extra trust anchors: %s." msg);
124124+ Ok cas
125125+110126let decode_pem_multiple data =
111127 X509.Certificate.fold_decode_pem_multiple
112128 (fun acc -> function
···118134119135let authenticator ?crls ?allowed_hashes () =
120136 let* data = trust_anchors () in
121121- let time () = Some (Ptime_clock.now ()) in
122122- let cas = decode_pem_multiple data in
123123- match cas with
137137+ match decode_pem_multiple data with
124138 | [] -> Error (`Msg ("ca-certs: empty trust anchors.\n" ^ issue))
125125- | _ -> Ok (X509.Authenticator.chain_of_trust ?crls ?allowed_hashes ~time cas)
139139+ | cas ->
140140+ let time () = Some (Ptime_clock.now ()) in
141141+ Ok (X509.Authenticator.chain_of_trust ?crls ?allowed_hashes ~time cas)
+8-3
lib/ca_certs.mli
···12121313val trust_anchors : unit -> (string, [> `Msg of string ]) result
1414(** [trust_anchors ()] detects the root CAs (trust anchors) in the operating
1515- system's trust store. On Unix systems, if the environment variable
1616- [SSL_CERT_FILE] is set, its value is used as path to the trust anchors.
1717- Otherwise, if [NIX_SSL_CERT_FILE] is set, its value is used.
1515+ system's trust store. Additional CAs can be provided by setting the
1616+ environment variable [OCAML_EXTRA_CA_CERTS] to a filename containing
1717+ pem-encoded X509 certificates.
1818+1919+ 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
2121+ [NIX_SSL_CERT_FILE] is set, its value is used.
2222+1823 The successful result is a list of pem-encoded X509 certificates. *)