Skip to content

Commit defa508

Browse files
committed
ssl: Improve interoperability
Do not calculate something that we can know, especially in a way that will not always work.
1 parent 10e20b1 commit defa508

File tree

4 files changed

+11
-26
lines changed

4 files changed

+11
-26
lines changed

lib/ssl/src/ssl_handshake.erl

Lines changed: 4 additions & 3 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
%%--------------------------------------------------------------------
@@ -3112,8 +3112,9 @@ decode_extensions(<<?UINT16(?PRE_SHARED_KEY_EXT), ?UINT16(Len),
31123112
#pre_shared_key_client_hello{
31133113
offered_psks = #offered_psks{
31143114
identities = decode_psk_identities(Identities),
3115-
binders = decode_psk_binders(Binders)}}});
3116-
3115+
binders = decode_psk_binders(Binders)},
3116+
binder_length = BLen + 2}}
3117+
);
31173118
decode_extensions(<<?UINT16(?PRE_SHARED_KEY_EXT), ?UINT16(Len),
31183119
ExtData:Len/binary, Rest/binary>>,
31193120
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
@@ -1735,28 +1735,11 @@ create_binders(Context, [#ticket_data{
17351735
%% } OfferedPsks;
17361736
truncate_client_hello(HelloBin0) ->
17371737
<<?BYTE(Type), ?UINT24(_Length), Body/binary>> = HelloBin0,
1738-
CH0 = #client_hello{
1739-
extensions = #{pre_shared_key := PSK0} = Extensions0} =
1738+
#client_hello{
1739+
extensions = #{pre_shared_key := PSK0}} =
17401740
tls_handshake:decode_handshake(?TLS_1_3, Type, Body),
1741-
#pre_shared_key_client_hello{offered_psks = OfferedPsks0} = PSK0,
1742-
OfferedPsks = OfferedPsks0#offered_psks{binders = []},
1743-
PSK = PSK0#pre_shared_key_client_hello{offered_psks = OfferedPsks},
1744-
Extensions = Extensions0#{pre_shared_key => PSK},
1745-
CH = CH0#client_hello{extensions = Extensions},
1746-
1747-
%% Decoding a ClientHello from an another TLS implementation can contain
1748-
%% unsupported extensions and thus executing decoding and encoding on
1749-
%% the input can result in a different handshake binary.
1750-
%% The original length of the binders can still be determined by
1751-
%% re-encoding the original ClientHello and using its size as reference
1752-
%% when we subtract the size of the truncated binary.
1753-
TruncatedSize = iolist_size(tls_handshake:encode_handshake(CH, ?TLS_1_3)),
1754-
RefSize = iolist_size(tls_handshake:encode_handshake(CH0, ?TLS_1_3)),
1755-
BindersSize = RefSize - TruncatedSize,
1756-
1757-
%% Return the truncated ClientHello by cutting of the binders from the original
1758-
%% ClientHello binary.
1759-
{Truncated, _} = split_binary(HelloBin0, byte_size(HelloBin0) - BindersSize - 2),
1741+
#pre_shared_key_client_hello{binder_length = BinderLen} = PSK0,
1742+
{Truncated, _} = split_binary(HelloBin0, byte_size(HelloBin0) - BinderLen),
17601743
Truncated.
17611744

17621745
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)