Files
felhom.eu/documentation/audits/release-2b-3-2026-11-15/part2/ca-wrong.sh
T

24 lines
1.7 KiB
Bash

# Part 2 step 4, demo-hp ONLY: make the agent's CA copy wrong (another, self-made CA in its place), restart the agent,
# and watch. The copy is saved first and compared at the end. Changes: /etc/felhom-agent/pve-root-ca.pem (one file),
# one restart of felhom-agent. Nothing under /etc/pve is touched.
set -u
[ "$(hostname)" = demo-hp ] || { echo "REFUSED: this is not demo-hp"; exit 2; }
busy=$(ps -eo comm | grep -cE "^(vzdump|apt-get|dpkg|pct|proxmox-backup-)")
[ "$busy" = 0 ] || { echo "REFUSED: something is in flight"; exit 2; }
C=/etc/felhom-agent/pve-root-ca.pem; SAVE=/root/pve-root-ca.pem.saved-part2
W=$(mktemp -d)
cp -p "$C" "$SAVE"
echo "#### $(date +%F\ %T) the copy before: sha256 $(sha256sum < "$C" | cut -c1-16), $(stat -c '%A %U:%G' "$C"); saved at $SAVE"
openssl req -x509 -newkey rsa:2048 -nodes -days 3650 -subj "/CN=CC wrong CA for a test 2026-11-15" -addext "basicConstraints=critical,CA:TRUE" -keyout "$W/k.pem" -out "$W/wrong.pem" 2>/dev/null
cat "$W/wrong.pem" > "$C"
rm -rf "$W"
echo "the copy staged wrong: sha256 $(sha256sum < "$C" | cut -c1-16), subject $(openssl x509 -in "$C" -noout -subject)"
T0=$(date '+%F %T')
systemctl restart felhom-agent; echo "agent restart rc=$? at $T0"
for i in $(seq 1 18); do sleep 5; [ "$(sha256sum < "$C")" = "$(sha256sum < "$SAVE")" ] && break; done
echo "the copy $([ "$(sha256sum < "$C")" = "$(sha256sum < "$SAVE")" ] && echo "is the saved one again, by itself, after about $((i*5)) s" || echo "is STILL WRONG after 90 s")"
sleep 20
journalctl -u felhom-agent --since "$T0" --no-pager -o short-iso | grep -v "sudo\[" | grep -iE "pvetrust|x509|certificate|level=ERROR" | cut -c1-380 | tail -10
echo "T0=$T0"
echo "#### end"