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
Hello!
Suppose you are building workflow (order / task / payment) processing system with the following requirements:
Each workflow con...
New
I’m aware of 2 such projects, are there others?
git: GitHub - team-alembic/realworld: A fullstack Phoenix LiveView application with back...
New
Hi all,
I’m working on a Phoenix project where I need to make external HTTP requests and I’m trying to choose between Req and HTTPoison....
New
Hi everyone.
My team and I have been working on a fairly modest app based around video streaming and chat, but we’ve landed a customer t...
New
Hi,
we run different LLM models across a cluster, with each node loading a configurable subset. Model-specific queues let nodes consume ...
New
Hi all, I’m new here and would like to hear peoples views on my Elixir/Phoenix based game-engine! :smiley:
Mutonex gamedesign was finish...
New
Do we have maintainer of absinthe-graphql/dataloader here? We have a PR that we’d like to merge to the library. Relatively small additive...
New
Other Trending Topics
Hey there,
I haven’t seen a list of useful Elixir specific skills for the popular AI tools yet so I’m starting one here with my first.
...
New
I fully migrated to my own harness from Anthropic/Gemini and I think it’s time to share it. Welcome DSH, the DeepSeek Harness, fully writ...
New
Hey. Is there anyone here who creates agents in their apps? Not talking about using agents, but creating them. I’m finding it pretty diff...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
With AI doing more of the implementation work, I’ve been wondering how much coding I should deliberately keep doing myself.
My main conc...
New
(I just needed to vent somewhere and LinkedIn is full of hope, or hype, I’m not sure which exactly)
AI dream has many faces, but general...
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
- #ai
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #blog-post
- #ecto-query
- #elixirconf-us
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #elixirconf-eu
- #api
- #forms
- #security
- #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.