Skip to content

Commit 1f5ee7d

Browse files
authored
Fixed SSL IP address verification (#244)
1 parent 6071f18 commit 1f5ee7d

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

lib/mongo/mongo_db_connection.ex

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,13 @@ defmodule Mongo.MongoDBConnection do
164164

165165
defp ssl(opts, %{connection: {:gen_tcp, socket}} = state) do
166166
host = (opts[:hostname] || "localhost") |> to_charlist
167-
ssl_opts = Keyword.put_new(opts[:ssl_opts] || [], :server_name_indication, host)
167+
168+
# Do not set SNI for IP addresses
169+
ssl_opts =
170+
case :inet.parse_address(host) do
171+
{:ok, _} -> opts[:ssl_opts]
172+
_ -> Keyword.put_new(opts[:ssl_opts] || [], :server_name_indication, host)
173+
end
168174

169175
case :ssl.connect(socket, ssl_opts, state.connect_timeout) do
170176
{:ok, ssl_sock} ->

0 commit comments

Comments
 (0)