Skip to content

Commit 221937d

Browse files
michaelklishinmergify[bot]
authored andcommitted
AMQP 1.0 client connection: implement format_status/1
To scrub two sensitive state values. Note that this callback is used/respect by some tools (via 'sys:get_status/1') but that won't be enough in all cases (namely a process crash logger would still log the original state). (cherry picked from commit 23e7639)
1 parent a08c957 commit 221937d

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

deps/amqp10_client/src/amqp10_client_connection.erl

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@
4848
opened/3,
4949
close_sent/3]).
5050

51+
-export([format_status/1, obfuscate_state_config_sasl/1, obfuscate_state_config_tls_opts/1, obfuscate_state/1]).
52+
5153
-type amqp10_socket() :: {tcp, gen_tcp:socket()} | {ssl, ssl:sslsocket()}.
5254

5355
-type milliseconds() :: non_neg_integer().
@@ -328,10 +330,45 @@ terminate(Reason, _StateName, #state{connection_sup = Sup,
328330
code_change(_OldVsn, StateName, State, _Extra) ->
329331
{ok, StateName, State}.
330332

333+
format_status(Context = #{data := ProcState}) ->
334+
%% Note: Context.state here refers to the gen_statem state name,
335+
%% so we need to use Context.data to get #state{}
336+
Obfuscated = obfuscate_state(ProcState),
337+
Context#{data => Obfuscated}.
338+
339+
331340
%% -------------------------------------------------------------------
332341
%% Internal functions.
333342
%% -------------------------------------------------------------------
334343

344+
obfuscate_state(State = #state{config = Cfg0}) ->
345+
Cfg1 = obfuscate_state_config_sasl(Cfg0),
346+
Cfg2 = obfuscate_state_config_tls_opts(Cfg1),
347+
State#state{config = Cfg2}.
348+
349+
-spec obfuscate_state_config_sasl(connection_config()) -> connection_config().
350+
obfuscate_state_config_sasl(Cfg) ->
351+
Sasl0 = maps:get(sasl, Cfg, none),
352+
Sasl = case Sasl0 of
353+
{plain, Username, _Password} ->
354+
{plain, Username, <<"[redacted]">>};
355+
Other ->
356+
Other
357+
end,
358+
Cfg#{sasl => Sasl}.
359+
360+
-spec obfuscate_state_config_tls_opts(connection_config()) -> connection_config().
361+
obfuscate_state_config_tls_opts(Cfg) ->
362+
TlsOpts0 = maps:get(tls_opts, Cfg, undefined),
363+
TlsOpts = case TlsOpts0 of
364+
{secure_port, PropL0} ->
365+
Obfuscated = proplists:delete(password, PropL0),
366+
{secure_port, Obfuscated};
367+
_ ->
368+
TlsOpts0
369+
end,
370+
Cfg#{tls_opts => TlsOpts}.
371+
335372
handle_begin_session({FromPid, _Ref},
336373
#state{sessions_sup = Sup, reader = Reader,
337374
next_channel = Channel,

0 commit comments

Comments
 (0)