【发布时间】:2012-03-20 20:35:04
【问题描述】:
我从中获取文件的供应商正在从 FTP 更改为 FTP over SSL。
我正在尝试将我的代码从 net/ftp 更新为 net/ftptls
我需要连接的新主机没有经过认证,我的脚本报告了这个错误。
主机名与服务器证书不匹配
供应商不会解决这个问题。
看着/usr/lib/ruby/1.8/net/ftptls.rb,我认为猴子修补 FTPTLS 以忽略不受信任的主机不会太难。
我尝试将 verify_mode 更改为 OpenSSL::SSL::VERIFY_NONE 并注释掉 post_connection_check` 行。
都没有用。
关于如何做到这一点的任何想法?
require 'socket'
require 'openssl'
require 'net/ftp'
module Net
class FTPTLS < FTP
def connect(host, port=FTP_PORT)
@hostname = host
super
end
def login(user = "anonymous", passwd = nil, acct = nil)
store = OpenSSL::X509::Store.new
store.set_default_paths
ctx = OpenSSL::SSL::SSLContext.new('SSLv23')
ctx.cert_store = store
ctx.verify_mode = OpenSSL::SSL::VERIFY_PEER
ctx.key = nil
ctx.cert = nil
voidcmd("AUTH TLS")
@sock = OpenSSL::SSL::SSLSocket.new(@sock, ctx)
@sock.connect
@sock.post_connection_check(@hostname)
super(user, passwd, acct)
voidcmd("PBSZ 0")
end
end
end
【问题讨论】: