Giter Club home page Giter Club logo

Comments (4)

tarcieri avatar tarcieri commented on August 30, 2024 1

Seems like you could use an accessor like HTTP::Connection#peer_cert

from http.

tarcieri avatar tarcieri commented on August 30, 2024

I don't believe so. Which type were you thinking of having an accessor for it?

from http.

jots avatar jots commented on August 30, 2024

some way to access peer_cert? like this

require 'openssl'
require 'net/http'
require 'uri'

url = ARGV[0] # get the URL from the command line arguments

uri = URI.parse(url)
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true # use SSL for the request

begin
  http.start
rescue OpenSSL::SSL::SSLError => e
  puts "Error: SSL connection could not be established. #{e.message}"
  exit
end

cert = http.peer_cert
if cert.nil?
  puts "Error: No SSL certificate could be retrieved."
  exit
end

cert = OpenSSL::X509::Certificate.new(cert)

puts "Issuer: #{cert.issuer}"
puts "Common Names: #{cert.subject.to_a.select { |name, _, _| name == 'CN' }.map { |_, value, _| value }.join(', ')}"
puts "Valid From: #{cert.not_before}"
puts "Valid Until: #{cert.not_after}"

example:

$ ruby getcert.rb https://google.com
Issuer: /C=US/O=Google Trust Services LLC/CN=GTS CA 1C3
Common Names: *.google.com
Valid From: 2023-03-20 08:22:16 UTC
Valid Until: 2023-06-12 08:22:15 UTC

from http.

jots avatar jots commented on August 30, 2024

I think this should suffice:
response = HTTP.get('https://www.example.com')
pp response.connection.instance_variable_get("@socket").instance_variable_get("@socket").peer_cert

from http.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.