2012-01-24 19 views
8

Próbuję pobrać zasób przez SSL za pomocą Net::HTTP. Oto odpowiedni fragment kodu:Ruby 1.8.7 i Net :: HTTP: Tworzenie żądania SSL GET za pomocą certyfikatu klienta?

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) } 

lub naprzemiennie z ostatniego wiersza:

resp = https.get(ContentURI.path) 

I sprawdzeniu, że poszczególne bity (cert, klucz, CA cert, itp) są prawidłowe .

Problemem jest to, że cx.request(req) zgłasza wyjątek:

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

Dziennik błędów Apache SSL na serwerze zawiera następujące elementy:

[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 

CERT, klucz, a praca CA plik cert z tym hostem SSL za pośrednictwem innych narzędzi; Mam problem z odtworzeniem tego sukcesu programowo przy użyciu Net::HTTP[S].

Dziękuję każdemu, kto potrafi rozpoznać, co robię źle!

Odpowiedz

5

Powiedziałbym, że to kwestia konfiguracji serwera Apache, a nie problem z samą Ruby.

to sprawdzić:

$ 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> 

A potem:

#!/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 

skutkuje:

$ 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] 

oczywiście config apache w pytaniu:

<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> 

Być może opublikowanie dodatkowych szczegółów (konfiguracja apache do przetestowania) może być pomocne podczas śledzenia tego problemu ...

+0

patrząc na źródło openssl, komunikat o błędzie jest związany z brakującym biletem sesji (dane dostarczone przez klienta wymagane do wznowienia sesji ssl); nie ma pojęcia, dlaczego tak się dzieje w tym przypadku ... – Wejn

Powiązane problemy