Provide specific f. to fix client ssl options
Provides a specific function to fix client ssl options, i.e.: apply all fixes that are applied for TLS listeneres and clients on previous versions but also sets `cacerts` option to CA certificates obtained by `public_key:cacerts_get`, only when no `cacertfile` or `cacerts` are provided.
This commit is contained in:
parent
f4e689310f
commit
3ff7e82c5c
|
@ -105,7 +105,8 @@ init([Sup, ConnConfig]) when is_map(ConnConfig) ->
|
||||||
{ok, expecting_connection_pid, State}
|
{ok, expecting_connection_pid, State}
|
||||||
end.
|
end.
|
||||||
|
|
||||||
connect(Address, Port, #{tls_opts := {secure_port, Opts}}) ->
|
connect(Address, Port, #{tls_opts := {secure_port, Opts0}}) ->
|
||||||
|
Opts = rabbit_ssl_options:fix_client(Opts0),
|
||||||
case ssl:connect(Address, Port, ?RABBIT_TCP_OPTS ++ Opts) of
|
case ssl:connect(Address, Port, ?RABBIT_TCP_OPTS ++ Opts) of
|
||||||
{ok, S} ->
|
{ok, S} ->
|
||||||
{ssl, S};
|
{ssl, S};
|
||||||
|
|
|
@ -137,7 +137,7 @@ do_connect({Addr, Family},
|
||||||
[Family | ?RABBIT_TCP_OPTS] ++ ExtraOpts,
|
[Family | ?RABBIT_TCP_OPTS] ++ ExtraOpts,
|
||||||
Timeout) of
|
Timeout) of
|
||||||
{ok, Sock} ->
|
{ok, Sock} ->
|
||||||
SslOpts = rabbit_ssl_options:fix(
|
SslOpts = rabbit_ssl_options:fix_client(
|
||||||
orddict:to_list(
|
orddict:to_list(
|
||||||
orddict:merge(fun (_, _A, B) -> B end,
|
orddict:merge(fun (_, _A, B) -> B end,
|
||||||
orddict:from_list(GlobalSslOpts),
|
orddict:from_list(GlobalSslOpts),
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
-module(rabbit_ssl_options).
|
-module(rabbit_ssl_options).
|
||||||
|
|
||||||
-export([fix/1]).
|
-export([fix/1]).
|
||||||
|
-export([fix_client/1]).
|
||||||
|
|
||||||
|
|
||||||
-define(BAD_SSL_PROTOCOL_VERSIONS, [
|
-define(BAD_SSL_PROTOCOL_VERSIONS, [
|
||||||
|
@ -22,6 +23,27 @@ fix(Config) ->
|
||||||
fix_ssl_protocol_versions(
|
fix_ssl_protocol_versions(
|
||||||
hibernate_after(Config))).
|
hibernate_after(Config))).
|
||||||
|
|
||||||
|
-spec fix_client(rabbit_types:infos()) -> rabbit_types:infos().
|
||||||
|
fix_client(Config) ->
|
||||||
|
fix_cacerts(
|
||||||
|
fix(Config)).
|
||||||
|
|
||||||
|
fix_cacerts(SslOptsConfig) ->
|
||||||
|
CACerts = proplists:get_value(cacerts, SslOptsConfig, undefined),
|
||||||
|
CACertfile = proplists:get_value(cacertfile, SslOptsConfig, undefined),
|
||||||
|
case {CACerts, CACertfile} of
|
||||||
|
{undefined, undefined} ->
|
||||||
|
try public_key:cacerts_get() of
|
||||||
|
CaCerts ->
|
||||||
|
[{cacerts, CaCerts} | SslOptsConfig]
|
||||||
|
catch
|
||||||
|
_ ->
|
||||||
|
SslOptsConfig
|
||||||
|
end;
|
||||||
|
_CaCerts ->
|
||||||
|
SslOptsConfig
|
||||||
|
end.
|
||||||
|
|
||||||
fix_verify_fun(SslOptsConfig) ->
|
fix_verify_fun(SslOptsConfig) ->
|
||||||
%% Starting with ssl 4.0.1 in Erlang R14B, the verify_fun function
|
%% Starting with ssl 4.0.1 in Erlang R14B, the verify_fun function
|
||||||
%% takes 3 arguments and returns a tuple.
|
%% takes 3 arguments and returns a tuple.
|
||||||
|
|
|
@ -205,7 +205,7 @@ do_http_req(Path0, Query) ->
|
||||||
ssl_options() ->
|
ssl_options() ->
|
||||||
case application:get_env(rabbitmq_auth_backend_http, ssl_options) of
|
case application:get_env(rabbitmq_auth_backend_http, ssl_options) of
|
||||||
{ok, Opts0} when is_list(Opts0) ->
|
{ok, Opts0} when is_list(Opts0) ->
|
||||||
Opts1 = [{ssl, rabbit_networking:fix_ssl_options(Opts0)}],
|
Opts1 = [{ssl, rabbit_ssl_options:fix_client(Opts0)}],
|
||||||
case application:get_env(rabbitmq_auth_backend_http, ssl_hostname_verification) of
|
case application:get_env(rabbitmq_auth_backend_http, ssl_hostname_verification) of
|
||||||
{ok, wildcard} ->
|
{ok, wildcard} ->
|
||||||
rabbit_log:debug("Enabling wildcard-aware hostname verification for HTTP client connections"),
|
rabbit_log:debug("Enabling wildcard-aware hostname verification for HTTP client connections"),
|
||||||
|
|
|
@ -761,7 +761,7 @@ ssl_conf() ->
|
||||||
end.
|
end.
|
||||||
|
|
||||||
ssl_options() ->
|
ssl_options() ->
|
||||||
Opts0 = rabbit_networking:fix_ssl_options(env(ssl_options)),
|
Opts0 = rabbit_ssl_options:fix_client(env(ssl_options)),
|
||||||
case env(ssl_hostname_verification, undefined) of
|
case env(ssl_hostname_verification, undefined) of
|
||||||
wildcard ->
|
wildcard ->
|
||||||
rabbit_log_ldap:debug("Enabling wildcard-aware hostname verification for LDAP client connections"),
|
rabbit_log_ldap:debug("Enabling wildcard-aware hostname verification for LDAP client connections"),
|
||||||
|
|
Loading…
Reference in New Issue