From 0d88d79319c84e55d99f241284e96eb0a4c4e3f3 Mon Sep 17 00:00:00 2001 From: igerzog Date: Tue, 5 Dec 2017 14:18:07 +0300 Subject: [PATCH] Fix peer verification (#336) Fixes the problem with `SSL_connect returned=1 errno=0 state=error: certificate verify failed` and solves hostname mismatch when use ip address instead of hostname --- lib/postal/smtp_sender.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/postal/smtp_sender.rb b/lib/postal/smtp_sender.rb index f911a29..3991c8c 100644 --- a/lib/postal/smtp_sender.rb +++ b/lib/postal/smtp_sender.rb @@ -46,7 +46,7 @@ module Postal end next end - smtp_client = Net::SMTP.new(@remote_ip, port) + smtp_client = Net::SMTP.new(hostname, port) if @source_ip_address # Set the source IP as appropriate smtp_client.source_address = ip_type == :aaaa ? @source_ip_address.ipv6 : @source_ip_address.ipv4 @@ -236,6 +236,8 @@ module Postal @ssl_context_with_verify ||= begin c = OpenSSL::SSL::SSLContext.new c.verify_mode = OpenSSL::SSL::VERIFY_PEER + c.cert_store = OpenSSL::X509::Store.new + c.cert_store.set_default_paths c end end