toddholmberg
Hello. I am trying to find the best way forward doing the following:
- Make an HTTPS request to an arbitrary URL.
- Make this request using a proxy.
- Be able to set the TLS/SSL protocol used for this connection.
- Be able to set the protocol-appropriate cipher used for this connection.
- Return the associated SSL certificate.
HTTPoison allows setting SSL options via its hackney foundation, but does not have return the SSL certificate with the response.
The Erlang :ssl library will allow setting the protocol and cipher for a request, but I am having trouble navigating the specifics of how to do this request via a proxy.
Has anyone had any experience making such a request and getting the associated SSL certificate? Thanks in advance for any advice.
Trending in Questions
Hey guys,
I’ve got a huge CSV ( around 10 GB ) that needs to be processed hourly
Do you guys have any suggestions what is the best prac...
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 have what I’ve heard referred to as a “lookup table” in my database. This is a way of assigning codes to common values. One common lo...
New
What approach to take when sending live updates to “random” users Hi! I have a question, I have a little chat app, and when I create a DM...
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
Anyone here using Honeybadger?
My Honeybadger account is being overwhelmed with noise from some bots. Seeing a lot of
Bandit.HTTPError...
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
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
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
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
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
There are three potential reasons for members of this forum to have a look at https://vutuv.de
You are tired or annoyed of LinkedIn.
Yo...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #blog-post
- #elixir-ls
- #elixirconf-us
- #ai
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #hex
- #security
- #metaprogramming











Showing Posts 1 to 7- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
voltone
Most HTTP clients abstract away the connection layer: they let you pass in the options to tune the connection establishment, but when they return the response they don’t include any connection information. Even Mint, which give you quite a lot of control over the lower layers, doesn’t let you extract the server certificate using a public API.
Having said that, it is possible to kind of make this work with HTTPoison. First of all, we’ll use ‘async’ mode, in which the response is delivered to a process mailbox. Then we’ll hook into the certificate verification callback and deliver the server cert (if it is valid) to the same mailbox in a custom message:
Update the proxy address as needed, and remember to update the destination hostname in two places: the URI at the top, and the hostname verification function further down. Of course you could wrap this in a function that takes care of this automatically.
The result might look something like this:
The certificate is sent as an Erlang record. You can convert it to other formats (DER, PEM) using the
:public_keymodule.Finally, keep in mind that not every HTTP request necessarily results in a TLS handshake, and therefore a peer certificate message. The HTTP client may keep the connection open for reuse by multiple HTTP requests, and even if a new connection is established, TLS session resumption may cause the handshake to be skipped (pass
reuse_sessions: falsein the ssl_options to prevent this).toddholmberg
Thank you, @voltone! This is exactly the help I needed. I will also be using your excellent X509 package to process the resulting certificate.
toddholmberg
One more boost for @voltone : couple this answer with the recursive approach in this blog post series by @alvises and you can pattern match on just the certificate and ignore the rest of the response chunks.
voltone
Well, if you don’t need the HTTP response at all you can take a few shortcuts. Drop the
stream_to: self()option, ignore the response fromHTTPoison.get(or check only for connection errors) and then see if you got a certificate:You can also change the method to HEAD, to avoid transferring data you’re going to throw away anyway.
At this point I’m wondering whether you need an HTTP client at all. You could just open a TCP connection to the proxy, send
"CONNECT some.host.name:443 HTTP/1.1\r\n\r\n", receive the"HTTP/1.1 200 Connection established\r\n\r\n"reply, then upgrade the connection to TLS with:ssl.connect/2with all the necessary ssl_options. If all goes well, call:ssl.peercert/1to get the peer certificate.You should now have the peer certificate in DER binary format.
toddholmberg
Thanks for this updated approach. To pass proxy authentication credentials, would you send a
Proxy-Authorizationstring along with theCONNECTstring? Something like::gen_tcp.send(tcp, "CONNECT some.host.name:443 HTTP/1.1\r\nProxy-Authorization: Basic #{:base64.encode_to_string('username:password')}\r\n")voltone
Something like that. But you’re missing the empty line at the end of the request there: you need another \r\n.
toddholmberg
Thanks, again, @voltone.. I really appreciate your help with this.