| 1 |
#!/bin/sh |
| 2 |
set -uxe |
| 3 |
echo "libpam-mount is working" > expected |
| 4 |
|
| 5 |
createluks() |
| 6 |
{ |
| 7 |
id=${1} |
| 8 |
type=${2} |
| 9 |
tdir=$(mktemp --directory) |
| 10 |
|
| 11 |
fallocate -l 32M "/tmp/disk-l${id}.img" |
| 12 |
cryptsetup luksFormat --batch-mode --verbose --force-password --key-file=/home/alice/alice.key --type "${type}" "/tmp/disk-l${id}.img" |
| 13 |
cryptsetup open --type "${type}" --batch-mode --verbose --key-file=/home/alice/alice.key "/tmp/disk-l${id}.img" "img-luks${id}" |
| 14 |
mkfs.ext4 -L "IMG-LUKS${id}" "/dev/mapper/img-luks${id}" |
| 15 |
mount "/dev/mapper/img-luks${id}" "${tdir}" |
| 16 |
echo "libpam-mount is working" > "${tdir}/testfile" |
| 17 |
umount "/dev/mapper/img-luks${id}" |
| 18 |
cryptsetup close "img-luks${id}" |
| 19 |
} |
| 20 |
|
| 21 |
checkluks() |
| 22 |
{ |
| 23 |
id=${1} |
| 24 |
bckp=$(mktemp) |
| 25 |
|
| 26 |
# backup and modify configuration |
| 27 |
cp /etc/security/pam_mount.conf.xml "${bckp}" |
| 28 |
sed -i -e 's/debug enable="0"/debug enable="1"/' /etc/security/pam_mount.conf.xml |
| 29 |
sed -i -e "/<!-- Volume definitions -->/a<volume user='alice' path='/tmp/disk-l${id}.img' mountpoint='~/img-luks${id}' fstype='crypt' fskeycipher='none' fskeyhash='md5' fskeypath='/home/alice/alice.key' />" /etc/security/pam_mount.conf.xml |
| 30 |
|
| 31 |
# smoke tests the mount and if not working print debug from journal |
| 32 |
# shellcheck disable=SC2029 |
| 33 |
ssh -o "StrictHostKeyChecking=no" -i test.key alice@localhost "ls -laF ~/img-luks${id}/testfile" || journalctl -xe -u ssh --no-pager |
| 34 |
sleep 5s |
| 35 |
|
| 36 |
# make sure we are using an actual mount |
| 37 |
ssh -o "StrictHostKeyChecking=no" -i test.key alice@localhost "mount" | grep "img-luks${id}" |
| 38 |
sleep 5s |
| 39 |
|
| 40 |
# compare data on encrypted disk via local login shell |
| 41 |
# ensure su from root (needs no PW) does not re-ask for a pass (gets it from ~alice/alice.key anyway) |
| 42 |
sed -i -e 's/pam_mount.so\s*$/pam_mount.so disable_interactive/' /etc/pam.d/common-auth |
| 43 |
sed -i -e 's/pam_mount.so\s*$/pam_mount.so disable_interactive/' /etc/pam.d/common-session |
| 44 |
su --login --command "cat ~/img-luks${id}/testfile" alice > "luks${id}" |
| 45 |
sleep 5s |
| 46 |
cmp expected "luks${id}" |
| 47 |
|
| 48 |
# compare data on encrypted disk via ssh based login |
| 49 |
# shellcheck disable=SC2029 |
| 50 |
ssh -o "StrictHostKeyChecking=no" -i test.key alice@localhost "cat ~/img-luks${id}/testfile" > "luks${id}" |
| 51 |
sleep 5s |
| 52 |
cmp expected "luks${id}" |
| 53 |
|
| 54 |
# restore configuration |
| 55 |
cp "${bckp}" /etc/security/pam_mount.conf.xml |
| 56 |
} |
| 57 |
|
| 58 |
# create user alice with PW alice |
| 59 |
useradd -m --password "$(openssl passwd -1 alice)" alice |
| 60 |
# trivial passphrase |
| 61 |
printf "alice" > ~alice/alice.key |
| 62 |
# non interactive ssh login |
| 63 |
ssh-keygen -t rsa -N "" -f test.key |
| 64 |
mkdir -p ~alice/.ssh |
| 65 |
chown alice:alice ~alice/.ssh |
| 66 |
cp test.key.pub ~alice/.ssh/authorized_keys |
| 67 |
# LUKS mountpoints |
| 68 |
mkdir -p /home/alice/img-luks1 /home/alice/img-luks2 |
| 69 |
chown alice:alice ~alice/.ssh/authorized_keys /home/alice/img-luks1 /home/alice/img-luks2 |
| 70 |
|
| 71 |
# create LUKS devices with known content |
| 72 |
createluks 1 luks |
| 73 |
createluks 2 luks2 |
| 74 |
|
| 75 |
checkluks 1 |
| 76 |
checkluks 2 |