xref: /openbmc/qemu/tests/qemu-iotests/294 (revision 11d80bfc6da00d8b53bf1cc2da19b4a2e0b23961)
1*11d80bfcSMaxim Levitsky#
2*11d80bfcSMaxim Levitsky# Copyright (C) 2019 Red Hat, Inc.
3*11d80bfcSMaxim Levitsky#
4*11d80bfcSMaxim Levitsky# This program is free software; you can redistribute it and/or modify
5*11d80bfcSMaxim Levitsky# it under the terms of the GNU General Public License as published by
6*11d80bfcSMaxim Levitsky# the Free Software Foundation; either version 2 of the License, or
7*11d80bfcSMaxim Levitsky# (at your option) any later version.
8*11d80bfcSMaxim Levitsky#
9*11d80bfcSMaxim Levitsky# This program is distributed in the hope that it will be useful,
10*11d80bfcSMaxim Levitsky# but WITHOUT ANY WARRANTY; without even the implied warranty of
11*11d80bfcSMaxim Levitsky# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12*11d80bfcSMaxim Levitsky# GNU General Public License for more details.
13*11d80bfcSMaxim Levitsky#
14*11d80bfcSMaxim Levitsky# You should have received a copy of the GNU General Public License
15*11d80bfcSMaxim Levitsky# along with this program.  If not, see <http://www.gnu.org/licenses/>.
16*11d80bfcSMaxim Levitsky#
17*11d80bfcSMaxim Levitsky
18*11d80bfcSMaxim Levitsky# creator
19*11d80bfcSMaxim Levitskyowner=mlevitsk@redhat.com
20*11d80bfcSMaxim Levitsky
21*11d80bfcSMaxim Levitskyseq=`basename $0`
22*11d80bfcSMaxim Levitskyecho "QA output created by $seq"
23*11d80bfcSMaxim Levitsky
24*11d80bfcSMaxim Levitskystatus=1	# failure is the default!
25*11d80bfcSMaxim Levitsky
26*11d80bfcSMaxim Levitsky_cleanup()
27*11d80bfcSMaxim Levitsky{
28*11d80bfcSMaxim Levitsky	_cleanup_test_img
29*11d80bfcSMaxim Levitsky}
30*11d80bfcSMaxim Levitskytrap "_cleanup; exit \$status" 0 1 2 3 15
31*11d80bfcSMaxim Levitsky
32*11d80bfcSMaxim Levitsky# get standard environment, filters and checks
33*11d80bfcSMaxim Levitsky. ./common.rc
34*11d80bfcSMaxim Levitsky. ./common.filter
35*11d80bfcSMaxim Levitsky
36*11d80bfcSMaxim Levitsky_supported_fmt luks
37*11d80bfcSMaxim Levitsky_supported_proto file #TODO
38*11d80bfcSMaxim Levitsky
39*11d80bfcSMaxim LevitskyQEMU_IO_OPTIONS=$QEMU_IO_OPTIONS_NO_FMT
40*11d80bfcSMaxim Levitsky
41*11d80bfcSMaxim Levitsky# you are supposed to see the password as *******, see :-)
42*11d80bfcSMaxim LevitskyS0="--object secret,id=sec0,data=hunter0"
43*11d80bfcSMaxim LevitskyS1="--object secret,id=sec1,data=hunter1"
44*11d80bfcSMaxim LevitskySECRETS="$S0 $S1"
45*11d80bfcSMaxim Levitsky
46*11d80bfcSMaxim Levitsky
47*11d80bfcSMaxim LevitskyIMGS0="--image-opts driver=$IMGFMT,file.filename=$TEST_IMG,key-secret=sec0"
48*11d80bfcSMaxim LevitskyIMGS1="--image-opts driver=$IMGFMT,file.filename=$TEST_IMG,key-secret=sec1"
49*11d80bfcSMaxim Levitsky
50*11d80bfcSMaxim Levitskyecho "== creating a test image =="
51*11d80bfcSMaxim Levitsky_make_test_img $S0 -o "key-secret=sec0,iter-time=10" 32M
52*11d80bfcSMaxim Levitsky
53*11d80bfcSMaxim Levitskyecho
54*11d80bfcSMaxim Levitskyecho "== test that key 0 opens the image =="
55*11d80bfcSMaxim Levitsky$QEMU_IO $S0 -c "read 0 4096" $IMGS0 | _filter_qemu_io | _filter_testdir
56*11d80bfcSMaxim Levitsky
57*11d80bfcSMaxim Levitskyecho
58*11d80bfcSMaxim Levitskyecho "== adding a password to slot 1 =="
59*11d80bfcSMaxim Levitsky$QEMU_IMG amend $SECRETS $IMGS0 -o state=active,new-secret=sec1,keyslot=1,iter-time=10
60*11d80bfcSMaxim Levitsky
61*11d80bfcSMaxim Levitskyecho
62*11d80bfcSMaxim Levitskyecho "== 'backup' the image header =="
63*11d80bfcSMaxim Levitskydd if=$TEST_IMG_FILE of=${TEST_IMG_FILE}.bk bs=4K skip=0 count=1
64*11d80bfcSMaxim Levitsky
65*11d80bfcSMaxim Levitskyecho
66*11d80bfcSMaxim Levitskyecho "== erase slot 0 =="
67*11d80bfcSMaxim Levitsky$QEMU_IMG amend $SECRETS $IMGS1 -o state=inactive,keyslot=0 | _filter_img_create
68*11d80bfcSMaxim Levitsky
69*11d80bfcSMaxim Levitskyecho
70*11d80bfcSMaxim Levitskyecho "== test that key 0 doesn't open the image =="
71*11d80bfcSMaxim Levitsky$QEMU_IO $S0 -c "read 0 4096" $IMGS0 | _filter_qemu_io | _filter_testdir
72*11d80bfcSMaxim Levitsky
73*11d80bfcSMaxim Levitskyecho
74*11d80bfcSMaxim Levitskyecho "== 'restore' the image header =="
75*11d80bfcSMaxim Levitskydd if=${TEST_IMG_FILE}.bk of=${TEST_IMG_FILE} bs=4K skip=0 count=1 conv=notrunc
76*11d80bfcSMaxim Levitsky
77*11d80bfcSMaxim Levitskyecho
78*11d80bfcSMaxim Levitskyecho "== test that key 0 still doesn't open the image (key material is erased) =="
79*11d80bfcSMaxim Levitsky$QEMU_IO $SECRETS -c "read 0 4096" $IMGS0 | _filter_qemu_io | _filter_testdir
80*11d80bfcSMaxim Levitsky
81*11d80bfcSMaxim Levitskyecho
82*11d80bfcSMaxim Levitskyecho "== test that key 1 still works =="
83*11d80bfcSMaxim Levitsky$QEMU_IO $SECRETS -c "read 0 4096" $IMGS1 | _filter_qemu_io | _filter_testdir
84*11d80bfcSMaxim Levitsky
85*11d80bfcSMaxim Levitskyecho "*** done"
86*11d80bfcSMaxim Levitskyrm -f $seq.full
87*11d80bfcSMaxim Levitskystatus=0
88*11d80bfcSMaxim Levitsky
89*11d80bfcSMaxim Levitsky
90*11d80bfcSMaxim Levitskyexit 0
91