供應商我抓取的文件正在通過SSL從FTP更改爲FTP。通過TLS/SSL通過FTP連接到未經認證的主機
我想更新我的代碼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