2012-01-24 22 views
8

Tôi đang cố tìm nạp tài nguyên qua SSL bằng cách sử dụng Net::HTTP. Dưới đây là đoạn mã liên quan:Ruby 1.8.7 và Net :: HTTP: Thực hiện yêu cầu SSL GET với chứng chỉ ứng dụng khách?

req = Net::HTTP::Get.new(ContentURI.path) 
https = Net::HTTP.new(ContentURI.host, ContentURI.port) 
https.use_ssl = true 
https.cert = OpenSSL::X509::Certificate.new(@cert_raw) 
https.key = OpenSSL::PKey::RSA.new(@cert_key_raw) 
https.verify_mode = OpenSSL::SSL::VERIFY_PEER 
https.ca_file = File.join(TestDataPath, 'cacert.pem') 
resp = https.start { |cx| cx.request(req) } 

hoặc qua các nhân thay thế dòng cuối cùng:

resp = https.get(ContentURI.path) 

Tôi đã xác minh rằng các bit khác nhau (cert, key, CA cert, , vv) là chính xác .

Vấn đề là các cx.request(req) ném một ngoại lệ:

OpenSSL::SSL::SSLError: SSL_connect SYSCALL returned=5 errno=0 state=SSLv3 read server session ticket A 

Apache SSL lỗi đăng nhập trên máy chủ chứa như sau:

[Tue Jan 24 11:47:26 2012] [debug] ssl_engine_kernel.c(1876): OpenSSL: Loop: SSLv3 read finished A 
[Tue Jan 24 11:47:26 2012] [debug] ssl_engine_kernel.c(1905): OpenSSL: Exit: error in SSLv3 write session ticket A 
[Tue Jan 24 11:47:26 2012] [debug] ssl_engine_kernel.c(1905): OpenSSL: Exit: error in SSLv3 write session ticket A 
[Tue Jan 24 11:47:26 2012] [info] [client 10.11.88.53] SSL handshake interrupted by system [Hint: Stop button pressed in browser?!] 
[Tue Jan 24 11:47:26 2012] [info] [client 10.11.88.53] Connection closed to child 0 with abortive shutdown (server _SERVERNAME_:443 

Các cert, key, và làm việc CA tập tin cert với máy chủ SSL này thông qua các công cụ khác; Tôi chỉ gặp sự cố khi tái tạo thành công đó bằng cách sử dụng Net::HTTP[S].

Nhờ bất kỳ ai có thể xác định những gì tôi đang làm sai!

Trả lời

5

Tôi muốn nói đây là vấn đề thiết lập Apache của bạn chứ không phải là vấn đề với Ruby.

Kiểm tra này ra:

$ curl https://palladium.wejn.cz/sslcerttest/ 
curl: (56) SSL read: error:14094410:SSL routines:SSL3_READ_BYTES:sslv3 alert handshake failure, errno 0 
$ curl https://palladium.wejn.cz/sslcerttest/ -E client.pem 
<pre>Yop.</pre> 

Và sau đó:

#!/usr/bin/ruby 
require 'net/http' 
require 'net/https' 
require 'openssl' 
require 'uri' 

ContentURI = URI.parse("https://palladium.wejn.cz/sslcerttest/") 
@cert_raw = File.read('client.pem') 
@cert_key_raw = @cert_raw 
TestDataPath = '.' 

req = Net::HTTP::Get.new(ContentURI.path) 
https = Net::HTTP.new(ContentURI.host, ContentURI.port) 
https.use_ssl = true 
https.cert = OpenSSL::X509::Certificate.new(@cert_raw) 
https.key = OpenSSL::PKey::RSA.new(@cert_key_raw) 
https.verify_mode = OpenSSL::SSL::VERIFY_PEER 
https.ca_file = File.join(TestDataPath, 'cacert.pem') 
resp = https.start { |cx| cx.request(req) } 
p resp 
p resp.body 

kết quả trong:

$ ruby a.rb 
#<Net::HTTPOK 200 OK readbody=true> 
"<pre>Yop.</pre>\n" 

$ dpkg -l ruby1.8 | tail -n1 | awk '{print $3}' 
1.8.7.302-2squeeze1 

$ ruby -v 
ruby 1.8.7 (2010-08-16 patchlevel 302) [x86_64-linux] 

Tất nhiên, cấu hình apache trong câu hỏi là:

<Directory /var/www/sslcerttest/> 
    SSLVerifyClient require 
    SSLVerifyDepth 5 
    SSLCACertificateFile /var/www/sslcerttest/cacert.pem 
    SSLCACertificatePath /var/www/sslcerttest/ 
    SSLOptions +FakeBasicAuth 
    SSLRequireSSL 
    SSLRequire %{SSL_CLIENT_S_DN_O} eq "Wejn s.r.o." and %{SSL_CLIENT_S_DN_OU} eq "Server Certificate" 
</Directory> 

Có thể đăng chi tiết bổ sung (cấu hình apache để kiểm tra chống lại) sẽ là một số trợ giúp khi theo dõi sự cố này ...

+0

xem nguồn openssl, thông báo lỗi có liên quan đến vé phiên bị thiếu (dữ liệu do khách hàng cung cấp cần thiết để tiếp tục phiên ssl); không biết tại sao điều đó lại xảy ra trong trường hợp này ... – Wejn