Skip to content

Instantly share code, notes, and snippets.

@waffle2k
Created November 19, 2009 04:10
Show Gist options
  • Save waffle2k/238542 to your computer and use it in GitHub Desktop.
Save waffle2k/238542 to your computer and use it in GitHub Desktop.
#!/usr/bin/perl
#
# Attempt to match modulus of SSL CERTs/KEYs/CSRs
#
# author: pblair(AT)tucows(dot)com
# updated: Fri Aug 28 09:47:10 EDT 2009
my( $KEY,$CRT,$CSR );
for my $key ( @ARGV ){
if ( $key =~ /crt$/i ){
$CRT = $key;
}
if( $key =~ /key$/i ){
$KEY = $key;
}
if( $key =~ /csr$/i ){
$CSR = $key;
}
}
# Get the checksum
my $crtsum = '';
my $keysum = '';
my $csrsum = '';
unless( $CRT eq '' ){
$crtsum = `openssl x509 -noout -modulus -in $CRT | openssl md5`;
}
unless ( $KEY eq '' ){
$keysum = `openssl rsa -noout -modulus -in $KEY | openssl md5`;
}
chomp( $crtsum );
chomp( $keysum );
print "CRT:[$CRT] : [$crtsum]\n";
print "KEY:[$KEY] : [$keysum]\n";
unless( $CSR eq '' ) {
$csrsum = `openssl req -noout -modulus -in $CSR | openssl md5`;
chomp( $csrsum );
if( $csrsum eq $keysum ){
print "CSR:[$CSR] : [$csrsum]\n";
}
else{
die("CSR does not match checksum test\n");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment