diff options
author | Mark Felder <feld@feld.me> | 2024-09-14 20:03:26 -0400 |
---|---|---|
committer | Mark Felder <feld@feld.me> | 2024-09-14 20:36:24 -0400 |
commit | 5539fea3bb0d272b4cefc2b72755cb3cd285cc67 (patch) | |
tree | 411e925a4620b7aa974c010ba2d2b9a98bf8a94a /lib | |
parent | 7def11d7c352f13ce0f12715649359344cbba9a6 (diff) | |
download | pleroma-5539fea3bb0d272b4cefc2b72755cb3cd285cc67.tar.gz pleroma-5539fea3bb0d272b4cefc2b72755cb3cd285cc67.zip |
LDAP: permit overriding the CA root
Diffstat (limited to 'lib')
-rw-r--r-- | lib/pleroma/web/auth/ldap_authenticator.ex | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/lib/pleroma/web/auth/ldap_authenticator.ex b/lib/pleroma/web/auth/ldap_authenticator.ex index d31f34747..7f2cd3d69 100644 --- a/lib/pleroma/web/auth/ldap_authenticator.ex +++ b/lib/pleroma/web/auth/ldap_authenticator.ex @@ -42,11 +42,14 @@ defmodule Pleroma.Web.Auth.LDAPAuthenticator do ssl = Keyword.get(ldap, :ssl, false) sslopts = Keyword.get(ldap, :sslopts, []) tlsopts = Keyword.get(ldap, :tlsopts, []) + cacertfile = Keyword.get(ldap, :cacertfile) || CAStore.file_path() options = [{:port, port}, {:ssl, ssl}, {:timeout, @connection_timeout}] ++ if sslopts != [], do: [{:sslopts, sslopts}], else: [] + cacerts = decode_certfile(cacertfile) + case :eldap.open([to_charlist(host)], options) do {:ok, connection} -> try do @@ -58,7 +61,7 @@ defmodule Pleroma.Web.Auth.LDAPAuthenticator do Keyword.merge( [ verify: :verify_peer, - cacerts: :certifi.cacerts(), + cacerts: cacerts, customize_hostname_check: [ fqdn_fun: fn _ -> to_charlist(host) end ] @@ -147,4 +150,16 @@ defmodule Pleroma.Web.Auth.LDAPAuthenticator do error -> error end end + + defp decode_certfile(file) do + with {:ok, data} <- File.read(file) do + data + |> :public_key.pem_decode() + |> Enum.map(fn {_, b, _} -> b end) + else + _ -> + Logger.error("Unable to read certfile: #{file}") + [] + end + end end |