- fixes, intendation
[oweals/gnunet.git] / src / gns / gnunet-gns-proxy-setup-ca
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 if ! which certtool > /dev/null
6 then
7   echo "'certtool' command not found. Please install it."
8   exit 1
9 fi
10
11 echo "Generating CA"
12 options=''
13 while getopts "c:" opt; do
14   case $opt in
15     c)
16       options="$options -c $OPTARG"
17       ;;
18     \?)
19       echo "Invalid option: -$OPTARG" >&2
20       exit 1
21       ;;
22     :)
23       echo "Option -$OPTARG requires an argument." >&2
24       exit 1
25       ;;
26   esac
27 done
28
29 GNSCERT=`mktemp /tmp/gnscertXXXXXX.pem`
30 GNSCAKY=`mktemp /tmp/gnscakeyXXXXXX.pem`
31 GNSCANO=`mktemp /tmp/gnscakeynoencXXXXXX.pem`
32 GNS_CA_CERT_PEM=`gnunet-config -s gns-proxy -o PROXY_CACERT -f $options`
33 mkdir -p `dirname $GNS_CA_CERT_PEM`
34
35 openssl req -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"
36
37 echo "Removing passphrase from key"
38 openssl rsa -passin pass:"GNU Name System" -in $GNSCAKY -out $GNSCANO
39
40 echo "Making private key available to gnunet-gns-proxy"
41 cat $GNSCERT $GNSCANO > $GNS_CA_CERT_PEM
42
43 echo "Importing CA into browsers"
44 for f in ~/.mozilla/firefox/*.default/
45 do
46   if [ -d $f ]; then
47     echo "Importing CA info Firefox at $f/"
48 # delete old certificate (if any)
49     certutil -D -n "GNS Proxy CA" -d "$f" >/dev/null 2>/dev/null
50 # add new certificate
51     certutil -A -n "GNS Proxy CA" -t CT,, -d "$f" < $GNSCERT
52   fi
53 done
54
55 if [ -d ~/.pki/nssdb/ ]; then
56   echo "Importing CA into Chrome at ~/.pki/nssdb/"
57 # delete old certificate (if any)
58   certutil -D -n "GNS Proxy CA" -d ~/.pki/nssdb/ >/dev/null 2>/dev/null
59 # add new certificate
60   certutil -A -n "GNS Proxy CA" -t CT,, -d ~/.pki/nssdb/ < $GNSCERT
61 fi
62
63 echo "Cleaning up."
64 rm -f $GNSCAKY $GNSCANO $GNSCERT
65
66 echo "==================================="
67 echo "You can now start gnunet-gns-proxy."
68 echo "Afterwards, configure your browser "
69 echo " to use a SOCKS proxy on port 7777."
70 echo "==================================="