···11+let src = Logs.Src.create "ca-certs" ~doc:"CA certificates"
22+33+module Log = (val Logs.src_log src : Logs.LOG)
44+15let issue =
26 {|Please report an issue at https://github.com/mirage/ca-certs, including:
37- the output of uname -s
···6973 let open Rresult.R.Infix in
7074 trust_anchors () >>= fun data ->
7175 let time () = Some (Ptime_clock.now ()) in
7272- X509.Certificate.decode_pem_multiple (Cstruct.of_string data) >>| fun cas ->
7373- X509.Authenticator.chain_of_trust ?crls ?hash_whitelist ~time cas
7676+ (* we cannot use decode_pem_multiple since this fails on the first
7777+ undecodable certificate - while we'd like to stay operational, and ignore
7878+ some certificates *)
7979+ let sep = "-----END CERTIFICATE-----" in
8080+ let certs = Astring.String.cuts ~sep ~empty:false data in
8181+ let cas =
8282+ List.fold_left
8383+ (fun acc data ->
8484+ let data = data ^ sep in
8585+ match X509.Certificate.decode_pem (Cstruct.of_string data) with
8686+ | Ok ca -> ca :: acc
8787+ | Error (`Msg msg) ->
8888+ Log.warn (fun m -> m "Failed to decode a trust anchor %s." msg);
8989+ Log.debug (fun m -> m "Full certificate:@.%s" data);
9090+ acc)
9191+ [] certs
9292+ in
9393+ let cas = List.rev cas in
9494+ match cas with
9595+ | [] -> Error (`Msg ("ca-certs: empty trust anchors.\n" ^ issue))
9696+ | _ -> Ok (X509.Authenticator.chain_of_trust ?crls ?hash_whitelist ~time cas)