2 # a script for exporting Netscape navigator's certificate database
5 # $Id: export_certs.pl,v 1.1 2000/08/08 06:37:56 aspa Exp $.
7 # additional information:
8 # - http://www.drh-consultancy.demon.co.uk/cert7.html
11 # conversion from DER format:
12 # /usr/local/ssl/bin/x509 -inform der -text < cert.der
17 my (%certhash, $key, $val);
18 my $cert_db_path = $ENV{'HOME'} . "/.netscape/cert7";
21 print STDERR "opening '$cert_db_path'.\n";
23 if( ! dbmopen(%certhash, $cert_db_path, undef) ) {
24 print STDERR "dbmopen failed: '$!'.\n";
27 while ( ($key, $val) = each %certhash ) {
28 my ($rec_type, $data, $klen, $vlen, $cert);
32 # get key info: [type] [data]
33 ($rec_type, $data) = unpack("Ca*", $key);
35 # get additional diagnostics info.
38 print STDERR "$rcnt: \t record type: '$rec_type'. key len: " .
39 "'$klen, \t value len: '$vlen'.\n";
43 # not a certificate record. skip it.
47 # it is a certificate record.
49 # certificates are stored in DER format starting at offset 13.
50 $cert = substr($val, 13);
52 # save cert in DER format.
53 open(C_FILE, ">tmp/cert-$rcnt.der");