Thank you guys very much! public_key is definitely the library I want to use. I am not sure I even need the RSA library/application which is great.
I am totally inexperienced with Erlang unfortunately and cannot seem to get it all working via iex. I am wondering what I am doing wrong.
Here’s what I got:
Application.ensure_all_started :inets
Application.ensure_all_started :ssl
\# amazon cert chain
{:ok, resp} = :httpc.request(:get, {'https://s3.amazonaws.com/echo.api/echo-api-cert.pem', []}, [], [body_format: :binary])
{{_, 200, 'OK'}, _headers, certificate_chain_bin} = resp
cert_chain = :public_key.pem_decode(certificate_chain_bin)
\# root cert
{:ok, resp} = :httpc.request(:get, {'https://www.symantec.com/content/dam/symantec/docs/other-resources/verisign-class-3-public-primary-certification-authority-g5-en.pem', []}, [], [body_format: :binary])
{{_, 200, 'OK'}, _headers, root_cert} = resp
[root_cert_decoded] = :public_key.pem_decode(root_cert)
foo = :public_key.pkix_path_validation(root_cert_decoded, cert_chain, nil)
No matter what I put in (nil, or a function call, etc…) it is returning with an error of some sort.
It looks like the erlang library is asking me to pass a function as part of the options but when I try to send it, it complains. I have tried looking at the Erlang codebase but could not identify the problem (let alone if I am using the correct version of Erlang :)). Thoughts on what I am doing wrong?
I have also tried the following but to no avail:
verify_fun = fn(cert, event, state) -> { :valid, state} end
foo = :public_key.pkix_path_validation(:RSA, cert_chain, [{:verify_fun, verify_fun}])
Docs are here:
http://erlang.org/doc/man/public_key.html#pkix_path_validation-3
Thanks in advance if you are able to figure out what I am doing wrong!