]> snippets.scripts.mit.edu Git - Scripts/git/.git/blame - certs/pkcs2pem
kdo: Upstream krb5 now supports kswitch
[Scripts/git/.git] / certs / pkcs2pem
CommitLineData
bd1c1551 1#!/bin/bash
6e450839
NE
2
3set -e
4
5usage() {
6 cat <<EOF
dedfe0c0 7Usage: $0 <cert.p12> <cert.pem>
6e450839
NE
8
9Transforms a .p12 file, for instance as exported by Firefox's
dedfe0c0
AK
10cerfiticate "backup" feature, into a PEM file that contains your
11private key and certificate.
6e450839
NE
12
13To export your certificate from Firefox, go to Edit|Preferences,
14Advanced|Security|View Certificates, and ``Backup'' your certificate
15to a file. Firefox will save it as a PKCS12 certificate. You must
16enter a passphrase, which this script will prompt you for.
17
18EOF
19 exit 1
20}
21
22[ "$#" -eq 2 ] || usage
23
24pkcs="$1"
dedfe0c0 25pem="$2"
6e450839 26
dedfe0c0 27openssl pkcs12 -in "$pkcs" -nodes -out "$pem"
6e450839
NE
28
29cat >&2 <<EOF
dedfe0c0 30Private key and certificate written to $pem
6e450839 31
dedfe0c0 32Keep this file safe!
6e450839 33
dedfe0c0
AK
34You can pass this to wget's --certificate and --private-key options,
35or to curl's --cert option.
6e450839 36
dedfe0c0 37To use it with perl's LWP, set the following environment variables:
6e450839
NE
38
39EOF
40
8dd88228
AK
41pem=$(readlink -f "$pem")
42
bd1c1551
AK
43printf 'HTTPS_CERT_FILE=%q\n' "$pem"
44printf 'HTTPS_KEY_FILE=%q\n' "$pem"
6e450839 45