revert sed and fix a typo
[oweals/gnunet.git] / src / gns / gnunet-gns-proxy-setup-ca.in
1 #!/bin/sh
2 # This shell script will generate an X509 certificate for your gnunet-gns-proxy
3 # and install it (for both GNUnet and your browser).
4 #
5
6 # TODO: We should sed the real paths to the binaries involved here.
7 OPENSSLCFG=@PREFIX@
8 if ! which openssl > /dev/null
9 then
10     echo "'openssl' command not found. Please install it."
11     exit 1
12 fi
13
14 # Keep it simple so that people can install the tools later on.
15 OPENSSLBIN=openssl
16 CERTUTILBIN=certutil
17
18 echo "Generating CA"
19 options=''
20 while getopts "c:" opt; do
21   case $opt in
22     c)
23       options="$options -c $OPTARG"
24       ;;
25     \?)
26       echo "Invalid option: -$OPTARG" >&2
27       exit 1
28       ;;
29     :)
30       echo "Option -$OPTARG requires an argument." >&2
31       exit 1
32       ;;
33   esac
34 done
35
36 GNSCERT=`mktemp /tmp/gnscertXXXXXX.pem`
37 GNSCAKY=`mktemp /tmp/gnscakeyXXXXXX.pem`
38 GNSCANO=`mktemp /tmp/gnscakeynoencXXXXXX.pem`
39 GNS_CA_CERT_PEM=`gnunet-config -s gns-proxy -o PROXY_CACERT -f $options`
40 mkdir -p `dirname $GNS_CA_CERT_PEM`
41
42 OPENSSLBIN req -config $OPENSSLCFG -new -x509 -days 3650 -extensions v3_ca -keyout $GNSCAKY -out $GNSCERT -subj "/C=ZZ/L=World/O=GNU/OU=GNUnet/CN=GNS Proxy CA/emailAddress=bounce@gnunet.org" -passout pass:"GNU Name System"
43
44 echo "Removing passphrase from key"
45 OPENSSLBIN rsa -passin pass:"GNU Name System" -in $GNSCAKY -out $GNSCANO
46
47 echo "Making private key available to gnunet-gns-proxy"
48 cat $GNSCERT $GNSCANO > $GNS_CA_CERT_PEM
49
50 if ! which certutil > /dev/null
51 then
52   echo "The 'certutil' command was not found. Not importing into browsers."
53   echo "For 'certutil' install nss."
54 else
55   echo "Importing CA into browsers"
56   for f in ~/.mozilla/firefox/*.*/
57   do
58     if [ -d $f ]; then
59       echo "Importing CA info Firefox at $f"
60       # delete old certificate (if any)
61       @CERTUTILBIN@ -D -n "GNS Proxy CA" -d "$f" >/dev/null 2>/dev/null
62       # add new certificate
63       @CERTUTILBIN@ -A -n "GNS Proxy CA" -t CT,, -d "$f" < $GNSCERT
64     fi
65   done
66
67   if [ -d ~/.pki/nssdb/ ]; then
68     echo "Importing CA into Chrome at ~/.pki/nssdb/"
69     # delete old certificate (if any)
70     @CERTUTILBIN@ -D -n "GNS Proxy CA" -d ~/.pki/nssdb/ >/dev/null 2>/dev/null
71     # add new certificate
72     @CERTUTILBIN@ -A -n "GNS Proxy CA" -t CT,, -d ~/.pki/nssdb/ < $GNSCERT
73   fi
74 fi
75
76 echo "Cleaning up."
77 rm -f $GNSCAKY $GNSCANO $GNSCERT
78
79 echo "==================================="
80 echo "You can now start gnunet-gns-proxy."
81 echo "Afterwards, configure your browser "
82 echo " to use a SOCKS proxy on port 7777."
83 echo "==================================="