Skip to content

Commit

Permalink
Fixed SSL IP address verification
Browse files Browse the repository at this point in the history
  • Loading branch information
hikui committed May 22, 2024
1 parent 6071f18 commit 3b9585f
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lib/mongo/mongo_db_connection.ex
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,13 @@ defmodule Mongo.MongoDBConnection do

defp ssl(opts, %{connection: {:gen_tcp, socket}} = state) do
host = (opts[:hostname] || "localhost") |> to_charlist
ssl_opts = Keyword.put_new(opts[:ssl_opts] || [], :server_name_indication, host)

# Do not set SNI for IP addresses
ssl_opts =
case :inet.parse_address(host) do
{:ok, _} -> opts[:ssl_opts]
_ -> Keyword.put_new(opts[:ssl_opts] || [], :server_name_indication, host)
end

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

0 comments on commit 3b9585f

Please sign in to comment.