quatermain

quatermain

Hello,

I have to do requests to some APIs with 2-way-ssl, so every request has to by signed with our cert and private key. We uploaded our certificate to 3rd party servers which provide these APIs.

We put this options into HTTPoison call:

[{:Certificate, cert_der, :not_encrypted}] =
      File.read!("/cert/cert.pem") |> :public_key.pem_decode()

    key = File.read!("/cert/key.pem") |> :public_key.pem_decode() |> hd |> Tuple.delete_at(2)

    [
      ssl: [
        versions: [:"tlsv1.2"],
        verify: :verify_peer,
        cacertfile: CAStore.file_path(),
        cert: cert_der,
        key: key,
        depth: 3,
        customize_hostname_check: [
          match_fun: :public_key.pkix_verify_hostname_match_fun(:https)
        ]
      ]
    ]

When we do request, it looks like server doesn’t know how to process it. Because their api should response error in json format and we got only this:

<html>\n<body>\n<h1>Fault</h1>env:Receiverfault:MessageBlocked</body>\n</html>\n

I tried make request with Postman (NodeJS) with same certificate and private key and it works without problem.

Any ideas where can be problem? I asked on slack and @voltone gave me some good advice but I’m a little bit lost and looks like I did something wrong.

Thanks for any help or suggeston

Showing Posts 1 to 10

ityonemo

ityonemo

Maybe try using the certfile and keyfile (instead of cert and key) options instead of decoding them yourself

voltone

voltone

I was thinking about the same root cause: missing intermediate certificates for the client cert. But in that case I would expect the ‘cert.pem’ file to contain more than one certificate, and that would cause the pattern match on the first line to fail.

@quatermain are these the exact files you used with Postman? Or is there another file with additional CA certificates to go with your client certificate?

See also my reply in this thread.

quatermain

quatermain OP

These files are same as in Postman

I tried, same response.

I will try this and others tomorrow. It’s too late now here. Thanks guys

voltone

voltone

Hmm, so in that case it wouldn’t be an issue of missing intermediates.

The server’s response is not very helpful. If you make a request without client certificate at all, does the server throw a TLS alert, or do you get the same HTML error? I’m trying to understand whether the server is configured to handle mutual TLS auth issues at a higher protocol layer. Most (but not all) servers would reply with a TLS alert. Maybe everything is fine on the TLS layer, and you have a missing HTTP header (“Accept: application/json” ?).

There isn’t anything to try here if you do not have any intermediate CA certificates…

tangui

tangui

Also you may try with curl, setting verbosity level to its maximum (-v) to determine:

  • if TLS client authentication is optional or disabled
  • if TLS client authentication actually happens
  • if not (which means TLS client authentication is optional), why it fails

Feel free to post it here, it’s usually quite informative. Beware before posting results here, I’m don’t remember whether the debug messages contain the private key or not.

quatermain

quatermain OP

You are the winner. Their API documentation and Sandbox API use for all api calls “application/x-www-form-urlencoded” and their Production API use “application/json” but only for auth api call. Others look like use www-form.

FYI - API owner is group of banks, about 7 countries and 7 banks in EU. So… I will write horror/comedy book after all my NDA will end.

quatermain

quatermain OP

Update: not done, I got json response with message ID and status code 400, no other information. I thought it’s working because I need id from this response. But I need consent id and not message id. But it looks like problem with their system. Not sure where can be problem when I got error with:

env:Receiverfault:MessageBlocked

or another error with message id.

So this pain is still there and I will have to resolve it ASAP :confused: . I contacted support last week so I hope they will get us something this week.

Thanks guys

quatermain

quatermain OP

Update: support gave answer. Sandbox api use another API than production. We got new documentation for production API, so we have to update our code and test it on production.

quatermain

quatermain OP

another update. We tried API of another Bank, where has to be same (hope so) Mutual TLS and we got:

[info] TLS client: In state cipher received SERVER ALERT: Fatal - Handshake Failure

and

 ** (OAuth2.Error) {:tls_alert, {:handshake_failure, 'received SERVER ALERT: Fatal - Handshake Failure'}}

with this setup:

[
      ssl: [
        versions: [:"tlsv1.2"],
        verify: :verify_peer,
        cacertfile: CAStore.file_path(), #"/app/lib/castore-0.1.5/priv/cacerts.pem"
        certfile: "/cert/cert.pem",
        keyfile: "/cert/key.pem",
        depth: 3,
        customize_hostname_check: [
          match_fun: :public_key.pkix_verify_hostname_match_fun(:https)
        ]
      ]
    ]

Where Next? Top

Trending in Questions Top

katta
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
achenet
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
bradley
I really like the adapter patterns that ecto, nebulex, waffle, etc. use and would love find something similar for a key management servic...
New
unaware8150
Hello folks! So at work, we are seeing some situations where we have to define some “fixed” strings that are used across the codebase in...
New
Cxx-mlr
I’m working on a small exercise involving update_in/3, and I came up with this solution: data = %{ name: "Periodic Table", category:...
New
ChrisAmelia
I’ve got trouble wrapping my head around the order in which functions are called in this snippet (from Phoenix’s authentication): toke...
New
dillonoconnor
Is there any way to avoid the Hologram compiler running when using iex? It seems like the front-end code could potentially be disregarded...
New

Other Trending Topics Top

GenericJam
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
garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
budgie
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
KristerV
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
mudasobwa
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
mcass19
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews