Skip to content

Commit bfb03f7

Browse files
committed
Fall back to system certs if neither cacertfile nor cacerts_pem_data
are provided to the `simple-bind` validation.
1 parent 3c79f6d commit bfb03f7

File tree

1 file changed

+28
-20
lines changed

1 file changed

+28
-20
lines changed

deps/rabbitmq_auth_backend_ldap/src/rabbit_auth_backend_ldap_mgmt.erl

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -117,16 +117,24 @@ tls_options(BodyMap) ->
117117
undefined ->
118118
{ok, []};
119119
SslOptionsMap ->
120+
CaCertfile = maps:get(<<"cacertfile">>, SslOptionsMap, undefined),
121+
CaCertPemData = maps:get(<<"cacert_pem_data">>, SslOptionsMap, undefined),
122+
TlsOpts0 = case {CaCertfile, CaCertPemData} of
123+
{undefined, undefined} ->
124+
[{cacerts, public_key:cacerts_get()}];
125+
_ ->
126+
[]
127+
end,
120128
%% NB: for some reason the "cacertfile" key isn't turned into an atom
121-
TlsOpts0 = case maps:get(<<"cacertfile">>, SslOptionsMap, undefined) of
129+
TlsOpts1 = case CaCertfile of
122130
undefined ->
123-
[];
131+
TlsOpts0;
124132
CaCertfile ->
125-
[{cacertfile, CaCertfile}]
133+
[{cacertfile, CaCertfile} | TlsOpts0]
126134
end,
127-
TlsOpts1 = case maps:get(<<"cacert_pem_data">>, SslOptionsMap, undefined) of
135+
TlsOpts2 = case CaCertPemData of
128136
undefined ->
129-
TlsOpts0;
137+
TlsOpts1;
130138
CaCertPems when is_list(CaCertPems) ->
131139
F0 = fun (P) ->
132140
case public_key:pem_decode(P) of
@@ -138,34 +146,34 @@ tls_options(BodyMap) ->
138146
end
139147
end,
140148
CaCertsDerEncoded = lists:filtermap(F0, CaCertPems),
141-
[{cacerts, CaCertsDerEncoded} | TlsOpts0];
149+
[{cacerts, CaCertsDerEncoded} | TlsOpts1];
142150
_ ->
143-
TlsOpts0
151+
TlsOpts1
144152
end,
145-
TlsOpts2 = case maps:get(<<"verify">>, SslOptionsMap, undefined) of
153+
TlsOpts3 = case maps:get(<<"verify">>, SslOptionsMap, undefined) of
146154
undefined ->
147-
TlsOpts1;
155+
TlsOpts2;
148156
Verify ->
149157
VerifyStr = unicode:characters_to_list(Verify),
150-
[{verify, list_to_existing_atom(VerifyStr)} | TlsOpts1]
158+
[{verify, list_to_existing_atom(VerifyStr)} | TlsOpts2]
151159
end,
152-
TlsOpts3 = case maps:get(<<"server_name_indication">>, SslOptionsMap, disable) of
160+
TlsOpts4 = case maps:get(<<"server_name_indication">>, SslOptionsMap, disable) of
153161
disable ->
154-
TlsOpts2;
162+
TlsOpts3;
155163
SniValue ->
156164
SniStr = unicode:characters_to_list(SniValue),
157-
[{server_name_indication, SniStr} | TlsOpts2]
165+
[{server_name_indication, SniStr} | TlsOpts3]
158166
end,
159-
TlsOpts4 = case maps:get(<<"depth">>, SslOptionsMap, undefined) of
167+
TlsOpts5 = case maps:get(<<"depth">>, SslOptionsMap, undefined) of
160168
undefined ->
161-
TlsOpts3;
169+
TlsOpts4;
162170
DepthValue ->
163171
Depth = rabbit_data_coercion:to_integer(DepthValue),
164-
[{depth, Depth} | TlsOpts3]
172+
[{depth, Depth} | TlsOpts4]
165173
end,
166-
TlsOpts5 = case maps:get(<<"versions">>, SslOptionsMap, undefined) of
174+
TlsOpts6 = case maps:get(<<"versions">>, SslOptionsMap, undefined) of
167175
undefined ->
168-
TlsOpts4;
176+
TlsOpts5;
169177
VersionStrs when is_list(VersionStrs) ->
170178
F1 = fun (VStr) ->
171179
try
@@ -176,7 +184,7 @@ tls_options(BodyMap) ->
176184
end
177185
end,
178186
Versions = lists:filtermap(F1, VersionStrs),
179-
[{versions, Versions} | TlsOpts4]
187+
[{versions, Versions} | TlsOpts5]
180188
end,
181-
{ok, TlsOpts5}
189+
{ok, TlsOpts6}
182190
end.

0 commit comments

Comments
 (0)