我试图在iOS 6教程:第1/2部分中运行Apple推送通知服务中的Ray Wenderlich教程.
我在本地目录中创建了AppID和SSL证书以及密钥和PEM文件.之后,我到了测试证书是否有效的步骤,我从这个本地目录调用了以下命令:
$ openssl s_client -connect gateway.sandbox.push.apple.com:2195
-cert PushChatCert.pem -key PushChatKey.pem
Run Code Online (Sandbox Code Playgroud)
这产生了很多输出.在输出的中间是以下内容:
verify error:num=20:unable to get local issuer certificate
verify return:0
Run Code Online (Sandbox Code Playgroud)
这是一个错误,还是一个错误的测试?如果是错误,原因是什么或者您建议解决什么?
这是完整的输出(减去证书数据):
Enter pass phrase for PushChatKey.pem:
CONNECTED(00000003)
depth=1 /C=US/O=Entrust, Inc./OU=www.entrust.net/rpa is incorporated by reference/OU=(c) 2009 Entrust, Inc./CN=Entrust Certification Authority - L1C
verify error:num=20:unable to get local issuer certificate
verify return:0
---
Certificate chain
0 s:/C=US/ST=California/L=Cupertino/O=Apple Inc./OU=iTMS Engineering/CN=gateway.sandbox.push.apple.com
i:/C=US/O=Entrust, Inc./OU=www.entrust.net/rpa is incorporated by reference/OU=(c) 2009 Entrust, Inc./CN=Entrust Certification Authority - L1C
1 s:/C=US/O=Entrust, …
Run Code Online (Sandbox Code Playgroud) 在C中使用OpenSSL时,我们在上下文中设置选项以删除弱受损和受伤的协议,如SSLv2和SSLv3.从ssl.h
,这里是一些有用的选项的位掩码:
#define SSL_OP_NO_SSLv2 0x01000000L
#define SSL_OP_NO_SSLv3 0x02000000L
#define SSL_OP_NO_TLSv1 0x04000000L
#define SSL_OP_NO_TLSv1_2 0x08000000L
#define SSL_OP_NO_TLSv1_1 0x10000000L
Run Code Online (Sandbox Code Playgroud)
但是,我在Ruby中设置它们时遇到了麻烦:
if uri.scheme == "https"
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_PEER
http.options = OpenSSL::SSL::SSL_OP_NO_SSLv2 | OpenSSL::SSL::OP_NO_SSLv3 |
OpenSSL::SSL::SSL_OP_NO_COMPRESSION
end
Run Code Online (Sandbox Code Playgroud)
结果是:
$ ./TestCert.rb
./TestCert.rb:12:in `<main>': uninitialized constant OpenSSL::SSL::SSL_OP_SSL2 (NameError)
Run Code Online (Sandbox Code Playgroud)
如何在Ruby中设置TLS上下文选项?
相关:在ruby中设置SSLContext选项.但是没有办法将上下文附加到http
何时http.use_ssl = true
.
我正在尝试用Ruby编写HTTPS客户端.它将使用HTTPS连接到服务器,传递身份验证令牌(通过单独的登录过程获得)和SSL客户端证书.
我正在使用rest-client执行以下操作:
client = RestClient::Resource.new(url,
:ssl_client_cert => OpenSSL::X509::Certificate.new(File.read('./certificate/client-2048.pem')),
:ssl_client_key => OpenSSL::PKey::RSA.new(File.read('./certificate/client-2048.key'), ''),
:verify_ssl => OpenSSL::SSL::VERIFY_NONE)
# ...
headers = {
'X-Application' => APP_KEY,
'X-Authentication' => @session_token,
'content-type' => 'application/json',
'Accept' => 'application/json'
}
response = client.post(request, headers)
Run Code Online (Sandbox Code Playgroud)
这是有效的,但我想做的是使用keep-alive来避免每次我想提出请求时都要经历整个连接过程.所涉及的延迟使得我正在编写的监控应用程序变得不那么有用.
不过,我不能似乎找到一个Ruby库,它提供了以下内容:
对于应该提供它的休息客户,有一个拉动请求. httparty具有persistent_httparty,但如果它支持SSL客户端证书,则没有相关文档.
我可以fork rest-client,合并现在已经位腐烂的pull-request,并使用它.但是我肯定在这里遗漏了一些东西......是否有现有的图书馆提供我正在寻找的东西?或者一些httparty文档解释了SSL库证书的SSL客户端证书使用情况?
任何帮助将不胜感激.
正如在OpenSSL :: X509 ::证书显示错误域证书中所引用的那样,我需要使用TLSv1或更高版本以及 服务器名称指示扩展.
即使使用ssl_version
和servername_cb
设置SSLContext
,我仍然得到错误的证书myproair.com
.
begin
timeout(1) do
tcp_client = TCPSocket.new("#{instance["domain"]}", 443)
ssl_context = OpenSSL::SSL::SSLContext.new()
ssl_context.ssl_version = :TLSv1
ssl_context.servername_cb = "https://#{instance["domain"]}"
ssl_client = OpenSSL::SSL::SSLSocket.new(tcp_client, ssl_context)
ssl_client.connect
cert = OpenSSL::X509::Certificate.new(ssl_client.peer_cert)
ssl_client.sysclose
tcp_client.close
#http://ruby-doc.org/stdlib-2.0/libdoc/openssl/rdoc/OpenSSL/X509/Certificate.html
date = Date.parse((cert.not_after).to_s)
row.push("#{date.strftime('%F')} #{cert.signature_algorithm} #{cert.subject.to_a.select{|name, _, _| name == 'CN' }.first[1]}".downcase.ljust(57))
end
rescue SocketError
row.push("down".ljust(57))
rescue Errno::ECONNREFUSED
row.push("connection refused".ljust(57))
rescue Errno::ECONNRESET
row.push("connection reset".ljust(57))
rescue Timeout::Error
row.push("no 443 listener".ljust(57))
rescue OpenSSL::SSL::SSLError
row.push("bad certificate - ssl …
Run Code Online (Sandbox Code Playgroud) openssl ×3
ruby ×3
ssl ×2
http ×1
https ×1
keep-alive ×1
macos ×1
options ×1
server-name ×1
sni ×1