Skip to content

Commit 4a085ea

Browse files
committed
Follow-up fix to 14655
Follow-up to rabbitmq#14655 The code to format `cacerts` and `certs_keys` needs to check if the incoming value is a list or map, and skip it if not. This is the same pattern as used in a later function head: ``` format_socket_opts([Head = {Name, Value} | Tail], Acc) when is_list(Value) -> ``` It ensures that the code won't be called again on an already-formatted value.
1 parent 5a3b62b commit 4a085ea

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

deps/rabbitmq_management_agent/src/rabbit_mgmt_format.erl

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
-module(rabbit_mgmt_format).
99

10+
-include_lib("kernel/include/logger.hrl").
11+
1012
-export([format/2, ip/1, ipb/1, amqp_table/1, tuple/1]).
1113
-export([parameter/1, now_to_str/0, now_to_str/1, strip_pids/1]).
1214
-export([protocol/1, resource/1, queue/1, queue/2, queue_state/1, queue_info/1]).
@@ -284,9 +286,15 @@ listener(#listener{node = Node, protocol = Protocol,
284286
].
285287

286288
web_context(Props0) ->
287-
SslOpts = pget(ssl_opts, Props0, []),
288-
Props = proplists:delete(ssl_opts, Props0),
289-
[{ssl_opts, format_socket_opts(SslOpts)} | Props].
289+
SslOpts0 = pget(ssl_opts, Props0, []),
290+
291+
% Note: cacerts is pre-formatted by cowboy, and is a very large binary
292+
% at this point. This fixes up the output to not show the contents of
293+
% the CA certs
294+
SslOpts1 = lists:keyreplace(cacerts, 1, SslOpts0, {cacerts, truncated}),
295+
296+
Props1 = proplists:delete(ssl_opts, Props0),
297+
[{ssl_opts, format_socket_opts(SslOpts1)} | Props1].
290298

291299
has_tls_enabled(Opts) ->
292300
S = proplists:get_value(socket_opts, Opts, Opts),
@@ -318,16 +326,16 @@ format_socket_opts([{user_lookup_fun, _Value} | Tail], Acc) ->
318326
format_socket_opts([{sni_fun, _Value} | Tail], Acc) ->
319327
format_socket_opts(Tail, Acc);
320328
%% https://www.erlang.org/doc/apps/ssl/ssl.html#t:server_option_cert/0
321-
format_socket_opts([{cacerts, Cacerts} | Tail], Acc) ->
329+
format_socket_opts([{cacerts, Cacerts} | Tail], Acc) when is_list(Cacerts) ->
322330
CacertsMsg = rabbit_data_coercion:to_utf8_binary(
323331
io_lib:format("(~b cacerts entries)", [length(Cacerts)])),
324332
format_socket_opts(Tail, [{cacerts, CacertsMsg} | Acc]);
325333
%% https://www.erlang.org/doc/apps/ssl/ssl.html#t:common_option_cert/0
326334
%% https://www.erlang.org/doc/apps/ssl/ssl.html#t:cert_key_conf/0
327-
format_socket_opts([{certs_keys, CertsKeys} | Tail], Acc) ->
335+
format_socket_opts([{certs_keys, CertsKeys} | Tail], Acc) when is_map(CertsKeys) ->
328336
CertsKeysMsg = rabbit_data_coercion:to_utf8_binary(
329337
io_lib:format("(~b certs_keys entries)", [length(CertsKeys)])),
330-
format_socket_opts(Tail, [{cacerts, CertsKeysMsg} | Acc]);
338+
format_socket_opts(Tail, [{certs_keys, CertsKeysMsg} | Acc]);
331339
%% we do not report SNI host details in the UI,
332340
%% so skip this option and avoid some recursive formatting
333341
%% complexity

0 commit comments

Comments
 (0)