thousandsofthem
Hi there,
I’ve encountered ssl handshake issue, details:
Elixir 1.4.2, Erlang 19.3
code:
HTTPoison.get("https://api.searchads.apple.com/...", [], [ssl: [keyfile: "...pem", certfile: "...cert.pem", ]])
# [error] SSL: :certify: tls_connection.erl:715:Fatal error: handshake failure - malformed_handshake_data
This specific query works perfectly fine via curl and python.
After investigating a bit (wireshark etc), the exact issue was found: server wants specifically TLS_RSA_WITH_AES_128_GCM_SHA256
… aaand elixir/erlang do not list such thing in its handshake
:ssl.cipher_suites(:openssl)
['ECDHE-ECDSA-AES256-GCM-SHA384', ...] #- no mentions of required chipher
:ssl.cipher_suites(:erlang)
[{:ecdhe_ecdsa, :aes_256_gcm, :null, :sha384},
{:ecdhe_rsa, :aes_256_gcm, :null, :sha384},
...
{:rsa, :aes_128_gcm, :null, :sha256} # <-- that's it
Also, present in the source code: otp/lib/ssl/src/ssl_cipher.erl at maint-19 · erlang/otp · GitHub
Still, i can’t switch it on:
... , versions: [:'tlsv1'], ciphers: ["TLS-RSA-WITH-AES-128-GCM-SHA256"] # -> same error
... , versions: [:'tlsv1'], ciphers: ["TLS_RSA_WITH_AES_128_GCM_SHA256"] # -> same error
... , versions: [:'tlsv1'], ciphers: [{:rsa, :aes_128_gcm, :null, :sha256}] # -> same error
... , ciphers: [{:rsa, :aes_128_gcm, :null, :sha256}] # -> same error
etc
Wireshark confirms elixir/erlang still sending list of cipher suits that not intersect with desired cipher (weirdly, it is different a bit each time, adding/removing some useless outdated ciphers).
Behavior confirmed on OSX brew installation and linux docker one (alpine)
Any thoughts how to proceed?
Trending in Questions
Other Trending Topics
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
- #ai
- #elixirconf-us
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #elixirconf-eu
- #metaprogramming
- #hex










Showing Posts 14 to 5- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
thousandsofthem
Unfortunately don’t work for me, there are some another issue persists. Using wrapped
curlfor nowperrautc
I was having this same problem. The solutions provided here worked if you’re using a weak encryption AES128 but does not work for AES256.
HTTPoison supports the full list of SSL supported by erlang’s ssl. To get HTTPoison to work correctly with ssl specify the options like this.
HTTPoison.get! “https://google.com”, , [ssl: [ciphers: [“ECDHE-ECDSA-AES128-SHA256”,“ECDHE-ECDSA-AES128-SHA”]]]
that should solve the problem.
thousandsofthem
That’s actually useful, thanks!

opensslsays all good, 1st one (out of 3 bundled) is personal and others are intermediate (which is expected).And of course i’ve tried it this way, always getting
handshake failure - malformed_handshake_dataas a response. I fear the root is deeper, maybe some misbehaving elliptic curve or something like that, and that’s not distro-dependent (tried various OSes, erlang versions, including 18.x). It wastes way too much timevoltone
You can verify each of the PEM certificates by copy & pasting them (one at a time) into
openssl x509 -text -noout: presumably if something is wrong with the PEM file contents, OpenSSL would also throw an error. In the output, note the subject and issuer, so you’ll know which PEM certificate is which, i.e. which one needs to be referenced fromcertfileand which ones need to go in the CA store.The server tells me (when connecting using
openssl s_client -connect api.searchads.apple.com:443) that it expects a client certificate that can be traced back to one of these root CAs:Presumably the intermediate CAs linking your end-certificate to one of these root CAs are in the PEM file.
voltone
I can’t remember if I ever tried using the
ssl_verify_funpackage myself, but I have tried Erlang/OTP 20’s built-in:public_key.pkix_verify_hostnameand it seems to work as advertised:https://blog.voltone.net/post/11
Azolo
I agree, even after looking at and trying to replicate hackney’s implementation for SSL connections, I still can’t get SSL connections working correctly.
It’s absolutely mind-boggling how crazy it is to establish a client SSL connection.
thousandsofthem
Thanks for the tip.
The most powerful, flexible, counterintuitive and illogical ssl implementation i’ve encountered.
providing cacerts as
cacerts: [cert1, cert2]doesn’t work either, producing the sameSSL WARNING: Ignoring a CA cert as it could not be...warning per line +handshake failureorreason: :closed:public_key.pem_decodeworks just fine, producing parsed data. tried some other formats - no luck as well.At this moment i gave up and just wrote wrapper which uses
Thanks everyone!
curl.Azolo
Instead of using the
:cacertfileuse the:cacertsoption.SSL in Erlang is the most confusing thing ever.
thousandsofthem
Thank you, that could be the reason. Certificate contains 3
CERTIFICATEsections. Playing with it atm.No progress so far though
decoded numbers:
SSL WARNING: Ignoring a CA cert as it could not be(probably ends withcorrectly decoded)Probably i’m not doing something right, just extracted one section to separate file and included other two as cacert.
Looks like it’s correct direction to dig in, thanks @voltone
P.S. cURL’s cacert bundle didn’t help as well
voltone
This is a bit of a long shot, but… the server requires a client certificate, and I’ve seen lots of unhelpful alert responses and log messages when things go wrong with client certs.
Does the client certificate include an intermediate cert? The way Erlang builds the chain of certs that is sent to the server is a bit different from some other tools. Instead of just sending all the certificates it finds in the PEM file, it expects to find just the end-certificate in there. It then scans the
cacertsfile (the same one that holds the trusted roots for verifying the server) for any intermediates that can be chained to it.So, if the client cert file does indeed contain more than one cert, did you copy the intermediate CAs to the
cacertsfile?