Sending / receiving TCP requests with SSL certificate

This worked for the SNI value, however; it didn’t resolve the problem :slightly_frowning_face: I’m still getting Fatal - Certificate Unknown

How 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_2

---
SSL handshake has read 10844 bytes and written 1790 bytes
Verification: OK
---
New, TLSv1.2, Cipher is ECDHE-RSA-AES256-GCM-SHA384
Server public key is 2048 bit
Secure Renegotiation IS supported
Compression: NONE
Expansion: NONE
No ALPN negotiated
SSL-Session:
    Protocol  : TLSv1.2
    Cipher    : ECDHE-RSA-AES256-GCM-SHA384
    Session-ID: AD15B5B774CE0C8D76B920B165F72C03DE1F1B0CEF8CCD8FC229A3008E6C0497
    Session-ID-ctx: 
    Master-Key: RedactedReallyLongString
    PSK identity: None
    PSK identity hint: None
    SRP username: None
    Start Time: 1724396369
    Timeout   : 7200 (sec)
    Verify return code: 0 (ok)
    Extended master secret: yes
---

This is my current function code:

  def ssl_start() do
    host = Application.get_env(:appname, :epp_host) |> String.to_charlist()
    port = Application.get_env(:appname, :epp_port)
    cert = File.cwd!() <> "/ssl/server/cert.pem"
    key = File.cwd!() <> "/ssl/server/key.pem"
    :public_key.cacerts_load(cert)

    opts = [
      # verify: :verify_peer,
      # cacerts: :public_key.cacerts_get(),
      verify: :verify_none, certs_keys: [%{certfile: cert, keyfile: key}],
      reuseaddr: true,
      server_name_indication: ~c"domain.ext",
      versions: [:"tlsv1.2"]
    ]

    :ssl.start()

    case :ssl.connect(host, port, opts, 5000) do
      {:ok, socket} ->
        socket

      {:error, err} ->
        dbg(err)
        nil
    end
  end