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
I having some trouble figuring out if I have set myself too strict of standards for my production server. Currently I can handle 75% of r...
New
Documentation
While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
Hello,
I’m trying to build a basic Phoenix web-app, and I’d like to use Tailwind.
However, when I launch mix phx.server, I get an error...
New
Hi everyone,
I am toying with the idea of building a “match maker” for giving personal help to people that wants to start coding.
I sta...
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
I recently noticed that Elixir’s Logger defaults its primary log level to :debug when no :logger, :level application configuration is pre...
New
So i have been using ash framework for a while and i love it. However currently the issue im having with ash framework is the error handl...
New
Other Trending Topics
Edit: 2026 May 15 - This post is archived.
Mob is alive!!
Main docs: mob v0.7.11 — Documentation
A bit of explanation for the slightly c...
New
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
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 everyone!
The first release candidate for the Expert language server project is now available!
We’ve published a press release detai...
New
A little off-topic, but I feel like people here have a good head on their shoulders.
I used to be quite good at making software. Was luc...
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
- #ai
- #ecto-query
- #elixirconf-us
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #elixirconf-eu
- #api
- #forms
- #metaprogramming
- #hex











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.