-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathtest-systemd.sh
executable file
·71 lines (55 loc) · 1.36 KB
/
test-systemd.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
61
62
63
64
65
66
67
68
69
70
71
#!/bin/bash
#
# This script needs to be run with root privilege
#
# TESTDIR=policy.test
PCR_MASK=0,2,4,12
pcr_oracle=pcr-oracle
if [ -x pcr-oracle ]; then
pcr_oracle=$PWD/pcr-oracle
fi
function call_oracle {
echo "****************"
echo "pcr-oracle $*"
$pcr_oracle --target-platform systemd -d "$@"
}
if [ -z "$TESTDIR" ]; then
tmpdir=$(mktemp -d /tmp/pcrtestXXXXXX)
trap "cd / && rm -rf $tmpdir" 0 1 2 10 11 15
TESTDIR=$tmpdir
fi
trap "echo 'FAIL: command exited with error'; exit 1" ERR
echo "This is super secret" >$TESTDIR/secret
set -e
cd $TESTDIR
POLICY_FILE=authorized.policy
SIGNED_POLICY_FILE=systemd-policy.json
rm -f sealed recovered
call_oracle \
--rsa-generate-key \
--private-key policy-key.pem \
--auth $POLICY_FILE \
create-authorized-policy $PCR_MASK
call_oracle \
--private-key policy-key.pem \
--public-key policy-pubkey \
store-public-key
call_oracle \
--auth $POLICY_FILE \
--input secret \
--output sealed \
seal-secret
for attempt in first second; do
echo "Sign the set of PCRs we want to authorize"
call_oracle \
--policy-name "authorized-policy-test" \
--private-key policy-key.pem \
--from current \
--output $SIGNED_POLICY_FILE \
sign $PCR_MASK
echo "*** Contents of $SIGNED_POLICY_FILE"
cat $SIGNED_POLICY_FILE
echo
echo "*** Terminating test early; the systemd code does not support unsealing yet" >&2
break;
done