xref: /openbmc/qemu/tests/qemu-iotests/294 (revision 57284d2ada481fe557c9a2f00228eca2a83e1d60)
111d80bfcSMaxim Levitsky#
211d80bfcSMaxim Levitsky# Copyright (C) 2019 Red Hat, Inc.
311d80bfcSMaxim Levitsky#
411d80bfcSMaxim Levitsky# This program is free software; you can redistribute it and/or modify
511d80bfcSMaxim Levitsky# it under the terms of the GNU General Public License as published by
611d80bfcSMaxim Levitsky# the Free Software Foundation; either version 2 of the License, or
711d80bfcSMaxim Levitsky# (at your option) any later version.
811d80bfcSMaxim Levitsky#
911d80bfcSMaxim Levitsky# This program is distributed in the hope that it will be useful,
1011d80bfcSMaxim Levitsky# but WITHOUT ANY WARRANTY; without even the implied warranty of
1111d80bfcSMaxim Levitsky# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1211d80bfcSMaxim Levitsky# GNU General Public License for more details.
1311d80bfcSMaxim Levitsky#
1411d80bfcSMaxim Levitsky# You should have received a copy of the GNU General Public License
1511d80bfcSMaxim Levitsky# along with this program.  If not, see <http://www.gnu.org/licenses/>.
1611d80bfcSMaxim Levitsky#
1711d80bfcSMaxim Levitsky
1811d80bfcSMaxim Levitsky# creator
1911d80bfcSMaxim Levitskyowner=mlevitsk@redhat.com
2011d80bfcSMaxim Levitsky
2111d80bfcSMaxim Levitskyseq=`basename $0`
2211d80bfcSMaxim Levitskyecho "QA output created by $seq"
2311d80bfcSMaxim Levitsky
2411d80bfcSMaxim Levitskystatus=1	# failure is the default!
2511d80bfcSMaxim Levitsky
2611d80bfcSMaxim Levitsky_cleanup()
2711d80bfcSMaxim Levitsky{
2811d80bfcSMaxim Levitsky	_cleanup_test_img
2911d80bfcSMaxim Levitsky}
3011d80bfcSMaxim Levitskytrap "_cleanup; exit \$status" 0 1 2 3 15
3111d80bfcSMaxim Levitsky
3211d80bfcSMaxim Levitsky# get standard environment, filters and checks
3311d80bfcSMaxim Levitsky. ./common.rc
3411d80bfcSMaxim Levitsky. ./common.filter
3511d80bfcSMaxim Levitsky
3611d80bfcSMaxim Levitsky_supported_fmt luks
37*57284d2aSMax Reitz_supported_proto file fuse #TODO
3811d80bfcSMaxim Levitsky
3911d80bfcSMaxim LevitskyQEMU_IO_OPTIONS=$QEMU_IO_OPTIONS_NO_FMT
4011d80bfcSMaxim Levitsky
4111d80bfcSMaxim Levitsky# you are supposed to see the password as *******, see :-)
4211d80bfcSMaxim LevitskyS0="--object secret,id=sec0,data=hunter0"
4311d80bfcSMaxim LevitskyS1="--object secret,id=sec1,data=hunter1"
4411d80bfcSMaxim LevitskySECRETS="$S0 $S1"
4511d80bfcSMaxim Levitsky
4611d80bfcSMaxim Levitsky
4711d80bfcSMaxim LevitskyIMGS0="--image-opts driver=$IMGFMT,file.filename=$TEST_IMG,key-secret=sec0"
4811d80bfcSMaxim LevitskyIMGS1="--image-opts driver=$IMGFMT,file.filename=$TEST_IMG,key-secret=sec1"
4911d80bfcSMaxim Levitsky
5011d80bfcSMaxim Levitskyecho "== creating a test image =="
5111d80bfcSMaxim Levitsky_make_test_img $S0 -o "key-secret=sec0,iter-time=10" 32M
5211d80bfcSMaxim Levitsky
5311d80bfcSMaxim Levitskyecho
5411d80bfcSMaxim Levitskyecho "== test that key 0 opens the image =="
5511d80bfcSMaxim Levitsky$QEMU_IO $S0 -c "read 0 4096" $IMGS0 | _filter_qemu_io | _filter_testdir
5611d80bfcSMaxim Levitsky
5711d80bfcSMaxim Levitskyecho
5811d80bfcSMaxim Levitskyecho "== adding a password to slot 1 =="
5911d80bfcSMaxim Levitsky$QEMU_IMG amend $SECRETS $IMGS0 -o state=active,new-secret=sec1,keyslot=1,iter-time=10
6011d80bfcSMaxim Levitsky
6111d80bfcSMaxim Levitskyecho
6211d80bfcSMaxim Levitskyecho "== 'backup' the image header =="
6311d80bfcSMaxim Levitskydd if=$TEST_IMG_FILE of=${TEST_IMG_FILE}.bk bs=4K skip=0 count=1
6411d80bfcSMaxim Levitsky
6511d80bfcSMaxim Levitskyecho
6611d80bfcSMaxim Levitskyecho "== erase slot 0 =="
6711d80bfcSMaxim Levitsky$QEMU_IMG amend $SECRETS $IMGS1 -o state=inactive,keyslot=0 | _filter_img_create
6811d80bfcSMaxim Levitsky
6911d80bfcSMaxim Levitskyecho
7011d80bfcSMaxim Levitskyecho "== test that key 0 doesn't open the image =="
7111d80bfcSMaxim Levitsky$QEMU_IO $S0 -c "read 0 4096" $IMGS0 | _filter_qemu_io | _filter_testdir
7211d80bfcSMaxim Levitsky
7311d80bfcSMaxim Levitskyecho
7411d80bfcSMaxim Levitskyecho "== 'restore' the image header =="
7511d80bfcSMaxim Levitskydd if=${TEST_IMG_FILE}.bk of=${TEST_IMG_FILE} bs=4K skip=0 count=1 conv=notrunc
7611d80bfcSMaxim Levitsky
7711d80bfcSMaxim Levitskyecho
7811d80bfcSMaxim Levitskyecho "== test that key 0 still doesn't open the image (key material is erased) =="
7911d80bfcSMaxim Levitsky$QEMU_IO $SECRETS -c "read 0 4096" $IMGS0 | _filter_qemu_io | _filter_testdir
8011d80bfcSMaxim Levitsky
8111d80bfcSMaxim Levitskyecho
8211d80bfcSMaxim Levitskyecho "== test that key 1 still works =="
8311d80bfcSMaxim Levitsky$QEMU_IO $SECRETS -c "read 0 4096" $IMGS1 | _filter_qemu_io | _filter_testdir
8411d80bfcSMaxim Levitsky
8511d80bfcSMaxim Levitskyecho "*** done"
8611d80bfcSMaxim Levitskyrm -f $seq.full
8711d80bfcSMaxim Levitskystatus=0
8811d80bfcSMaxim Levitsky
8911d80bfcSMaxim Levitsky
9011d80bfcSMaxim Levitskyexit 0
91