Skip to content

Instantly share code, notes, and snippets.

@mschmitt
Created August 23, 2010 13:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mschmitt/545485 to your computer and use it in GitHub Desktop.
Save mschmitt/545485 to your computer and use it in GitHub Desktop.
Trying to figure out how to extract certificate from SSL session
#!/usr/bin/perl -w
use strict;
use diagnostics;
use Data::Dumper;
use IO::Socket::INET;
use Net::SSLeay::OO;
use Net::SSLeay::OO::X509;
use Net::SSLeay::OO::Constants qw(OP_ALL);
my $sslctx = Net::SSLeay::OO::Context->new;
$sslctx->set_options(OP_ALL);
my $client = IO::Socket::INET->new('www.google.com:443')
or die "FAIL: $!";
my $sslclient = Net::SSLeay::OO::SSL->new(ctx => $sslctx);
$sslclient->set_fd($client);
$sslclient->connect;
my $cert = $sslclient->get_peer_certificate;
# Shows the certificate subject
print $cert->get_subject_name->oneline . "\n";
print Dumper($cert);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment