Using client certificates from a string with HTTPosion

Andy,

I’m a little late to the party but I believe you can do the following:

https: [
  cert: find_cert(),
  key: find_key()
]

def find_cert do 
  System.get_env("SSL_CERT") |> :public_key.pem_decode() |> hd() |> elem(1)
end

def find_key do 
  {type, encoded, _atom} = System.get_env("SSL_KEY") |> :public_key.pem_decode() |> hd()

  {type, encoded}
end

According to erlang’s documentation here: http://erlang.org/doc/man/public_key.html#pem_decode-1
This “Decodes PEM binary data and returns entries as ASN.1 DER encoded entities.”

We want to match the definition of ssl_option() here: http://erlang.org/doc/man/ssl.html
Which we do with the above functions. Let me know if this simplifies your code.

5 Likes