Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add: additional key path for macos #28

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .ocamlformat
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
version = 0.25.1
version = 0.26.2
profile=conventional
48 changes: 40 additions & 8 deletions lib/ca_certs.ml
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,11 @@ let linux_locations =
let openbsd_location = "/etc/ssl/cert.pem"
let freebsd_location = "/usr/local/share/certs/ca-root-nss.crt"

let macos_keychain_location =
"/System/Library/Keychains/SystemRootCertificates.keychain"
let macos_keychain_locations =
[
"/System/Library/Keychains/SystemRootCertificates.keychain";
"/Library/Keychains/System.keychain";
]

external iter_on_anchors : (string -> unit) -> unit = "ca_certs_iter_on_anchors"

Expand Down Expand Up @@ -99,12 +102,41 @@ let trust_anchors () =
| "OpenBSD" -> detect_one openbsd_location
| "Linux" -> detect_list linux_locations
| "Darwin" ->
let cmd =
Bos.Cmd.(
v "security" % "find-certificate" % "-a" % "-p"
% macos_keychain_location)
in
Bos.OS.Cmd.(run_out cmd |> out_string |> success)
macos_keychain_locations
|> List.map (fun path ->
let cmd =
Bos.Cmd.(
v "security" % "find-certificate" % "-a" % "-p" % path)
in
Bos.OS.Cmd.(run_out cmd |> out_string |> success))
|> List.fold_left
(fun acc cert ->
match (cert, acc) with
| Ok cert, Ok acc -> Ok (cert ^ "\n" ^ acc)
| Ok cert, Error (`Msg msg) ->
Log.warn (fun m ->
m
"ignoring error %s (got another set of \
certificates)"
msg);
Ok cert
| Error e, Ok "" -> Error e
| Error (`Msg msg), Ok x ->
Log.warn (fun m ->
m
"ignoring error %s (already have another set of \
certificates)"
msg);
Ok x
| Error e, Error (`Msg msg) ->
Log.warn (fun m ->
m "ignoring error %s (got another error)" msg);
Error e)
(Ok "")
|> Result.map_error (function `Msg msg ->
`Msg
("ca-certs: no trust anchor file found on macOS: " ^ msg
^ ".\n" ^ issue))
| s -> Error (`Msg ("ca-certs: unknown system " ^ s ^ ".\n" ^ issue)))

let authenticator ?crls ?allowed_hashes () =
Expand Down