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