willc0de4food
Hello,
I’m attempting to communicate with the Verisign EPP server over a TCP / SSL connection. This connection requires an SSL certificate, but I’m having trouble with the SSL certificate. I am inexperienced in working with anything like this, in the past all I’ve done is use Req to send various requests of different verbs. So has anyone written a library to make this easier? Or can anyone assist in the correct configuration of including an SSL certificate, sending a request and listening for a response? Here’s what I have so far, just shooting in the dark:
def ssl_client() do
host = Application.get_env(:appname, :epp_host) |> String.to_charlist()
port = Application.get_env(:appname, :epp_port)
cert = File.cwd!() <> "/ssl/cert.chain.pem"
{:ok, connect_socket} =
:ssl.connect(host, port, [verify: :verify_none, cacertfile: cert, active: true], :infinity)
connect_socket
end
defp listen_ssl(socket) do
case :ssl.recv(socket, 0) do
{:ok, line} ->
IO.puts(~s(Client got: "#{String.trim(line)}"))
:ok = :ssl.close(socket)
{:error, :closed} ->
IO.puts("Server closed socket.")
{:error, :enotconn} ->
IO.puts("Server is not connected.")
{:error, reason} ->
IO.puts("Server errored with code: #{reason}")
end
end
def send_ssl_request(line) do
socket = ssl_client()
:ssl.send(socket, line)
listen_ssl(socket)
end
The response that I get when I attempt to call send_ssl_request() is:
TLS :client: In state :connection received SERVER ALERT: Fatal - Bad Certificate
Thanks!
Trending in Questions
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
Hello,
I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
So my question is quite simple and i have found no conclusive answer on forum, google or AI.
Should we use :erlang.float for Integer to ...
New
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
Documentation
While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
If a change or preparation module uses Ash.Changeset.get_argument/2 or Ash.Query.get_argument/2 (or any of the other get_argument functio...
New
Other Trending Topics
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
New
Hi there! We created Gust: A task orchestrator inspired by Airflow.
For those who have never heard about Aiflow, it’s a Python-based wor...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
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
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
- #hex
- #security
- #metaprogramming










Showing Posts 1 to 10- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
zacksiri
Your configuration for the certificate looks correct, however any reason you are setting
verify: :verify_noneinstead ofverify: :verify_peer?Also if you try
cacerts: :public_key.cacerts_get()instead of passing in your own cert what happens?willc0de4food
I used
:verify_nonebecause if I use:verify_peer, I get the following error:~c"TLS client: In state wait_cert at ssl_handshake.erl:2180 generated CLIENT ALERT: Fatal - Unknown CA\n"If I try
cacerts: :public_key.cacerts_get()I get the same error:TLS :client: In state :connection received SERVER ALERT: Fatal - Bad CertificateI assume that’s because it doesn’t have a certificate, or the certificate it does have isn’t for the domain I need to authenticate.
If I do
:public_key.cacerts_load(cert), I get:ok, but then withcacerts: :public_key.cacerts_get()I still get the same error:TLS :client: In state :connection received SERVER ALERT: Fatal - Bad Certificatemuelthe
A couple of things that have caught me out in the past, one being when using
:public_key_cacerts_get()I didn’t have the certificate store configured correctly on my host machine.Second, I’ve found that I also need to include the
server_name_indication(SNI) in my ssl opts (some info here on SNI: https://www.cloudflare.com/learning/ssl/what-is-sni/).willc0de4food
What type of value should I provide for the SNI? The only thing I see listed in the Erlang docs are
disableI tried providing a string with the domain (
server_name_indication: "domain.ext"), but that produces an error.This could be what I need, though. I’ve added
certs_keys: [...]to the options and I’m gettingTLS :client: In state :connection received SERVER ALERT: Fatal - Certificate Unknownmuelthe
Yep you have it right, but I think you have to provide it as a charlist, so:
~c"foo.bar.com"(ref: Binaries, strings, and charlists — Elixir v1.20.2)willc0de4food
This worked for the SNI value, however; it didn’t resolve the problem
I’m still getting
Fatal - Certificate UnknownHow do I specify the version of TLS to use? I’ve tried appending the following to the options to no avail:
versions: ["tlsv1.2"],versions: [~c"tlsv1.2"],versions: ["tlsv1_2"],versions: [~c"tlsv1_2"]// Update
Finally found the correct format, it’s:
versions: [:"tlsv1.2"]Sadly, I’m still getting errors. When I try
verify: :verify_peer, cacerts: :public_key.cacerts_get()I get this error:
{:tls_alert, {:unknown_ca, ~c"TLS client: In state certify at ssl_handshake.erl:2180 generated CLIENT ALERT: Fatal - Unknown CA\n"}}When I try
verify: :verify_none, certs_keys: [%{certfile: cert, keyfile: key}],I get this error:
{:tls_alert, {:certificate_unknown, ~c"TLS client: In state cipher received SERVER ALERT: Fatal - Certificate Unknown\n"}}I don’t think it’s an issue with the cert / key, as when I test them with the openssl command, I seem to get a successful response, so I’m at a loss:
openssl s_client -connect domain.com:700 -cert cert.pem -key key.pem -tls1_2This is my current function code:
D4no0
On what are you running this server? It might be possible that you are missing the client certificates on your deployed system, the symptom usually is that it works on dev envs but fails on deployed server.
To check that fast, you can try adding castore to your project and use the provided certs by
castorewith:CAStore.file_path()muelthe
Had a chance to test it myself.
It worked using the options setup below and I didn’t need to use the SNI. I think as mentioned before and as @D4no0 indicated, there might be an issue with the application host certificate store i.e. wherever you’re running this from (obviously, I don’t know where you’re connecting to, so I used a fairly well-known address!).
Edit: you might still need the SNI depending on what you’re connecting to.
For example, say you’re using
maps.google.com, you’re SNI value could be*.google.comthat’s just a contrived example.willc0de4food
This isn’t deployed anywhere, I’m working on my localhost. So I can’t even get it to work locally
Good to know about the SNI value, I misunderstood what was needed there so I’ll modify that and give it a try. I’ll also try reducing the options and seeing if that has any effect. Thanks!
willc0de4food
I finally found the right combination of options to get it working. What a pain! Somehow this ended up working:
I received a file with 1 key & 3 certs. I tried separating each cert into it’s own file, but the working combination was to have the 3 certs in 1 file, and the key in another.