Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- irb(main):219:0* tcp_client = TCPSocket.new("paypal.com", 443)
- ssl_client = OpenSSL::SSL::SSLSocket.new(tcp_client)
- ssl_client.connect
- cert = OpenSSL::X509::Certificate.new(ssl_client.peer_cert)
- ssl_client.sysclose
- tcp_client.close
- certprops = OpenSSL::X509::Name.new(cert.issuer).to_a
- issuer = certprops.select { |name, data, type| name == "O" }.first[1]
- results = {
- :valid_on => cert.not_before,
- :valid_until => cert.not_after,
- :issuer => issuer,
- :valid => (ssl_client.verify_result == 0)
- }
- => #<TCPSocket:fd 11>
- irb(main):220:0> ssl_client = OpenSSL::SSL::SSLSocket.new(tcp_client)
- => #<OpenSSL::SSL::SSLSocket:0x007fed94277548 @io=#<TCPSocket:fd 11>, @context=#<OpenSSL::SSL::SSLContext:0x007fed94277520 @cert=nil, @key=nil, @client_ca=nil, @ca_file=nil, @ca_path=nil, @timeout=nil, @verify_mode=nil, @verify_depth=nil, @renegotiation_cb=nil, @verify_callback=nil, @options=nil, @cert_store=nil, @extra_chain_cert=nil, @client_cert_cb=nil, @tmp_dh_callback=nil, @session_id_context=nil, @session_get_cb=nil, @session_new_cb=nil, @session_remove_cb=nil, @servername_cb=nil, @npn_protocols=nil, @npn_select_cb=nil>, @sync_close=false, @hostname=nil, @eof=false, @rbuffer="", @sync=true>
- irb(main):221:0> ssl_client.connect
- => #<OpenSSL::SSL::SSLSocket:0x007fed94277548 @io=#<TCPSocket:fd 11>, @context=#<OpenSSL::SSL::SSLContext:0x007fed94277520 @cert=nil, @key=nil, @client_ca=nil, @ca_file=nil, @ca_path=nil, @timeout=nil, @verify_mode=nil, @verify_depth=nil, @renegotiation_cb=nil, @verify_callback=nil, @options=nil, @cert_store=nil, @extra_chain_cert=nil, @client_cert_cb=nil, @tmp_dh_callback=nil, @session_id_context=nil, @session_get_cb=nil, @session_new_cb=nil, @session_remove_cb=nil, @servername_cb=nil, @npn_protocols=nil, @npn_select_cb=nil>, @sync_close=false, @hostname=nil, @eof=false, @rbuffer="", @sync=true, @callback_state=nil>
- irb(main):222:0> cert = OpenSSL::X509::Certificate.new(ssl_client.peer_cert)
- => #<OpenSSL::X509::Certificate subject=#<OpenSSL::X509::Name:0x007fed9427e028>, issuer=#<OpenSSL::X509::Name:0x007fed9427dfb0>, serial=#<OpenSSL::BN:0x007fed9427df38>, not_before=2013-01-10 00:00:00 UTC, not_after=2015-01-11 23:59:59 UTC>
- irb(main):223:0> ssl_client.sysclose
- => nil
- irb(main):224:0> tcp_client.close
- => nil
- irb(main):225:0>
- irb(main):226:0* certprops = OpenSSL::X509::Name.new(cert.issuer).to_a
- => [["C", "US", 19], ["O", "VeriSign, Inc.", 19], ["OU", "VeriSign Trust Network", 19], ["OU", "Terms of use at https://www.verisign.com/rpa (c)10", 19], ["CN", "VeriSign Class 3 Secure Server CA - G3", 19]]
- irb(main):227:0> issuer = certprops.select { |name, data, type| name == "O" }.first[1]
- => "VeriSign, Inc."
- irb(main):228:0> results = {
- irb(main):229:1* :valid_on => cert.not_before,
- irb(main):230:1* :valid_until => cert.not_after,
- irb(main):231:1* :issuer => issuer,
- irb(main):232:1* :valid => (ssl_client.verify_result == 0)
- irb(main):233:1> }
- => {:valid_on=>2013-01-10 00:00:00 UTC, :valid_until=>2015-01-11 23:59:59 UTC, :issuer=>"VeriSign, Inc.", :valid=>false}
- irb(main):234:0>
- irb(main):235:0*
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement