diff --git a/update/Readme.md b/update/Readme.md new file mode 100644 index 0000000..e00099b --- /dev/null +++ b/update/Readme.md @@ -0,0 +1,23 @@ +## Istruzioni +### Intro +Questo script consiste nell'ultimo step della challenge. Questo script viene eseguito con `sudo` dall'interfaccia nella pagina di aggiornamento firmware. + +Da inserire in `/etc/sudoers`: + +``` +www-data ALL=(root) NOPASSWD: /bin/bash /root/update.sh +``` + +Per generare la chiave per firmware le immagini: +``` +openssl genrsa -out key.pem 2048 +openssl rsa -in key.pem -outform PEM -pubout -out pub.pem + +``` + +Per firmare un file: +``` +openssl dgst -sha256 -sign private.pem -out update.tgz.sig update.tgz +cat update.tgz.sig > update.tgz.cc +cat update.tgz >> update.tgz.cc +``` diff --git a/update/update.sh b/update/update.sh new file mode 100644 index 0000000..5093317 --- /dev/null +++ b/update/update.sh @@ -0,0 +1,24 @@ +#!/bin/bash + +pubkey="/pub.pem" +echo "### ccOS Update Script ###" +echo "[+] Starting" +sleep 1 +echo "[+] Extracting Signature" +skip=$(expr $(stat -c '%s' update.tgz.cc) - 256) +dd if=/tmp/update.tgz.cc of=sig bs=1 count=256 skip=$skip > /dev/null 2>&1 +truncate -s $skip update.tgz.cc +check=`openssl dgst -sha256 -verify $pubkey -signature /tmp/sig /tmp/update.tgz.cc` +if [ "$check" == "Verified OK" ] +then + echo "[+] Signature is valid!" + echo "[+] Upgrading..." + tar -xvzf /tmp/update.tgz.cc -C / + rm /tmp/update.tgz.cc /tmp/sig + echo "[+] Done" + exit 0 +else + echo "[-] Signature error, exiting..." + rm /tmp/update.tgz.cc /tmp/sig + exit 1 +fi