Skip to content

Commit 6931b67

Browse files
author
Erlang/OTP
committed
Merge branch 'ingela/ssl/maint-27/psk-bugs/OTP-19825' into maint-27
* ingela/ssl/maint-27/psk-bugs/OTP-19825: ssl: pre_shared_key shall be last client hello extension ssl: Improve interoperability # Conflicts: # lib/ssl/src/ssl_handshake.erl
2 parents bcbf518 + 1ea2ea9 commit 6931b67

File tree

4 files changed

+17
-27
lines changed

4 files changed

+17
-27
lines changed

lib/ssl/src/ssl_handshake.erl

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,7 @@ certificate_verify(Signature, PublicKeyInfo, Version,
431431
end.
432432
%%--------------------------------------------------------------------
433433
-spec verify_signature(ssl_record:ssl_version(), binary(), {term(), term()}, binary(),
434-
public_key_info()) -> true | false.
434+
public_key_info()) -> true | false.
435435
%%
436436
%% Description: Checks that a public_key signature is valid.
437437
%%--------------------------------------------------------------------
@@ -2687,9 +2687,13 @@ encode_psk_binders(Binders) ->
26872687
Len = byte_size(Result),
26882688
<<?UINT16(Len), Result/binary>>.
26892689

2690-
26912690
hello_extensions_list(HelloExtensions) ->
2692-
[Ext || {_, Ext} <- maps:to_list(HelloExtensions), Ext =/= undefined].
2691+
case maps:take(pre_shared_key, HelloExtensions) of
2692+
{#pre_shared_key_client_hello{} = PSK, Rest} ->
2693+
[Ext || {_, Ext} <- maps:to_list(Rest), Ext =/= undefined] ++ [PSK];
2694+
_ ->
2695+
[Ext || {_, Ext} <- maps:to_list(HelloExtensions), Ext =/= undefined]
2696+
end.
26932697

26942698
%%-------------Decode handshakes---------------------------------
26952699
dec_server_key(<<?UINT16(PLen), P:PLen/binary,
@@ -3133,7 +3137,9 @@ decode_extensions(<<?UINT16(?PRE_SHARED_KEY_EXT), ?UINT16(Len),
31333137
#pre_shared_key_client_hello{
31343138
offered_psks = #offered_psks{
31353139
identities = decode_psk_identities(Identities),
3136-
binders = decode_psk_binders(Binders)}}});
3140+
binders = decode_psk_binders(Binders)},
3141+
binder_length = BLen + 2}}
3142+
);
31373143
decode_extensions(<<?UINT16(?PRE_SHARED_KEY_EXT), ?UINT16(Len),
31383144
ExtData:Len/binary, Rest/binary>>,
31393145
Version, MessageType = server_hello, Acc) ->

lib/ssl/src/tls_client_connection_1_3.erl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -632,7 +632,7 @@ do_handle_exlusive_1_3_hello_or_hello_retry_request(
632632
connection_states = ConnectionStates0
633633
} = State0) ->
634634
{Ref,Maybe} = tls_gen_connection_1_3:do_maybe(),
635-
try
635+
try
636636
ClientGroups =
637637
Maybe(tls_handshake_1_3:get_supported_groups(ClientGroups0)),
638638
Cookie = maps:get(cookie, Extensions, undefined),

lib/ssl/src/tls_handshake_1_3.erl

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1750,28 +1750,11 @@ create_binders(Context, [#ticket_data{
17501750
%% } OfferedPsks;
17511751
truncate_client_hello(HelloBin0) ->
17521752
<<?BYTE(Type), ?UINT24(_Length), Body/binary>> = HelloBin0,
1753-
CH0 = #client_hello{
1754-
extensions = #{pre_shared_key := PSK0} = Extensions0} =
1753+
#client_hello{
1754+
extensions = #{pre_shared_key := PSK0}} =
17551755
tls_handshake:decode_handshake(?TLS_1_3, Type, Body),
1756-
#pre_shared_key_client_hello{offered_psks = OfferedPsks0} = PSK0,
1757-
OfferedPsks = OfferedPsks0#offered_psks{binders = []},
1758-
PSK = PSK0#pre_shared_key_client_hello{offered_psks = OfferedPsks},
1759-
Extensions = Extensions0#{pre_shared_key => PSK},
1760-
CH = CH0#client_hello{extensions = Extensions},
1761-
1762-
%% Decoding a ClientHello from an another TLS implementation can contain
1763-
%% unsupported extensions and thus executing decoding and encoding on
1764-
%% the input can result in a different handshake binary.
1765-
%% The original length of the binders can still be determined by
1766-
%% re-encoding the original ClientHello and using its size as reference
1767-
%% when we subtract the size of the truncated binary.
1768-
TruncatedSize = iolist_size(tls_handshake:encode_handshake(CH, ?TLS_1_3)),
1769-
RefSize = iolist_size(tls_handshake:encode_handshake(CH0, ?TLS_1_3)),
1770-
BindersSize = RefSize - TruncatedSize,
1771-
1772-
%% Return the truncated ClientHello by cutting of the binders from the original
1773-
%% ClientHello binary.
1774-
{Truncated, _} = split_binary(HelloBin0, byte_size(HelloBin0) - BindersSize - 2),
1756+
#pre_shared_key_client_hello{binder_length = BinderLen} = PSK0,
1757+
{Truncated, _} = split_binary(HelloBin0, byte_size(HelloBin0) - BinderLen),
17751758
Truncated.
17761759

17771760
maybe_add_early_data_indication(#client_hello{

lib/ssl/src/tls_handshake_1_3.hrl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,8 @@
115115
%% } PreSharedKeyExtension;
116116
-record(pre_shared_key_client_hello,
117117
{
118-
offered_psks
118+
offered_psks,
119+
binder_length
119120
}).
120121

121122
-record(pre_shared_key_server_hello,

0 commit comments

Comments
 (0)