我試圖連接通過SSL訪問某個站點的web爬蟲,並在該站點上查詢我的數據。本網站的身份驗證通過自簽名數字證書進行。目前我想訪問該站點,我將這個證書以.pfx格式上傳到我的api,將其轉換爲.pem,當我嘗試使用此證書訪問站點時,響應狀態爲403(禁止)。 但是,當我嘗試通過具有.pfx格式證書的瀏覽器訪問站點時,我通常會得到它。 我已經嘗試使用機械化,它工作了一段時間(直到幾個月前它工作),但然後它開始給出的錯誤: SSL_connect returned = 1 errno = 0 state = SSLv3 read finished A: sslv3 alert bad certificate
該網站是舊的,它不會經常收到更新。 之後,我已經嘗試使用net/http lib並且錯誤仍然存在,我嘗試使用httprb gem,最後我嘗試使用Faraday。所有嘗試都以上面引用的錯誤或響應狀態== 403結束。 我能做些什麼才能連接?我的腳本有問題嗎?它是否缺少我需要通過的任何信息?Ruby - 使用SSL連接並通過客戶端證書進行身份驗證 - sslv3警告錯誤證書
代碼:
# Faraday customs method:
class FaradayHttp
def with_openssl
system "openssl pkcs12 -in my-certificate-path -out certificate-output-path -nodes -password pass:certificate-password"
def cert_object
OpenSSL::X509::Certificate.new File.read("certificate-output-path")
end
# create PKey
def key_object
OpenSSL::PKey.read File.read("certificate-output-path")
end
faraday = Faraday::Connection.new 'https://example-site.com',
:ssl => {
certificate: cert_object,
private_key: key_object,
version: :SSLv3,
verify: false
}
faraday
end
end
# Controller that try to connect with the ssl server:
agent = FaradayHttp.new.with_openssl
page = agent.get '/login_path'