-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.sh
executable file
·60 lines (50 loc) · 1.16 KB
/
test.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/usr/bin/env bash
set -xeuo pipefail
LUKS_NAME=crypty
DISK=${LUKS_NAME}.img
LUKS_DEV=/dev/mapper/$LUKS_NAME
MNT=mnt
RUST_LOG=debug
teardown() {
sudo umount $MNT || true
sudo cryptsetup remove $LUKS_NAME || true
sudo losetup -d $loopdevice || true
}
trap teardown EXIT
setup() {
rm -f $DISK
fallocate -l 20MiB $DISK
export PASSPHRASE=$(openssl rand -base64 33)
loopdevice=$(losetup -f)
sudo losetup $loopdevice $DISK
echo -n "$PASSPHRASE" | sudo cryptsetup luksFormat -q $loopdevice -
echo -n "$PASSPHRASE" | sudo cryptsetup luksOpen $loopdevice $LUKS_NAME -
sudo mkfs.ext4 -j $LUKS_DEV
mkdir -p $MNT
sudo mount $LUKS_DEV $MNT
sudo touch ${MNT}/plain.txt
sudo chmod 777 ${MNT}/plain.txt
sudo echo "This is my plain text" > ${MNT}/plain.txt
}
seal() {
setup
echo "using existing $PASSPHRASE to add second key"
sudo PASSPHRASE=$PASSPHRASE $tpm_luks seal $loopdevice
teardown
}
unseal() {
loopdevice=$(losetup -f)
sudo losetup $loopdevice $DISK
sudo $tpm_luks unseal $loopdevice $LUKS_NAME
mount $LUKS_DEV $MNT
ls mnt
teardown
}
if [ -n ${BUILD+x} ]; then
cargo build --release
tpm_luks=target/release/tpm-luks
else
tpm_luks=./tpm-luks
fi
seal
unseal