1#
2# a script for exporting Netscape navigator's certificate database
3# (aspa@hip.fi).
4#
5# $Id: export_certs.pl,v 1.1 2000/08/08 06:37:56 aspa Exp $.
6#
7# additional information:
8# - http://www.drh-consultancy.demon.co.uk/cert7.html
9# - man xxd
10#
11# conversion from DER format:
12# /usr/local/ssl/bin/x509 -inform der -text < cert.der
13#
14
15use strict;
16
17my (%certhash, $key, $val);
18my $cert_db_path = $ENV{'HOME'} . "/.netscape/cert7";
19my $rcnt = 0;
20
21print STDERR "opening '$cert_db_path'.\n";
22
23if( ! dbmopen(%certhash, $cert_db_path, undef) ) {
24	print STDERR "dbmopen failed: '$!'.\n";
25}
26
27while ( ($key, $val) = each %certhash ) {
28  my ($rec_type, $data, $klen, $vlen, $cert);
29
30  $rcnt++;
31
32  # get key info: [type] [data]
33  ($rec_type, $data) = unpack("Ca*", $key);
34
35  # get additional diagnostics info.
36  $klen = length($key);
37  $vlen = length($val);
38  print STDERR "$rcnt: \t record type: '$rec_type'. key len: " .
39    "'$klen, \t value len: '$vlen'.\n";
40
41  # check record type.
42  if($rec_type != 1) {
43    # not a certificate record. skip it.
44    next;
45  }
46
47  # it is a certificate record.
48
49  # certificates are stored in DER format starting at offset 13.
50  $cert = substr($val, 13);
51
52  # save cert in DER format.
53  open(C_FILE, ">tmp/cert-$rcnt.der");
54  print C_FILE "$cert";
55  close(C_FILE);
56
57}
58
59dbmclose(%certhash);
60
61