Skip to content

Facilitate the use of extra CA certificates#30

Merged
hannesm merged 1 commit intomirage:mainfrom
art-w:extra-ca
Apr 15, 2025
Merged

Facilitate the use of extra CA certificates#30
hannesm merged 1 commit intomirage:mainfrom
art-w:extra-ca

Conversation

@art-w
Copy link
Copy Markdown
Contributor

@art-w art-w commented Jul 15, 2024

I found the following changes useful to quickly enable exceptional CA certificates when experimenting with Cohttp HTTPS requests to the (untrustworthy) mitmproxy for debugging, and to various localhost test servers (with locally generated CA certificates). I'm not entirely sure that this PR behavior is desirable, so I've broken it in two commits:

  • One commit to make it easier to parse a certificates file, to eg manually configure Cohttp/Conduit ctx => This could also be done through the existing X509.Certificate.decode_pem_multiple, with some caveats (perhaps I should propose a fix to x509 instead, to handle failures more gracefully?)
  • And one commit to automatically read additional certificates from the environment variable OCAML_EXTRA_CA_CERTS file. This has some precedent on other platform, eg NODE_EXTRA_CA_CERTS in nodejs, because users can't always install certificates... but it could also be argued that it's a security risk to provide an escape hatch! (but installing a mitmproxy CA isn't great either ^^')

I can always configure Cohttp authenticator manually with extra CAs, so feel free to reject this PR!

@hannesm
Copy link
Copy Markdown
Member

hannesm commented Jul 17, 2024

thanka for your pr. would you mind to move the decode_pem_multiple_log_error (or similar) to x509 (best on top of the string pr) -- then we can have that included in the upcoming x509 release.

OCAML_EXTRA_CA_CERTS - I'm pretty unsure about that, esp. since SSL_CERT_FILE / NIX_SSL_CERT_FILE is already supported - and I find these environment variable escape hatches very ugly. Would/should the SSL_CERT_FILE take a list of files, and/or have a way to specify "also add the system certs" (using sth like the path "+system") be sufficient for your use case?

@hannesm
Copy link
Copy Markdown
Member

hannesm commented Jul 18, 2024

maybe @dinosaure or @reynir, would you mind to open a PR for x509 which has an improved version of decode_pem_multiple (more like a fold, the signature I have in mind: val decode_pem_multiple : ('a -> (Certificate.t, `Msg of string) result -> 'a) -> 'a -> string -> 'a -- thus the caller can decide what do to with errors.

what do you think? (of course @art-w , feel free to jump in and open a pr to x509)

@hannesm
Copy link
Copy Markdown
Member

hannesm commented Jul 18, 2024

maybe a new function fold_decode_multiple_pem would be the way forward.

@art-w
Copy link
Copy Markdown
Contributor Author

art-w commented Jul 18, 2024

Yes a fold makes sense in x509, I'll get at it right away!

Changing the behavior of SSL_CERT_FILE might introduce some problems however, as this environment variable is also used by other applications (notably curl), so I don't think it's ideal..

@art-w
Copy link
Copy Markdown
Contributor Author

art-w commented Jul 18, 2024

I added two commits, one for compatibility with the latest X509 library and one to use its fold_decode_pem_multiple implementation. Should I open a separate PR for the cstructs removal? :)

@hannesm
Copy link
Copy Markdown
Member

hannesm commented Jul 18, 2024

there's #29 already which removes cstruct.

@hannesm
Copy link
Copy Markdown
Member

hannesm commented Aug 5, 2024

I'm still puzzled about this PR. So, what is the interoperability story, in terms of macOS/windows/Unix?

Also, in the documentation you write "Additional CAs can be enabled by setting the environment variable [OCAML_EXTRA_CA_CERTS] to a file path containing more trust anchors" - so that file is supposed to contain a list of certificates? PEM encoded? Maybe worth specifying?

Why is SSL_CERT_FILE / NIX_SSL_CERT_FILE used and documented for trust_anchors, and your proposed OCAML_EXTRA_CA_CERTS for authenticator? I'd semantically-wise find it cleaner if trust_anchors would do the environment variable stuff.

What is the information and error paths? Shouldn't there be specific messages about "using OCAML_EXTRA_CA_CERTS from %s" (path) [to inform the user] and as questioned, what should the failure behaviour be (if the file does not exist or has invalid data)?

@hannesm
Copy link
Copy Markdown
Member

hannesm commented Aug 5, 2024

the second commit slurps the previous log messages - I don't understand why (but please don't bother, I'll have that as a separate PR anyways).

@hannesm hannesm mentioned this pull request Aug 5, 2024
@hannesm
Copy link
Copy Markdown
Member

hannesm commented Aug 5, 2024

in case you like to have this merged (also addressing #25 (comment)), it would be great if you could:

@hannesm
Copy link
Copy Markdown
Member

hannesm commented Aug 6, 2024

I'll cut a release without the OCAML_EXTRA_CA_CERTS, but I'm happy to merge and release it once the semantics is more clear.

@dinosaure
Copy link
Copy Markdown
Member

The PR was rebased 👍.

@art-w art-w force-pushed the extra-ca branch 2 times, most recently from 53fac6c to 82c1fae Compare August 29, 2024 08:50
@art-w
Copy link
Copy Markdown
Contributor Author

art-w commented Aug 29, 2024

Thanks! (sorry for the late reply, I was on holidays without internet for a long time)

I still think this is useful, and tried to address your feedback (log reports, trust_anchors includes the extra CA certs, documentation of pem-encoded file format)... but do let me know if the semantics are still unclear?
Regarding the interoperability story, the OCAML_EXTRA_CA_CERTS is used on all platforms. Are there specific issues on eg windows that would make this a bad idea?

PS: May I suggest a patch for trust_anchors to return an X509.Certificate.t list instead of a string? :) (I don't need it but think it would be cleaner)

@hannesm hannesm merged commit f21a17f into mirage:main Apr 15, 2025
@hannesm
Copy link
Copy Markdown
Member

hannesm commented Apr 15, 2025

thanks

hannesm added a commit to hannesm/opam-repository that referenced this pull request Apr 15, 2025
CHANGES:

* Add OCAML_EXTRA_CA_CERTS env variable (mirage/ca-certs#30 @art-w)
* macOS: add additional keychain path `/Library/Keychains/System.keychain`
  (mirage/ca-certs#28 @ajbt200128)
* Demote log levels of trust anchor parsing failures (now on the debug level),
  log a single warning message how many failures occured (mirage/ca-certs#36 @Julow)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants