use strict;
my (%certhash, $key, $val);
my $cert_db_path = $ENV{'HOME'} . "/.netscape/cert7";
my $rcnt = 0;
print STDERR "opening '$cert_db_path'.\n";
if( ! dbmopen(%certhash, $cert_db_path, undef) ) {
print STDERR "dbmopen failed: '$!'.\n";
}
while ( ($key, $val) = each %certhash ) {
my ($rec_type, $data, $klen, $vlen, $cert);
$rcnt++;
($rec_type, $data) = unpack("Ca*", $key);
$klen = length($key);
$vlen = length($val);
print STDERR "$rcnt: \t record type: '$rec_type'. key len: " .
"'$klen, \t value len: '$vlen'.\n";
if($rec_type != 1) {
next;
}
$cert = substr($val, 13);
open(C_FILE, ">tmp/cert-$rcnt.der");
print C_FILE "$cert";
close(C_FILE);
}
dbmclose(%certhash);