How do I decode/parse a X509 SSL Cert

Discussion in 'Ruby' started by marc spitzer, Sep 3, 2009.

  1. marc spitzer

    marc spitzer Guest

    Hi,

    Did a bit of googleing on this and did not have much luck.
    I would like to connect to a ssl webserver and download the
    cert. Then I would like to decode the cert and pares out some
    fields of interest, host name and expire date, and make it a
    report that gets mailed out weekly.

    My question is what would be the best way to get and decode the
    cert? Decode could be selective, I ask for the bits I want or a
    dump of the cert lile 'openssl x509 -noout -text -in file.crt'

    thanks,

    marc



    --

    SDF Public Access UNIX System - http://sdf.lonestar.org
     
    marc spitzer, Sep 3, 2009
    #1
    1. Advertising

  2. marc spitzer

    yermej Guest

    On Sep 3, 3:43 pm, marc spitzer <> wrote:
    > Hi,
    >
    > Did a bit of googleing on this and did not have much luck.
    > I would like to connect to a ssl webserver and download the
    > cert.  Then I would like to decode the cert and pares out some
    > fields of interest, host name and expire date, and make it a
    > report that gets mailed out weekly.  
    >
    > My question is what would be the best way to get and decode the
    > cert?


    require 'openssl'

    cert = OpenSSL::X509::Certificate.new(File.read(cert_file_name))
    cert.subject
    cert.not_after
     
    yermej, Sep 4, 2009
    #2
    1. Advertising

  3. marc spitzer

    yermej Guest

    On Sep 3, 3:43 pm, marc spitzer <> wrote:
    > Hi,
    >
    > Did a bit of googleing on this and did not have much luck.
    > I would like to connect to a ssl webserver and download the
    > cert.  Then I would like to decode the cert and pares out some
    > fields of interest, host name and expire date, and make it a
    > report that gets mailed out weekly.  
    >
    > My question is what would be the best way to get and decode the
    > cert?


    Sorry, I forgot to answer the first part of the question. And I was
    less sure of that anyway. This should do it though:

    require 'net/https'

    host = 'www.example.com'
    port = 443
    path = '/'

    http = Net::HTTP.new(host, port)
    http.use_ssl = true

    http.start(path) do |conn|
    cert = OpenSSL::X509::Certificate.new conn.peer_cert
    cert.not_after
    cert.subject
    end

    There are some useful files in the Ruby tarball in sample/openssl if
    you'll be using Ruby OpenSSL very much.
     
    yermej, Sep 4, 2009
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. David Chan via .NET 247
    Replies:
    1
    Views:
    362
    Dominick Baier [DevelopMentor]
    Jun 2, 2005
  2. Keyset does not exist X509Certificate

    Keyset does not exist at Microsoft.Web.Services.Security.X509.X509

    Keyset does not exist X509Certificate, Jun 12, 2004, in forum: ASP .Net Web Services
    Replies:
    0
    Views:
    225
    Keyset does not exist X509Certificate
    Jun 12, 2004
  3. gardavis
    Replies:
    0
    Views:
    257
    gardavis
    Jul 2, 2004
  4. Bat'on

    Websevice secured with X509 cert (ssl)

    Bat'on, Feb 2, 2005, in forum: ASP .Net Web Services
    Replies:
    2
    Views:
    133
    JerryK
    Mar 9, 2005
  5. charlief1975

    Consuming a secure webservice using x509 cert (p12)

    charlief1975, May 19, 2005, in forum: ASP .Net Web Services
    Replies:
    0
    Views:
    172
    charlief1975
    May 19, 2005
Loading...

Share This Page