diff options
author | Ingela Anderton Andin <ingela@erlang.org> | 2022-05-09 12:19:34 +0200 |
---|---|---|
committer | Ingela Anderton Andin <ingela@erlang.org> | 2022-05-09 16:16:32 +0200 |
commit | a47d9ced35c59781a9694fd517c381929c0abb45 (patch) | |
tree | b6800775b7ec7fc7a8cbfbb894b7c78d43d9e5c4 | |
parent | 0863bd30aabd035c83158c78046c5ffda16127e1 (diff) | |
download | erlang-a47d9ced35c59781a9694fd517c381929c0abb45.tar.gz |
ssl: Improve names
-rw-r--r-- | lib/ssl/src/tls_gen_connection.erl | 9 | ||||
-rw-r--r-- | lib/ssl/src/tls_handshake.erl | 18 | ||||
-rw-r--r-- | lib/ssl/test/ssl_handshake_SUITE.erl | 4 | ||||
-rw-r--r-- | lib/ssl/test/ssl_npn_hello_SUITE.erl | 8 |
4 files changed, 20 insertions, 19 deletions
diff --git a/lib/ssl/src/tls_gen_connection.erl b/lib/ssl/src/tls_gen_connection.erl index cff0abdcb3..2a790097b9 100644 --- a/lib/ssl/src/tls_gen_connection.erl +++ b/lib/ssl/src/tls_gen_connection.erl @@ -399,10 +399,11 @@ handle_protocol_record(#ssl_tls{type = ?HANDSHAKE, fragment = Data}, %% Calculate the effective version that should be used when decoding an incoming handshake %% message. EffectiveVersion = effective_version(Version, Options, Role, StateName), - {Packets, Buf} = tls_handshake:get_tls_handshake(EffectiveVersion,Data,Buf0, Options), - State = - State0#state{protocol_buffers = - Buffers#protocol_buffers{tls_handshake_buffer = Buf}}, + {Packets, Buf} = tls_handshake:get_tls_handshakes(EffectiveVersion,Data,Buf0, Options), + + State = case EffectiveVersion =/= NegotiatedVersion of + State0#state{protocol_buffers = + Buffers#protocol_buffers{tls_handshake_buffer = Buf}}, case Packets of [] -> assert_buffer_sanity(Buf, Options), diff --git a/lib/ssl/src/tls_handshake.erl b/lib/ssl/src/tls_handshake.erl index 7a3d9712aa..6f9fc54fad 100644 --- a/lib/ssl/src/tls_handshake.erl +++ b/lib/ssl/src/tls_handshake.erl @@ -42,7 +42,7 @@ -export([encode_handshake/2]). %% Handshake decoding --export([get_tls_handshake/4, decode_handshake/3]). +-export([get_tls_handshakes/4, decode_handshake/3]). %% Handshake helper -export([ocsp_nonce/2]). @@ -285,7 +285,7 @@ encode_handshake(Package, Version) -> %%-------------------------------------------------------------------- %%-------------------------------------------------------------------- --spec get_tls_handshake(tls_record:tls_version(), binary(), binary() | iolist(), +-spec get_tls_handshakes(tls_record:tls_version(), binary(), binary() | iolist(), ssl_options()) -> {[{tls_handshake(), binary()}], binary()}. %% @@ -293,10 +293,10 @@ encode_handshake(Package, Version) -> %% and returns it as a list of handshake messages, also returns leftover %% data. %%-------------------------------------------------------------------- -get_tls_handshake(Version, Data, <<>>, Options) -> - get_tls_handshake_aux(Version, Data, Options, []); -get_tls_handshake(Version, Data, Buffer, Options) -> - get_tls_handshake_aux(Version, list_to_binary([Buffer, Data]), Options, []). +get_tls_handshakes(Version, Data, <<>>, Options) -> + get_tls_handshakes_aux(Version, Data, Options, []); +get_tls_handshakes(Version, Data, Buffer, Options) -> + get_tls_handshakes_aux(Version, list_to_binary([Buffer, Data]), Options, []). %%-------------------------------------------------------------------- %%% Handshake helper @@ -426,19 +426,19 @@ enc_handshake(HandshakeMsg, Version) -> ssl_handshake:encode_handshake(HandshakeMsg, Version). %%-------------------------------------------------------------------- -get_tls_handshake_aux(Version, <<?BYTE(Type), ?UINT24(Length), +get_tls_handshakes_aux(Version, <<?BYTE(Type), ?UINT24(Length), Body:Length/binary,Rest/binary>>, #{log_level := LogLevel} = Opts, Acc) -> Raw = <<?BYTE(Type), ?UINT24(Length), Body/binary>>, try decode_handshake(Version, Type, Body) of Handshake -> ssl_logger:debug(LogLevel, inbound, 'handshake', Handshake), - get_tls_handshake_aux(Version, Rest, Opts, [{Handshake,Raw} | Acc]) + get_tls_handshakes_aux(Version, Rest, Opts, [{Handshake,Raw} | Acc]) catch error:_ -> throw(?ALERT_REC(?FATAL, ?HANDSHAKE_FAILURE, handshake_decode_error)) end; -get_tls_handshake_aux(_Version, Data, _, Acc) -> +get_tls_handshakes_aux(_Version, Data, _, Acc) -> {lists:reverse(Acc), Data}. decode_handshake({3, N}, ?HELLO_REQUEST, <<>>) when N < 4 -> diff --git a/lib/ssl/test/ssl_handshake_SUITE.erl b/lib/ssl/test/ssl_handshake_SUITE.erl index ec770168a3..b3f7011d25 100644 --- a/lib/ssl/test/ssl_handshake_SUITE.erl +++ b/lib/ssl/test/ssl_handshake_SUITE.erl @@ -129,8 +129,8 @@ decode_hello_handshake(_Config) -> 16#70, 16#64, 16#79, 16#2f, 16#32>>, Version = {3, 0}, - {Records, _Buffer} = tls_handshake:get_tls_handshake(Version, HelloPacket, <<>>, - default_options_map()), + {Records, _Buffer} = tls_handshake:get_tls_handshakes(Version, HelloPacket, <<>>, + default_options_map()), {Hello, _Data} = hd(Records), Extensions = Hello#server_hello.extensions, diff --git a/lib/ssl/test/ssl_npn_hello_SUITE.erl b/lib/ssl/test/ssl_npn_hello_SUITE.erl index dae07aae63..e14c1b3aed 100644 --- a/lib/ssl/test/ssl_npn_hello_SUITE.erl +++ b/lib/ssl/test/ssl_npn_hello_SUITE.erl @@ -87,7 +87,7 @@ encode_and_decode_client_hello_test(Config) -> HandShakeData = create_client_handshake(undefined), Version = ssl_test_lib:protocol_version(Config), {[{DecodedHandshakeMessage, _Raw}], _} = - tls_handshake:get_tls_handshake(Version, list_to_binary(HandShakeData), <<>>, + tls_handshake:get_tls_handshakes(Version, list_to_binary(HandShakeData), <<>>, default_options_map()), Extensions = DecodedHandshakeMessage#client_hello.extensions, #{next_protocol_negotiation := undefined} = Extensions. @@ -96,7 +96,7 @@ encode_and_decode_npn_client_hello_test(Config) -> HandShakeData = create_client_handshake(#next_protocol_negotiation{extension_data = <<>>}), Version = ssl_test_lib:protocol_version(Config), {[{DecodedHandshakeMessage, _Raw}], _} = - tls_handshake:get_tls_handshake(Version, list_to_binary(HandShakeData), <<>>, + tls_handshake:get_tls_handshakes(Version, list_to_binary(HandShakeData), <<>>, default_options_map()), Extensions = DecodedHandshakeMessage#client_hello.extensions, #{next_protocol_negotiation := #next_protocol_negotiation{extension_data = <<>>}} = Extensions. @@ -105,7 +105,7 @@ encode_and_decode_server_hello_test(Config) -> HandShakeData = create_server_handshake(undefined), Version = ssl_test_lib:protocol_version(Config), {[{DecodedHandshakeMessage, _Raw}], _} = - tls_handshake:get_tls_handshake(Version, list_to_binary(HandShakeData), <<>>, + tls_handshake:get_tls_handshakes(Version, list_to_binary(HandShakeData), <<>>, default_options_map()), Extensions = DecodedHandshakeMessage#server_hello.extensions, #{next_protocol_negotiation := undefined} = Extensions. @@ -115,7 +115,7 @@ encode_and_decode_npn_server_hello_test(Config) -> HandShakeData = create_server_handshake(#next_protocol_negotiation{extension_data = <<6, "spdy/2">>}), Version = ssl_test_lib:protocol_version(Config), {[{DecodedHandshakeMessage, _Raw}], _} = - tls_handshake:get_tls_handshake(Version, list_to_binary(HandShakeData), <<>>, + tls_handshake:get_tls_handshakes(Version, list_to_binary(HandShakeData), <<>>, default_options_map()), Extensions = DecodedHandshakeMessage#server_hello.extensions, ct:log("~p ~n", [Extensions]), |