122
122
my $fname = $_[0];
123
123
my $hashopt = $_[1] || '-subject_hash';
124
124
$fname =~ s/'/'\\''/g;
125
my ($hash, $fprint) = `"$openssl" x509 $hashopt -fingerprint -noout -in "$fname"`;
131
# Search for an unused hash filename
132
while(exists $hashlist{"$hash.$suffix"}) {
133
# Hash matches: if fingerprint matches its a duplicate cert
134
if($hashlist{"$hash.$suffix"} eq $fprint) {
135
print STDERR "WARNING: Skipping duplicate certificate $fname\n";
141
print "$fname => $hash\n";
142
$symlink_exists=eval {symlink("",""); 1};
143
if ($symlink_exists) {
144
symlink $fname, $hash;
146
open IN,"<$fname" or die "can't open $fname for read";
147
open OUT,">$hash" or die "can't open $hash for write";
148
print OUT <IN>; # does the job for small text files
152
$hashlist{$hash} = $fprint;
125
open my $in_fh, '<', $fname or die "can't open $fname for read";
126
my $cert = eval {local $/ = undef; <$in_fh>};
129
while ($cert =~ /^(-----BEGIN CERTIFICATE-----.*?-----END CERTIFICATE-----)$/gms)
132
my $tfile = `tempfile`;
134
open my $tfile_fh, '>', $tfile or die "can't open $tfile for write";
135
print {$tfile_fh} "$part\n";
138
my ($hash, $fprint) = `"$openssl" x509 $hashopt -fingerprint -noout -in "$tfile"`;
144
# Search for an unused hash filename
145
while(exists $hashlist{"$hash.$suffix"}) {
146
# Hash matches: if fingerprint matches its a duplicate cert
147
if($hashlist{"$hash.$suffix"} eq $fprint) {
148
print STDERR "WARNING: Skipping duplicate certificate $fname\n";
155
print "$fname => $hash\n";
156
$symlink_exists=eval {symlink("",""); 1};
157
if ($symlink_exists) {
158
symlink $fname, $hash;
160
open IN,"<$tfile" or die "can't open $tfile for read";
161
open OUT,">$hash" or die "can't open $hash for write";
162
print OUT <IN>; # does the job for small text files
166
$hashlist{$hash} = $fprint;
168
} ## end while ($cert =~ /^(-----BEGIN ...
155
171
sub link_hash_cert_old {