Skip to content

Commit

Permalink
Refattor change to sue common function
Browse files Browse the repository at this point in the history
  • Loading branch information
martinsumner committed Jul 6, 2024
1 parent c7b5f0c commit ff83508
Showing 1 changed file with 14 additions and 19 deletions.
33 changes: 14 additions & 19 deletions src/riak_core_ssl_util.erl
Original file line number Diff line number Diff line change
Expand Up @@ -130,36 +130,31 @@ upgrade_client_to_ssl(Socket, App) ->
false ->
{error, no_ssl_config};
Config ->
ClientConfig =
lists:foldl(
fun(K, CfgAcc) ->
lists:keydelete(K, 1, CfgAcc)
end,
Config,
server_only_options()),
ssl:connect(Socket, ClientConfig)
ssl:connect(Socket, deduct_options(Config, server_only_options()))
end.

client_only_options() ->
[server_name_indication].

server_only_options() ->
[fail_if_no_peer_cert].

deduct_options(StandardOptions, SpecificOptions) ->
lists:foldl(
fun(K, CfgAcc) ->
lists:keydelete(K, 1, CfgAcc)
end,
StandardOptions,
SpecificOptions).

upgrade_server_to_ssl(Socket, App) ->
case maybe_use_ssl(App) of
false ->
{error, no_ssl_config};
Config ->
ServerConfig =
lists:foldl(
fun(K, CfgAcc) ->
lists:keydelete(K, 1, CfgAcc)
end,
Config,
client_only_options()),
ssl_handshake(Socket, ServerConfig)
ssl_handshake(
Socket, deduct_options(Config, client_only_options()))
end.

server_only_options() ->
[fail_if_no_peer_cert].

load_certs(undefined) ->
undefined;
Expand Down

0 comments on commit ff83508

Please sign in to comment.