wgwz
wgwz

Reputation: 2769

Obtaining SSL cert using Elixir and Erlang ssl module

I'm trying to validate my websites SSL certificate with help from the tls_certificate_check library, Elixir and some calls to the Erlang :ssl module. The end goal is get the expiration date of the certificate, and maybe some other metadata. Here is my code:

defmodule ElixirSslCheck do
  def check do
    host = "www.lawlorbagcal.org"
    options = :tls_certificate_check.options(host)
    :ssl.connect(host, 443, options, 5000)
  end
end

Upon running this in iex, I'm seeing this output:

iex(4)> ElixirSslCheck.check                    
{:error,
 {:options,
  {:socket_options,
   [packet_size: 0, packet: 0, header: 0, active: false, mode: :binary]}}}

I don't understand what this means. Reading the docs about the :ssl.connect function, I see that the spec says I should be receiving reason in the error tuple:

 connect(Host, Port, TLSOptions, Timeout) ->
           {ok, sslsocket()} |
           {ok, sslsocket(), Ext :: protocol_extensions()} |
           {error, reason()} |
           {option_not_a_key_value_tuple, any()}

What I'm getting back does not seem to be a reason. I'm making use of the tls_certificate_check library because I thought that the TLS options it provided would help me get past any weird issues related to my SSL certificate. That said, it's wildcard let's encrypt certificate.

Can anyone help me to debug this further and get me headed in the right direction? Once I am getting past the connection issue, I was thinking the next step is to make a call to :ssl.peer_cert and I'm assuming that will lead me to certificate expiration date, among other things.

Upvotes: 4

Views: 1193

Answers (1)

wgwz
wgwz

Reputation: 2769

It turns out that I should be using a charstring and not a string for the host parameter:

defmodule ElixirSslCheck do
  def check do
    host = 'www.lawlorbagcal.org'
    options = :tls_certificate_check.options(host)
    :ssl.connect(host, 443, options, 5000)
  end
end

The difference is to use single-quote instead of double-quote. This has nothing to do with the :tls_certificate_check library.

Upvotes: 3

Related Questions