-
Notifications
You must be signed in to change notification settings - Fork 436
Open
Labels
Description
Currently to get mutual TLS working with my client certificate I had to:
- Manually add back the default SSL options for things like server certificate verification and maximum certificate chain length. I did it slightly differently than the readme recommends by calling
:hackney_connect.ssl_opts/2. - Manually append my client certificate's intermediate certificate to the certifi
cacertsso that my client certificate chain could be properly sent - Manually append my organization's custom CA certificate to
cacertswhich is used by our internal test server to test mutual TLS
The (Elixir) code looks like this:
def set_ssl_options(host) do
custom_options = [
versions: [:"tlsv1.2"],
certfile: client_certificate_path(),
keyfile: client_key_path()
]
# 1
default_hackney_options = :hackney_connect.ssl_opts(host, [])
merged_options = default_hackney_options ++ custom_options
# 2
[{:Certificate, certificate_chain_binary, :not_encrypted}] =
:public_key.pem_decode(client_intermediate_certificate())
# 3
[{:Certificate, custom_ca_binary, :not_encrypted}] =
:public_key.pem_decode(custom_ca_certificate())
merged_cacerts = default_hackney_options[:cacerts] ++ [certificate_chain_binary, custom_ca_binary]
Keyword.put(merged_options, :cacerts, merged_cacerts)
endI want to clean this up by:
- Getting hackney to add these default SSL options so I just have to add the options for the client certificate. I know the current behaviour is to override all the default SSL options if you provide your own but I think in some cases it'd still be good to have the default ones
- Adding a
client_chainoption that hackney will append tocacerts - Adding a
custom_caoption that hackney will append tocacerts
What do you think?