peer_name should be strongly typed#434
Conversation
|
the API change looks good to me -- tls predates the domain-name library, that's the reason why peer_name is a string option at the moment. I'll need to refresh my brain about length restrictions in SNI and Domain names -- and whether there are use cases where the peer name is not a host name. |
I think the only practical limit is enforced by DNS and limits [peer_name] to 253 bytes. The TLS RFC dances around the issue a bit (16 bit length for the "list" of server names, but there must only be one of each type, and DNS is the only type). |
|
I think there are ocaml-ci problems, possibly with tls-async.opam? I think aside from that this PR is ready for review. EDIT: Ah, I needed to merge the changes from main! CI is working now. |
40a5777 to
629968b
Compare
|
I needed to make some adjustments to the test suite to get this to compile. The long strings like |
|
Thanks for your work, this looks good to go. |
The peer_name field is configured by the client (emitting a SNI (Server Name Indication) extension in the ClientHello). The own_name is filled by the server from the ClientHello SNI. This extends mirleft#434.
The peer_name field is configured by the client (emitting a SNI (Server Name Indication) extension in the ClientHello). The own_name is filled by the server from the ClientHello SNI. This extends mirleft#434.
CHANGES: * Breaking: peer_name (in config and epoch data, also own_name) is now a [`host] Domain_name.t instead of a string. (mirleft/ocaml-tls#434 mirleft/ocaml-tls#438 @torinnd @hannesm) * Add a X509_async module (mirleft/ocaml-tls#435 @torinnd) * Client and server constructor log messages are on the debug level (mirleft/ocaml-tls#436 reported by @talex5, fix by @hannesm) * Adapt to cstruct 6.0.0 API (Cstruct.len is deprecated) mirleft/ocaml-tls#439 @hannesm
Change [peer_name] to a [[`host] Domain_name.t]. This passes the obligation to handle errors to the caller.
[peer_name] is defined as a [string option] and passed around as such until it arrives at the function [host_name_opt] in lib/handshake_common.ml, where it is converted into a [[`host] Domain_name.t option]. A malformed string that cannot be lifted into a [[`host] Domain_name.t] will return [None], which will disable hostname verification. This will cause, for example, connections to IP addresses like “1.2.3.4” over HTTPS to succeed where one might’ve expected them to fail.
I haven't updated the lwt/ code and expect that won't compile, so I'm tagging this as a draft. It's also an interface change and probably should be rolled into a major version bump, if the project is interested in this change.