summaryrefslogtreecommitdiff
path: root/lib/net/smtp.rb
diff options
context:
space:
mode:
authortenderlove <tenderlove@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-12-22 21:37:13 +0000
committertenderlove <tenderlove@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-12-22 21:37:13 +0000
commit4a7f4d1f4874898a89f929102d03d7ce5821045d (patch)
tree2771ad33a0a06e270f9de0bd638a333a069967f1 /lib/net/smtp.rb
parent7a033184ae9ecdf4a50c80ac4b181490b4b07a27 (diff)
* lib/net/smtp.rb: Net::SMTP should close the SSL connection if the
connection verification fails. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@30294 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/net/smtp.rb')
-rw-r--r--lib/net/smtp.rb16
1 files changed, 14 insertions, 2 deletions
diff --git a/lib/net/smtp.rb b/lib/net/smtp.rb
index 52ea003771..1143def104 100644
--- a/lib/net/smtp.rb
+++ b/lib/net/smtp.rb
@@ -542,13 +542,17 @@ module Net
private
+ def tcp_socket(address, port)
+ TCPSocket.open address, port
+ end
+
def do_start(helo_domain, user, secret, authtype)
raise IOError, 'SMTP session already started' if @started
if user or secret
check_auth_method(authtype || DEFAULT_AUTH_TYPE)
check_auth_args user, secret
end
- s = timeout(@open_timeout) { TCPSocket.open(@address, @port) }
+ s = timeout(@open_timeout) { tcp_socket(@address, @port) }
logging "Connection opened: #{@address}:#{@port}"
@socket = new_internet_message_io(tls? ? tlsconnect(s) : s)
check_response critical { recv_response() }
@@ -573,15 +577,23 @@ module Net
end
end
+ def ssl_socket(socket, context)
+ OpenSSL::SSL::SSLSocket.new socket, context
+ end
+
def tlsconnect(s)
- s = OpenSSL::SSL::SSLSocket.new(s, @ssl_context)
+ verified = false
+ s = ssl_socket(s, @ssl_context)
logging "TLS connection started"
s.sync_close = true
s.connect
if @ssl_context.verify_mode != OpenSSL::SSL::VERIFY_NONE
s.post_connection_check(@address)
end
+ verified = true
s
+ ensure
+ s.close unless verified
end
def new_internet_message_io(s)