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

conduit-lwt-unix: allow openssl clients to customize the ssl context and the verification #417

Merged
merged 6 commits into from
Dec 14, 2022

Conversation

psafont
Copy link
Contributor

@psafont psafont commented Nov 7, 2022

Opening the PR to gather comments and discussion around it, supersedes #390

This PR allows clients to have complete control of the ssl context used by conduit, as the previous PR intended. Unlike it, this one integrates into the conduit context creation, like the client-side authenticator. It doesn't allow to control the hostname that verifies the server. xapi doesn't use it anymore and doubt it's going to be useful for anybody else.

It similarly includes into the context a verification control to be able to set whether to verify the hostname and/or the IP

Issues:

  • The name of the new parameter ssl_ctx does not make it explicit that it will be used only for client connections, not server ones. If clients want to change the ssl context for server connections a new parameter will be added and might make things confusing. Do we want to use client_ssl_ctx here? I can even add server_ssl_ctx parameter even if I don't have a need for it.

@psafont psafont changed the title conduit-lwt-unix: allow custom client ssl contexts on conduit context creation conduit-lwt-unix: allow openssl clients to customize the ssl context and the verification Nov 29, 2022
@psafont psafont force-pushed the openssl-ctx branch 2 times, most recently from 7e349c4 to 4de8786 Compare November 29, 2022 16:34
@psafont psafont marked this pull request as ready for review November 29, 2022 16:40
The ssl context may be used for connect_with_ssl.

When tls_own_key is not configured the configured ssl_ctx is used, by
default this is the default client ssl_ctx, just as before.

Signed-off-by: Pau Ruiz Safont <pau.safont@citrix.com>
@psafont
Copy link
Contributor Author

psafont commented Dec 2, 2022

@hannesm Would you mind reviewing these changes? I've integrated them into a xenserver build and all related tests are passing which gives me confidence it's working. I've also manually tested the defaults for the client and it's verifying the domain name of certificate as previously

@hannesm
Copy link
Member

hannesm commented Dec 2, 2022

I guess this is fine, although it makes the ocaml-tls and openssl versions slightly different. The API is only changed in a minor way (adding optional arguments) which allows old programs to use the new API as well.

@psafont psafont force-pushed the openssl-ctx branch 3 times, most recently from c2d9e06 to ddd44e1 Compare December 9, 2022 09:31
When a valid hostname is not available it's better to fail early with
a useful error message rather than letting the connection go on and
letting OpenSSL fail with an undecipherable message.

Note that the "hostname" parameters are strings and don't have to be
hostnames, they can be IPs as well when using cohttp. Ideally these
should be a union type of domain names and ip addresses for better
clarity, but this would be a breaking change.

Signed-off-by: Pau Ruiz Safont <pau.safont@citrix.com>
This is not exposed currently to the user, so there is no change in
functionality.

This allows clients to turn on and off hostname and ip verification in
the remote cert independently in the unusual case where it's needed by
changing the default in the library.

Signed-off-by: Pau Ruiz Safont <pau.safont@citrix.com>
The only options allowed are whether the hostname or the IP are used to
validate the remote host's certificate

Signed-off-by: Pau Ruiz Safont <pau.safont@citrix.com>
@psafont
Copy link
Contributor Author

psafont commented Dec 9, 2022

I've tried to clarify the confusing situation of "hostname"s by changing some the names of some values and explaining it into a commit message. Not sure what more can I do there without breaking compatibility

Now the SNIs is only sent when there's a domain name, as this is the
only type of server names allowed by the RFC

Additionally IP verification for the peer certificate can be enabled if
needed

Signed-off-by: Pau Ruiz Safont <pau.ruizsafont@cloud.com>
Signed-off-by: Pau Ruiz Safont <pau.ruizsafont@cloud.com>
@hannesm
Copy link
Member

hannesm commented Dec 13, 2022

looks good to me. does the latest commit still work in your environment?

@psafont
Copy link
Contributor Author

psafont commented Dec 13, 2022

unit tests look good. I'll do a whole build and let you know tomorrow whether the tests went well

@psafont
Copy link
Contributor Author

psafont commented Dec 14, 2022

All tests passed successfully :)

@hannesm hannesm merged commit a2bf588 into mirage:main Dec 14, 2022
@psafont psafont deleted the openssl-ctx branch December 14, 2022 14:56
hannesm added a commit to hannesm/opam-repository that referenced this pull request Dec 14, 2022
…and conduit-async (6.0.2)

CHANGES:

* conduit-lwt-unix-ssl: allow users to create a client ssl_context and use it for
  any connections. This allows users to manage the lifecycle of the context.
* conduit-lwt-unix-ssl: domain name verification can be disabled by users,
  it's enabled by default. The library returns an error when the hostname
  verification is turned on but it cannot be performed, this follows the TLS
  implementation.
