summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xexamples/browser-export.sh31
1 files changed, 31 insertions, 0 deletions
diff --git a/examples/browser-export.sh b/examples/browser-export.sh
new file mode 100755
index 0000000..efb51de
--- /dev/null
+++ b/examples/browser-export.sh
@@ -0,0 +1,31 @@
1#!/bin/sh
2
3extract_certificate_and_private_key()
4{
5 passphrase_file=$(mktemp) || exit
6 echo asdf > $passphrase_file
7 local nssdb="$1" name="$2"
8 pk12util -d sql:"$nssdb" -n "$name" -w "$passphrase_file" -o /dev/stdout |
9 openssl pkcs12 -passin file:"$passphrase_file" -nodes
10 rm "$passphrase_file"
11}
12
13extract_public_key()
14{
15 local nssdb="$1" name="$2"
16 certutil -d sql:"$nssdb" -L -n "$name" -a | openssl x509 -pubkey -noout
17}
18
19for nssdb in "$HOME/.pki/nssdb" "$HOME"/.mozilla/firefox/*; do
20 [ -d "$nssdb" ] || continue
21 [ -e "$nssdb"/cert8.db -o -e "$nssdb"/cert9.db ] || continue
22 echo "nssdb=$nssdb" >&2
23 certutil -d sql:"$nssdb" -L | sed -ne 's/ *.,.,.$//p' |
24 while read name; do
25
26# certutil -d sql:"$nssdb" -K -n "$name"
27# extract_public_key "$nssdb" "$name"
28 extract_certificate_and_private_key "$nssdb" "$name"
29
30 done
31done