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