Skip to content

Adding more SSL options for client certificates (Mutual TLS) #587

@MichaelViveros

Description

@MichaelViveros

Currently to get mutual TLS working with my client certificate I had to:

  1. 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.
  2. Manually append my client certificate's intermediate certificate to the certifi cacerts so that my client certificate chain could be properly sent
  3. Manually append my organization's custom CA certificate to cacerts which 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)
end

I want to clean this up by:

  1. 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
  2. Adding a client_chain option that hackney will append to cacerts
  3. Adding a custom_ca option that hackney will append to cacerts

What do you think?

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions