Skip to content

Commit 6adc689

Browse files
stevewatanabePeter-Searby
authored andcommitted
Ensure host name when setting up TLS connection
Validate the host specified is a host name vs an ip address before specifying server_name_indication when setting up TLS connection.
1 parent 8c683b2 commit 6adc689

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

lib/ssl/src/inet_tls_dist.erl

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -636,20 +636,28 @@ do_setup(
636636
Timer = trace(dist_util:start_timer(SetupTime)),
637637
ParseAddress = fun (A) -> inet:parse_strict_address(A, Family) end,
638638
{#net_address{
639-
host = _Host,
639+
host = Host,
640640
address = {Ip, PortNum}},
641641
ConnectOptions,
642642
Version} =
643643
trace(inet_tcp_dist:fam_setup(
644644
Family, Node, LongOrShortNames, ParseAddress)),
645+
%% Ensure Host is a name (vs an IP address) before specifying server
646+
%% name indication.
647+
MaybeOpts = case inet:parse_address(Host) of
648+
{ok, _} ->
649+
[];
650+
_ ->
651+
[{server_name_indication, Host}]
652+
end,
645653
Opts =
646654
inet_tcp_dist:merge_options(
647655
inet_tcp_dist:merge_options(
648656
ConnectOptions,
649657
get_ssl_options(client)),
650658
[Family, binary, {active, false}, {packet, 4},
651659
{read_ahead, false}, {nodelay, true}],
652-
[]),
660+
MaybeOpts),
653661
KTLS = proplists:get_value(ktls, Opts, false),
654662
dist_util:reset_timer(Timer),
655663
maybe

0 commit comments

Comments
 (0)