Skip to content

Commit 28409be

Browse files
committed
ssl: RFC compliance
Ensure signature algs are checked for intermediates. If user hade own verify fun these would previously be missed. Add missing extension assertion.
1 parent 6b5475d commit 28409be

2 files changed

Lines changed: 14 additions & 6 deletions

File tree

lib/ssl/src/ssl_handshake.erl

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2185,14 +2185,15 @@ path_validation_options(Opts, ValidationFunAndState) ->
21852185

21862186
apply_user_fun(Fun, OtpCert, DerCert, VerifyResult0, UserState0, SslState, CertPath, LogLevel) when
21872187
VerifyResult0 == valid; VerifyResult0 == valid_peer ->
2188-
VerifyResult = maybe_check_hostname(OtpCert, VerifyResult0, SslState, LogLevel),
2188+
VerifyResult = tls_verify_fun(OtpCert, VerifyResult0, SslState, LogLevel),
21892189
case apply_fun(Fun, OtpCert, DerCert, VerifyResult, UserState0) of
21902190
{Valid, UserState} when (Valid == valid) orelse (Valid == valid_peer) ->
21912191
case cert_status_check(OtpCert, SslState, VerifyResult, CertPath, LogLevel) of
21922192
valid ->
21932193
{Valid, {SslState, UserState}};
21942194
Result ->
2195-
apply_user_fun(Fun, OtpCert, DerCert, Result, UserState, SslState, CertPath, LogLevel)
2195+
apply_user_fun(Fun, OtpCert, DerCert, Result, UserState,
2196+
SslState, CertPath, LogLevel)
21962197
end;
21972198
{fail, _} = Fail ->
21982199
Fail
@@ -2214,15 +2215,20 @@ apply_fun(Fun, OtpCert, DerCert, ExtensionOrError, UserState) ->
22142215
Fun(OtpCert, ExtensionOrError, UserState)
22152216
end.
22162217

2217-
maybe_check_hostname(OtpCert, valid_peer, SslState, LogLevel) ->
2218+
tls_verify_fun(OtpCert, valid_peer, SslState, LogLevel) ->
22182219
case ssl_certificate:validate(OtpCert, valid_peer, SslState, LogLevel) of
22192220
{valid, _} ->
22202221
valid_peer;
22212222
{fail, Reason} ->
22222223
Reason
22232224
end;
2224-
maybe_check_hostname(_, valid, _, _) ->
2225-
valid.
2225+
tls_verify_fun(OtpCert, valid, SslState, LogLevel) ->
2226+
case ssl_certificate:validate(OtpCert, valid, SslState, LogLevel) of
2227+
{valid, _} ->
2228+
valid;
2229+
{fail, Reason} ->
2230+
Reason
2231+
end.
22262232

22272233
path_validation_alert({bad_cert, cert_expired}, _, _) ->
22282234
?ALERT_REC(?FATAL, ?CERTIFICATE_EXPIRED);
@@ -3186,6 +3192,7 @@ decode_extensions(<<?UINT16(?KEY_SHARE_EXT), ?UINT16(Len),
31863192
<<?UINT16(EnumGroup),?UINT16(KeyLen),KeyExchange0:KeyLen/binary>> = ExtData,
31873193
Group = tls_v1:enum_to_group(EnumGroup),
31883194
KeyExchange = maybe_dec_server_hybrid_share(Group, KeyExchange0),
3195+
assert_unique_extension(key_share, Acc),
31893196
decode_extensions(Rest, Version, MessageType,
31903197
Acc#{key_share =>
31913198
#key_share_server_hello{
@@ -3198,6 +3205,7 @@ decode_extensions(<<?UINT16(?KEY_SHARE_EXT), ?UINT16(Len),
31983205
ExtData:Len/binary, Rest/binary>>,
31993206
Version, MessageType = hello_retry_request, Acc) ->
32003207
<<?UINT16(Group)>> = ExtData,
3208+
assert_unique_extension(key_share, Acc),
32013209
decode_extensions(Rest, Version, MessageType,
32023210
Acc#{key_share =>
32033211
#key_share_hello_retry_request{

lib/ssl/src/ssl_trace.erl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -477,7 +477,7 @@ trace_profiles() ->
477477
{ssl_handshake, [{path_validate, 11}, {path_validation, 10},
478478
{select_hashsign, 5}, {get_cert_params, 1},
479479
{cert_curve, 3},
480-
{maybe_check_hostname, 4}]},
480+
{tls_verify_fun, 4}]},
481481
{ssl_pkix_db, [{decode_cert, 2}]},
482482
{tls_handshake_1_3, [{path_validation, 10}]},
483483
{tls_server_connection_1_3, [{init,1}]},

0 commit comments

Comments
 (0)