我试图连接通过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'