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.


In reply to Re: Getting an SSL Certificate Expiration Date by haukex
in thread Getting an SSL Certificate Expiration Date by enemyofthestate

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.