File: test_swtpm_setup_misc

package info (click to toggle)
swtpm 0.10.1%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,008 kB
  • sloc: ansic: 20,787; sh: 14,667; makefile: 760; python: 173
file content (126 lines) | stat: -rwxr-xr-x 3,141 bytes parent folder | download
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#!/usr/bin/env bash

# For the license, see the LICENSE file in the root directory.

ROOT=${abs_top_builddir:-$(dirname "$0")/..}
TESTDIR=${abs_top_testdir:-$(dirname "$0")}

source "${TESTDIR}/common"

trap "cleanup" SIGTERM EXIT

function cleanup()
{
	rm -rf "${workdir}"
}

workdir="$(mktemp -d)" || exit 1

# Simple tests with options and combination of options

if ! ${SWTPM_SETUP} --help &>/dev/null; then
	echo "Error: Displaying help screen failed"
	exit 1
fi

if ! ${SWTPM_SETUP} --version &>/dev/null; then
	echo "Error: Displaying version info failed"
	exit 1
fi

# Omit --tpm-state
if ${SWTPM_SETUP} --overwrite 2>/dev/null; then
	echo "Error: Should have failed without --tpmstate option"
	exit 1
fi

# Options that require --tpm2
for opt in --ecc --create-spk --reconfigure --allow-signing --decryption '--pcr-banks -'; do
	if ${SWTPM_SETUP} --tpmstate "dir://${workdir}" --overwrite ${opt:+${opt}} 2>/dev/null; then
		echo "Error: Option ${opt} should have required --tpm2"
		exit 1
	fi
done

# Unreasonble RSA key size
if ${SWTPM_SETUP} --tpmstate "dir://${workdir}" --overwrite --tpm2 --rsa-keysize 2222 &>/dev/null; then
	echo "Error: Should have failed with unreasonable key size"
	exit 1
fi

# Unsupported option with --tpm2
if ${SWTPM_SETUP} --tpmstate "dir://${workdir}" --overwrite --tpm2 --take-ownership 2>/dev/null; then
	echo "Error: Option ${opt} should have failed with --tpm2"
	exit 1
fi

# Unsupported cipher
if ${SWTPM_SETUP} --tpmstate "dir://${workdir}" --overwrite --cipher aes-192-cbc &>/dev/null; then
	echo "Error: Should have failed on unsupported cipher aes-192-cbc"
	exit 1
fi

# Unsupported option combination
if ${SWTPM_SETUP} --tpmstate "dir://${workdir}" --overwrite --tpm2 --create-ek-cert --reconfigure 2>/dev/null; then
	echo "Error: Should have failed on unsupported option combination"
	exit 1
fi

echo "Test 1: Ok"
cleanup

if [ "$(id -u)" -eq 0 ]; then
	echo "Skipping fruther tests: Not running tests as root."
	exit 0
fi

FILES="swtpm-localca.conf swtpm-localca.options swtpm_setup.conf"

if ! XDG_CONFIG_HOME="${workdir}" ${SWTPM_SETUP} \
	--create-config-files 1>/dev/null;
then
	echo "Error: Could not created config files (without parameters)"
	exit 1
fi
for f in ${FILES}; do
	if ! [ -f "${workdir}/${f}" ]; then
		echo "Error: File ${workdir}/${f} was not created"
		exit 1
	fi
done
if ! [ -d "${workdir}/var/lib/swtpm-localca" ]; then
	echo "Error: Directory var/lib/swtpm-localca was not created"
	exit 1
fi

if ! XDG_CONFIG_HOME="${workdir}" ${SWTPM_SETUP} \
	--create-config-files skip-if-exist 1>/dev/null;
then
	echo "Error: skip-if-exists should have exit'ed with 0."
	exit 1
fi

echo "Test 2: Ok"
cleanup

if ! XDG_CONFIG_HOME="${workdir}" ${SWTPM_SETUP} \
	--create-config-files skip-if-exist 1>/dev/null;
then
	echo "Error: skip-if-exists should have exit'ed with 0."
	exit 1
fi
for f in ${FILES}; do
	if ! [ -f "${workdir}/${f}" ]; then
		echo "Error: File ${workdir}/${f} was not created"
		exit 1
	fi
done
if ! [ -d "${workdir}/var/lib/swtpm-localca" ]; then
	echo "Error: Directory var/lib/swtpm-localca was not created"
	exit 1
fi

echo "Test 3: Ok"
cleanup

exit 0