DennisKh

DennisKh

TLS client: In state cipher received SERVER ALERT: Fatal - Unknown CA for Apple Pay Payment Session

Hi all,
I’m stuck with a problem and would really appreciate any feedback or ideas you might have.

I followed the official documentation Apple Pay on the Web and finally got the Payment Processing Certificate (.cer) and the .p12 certificate. Then I extracted the certificate and the key from .p12 cert into 2 separate files.

The problem

I’m trying to start Payment Session via Httposon.post request like

   opts = [
       {:certfile, "priv/cert/apple_pay.cert.pem"},
       {:keyfile, "priv/cert/apple_pay.key.pem"},
       {:versions, [:"tlsv1.2"]},
     ]
    with %{body: response} <- HTTPoison.post("#{validation_url}/paymentSession", body,
                                      [{"Content-Type", "application/json"}],
                                      ssl: opts),
      {:ok, result} <- Jason.decode(response) do
        IO.inspect(result)
    else
      _ -> false
    end

Error

[info] TLS client: In state cipher received SERVER ALERT: Fatal - Unknown CA

{:error, %HTTPoison.Error{id: nil, reason: {:tls_alert, 'unknown ca'}}}

Marked As Solved

DennisKh

DennisKh

I finally figured out what the problem was.
I made a mistake in the beginning when creating certificates. The problem was that I did not have all the necessary additional certificates installed, namely:

Then I created new certificates and everything worked!
But now I have a new challenge. I need to decrypt the encrypted payment data as described here.
I found a sample code on JS, but I didn’t figure out how to rewrite it on Elixir.
I would be very grateful if you would show me a sample code on Elixir.

Also Liked

voltone

voltone

The server is saying it can’t accept your client certificate because it cannot build a trust chain to a trusted root CA. I’m guessing the p12 file contains not just an end certificate, but also one or more intermediate CAs. The server is expecting you to send the full chain, but in your current configuration only the end certificate is sent.

The challenge here is that Erlang’s :ssl application uses the cacerts / cacertfile option both as the local trust store (the root CA certificates it checks the server certificate against) and as a pool of intermediate CAs that may be sent with the client certificate. What’s more, HTTPoison (or rather Hackney) will set cacerts to its CA trust store, but only if you didn’t specify any ssl options of your own. Since you want to set a client certificate, you need to pass in a bunch of extra options to enable server certificate verification, or you’ll be susceptible to MitM attacks. See [here]Erlang standard library: ssl | EEF Security WG and here for details.

The simplest way to get this working is to find out what is the root CA you need to talk to Apple, and put it in a file together with any intermediate CAs from the p12 file. Then add verify: :verify_peer, cacertfile: <path-to-your-new-file>, ... to the ssl options.

If you don’t want to pin the connection to one root CA, you could load the intermediate certificates into memory in DER format, and then pass verify: :verify_peer, cacertfile: [int_ca1_der, int_ca2_der | :certifi.cacert().

Where Next?

Popular in Questions Top

rms.mrcs
Hi, I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list. ...
New
electic
Hi, I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
Brian
What is the proper way to load a module from a file in to IEX? In the python world, doing something like this pretty standard: from ....
New
openscript
Hello! Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New
Fl4m3Ph03n1x
About me? ( if you have nothing better to do than reading about some random guy in the internet :stuck_out_tongue: ) Hello all, this is ...
New
WestKeys
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New

Other popular topics Top

KronicDeth
Elixir plugin for JetBrain’s IntelliJ Platform (including Rubymine) This is a plugin that adds support for Elixir to JetBrains IntelliJ...
289 36654 110
New
aadeshere1
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible. total = 10 while total != 0 ...
New
chrismccord
Phoenix 1.4.0 released Phoenix 1.4 is out! This release ships with exciting new features, most notably with HTTP2 support, improved deve...
688 31494 112
New
WestKeys
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New
romenigld
I am trying to run a deploy with docker and I successfully runned with this command: docker build -t romenigld/blog-prod . but when I t...
New
sergio
Kind of like when jquery came out, it was super necessary. Existing drag and drop libraries have a bunch of baggage to support old browse...
New

We're in Beta

About us Mission Statement