2018-04-09 12:33:54 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
set -e
|
|
|
|
set -x
|
|
|
|
umask 022
|
|
|
|
|
|
|
|
VERSION=17.01.4
|
|
|
|
BASENAME=lede-imagebuilder-$VERSION-ar71xx-generic.Linux-x86_64
|
|
|
|
FILENAME=$BASENAME.tar.xz
|
|
|
|
URL=http://downloads.lede-project.org/releases/$VERSION/targets/ar71xx/generic/$FILENAME
|
|
|
|
|
2018-04-27 07:48:15 +00:00
|
|
|
# curl of vanilla LEDE doesn't support ECDSA at the moment
|
|
|
|
BASENAME=lede-imagebuilder-ar71xx-generic.Linux-x86_64
|
|
|
|
FILENAME=$BASENAME.tar.xz
|
|
|
|
URL=https://www.koodur.com/$FILENAME
|
|
|
|
|
|
|
|
|
2018-04-09 12:33:54 +00:00
|
|
|
if [ ! -e $BUILD/$FILENAME ]; then
|
|
|
|
wget -q $URL -O $BUILD/$FILENAME
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ ! -e $BUILD/$BASENAME ]; then
|
|
|
|
tar xf $BUILD/$FILENAME -C $BUILD
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Copy CA certificate
|
|
|
|
AUTHORITY=$(hostname -f)
|
|
|
|
|
|
|
|
mkdir -p $OVERLAY/etc/config
|
|
|
|
mkdir -p $OVERLAY/etc/uci-defaults
|
2018-04-27 07:48:15 +00:00
|
|
|
mkdir -p $OVERLAY/etc/certidude/authority/$AUTHORITY/
|
2018-05-15 07:45:29 +00:00
|
|
|
cp /var/lib/certidude/ca_cert.pem $OVERLAY/etc/certidude/authority/$AUTHORITY/
|
2018-04-27 07:48:15 +00:00
|
|
|
|
2018-04-09 12:33:54 +00:00
|
|
|
cat <<EOF > $OVERLAY/etc/config/certidude
|
|
|
|
|
|
|
|
config authority
|
2018-04-27 07:48:15 +00:00
|
|
|
option gateway "$ROUTER"
|
|
|
|
option hostname "$AUTHORITY"
|
2018-04-09 12:33:54 +00:00
|
|
|
option trigger wan
|
2018-04-27 07:48:15 +00:00
|
|
|
option key_type $AUTHORITY_CERTIFICATE_ALGORITHM
|
2018-04-09 12:33:54 +00:00
|
|
|
option key_length 2048
|
2018-04-27 07:48:15 +00:00
|
|
|
option key_curve secp384r1
|
2018-04-09 12:33:54 +00:00
|
|
|
|
|
|
|
EOF
|
|
|
|
|
2018-04-27 07:48:15 +00:00
|
|
|
case $AUTHORITY_CERTIFICATE_ALGORITHM in
|
|
|
|
rsa)
|
|
|
|
echo ": RSA /etc/certidude/authority/$AUTHORITY/host_key.pem" >> $OVERLAY/etc/ipsec.secrets
|
|
|
|
;;
|
|
|
|
ec)
|
|
|
|
echo ": ECDSA /etc/certidude/authority/$AUTHORITY/host_key.pem" >> $OVERLAY/etc/ipsec.secrets
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
echo "Unknown algorithm $AUTHORITY_CERTIFICATE_ALGORITHM"
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
cat << EOF > $OVERLAY/etc/certidude/authority/$AUTHORITY/updown
|
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
CURL="curl -m 3 -f --key /etc/certidude/authority/$AUTHORITY/host_key.pem --cert /etc/certidude/authority/$AUTHORITY/host_cert.pem --cacert /etc/certidude/authority/$AUTHORITY/ca_cert.pem"
|
|
|
|
URL="https://$AUTHORITY:8443/api/signed/\$(uci get system.@system[0].hostname)/script/"
|
|
|
|
|
|
|
|
case \$PLUTO_VERB in
|
|
|
|
up-client)
|
|
|
|
logger -t certidude -s "Downloading and executing \$URL"
|
|
|
|
\$CURL \$URL -o /tmp/script.sh && sh /tmp/script.sh
|
|
|
|
;;
|
|
|
|
*) ;;
|
|
|
|
esac
|
2018-04-09 12:33:54 +00:00
|
|
|
EOF
|
|
|
|
|
2018-04-27 07:48:15 +00:00
|
|
|
chmod +x $OVERLAY/etc/certidude/authority/$AUTHORITY/updown
|
|
|
|
|
2018-04-09 12:33:54 +00:00
|
|
|
cat << EOF > $OVERLAY/etc/ipsec.conf
|
|
|
|
|
|
|
|
config setup
|
2018-04-27 07:48:15 +00:00
|
|
|
strictcrlpolicy=yes
|
2018-04-09 12:33:54 +00:00
|
|
|
|
|
|
|
ca $AUTHORITY
|
2018-04-27 07:48:15 +00:00
|
|
|
auto=add
|
|
|
|
cacert=/etc/certidude/authority/$AUTHORITY/ca_cert.pem
|
|
|
|
ocspuri = http://$AUTHORITY/api/ocsp/
|
|
|
|
|
|
|
|
conn %default
|
|
|
|
keyingtries=%forever
|
|
|
|
dpdaction=restart
|
|
|
|
closeaction=restart
|
2018-05-02 08:11:01 +00:00
|
|
|
ike=$IKE
|
|
|
|
esp=$ESP
|
2018-04-27 07:48:15 +00:00
|
|
|
left=%defaultroute
|
|
|
|
leftcert=/etc/certidude/authority/$AUTHORITY/host_cert.pem
|
|
|
|
leftca="$AUTHORITY_CERTIFICATE_DISTINGUISHED_NAME"
|
|
|
|
rightca="$AUTHORITY_CERTIFICATE_DISTINGUISHED_NAME"
|
|
|
|
|
|
|
|
conn client-to-site
|
|
|
|
auto=start
|
|
|
|
right="$ROUTER"
|
2018-05-02 08:11:01 +00:00
|
|
|
rightsubnet="$SUBNETS"
|
2018-04-27 07:48:15 +00:00
|
|
|
leftsourceip=%config
|
|
|
|
leftupdown=/etc/certidude/authority/$AUTHORITY/updown
|
2018-04-09 12:33:54 +00:00
|
|
|
|
|
|
|
EOF
|
|
|
|
|
2018-04-27 07:48:15 +00:00
|
|
|
cat << EOF > $OVERLAY/etc/uci-defaults/99-uhttpd-disable-https
|
|
|
|
uci delete uhttpd.main.listen_https
|
|
|
|
uci delete uhttpd.main.redirect_https
|
|
|
|
EOF
|