Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
functions to extract SSL certs for Erlang SSL from ENV variables
def ssl_config do
ssl_config(client_cert, client_cert_key)
end
def ssl_config(_client_cert=nil, _client_cert_key=nil) do
[]
end
def ssl_config(client_cert, client_cert_key) do
[
ssl: [
cert: client_cert,
key: client_cert_key,
]
]
end
def client_cert do
case System.get_env("CLIENT_CERT") do
nil -> nil
cert -> extract_der(cert)
end
end
def client_cert_key do
case System.get_env("CLIENT_CERT_KEY") do
nil -> nil
cert_key -> extract_type_and_der(cert_key)
end
end
def decode_pem(pem) do
pem
|> :public_key.pem_decode
|> List.first
end
def extract_der(cert) do
{_type, der, _} = decode_pem(cert)
der
end
def extract_type_and_der(cert_key) do
{type, der_cert, _} = decode_pem(cert_key)
{type, der_cert}
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment