File 0542-Remove-duplicated-code.patch of Package erlang
From fdfe80b2f0928ecd24debb0c6c4923d0c06178bc Mon Sep 17 00:00:00 2001
From: Nelson Vides <videsnelson@gmail.com>
Date: Sun, 11 Apr 2021 23:22:04 +0200
Subject: [PATCH 2/6] Remove duplicated code
PRF is specific to pre-TLSv1.3, so it should not be on ssl_gen_statem.
Indeed, the exact same code can be found in tls_dtls_connection, but a
quick look at test coverage said that it wasn't being called to begin
with. I believe that this duplication was introduced in ff15b5748d2.
---
lib/ssl/src/ssl_gen_statem.erl | 26 +-------------------------
lib/ssl/src/tls_dtls_connection.erl | 2 ++
2 files changed, 3 insertions(+), 25 deletions(-)
diff --git a/lib/ssl/src/ssl_gen_statem.erl b/lib/ssl/src/ssl_gen_statem.erl
index c2dd4e5c7a..b84f544228 100644
--- a/lib/ssl/src/ssl_gen_statem.erl
+++ b/lib/ssl/src/ssl_gen_statem.erl
@@ -774,33 +774,9 @@ handle_call({set_opts, Opts0}, From, StateName,
handle_call(renegotiate, From, StateName, _) when StateName =/= connection ->
{keep_state_and_data, [{reply, From, {error, already_renegotiating}}]};
-handle_call({prf, Secret, Label, Seed, WantedLength}, From, _,
- #state{connection_states = ConnectionStates,
- connection_env = #connection_env{negotiated_version = Version}}) ->
- #{security_parameters := SecParams} =
- ssl_record:current_connection_state(ConnectionStates, read),
- #security_parameters{master_secret = MasterSecret,
- client_random = ClientRandom,
- server_random = ServerRandom,
- prf_algorithm = PRFAlgorithm} = SecParams,
- Reply = try
- SecretToUse = case Secret of
- _ when is_binary(Secret) -> Secret;
- master_secret -> MasterSecret
- end,
- SeedToUse = lists:reverse(
- lists:foldl(fun(X, Acc) when is_binary(X) -> [X|Acc];
- (client_random, Acc) -> [ClientRandom|Acc];
- (server_random, Acc) -> [ServerRandom|Acc]
- end, [], Seed)),
- ssl_handshake:prf(ssl:tls_version(Version), PRFAlgorithm, SecretToUse, Label, SeedToUse, WantedLength)
- catch
- exit:_ -> {error, badarg};
- error:Reason -> {error, Reason}
- end,
- {keep_state_and_data, [{reply, From, Reply}]};
handle_call(_,_,_,_) ->
{keep_state_and_data, [postpone]}.
+
handle_info({ErrorTag, Socket, econnaborted}, StateName,
#state{static_env = #static_env{role = Role,
host = Host,
diff --git a/lib/ssl/src/tls_dtls_connection.erl b/lib/ssl/src/tls_dtls_connection.erl
index c27feadfcf..767cd826d2 100644
--- a/lib/ssl/src/tls_dtls_connection.erl
+++ b/lib/ssl/src/tls_dtls_connection.erl
@@ -646,6 +646,8 @@ connection({call, From}, negotiated_protocol,
negotiated_protocol = undefined}} = State) ->
ssl_gen_statem:hibernate_after(?FUNCTION_NAME, State,
[{reply, From, {ok, SelectedProtocol}}]);
+connection({call, From}, Msg, State) when element(1, Msg) =:= prf ->
+ handle_call(Msg, From, ?FUNCTION_NAME, State);
connection(cast, {internal_renegotiate, WriteState}, #state{static_env = #static_env{protocol_cb = tls_gen_connection},
handshake_env = HsEnv,
connection_states = ConnectionStates}
--
2.26.2