toddholmberg
Hello. I am trying to understand and fix an error I am receiveing when trying to retrieve the ssl certificate from an ssl handshake. Any handshake action that returns anything other than a 200 status code results in the following error:
TLS :client: In state :hello at tls_record.erl:471 generated CLIENT ALERT: Fatal - Unexpected Message.
I would like to retrieve the certificate regardless of the response code. Here is how I initiate the handshake. FYI, I am issuing the request through a proxy.
{:ok, tcp} = :gen_tcp.connect('#{proxy_ip}', proxy_port, active: false)
:gen_tcp.send(tcp, "CONNECT #{host_name}:443 HTTP/1.1\r\nProxy-Authorization: Basic #{:base64.encode_to_string('#{proxy_uername}:#{proxy_password}')}\r\n\r\n")
ssl_options = [
versions: [:"tlsv1.2"],
server_name_indication: '#{host_name}',
verify: :verify_none,
depth: 3,
reuse_sessions: false
]
recv = :gen_tcp.recv(tcp, 0, 5000)
:ssl.start()
:ssl.connect(tcp, ssl_options, timeout)
Is there anything that jumps out here as an obviouse possible issue with how I am making the request?
Thank you
Trending in Questions
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
Hello!
Could someone please give me a help/sample code, how to delete a file from s3 using waffle/waffle_ecto from Phoenix app.
I creat...
New
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
So my question is quite simple and i have found no conclusive answer on forum, google or AI.
Should we use :erlang.float for Integer to ...
New
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
If a change or preparation module uses Ash.Changeset.get_argument/2 or Ash.Query.get_argument/2 (or any of the other get_argument functio...
New
apply_graft/2 doesn’t rewrite an add_many sub-workflow’s deps on an add step. Grafted jobs cancel with “upstream job was deleted”
Version...
New
Other Trending Topics
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
New
Hobbes is a low-level distributed database for the Elixir programming language.
Hobbes provides a simple, safe, and scalable storage lay...
New
Hi there! We created Gust: A task orchestrator inspired by Airflow.
For those who have never heard about Aiflow, it’s a Python-based wor...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve.
They are GUI (Emerge) and State management (S...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixirconf-us
- #blog-post
- #ai
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #hex
- #security
- #metaprogramming










Showing Posts 1 to 2- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
voltone
If you are referring to the HTTP response to the proxy CONNECT request, then presumably an error means the proxy is not actually connecting you to the upstream server, so you won’t be able to complete a TLS handshake with it.
If you start the TLS handshake anyway, the ClientHello message will be interpreted by the proxy, which will likely respond with an error, which the TLS client will fail to interpret as handshake messages. Hence the
CLIENT ALERT: Fatal - Unexpected Messageresponse.Another issue with your sample code is that
:gen_tcp.recv(tcp, 0, 5000)is not guaranteed to consume the entire response to the CONNECT request. One way to ensure the entire HTTP response is read is by usingactive: false, packet: : http_binin the connect call, and then iterating over the:http_response,::http_headerand:http_eohmessages you’ll receive. Then you call:inet.setopts(tcp, packet: :raw), and if necessary read the request body (number of bytes indicated in the Content-Length header). Only then can you be actually sure that the TCP connection is ready for the handshake (provided the proxy returned a success response).toddholmberg
Thank you for the information, @voltone.
The
:gen_tcp.recvresults for hosts that are supposed to return a non-200 status code all return following:Is the
{:ok, {:http_response, {1, 1}, 200, "Connection established"}}maybe from the proxy, and then the rest of the request is timing out for hosts that return a 30X, 40X, 50X?Here is my updated test code. Does the following code example correctly implement what you are talking about?
How do I read the request body
:inet.setopts(tcp, packet: :raw)if there don’t seem to be any other headers available in the response?One very confusing aspect of this is that many of the hosts I am trying to connect to should return something other than a
200status code, but the http response is{:ok, {:http_response, {1, 1}, 200, "Connection established"}}and a resulting TLS error. Do you think this is further indication of a proxy issue? Maybe the proxy connection is closing?Thanks, again, for any insight into this.
FYI, I am using