Skip to content

Commit

Permalink
Merge pull request #26 from zdaniel86/otp-26-migration
Browse files Browse the repository at this point in the history
make default cacerts connection options
  • Loading branch information
carlisom authored May 21, 2024
2 parents 8e34985 + 05159e8 commit 405c9bf
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
5 changes: 4 additions & 1 deletion rebar.config
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
{erl_opts, [debug_info]}.
{erl_opts, [
debug_info,
{platform_define, "^2[5-9]", cacerts}
]}.
{cover_enabled, true}.
{eunit_opts, [verbose, {report,{eunit_surefire,[{dir,"."}]}}]}.
{cover_enabled, true}.
Expand Down
24 changes: 23 additions & 1 deletion src/lhttpc_client.erl
Original file line number Diff line number Diff line change
Expand Up @@ -164,10 +164,11 @@ execute(From, Host, Port, Ssl, Path, Method, Hdrs0, Body, Options) ->
true ->
DefSslOptions = application:get_env(lhttpc, ssl_options, []),
UserSslOptions = proplists:get_value(ssl_options, Options, []),
EffectiveSslOpts = lists:ukeymerge(1,
EffectiveSslOpts0 = lists:ukeymerge(1,
lists:ukeysort(1, UserSslOptions),
lists:ukeysort(1, DefSslOptions)
),
EffectiveSslOpts = add_cacerts(EffectiveSslOpts0),
EffectiveTcpOptions ++ EffectiveSslOpts;
false ->
EffectiveTcpOptions
Expand Down Expand Up @@ -972,3 +973,24 @@ fix_inet_options(Options) ->
end;
(Option) -> {true, Option}
end, Options).

-ifdef(cacerts).
add_cacerts(ConnOpts) ->
case proplists:get_value(cacerts, ConnOpts) of
undefined ->
case proplists:get_value(verify, ConnOpts) of
verify_none ->
%% don't retrieve system certificates if verify option
%% is explicitly set to verify_none.
ConnOpts;
_ ->
%% Calling the `public_key:cacerts_get()` can be avoided
%% if either {cacerts, ...} or {verify, verify_none} are
%% configured
[{cacerts, public_key:cacerts_get()} | ConnOpts]
end;
_ -> ConnOpts
end.
-else.
add_cacerts(ConnOpts) -> ConnOpts.
-endif.

0 comments on commit 405c9bf

Please sign in to comment.