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