-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a tool to check public key size of key authorities (not embedded …
…certificates, but our trusted roots).
- Loading branch information
Showing
2 changed files
with
89 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| #!/usr/bin/perl -w | ||
| use File::Temp qw(tempfile); | ||
|
|
||
| while (<>) { | ||
|
|
||
| # | ||
| # Handle certificate header line. | ||
| # | ||
| if (/BEGIN CERTIFICATE/) { | ||
|
|
||
| # | ||
| # Output header line. | ||
| # | ||
| print "Authority certificate:\n"; | ||
|
|
||
| # | ||
| # Create a temporary file for this certificate in PEM format. | ||
| # | ||
| ($fh, $filename) = tempfile(UNLINK => 1); | ||
| #print "temp file is: $filename\n"; | ||
|
|
||
| # do not buffer output to the temporary file | ||
| select((select($fh), $|=1)[0]); | ||
| } | ||
|
|
||
| # | ||
| # Put all lines into a temporary file. | ||
| # | ||
| print $fh $_; | ||
|
|
||
| # | ||
| # If this is the last line of the certificate, actually do | ||
| # something with it. | ||
| # | ||
| if (/END CERTIFICATE/) { | ||
| # | ||
| # Don't close the temporary file yet, because that would cause it | ||
| # to be deleted. We've already arranged for buffering to be | ||
| # disabled, so the file can simply be passed to other applications | ||
| # as input, perhaps multiple times. | ||
| # | ||
|
|
||
| # | ||
| # Use openssl to convert the certificate to text | ||
| # | ||
| my(@lines, $issuer, $subjectCN, $issuerCN, $pubSize); | ||
| $cmd = "openssl x509 -in $filename -noout -text -nameopt RFC2253 |"; | ||
| open(SSL, $cmd) || die "could not open openssl subcommand"; | ||
| while (<SSL>) { | ||
| push @lines, $_; | ||
| if (/^\s*Issuer:\s*(.*)$/) { | ||
| $issuer = $1; | ||
| print " Issuer: $issuer\n"; | ||
| } | ||
| if (/^\s*Subject:\s*(.*)$/) { | ||
| $subject = $1; | ||
| print " Subject: $subject\n"; | ||
| } | ||
| if (/RSA Public Key: \((\d+) bit\)/) { | ||
| $pubSize = $1; | ||
| print " Public key size: $pubSize\n"; | ||
| if ($pubSize < 1024) { | ||
| print " *** PUBLIC KEY TOO SHORT ***\n"; | ||
| } | ||
| } | ||
| } | ||
| close SSL; | ||
| #print " text lines: $#lines\n"; | ||
|
|
||
| # | ||
| # Close the temporary file, which will also cause | ||
| # it to be deleted. | ||
| # | ||
| close $fh; | ||
|
|
||
| print "\n"; | ||
| } | ||
| } |