Skip to content

Instantly share code, notes, and snippets.

@buckett
Created July 22, 2015 14:03
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 buckett/cc3ceca23a43beab2b71 to your computer and use it in GitHub Desktop.
Save buckett/cc3ceca23a43beab2b71 to your computer and use it in GitHub Desktop.
Show all the certificates in a certificate chains file.
#!/usr/bin/perl
# script for splitting multi-cert input into individual certs
# Artistic Licence
#
# v0.0.1 Nick Burch <nick@tirian.magd.ox.ac.uk>
# v0.0.2 Tom Yates <tyates@gatekeeper.ltd.uk>
# v0.0.3 Matthew Buckett <matthew.buckett@it.ox.ac.uk>
#
use strict;
use warnings;
my $filename = shift;
unless($filename) {
die("You must specify a cert file.\n");
}
open INP, "<$filename" or die("Unable to load \"$filename\"\n");
my $thisfile = "";
while(<INP>) {
$thisfile .= $_;
# Some certs have had trailing whitespace after the ---- so we're relaxed about this.
if($_ =~ /^-+END(\s\w+)?\sCERTIFICATE-+/) {
print "Found a complete certificate:\n";
print `echo "$thisfile" | openssl x509 -noout -text`;
$thisfile = "";
}
}
close INP;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment