Skip to content

Commit

Permalink
Merge pull request #494 from piotrklibert/master
Browse files Browse the repository at this point in the history
Fix accessing HTTPS sites with an IPv4 address
  • Loading branch information
benoitc committed Jun 9, 2018
2 parents 8319244 + 88c4bc1 commit 13dd2f4
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/hackney_ssl.erl
Expand Up @@ -44,21 +44,34 @@
%% @doc Atoms used to identify messages in {active, once | true} mode.
messages(_) -> {ssl, ssl_closed, ssl_error}.

%% @doc The ssl:connect/4 (and related) doesn't work with textual representation
%% of IP addresses. It accepts either a string with a DNS-resolvable name or a
%% tuple with parts of an IP as numbers. This function attempts to parse given
%% string and either returns such tuple, or the string if it's impossible to
%% parse.
parse_address(Host) when is_list(Host) ->
case inet:parse_address(Host) of
{ok, Address} -> Address;
{error, _} -> Host
end.


connect(Host, Port, Opts) ->
connect(Host, Port, Opts, infinity).

connect(Host, Port, Opts, Timeout) when is_list(Host), is_integer(Port),
(Timeout =:= infinity orelse is_integer(Timeout)) ->

BaseOpts = [binary, {active, false}, {packet, raw},
{secure_renegotiate, true},
{reuse_sessions, true},
{honor_cipher_order, true},
{versions,['tlsv1.2', 'tlsv1.1', tlsv1, sslv3]},
{ciphers, ciphers()}],
Opts1 = hackney_util:merge_opts(BaseOpts, Opts),

Host1 = parse_address(Host),
%% connect
ssl:connect(Host, Port, Opts1, Timeout).
ssl:connect(Host1, Port, Opts1, Timeout).


ciphers() ->
Expand Down

0 comments on commit 13dd2f4

Please sign in to comment.