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]https://erlef.github.io/security-wg/secure_coding_and_deployment_hardening/ssl 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

srinivasu
How to handle excepions in elixir? Suppose i have A, B, C ,D, E modules. and each module has get() function. A.get() method will call th...
New
dotdotdotPaul
Okay, I'm having a heck of a time trying to figure out how to best handle the validation of belongs_to associations in Ecto. I'm sure I'...
New
joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 record...
New
_russellb
I want to try my hand at web scraping. What tools/libraries do I need to use. I’m hoping to turn this into something professional so don’...
New
sacepums
Hey guys. I'm new to elixir and im really stocked about it. But I ran into a bit of problem - I need to convert a date sting, for examp...
New
myronmarston
The Elixir Typespec docs show the following syntax for keyword lists in typespecs: # ... | [key: type] # keyword lis...
New
mcarvalho
What is the difference between System.get_env and Application.get_env? For example, what are best practices to use one versus another.
New
chensan
I have a User schema with a :from_id field set to type :string: defmodule TweetBot.Repo.Migrations.CreateUsers do use Ecto.Migration ...
New
fireproofsocks
Forgive me if this is obvious, but how does one delete a database record WITHOUT selecting it first? https://hexdocs.pm/ecto/Ecto.Repo.h...
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

Other popular topics Top

JDanielMartinez
Hi! May someone helps me, please! I have two apps into an umbrella project: the first one is Database, which manages queries, and the se...
New
dotdotdotPaul
Okay, I'm having a heck of a time trying to figure out how to best handle the validation of belongs_to associations in Ecto. I'm sure I'...
New
yawaramin
In the Dialyzer docs ( http://erlang.org/doc/man/dialyzer.html#requesting-or-suppressing-warnings-in-source-files ), there is a way to tu...
New
Jim
As a follow up to my earlier question: I have the code compiling and running but not getting a successful login from the rest server. ...
New
fireproofsocks
I’m working on defining a simple Ecto schema for a table (in PostGres), but I don’t see where I can define a column as NOT NULL. Conside...
New
alice
Hey, Just curious what are the main benefits of Elixir compared to Clojure? When is Elixir more useful than Clojure and vice versa? Th...
New
vonH
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
New
ovidiubadita
Hey all, I discovered Elixir and I love it. I always wanted to learn a functional programming and I intended to go for Haskell, but afte...
New
chrisalley
ExUnit now has describe blocks which is a welcome addition coming from RSpec. In the docs, it states that nested hierarchies of describe ...
New
AstonJ
by Lance Halvorsen Elixir and Phoenix are generating tremendous excitement as an unbeatable platform for building modern web application...
460 27162 124
New

We're in Beta

About us Mission Statement