简体   繁体   English

SSL_connect返回= 1 errno = 0状态= SSLv3读取服务器证书B:证书验证仅在代理时失败

[英]SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed ONLY WHEN PROXYING

This post nearly duplicates a number of other posts, including Rails 4 and Ruby 2 Net/HTTP SSL Request: OpenSSL::SSL::SSLError: SSL_connect returned=1 errno=0 state=SSLv2/v3 read server hello A: unknown protocol and SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed , but with one key difference: the "certificate verify failed" error only happens when proxied via an SSL proxy ( Charles ), and only in the latest version of Ruby. 这篇文章几乎复制了许多其他帖子,包括Rails 4和Ruby 2 Net / HTTP SSL请求:OpenSSL :: SSL :: SSLError:SSL_connect返回= 1 errno = 0状态= SSLv2 / v3读取服务器问候A:未知协议SSL_connect返回= 1 errno = 0状态= SSLv3读取服务器证书B:证书验证失败 ,但有一个关键区别:“证书验证失败”错误仅在通过SSL代理( Charles )代理时发生,并且仅在最新版本中Ruby。

Specifically, this (non-proxied) code works: 具体来说,这个(非代理)代码有效:

  uri = URI.parse('https://www.ibm.com')
  http = Net::HTTP.new(uri.host, uri.port, nil)
  http.use_ssl = true
  http.start { |agent| agent.get(uri.path) }

and this (proxied) code fails with a "certificate verify failed" error: 并且此(代理)代码因“证书验证失败”错误而失败:

  uri = URI.parse('https://www.ibm.com')
  http = Net::HTTP.new(uri.host, uri.port, "localhost", 8888)
  http.use_ssl = true
  http.start { |agent| agent.get(uri.path) }

the puzzle 这个谜题

The error ONLY appears when going through the proxy in the current versions of Ruby/OpenSSL. 在当前版本的Ruby / OpenSSL中通过代理时,仅出现错误。 In particular: 特别是:

  • There's no error when NOT going through the proxy, which leads me to think that the local certs are valid. 不通过代理时没有错误,这让我认为本地证书是有效的。
  • There's no error when going through the proxy with Firefox or curl -v https://www.ibm.com/ , which leads me to think that the Charles certs are valid. 使用Firefox或curl -v https://www.ibm.com/进行代理时没有错误,这使我认为Charles证书是有效的。
  • There's no error going through the proxy on an earlier version of Ruby / OpenSSL (see below for the two environments). 早期版本的Ruby / OpenSSL上的代理没有错误(请参阅下面的两个环境)。

All this makes me suspect an actual Ruby bug rather than a problem with my certs, but I'd be happy to be shown otherwise. 所有这些让我怀疑一个真正的Ruby bug,而不是我的证书的问题,但我很乐意以其他方式显示。

the current environment 当前的环境

I'm observing the error with this environment: 我正在观察这个环境的错误:

$ system_profiler SPSoftwareDataType | grep "System Version"
    System Version: OS X 10.8.5 (12F45)
$ ruby --version ; openssl version ; gem list | grep http
ruby 2.0.0p247 (2013-06-27) [x86_64-darwin12.4.0]
OpenSSL 1.0.1e 11 Feb 2013
http-cookie (1.0.2)
http_router (0.10.2)
net-http-digest_auth (1.4)
net-http-persistent (2.9)
ntlm-http (0.1.1)

the previous environment 以前的环境

The error does not appear with a slightly older version of ruby/OpenSSL: 稍微旧版本的ruby / OpenSSL不会出现该错误:

$ ruby --version ; openssl version ; gem list | grep http
ruby 2.0.0p0 (2013-02-24 revision 39474) [x86_64-darwin10.8.0]
OpenSSL 0.9.8y 5 Feb 2013
http_router (0.11.0, 0.10.2)
httpauth (0.2.0)
net-http-digest_auth (1.2.1)
net-http-persistent (2.8)
ntlm-http (0.1.1)

What is going on here is that Charles cannot provide you with a valid certificate for " https://www.ibm.com ", because whatever certificate you set up Charles with (or if Charles creates its own certificate) it cannot be for the "www.ibm.com" name AND certified by a trusted certificate authority. 这里发生的事情是Charles无法为您提供“ https://www.ibm.com ”的有效证书,因为您设置Charles的任何证书(或者如果Charles创建自己的证书),它不能用于“www.ibm.com”名称并由受信任的证书颁发机构认证。 That's why the connection fails if the client verifies the the certificate, and works if you skip verification with 这就是如果客户端验证证书,连接失败的原因,如果您跳过验证,则连接失败

http.verify_mode = OpenSSL::SSL::VERIFY_NONE

It probably worked with the older version of ruby because "net/https" was adjusted to verify certificates by default only recently. 它可能适用于旧版本的ruby,因为“net / https”已经过调整,默认情况下最近才会验证证书。

I seem to recall needing to point to that cert in an ENV var. 我似乎记得需要在ENV var中指出该证书。 If you're not really concerned with verifying, it's easier to just: 如果你真的不关心验证,那么更容易:

http.verify_mode = OpenSSL::SSL::VERIFY_NONE

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 SSL_connect 返回=1 errno=0 state=SSLv3 读取服务器证书B:证书验证失败 - SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed SSL_connect返回= 1 errno = 0状态= SSLv3读取服务器证书B:证书验证失败的MAC - SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed MAC SSL_connect返回= 1 errno = 0状态= SSLv3读取服务器证书B:Mac上的证书验证失败 - SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed on Mac connect:SSL_connect返回= 1 errno = 0 state = SSLv3读取服务器证书B:证书验证失败(OpenSSL :: SSL :: SSLError) - connect: SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed (OpenSSL::SSL::SSLError) OpenSSL :: SSL :: SSLError(连接到Paypal时,返回SSL_connect = 1 errno = 0 state = SSLv3读取服务器证书B:证书验证失败) - OpenSSL::SSL::SSLError (SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed) while connecting to Paypal Heroku Rails Net :: HTTP:OpenSSL :: SSL :: SSLError:SSL_connect返回= 1 errno = 0状态= SSLv3读取服务器证书B:证书验证失败 - Heroku Rails Net::HTTP: OpenSSL::SSL::SSLError: SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed OpenSSL :: SSL :: SSLError:SSL_connect返回= 1 errno = 0状态= SSLv3读取服务器证书B:证书验证失败-向外部API耙任务 - OpenSSL::SSL::SSLError: SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed - rake task to external API OpenSSL::SSL::SSLError: SSL_connect SYSCALL 返回=5 errno=0 state=SSLv3 read server hello A - OpenSSL::SSL::SSLError: SSL_connect SYSCALL returned=5 errno=0 state=SSLv3 read server hello A SSL_connect SYSCALL返回= 5 errno = 0 state = SSLv3读取服务器hello A(OpenSSL :: SSL :: SSLError) - SSL_connect SYSCALL returned=5 errno=0 state=SSLv3 read server hello A (OpenSSL::SSL::SSLError) 红宝石SSLv3上的SSL客户端身份验证Web服务读取服务器证书B:证书验证失败 - SSL Client Authenticated Webservice on ruby SSLv3 read server certificate B: certificate verify failed
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM