Skip to content

Instantly share code, notes, and snippets.

@bramford
Created April 26, 2018 11:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bramford/93212ddff807bc131d1562197f5f2d01 to your computer and use it in GitHub Desktop.
Save bramford/93212ddff807bc131d1562197f5f2d01 to your computer and use it in GitHub Desktop.
A TLS error using cohttp-lwt and cohttp-lwt-unix. How can I debug it further?
(* Paste this source file in to your toplevel *)
(* There is some attribute of the TLS connection to remoteok.io that causes
a fatal Tls_alert (HANDSHAKE_FAILURE). `curl` has no trouble connecting to
this same host. I assume there's a difference between the defaults used by
`Cohttp_lwt_unix.Client.get` and those used by`curl`.
site.
How can I debug it further? I've tried to establish a TLS connection directly with Tls_lwt.connect but it's too complex to use without more reading.
*)
#require "lwt";;
#require "cohttp-lwt";;
#require "cohttp-lwt-unix";;
let body =
let open Lwt in
try
(* google.com, for example, has no errors and the response is valid
Cohttp_lwt_unix.Client.get (Uri.of_string "https://google.com") >>= fun (resp,body) ->
*)
Cohttp_lwt_unix.Client.get (Uri.of_string "https://remoteok.io/api") >>= fun (resp,body) ->
Cohttp_lwt.Body.to_string body >|= fun body ->
body
with
(* This attempt to catch and print the exception fails. I assume this is because it is FATAL and causes the program to exit immediately before this logic can run *)
| Tls_lwt.Tls_alert e ->
print_endline (Tls.Packet.alert_type_to_string e);
exit 1
;;
let body = Lwt_main.run body;;
(* toplevel output *)
(*
Exception:
Tls_lwt.Tls_alert
Tls.Packet.HANDSHAKE_FAILURE.
Raised at file "src/core/lwt.ml", line 3008, characters 20-29
Called from file "src/unix/lwt_main.ml", line42, characters 8-18
Called from file "//toplevel//", line 1, characters 11-28
Called from file "toplevel/toploop.ml", line 180, characters 17-56
*)
(* I also tried using `cohttp-curl-lwt` but received the same error *)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment