diff options
author | Ingela Anderton Andin <[email protected]> | 2017-08-31 18:31:06 +0200 |
---|---|---|
committer | Ingela Anderton Andin <[email protected]> | 2017-09-01 11:29:40 +0200 |
commit | fbbf7a989750930068826dc165b8567fc1ca9a76 (patch) | |
tree | fa9065f3942610648e743856e5eb65f6bb6f6e1b /lib/ssl/src/ssl_alert.erl | |
parent | 614cc9aba105f6fe5c72de356be4735c22579ca2 (diff) | |
download | otp-fbbf7a989750930068826dc165b8567fc1ca9a76.tar.gz otp-fbbf7a989750930068826dc165b8567fc1ca9a76.tar.bz2 otp-fbbf7a989750930068826dc165b8567fc1ca9a76.zip |
ssl: Add the role (server or client) to the alert message
It is desirable to be as specific as possible in the info message, so
there can be no mistake if the alert is form the peer or generated by
us. This use to be an error message, but it is better to make it an
info message as sending an ALERT ending the connection is an expected
behaviour.
Diffstat (limited to 'lib/ssl/src/ssl_alert.erl')
-rw-r--r-- | lib/ssl/src/ssl_alert.erl | 24 |
1 files changed, 20 insertions, 4 deletions
diff --git a/lib/ssl/src/ssl_alert.erl b/lib/ssl/src/ssl_alert.erl index 2749feb1eb..db415a3666 100644 --- a/lib/ssl/src/ssl_alert.erl +++ b/lib/ssl/src/ssl_alert.erl @@ -32,7 +32,7 @@ -include("ssl_record.hrl"). -include("ssl_internal.hrl"). --export([decode/1, alert_txt/1, reason_code/2]). +-export([decode/1, own_alert_txt/1, alert_txt/1, reason_code/2]). %%==================================================================== %% Internal application API @@ -60,12 +60,28 @@ reason_code(#alert{description = Description}, _) -> {tls_alert, string:to_lower(description_txt(Description))}. %%-------------------------------------------------------------------- +-spec own_alert_txt(#alert{}) -> string(). +%% +%% Description: Returns the error string for given alert generated +%% by the erlang implementation. +%%-------------------------------------------------------------------- +own_alert_txt(#alert{level = Level, description = Description, where = {Mod,Line}, reason = undefined, role = Role}) -> + "at " ++ Mod ++ ":" ++ integer_to_list(Line) ++ " generated " ++ string:to_upper(atom_to_list(Role)) ++ " ALERT: " ++ + level_txt(Level) ++ description_txt(Description); +own_alert_txt(#alert{reason = Reason} = Alert) -> + BaseTxt = own_alert_txt(Alert#alert{reason = undefined}), + FormatDepth = 9, % Some limit on printed representation of an error + ReasonTxt = lists:flatten(io_lib:format("~P", [Reason, FormatDepth])), + BaseTxt ++ " - " ++ ReasonTxt. + +%%-------------------------------------------------------------------- -spec alert_txt(#alert{}) -> string(). %% -%% Description: Returns the error string for given alert. +%% Description: Returns the error string for given alert received from +%% the peer. %%-------------------------------------------------------------------- -alert_txt(#alert{level = Level, description = Description, where = {Mod,Line}, reason = undefined, role = Role}) -> - "at " ++ Mod ++ ":" ++ integer_to_list(Line) ++ " " ++ string:to_upper(atom_to_list(Role)) ++ " ALERT: " ++ +alert_txt(#alert{level = Level, description = Description, reason = undefined, role = Role}) -> + "received " ++ string:to_upper(atom_to_list(Role)) ++ " ALERT: " ++ level_txt(Level) ++ description_txt(Description); alert_txt(#alert{reason = Reason} = Alert) -> BaseTxt = alert_txt(Alert#alert{reason = undefined}), |