Skip to content

Commit b7065aa

Browse files
yordiskinyoklion
andauthored
feat: For otp 25+ use public_key:cacerts_get for the default certificate list. (#114)
closes #113 Signed-off-by: Yordis Prieto <[email protected]> --------- Co-authored-by: Ryan Lamb <[email protected]>
1 parent 124544e commit b7065aa

File tree

2 files changed

+51
-19
lines changed

2 files changed

+51
-19
lines changed

src/ldclient_config.erl

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,27 @@ get_event_schema() ->
281281
%% @end
282282
-spec tls_basic_options() -> [ssl:tls_client_option()].
283283
tls_basic_options() ->
284-
tls_basic_options(filelib:is_regular(?HTTP_DEFAULT_LINUX_CASTORE)).
284+
case erlang:list_to_integer(erlang:system_info(otp_release)) >= 25 of
285+
true -> tls_basic_erlef_options();
286+
false -> tls_basic_options(filelib:is_regular(?HTTP_DEFAULT_LINUX_CASTORE))
287+
end.
288+
289+
%% The public_key:cacerts_get function does not exist prior to OTP 25, so we
290+
%% need to ignore the warning when building code that will not be using it.
291+
-dialyzer({no_missing_calls, tls_basic_erlef_options/0}).
292+
293+
%% @doc Provide basic options for using TLS with the default OTP 25+.
294+
%% Follows the recommendations from the Erlang Security Working Group.
295+
%% https://erlef.github.io/security-wg/secure_coding_and_deployment_hardening/ssl
296+
%%
297+
%% @end
298+
-spec tls_basic_erlef_options() -> [ssl:tls_client_option()].
299+
tls_basic_erlef_options() ->
300+
CaCerts = public_key:cacerts_get(),
301+
[
302+
{cacerts, CaCerts}
303+
| tls_base_options()
304+
].
285305

286306
%% @doc Provide basic options for using TLS with the default linux store.
287307
%% This will try to use the a certificate store located at

test/ldclient_config_SUITE.erl

Lines changed: 30 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -133,24 +133,36 @@ get_http_options_multiple_options(_) ->
133133
} = maps:get(http_options, Settings, undefined).
134134

135135
tls_basic_options(_) ->
136-
BasicOptions = ldclient_config:tls_basic_options(),
137-
case os:type() of
138-
{unix, linux} ->
139-
[
140-
{cacertfile, "/etc/ssl/certs/ca-certificates.crt"},
141-
{verify, verify_peer},
142-
{ciphers, Ciphers},
143-
{depth, 3},
144-
{customize_hostname_check, _}] = BasicOptions,
145-
true = (length(Ciphers) =/= 0);
146-
{_, _} ->
147-
[
148-
{cacerts, _},
149-
{verify, verify_peer},
150-
{ciphers, Ciphers},
151-
{depth, 3},
152-
{customize_hostname_check, _}] = BasicOptions,
153-
true = (length(Ciphers) =/= 0)
136+
case erlang:list_to_integer(erlang:system_info(otp_release)) >= 25 of
137+
true ->
138+
BasicOptions = ldclient_config:tls_basic_options(),
139+
CaCerts = public_key:cacerts_get(),
140+
[{cacerts, CaCerts},
141+
{verify, verify_peer},
142+
{ciphers, Ciphers},
143+
{depth, 3},
144+
{customize_hostname_check, _}] = BasicOptions,
145+
true = (length(Ciphers) =/= 0);
146+
false ->
147+
BasicOptions = ldclient_config:tls_basic_options(),
148+
case os:type() of
149+
{unix, linux} ->
150+
[
151+
{cacertfile, "/etc/ssl/certs/ca-certificates.crt"},
152+
{verify, verify_peer},
153+
{ciphers, Ciphers},
154+
{depth, 3},
155+
{customize_hostname_check, _}] = BasicOptions,
156+
true = (length(Ciphers) =/= 0);
157+
{_, _} ->
158+
[
159+
{cacerts, _},
160+
{verify, verify_peer},
161+
{ciphers, Ciphers},
162+
{depth, 3},
163+
{customize_hostname_check, _}] = BasicOptions,
164+
true = (length(Ciphers) =/= 0)
165+
end
154166
end.
155167

156168
tls_with_ca_certfile_options(_) ->

0 commit comments

Comments
 (0)