in reply to Getting an SSL Certificate Expiration Date

I'm not enough of an expert with LWP to know if this is the "right" way, but it's based on what worked for me over in Re: "This site is not secure" warning message:

use warnings; use strict; use LWP::UserAgent; use Net::SSLeay; use LWP::Protocol::https (); # just to make sure this is installed use Class::Method::Modifiers qw/around/; # wrap this method to fetch additional info from the cert around 'LWP::Protocol::https::_get_sock_info' => sub { my $orig = shift; my ($self, $res, $sock) = @_; my $cert = $sock->peer_certificate; $res->push_header("Client-SSL-Cert-NotAfter" => Net::SSLeay::P_ASN1_TIME_get_isotime( Net::SSLeay::X509_get_notAfter($cert) ) ); $orig->(@_); }; my $ua = LWP::UserAgent->new; my $res = $ua->get("https://www.perlmonks.org/"); die $res->status_line unless $res->is_success; my @issuer = $res->header("client-ssl-cert-issuer"); my @subject = $res->header("client-ssl-cert-subject"); my @notAfter = $res->header("client-ssl-cert-notafter"); print " Issuer: @issuer\n Subject: @subject\nnotAfter: @notAfter\n"; __END__ Issuer: /C=US/ST=New Jersey/L=Jersey City/O=The USERTRUST Network/CN +=USERTrust RSA Domain Validation Secure Server CA Subject: /CN=perlmonks.org notAfter: 2022-09-02T23:59:59Z

Update: See also my other post.

Replies are listed 'Best First'.
Re^2: Getting an SSL Certificate Expiration Date
by Discipulus (Canon) on Feb 09, 2022 at 08:07 UTC
    Thanks haukex for this code! really useful. I must admit I tried something similar quite few times, with no success.

    Thanks to enemyofthestate for the interesting question and hippo for the contribution pointing to the right callback.

    What I ended using could be interesting and useful for someone else so I share it: I used the online service provided by digicert and a chrome extension (contextual menu ie: right clicking on a URL), an extension generated with my Automatic chrome extension generator

    extgen.pl SSL_Check https://www.digicert.com/help/?host=

    L*

    There are no rules, there are no thumbs..
    Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.