Class: SSLCheck::Client
- Inherits:
-
Object
- Object
- SSLCheck::Client
- Defined in:
- lib/sslcheck/client.rb
Defined Under Namespace
Classes: Response
Instance Method Summary collapse
- #get(url) ⇒ Object
-
#initialize ⇒ Client
constructor
A new instance of Client.
Constructor Details
#initialize ⇒ Client
Returns a new instance of Client.
31 32 33 |
# File 'lib/sslcheck/client.rb', line 31 def initialize @response = Response.new end |
Instance Method Details
#get(url) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/sslcheck/client.rb', line 35 def get(url) begin uri = determine_uri(url) sock = TCPSocket.new(uri.host, 443) ctx = OpenSSL::SSL::SSLContext.new ctx.set_params(:verify_mode => OpenSSL::SSL::VERIFY_PEER) @socket = OpenSSL::SSL::SSLSocket.new(sock, ctx).tap do |socket| socket.sync_close = true socket.connect @response.host_name = uri.host @response.raw_peer_cert = OpenSSL::X509::Certificate.new(socket.peer_cert) @response.raw_peer_cert_chain = socket.peer_cert_chain end @socket.sysclose rescue SocketError @response.errors << SSLCheck::Errors::Connection::SocketError.new({:name => "Connection Error", :type => :socket_error, :message => "The connection to #{url} failed."}) rescue URI::InvalidURIError @response.errors << SSLCheck::Errors::Connection::InvalidURI.new({:name => "Invalid URI Error", :type => :invalid_uri, :message => "The URI, #{url}, is not a valid URI."}) rescue OpenSSL::SSL::SSLError @response.errors << SSLCheck::Errors::Connection::SSLVerify.new({:name => "OpenSSL Verification Error", :type => :openssl_error, :message => "There was a peer verification error."}) end @response end |