* conduit-lwt-unix-ssl: IP verification can be enabled by users, it's disabled
  by default.
* conduit-lwt-unix-ssl: SNI is not sent when there isn't a domain name available

all done by @psafont in mirage/ocaml-conduit#417
@hannesm
Copy link
Member

hannesm commented Dec 14, 2022

thanks for your patience, merged and released as 6.0.2 in ocaml/opam-repository#22665

@hannesm
Copy link
Member

hannesm commented Dec 14, 2022

Sorry, but in the case that ssl is not installed (it is an optional dependency), the opam-repository-ci caught an error:

#=== ERROR while compiling conduit-lwt-unix.6.0.2 =============================#
# context              2.2.0~alpha~dev | linux/x86_64 | ocaml-base-compiler.4.08.1 | pinned(https://github.com/mirage/ocaml-conduit/releases/download/v6.0.2/conduit-6.0.2.tbz)
# path                 ~/.opam/4.08/.opam-switch/build/conduit-lwt-unix.6.0.2
# command              ~/.opam/opam-init/hooks/sandbox.sh build dune build -p conduit-lwt-unix -j 255
# exit-code            1
# env-file             ~/.opam/log/conduit-lwt-unix-7-dd95c6.env
# output-file          ~/.opam/log/conduit-lwt-unix-7-dd95c6.out
### output ###
# (cd _build/default && /home/opam/.opam/4.08/bin/ocamlc.opt -w -40 -g -bin-annot -I src/conduit-lwt-unix/.conduit_lwt_unix.objs/byte -I /home/opam/.opam/4.08/lib/angstrom -I /home/opam/.opam/4.08/lib/astring -I /home/opam/.opam/4.08/lib/base/caml -I /home/opam/.opam/4.08/lib/bigstringaf -I /home/opam/.opam/4.08/lib/conduit -I /home/opam/.opam/4.08/lib/conduit-lwt -I /home/opam/.opam/4.08/lib/domain-name -I /home/opam/.opam/4.08/lib/ipaddr -I /home/opam/.opam/4.08/lib/ipaddr-sexp -I /home/opam/.opam/4.08/lib/ipaddr/unix -I /home/opam/.opam/4.08/lib/logs -I /home/opam/.opam/4.08/lib/lwt -I /home/opam/.opam/4.08/lib/lwt/unix -I /home/opam/.opam/4.08/lib/macaddr -I /home/opam/.opam/4.08/lib/ocaml/threads -I /home/opam/.opam/4.08/lib/ocplib-endian -I /home/opam/.opam/4.08/lib/ocplib-endian/bigstring -I /home/opam/.opam/4.08/lib/parsexp -I /home/opam/.opam/4.08/lib/ppx_sexp_conv/runtime-lib -I /home/opam/.opam/4.08/lib/sexplib -I /home/opam/.opam/4.08/lib/sexplib0 -I /home/opam/.opam/4.08/lib/stringext -I /home/opam/.opam/4.08/lib/uri -I /home/opam/.opam/4.08/lib/uri/services -no-alias-deps -o src/conduit-lwt-unix/.conduit_lwt_unix.objs/byte/conduit_lwt_unix.cmi -c -intf src/conduit-lwt-unix/conduit_lwt_unix.pp.mli)
# File "src/conduit-lwt-unix/conduit_lwt_unix.mli", line 164, characters 11-22:
# 164 |   ?ssl_ctx:Ssl.context ->
#                  ^^^^^^^^^^^
# Error: Unbound module Ssl

I suspect we'll have to define Conduit_lwt_unix_ssl.Client.ctx (in _dummy as unit, in _real as an alias for Ssl.context) - does this make sense?

@psafont
Copy link
Contributor Author

psafont commented Dec 14, 2022

Ah, sorry about that. Yes the solution makes sense.

@hannesm
Copy link
Member

hannesm commented Dec 14, 2022

@psafont great, would you have time to provide a PR?

@psafont
Copy link
Contributor Author

psafont commented Dec 14, 2022

Yes, of course.here it is: #418

hannesm added a commit to hannesm/opam-repository that referenced this pull request Dec 15, 2022
…and conduit-async (6.1.0)

CHANGES:

done by @psafont in mirage/ocaml-conduit#417:
* conduit-lwt-unix-ssl: allow users to create a client ssl_context and use it for
  any connections. This allows users to manage the lifecycle of the context.
* conduit-lwt-unix-ssl: domain name verification can be disabled by users,
  it's enabled by default. The library returns an error when the hostname
  verification is turned on but it cannot be performed, this follows the TLS
  implementation.
* conduit-lwt-unix-ssl: IP verification can be enabled by users, it's disabled
  by default.
* conduit-lwt-unix-ssl: SNI is not sent when there isn't a domain name available
* conduit-lwt-unix: avoid direct use of Ssl in conduit_lwt_unix (mirage/ocaml-conduit#418 @psafont)
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.

None yet

3 participants