1*8e4ffb4eSKevin Wolf#!/usr/bin/env bash 2*8e4ffb4eSKevin Wolf# group: rw quick 3*8e4ffb4eSKevin Wolf# 4*8e4ffb4eSKevin Wolf# Test case for encryption support in qcow2 5*8e4ffb4eSKevin Wolf# 6*8e4ffb4eSKevin Wolf# Copyright (C) 2025 Red Hat, Inc. 7*8e4ffb4eSKevin Wolf# 8*8e4ffb4eSKevin Wolf# This program is free software; you can redistribute it and/or modify 9*8e4ffb4eSKevin Wolf# it under the terms of the GNU General Public License as published by 10*8e4ffb4eSKevin Wolf# the Free Software Foundation; either version 2 of the License, or 11*8e4ffb4eSKevin Wolf# (at your option) any later version. 12*8e4ffb4eSKevin Wolf# 13*8e4ffb4eSKevin Wolf# This program is distributed in the hope that it will be useful, 14*8e4ffb4eSKevin Wolf# but WITHOUT ANY WARRANTY; without even the implied warranty of 15*8e4ffb4eSKevin Wolf# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16*8e4ffb4eSKevin Wolf# GNU General Public License for more details. 17*8e4ffb4eSKevin Wolf# 18*8e4ffb4eSKevin Wolf# You should have received a copy of the GNU General Public License 19*8e4ffb4eSKevin Wolf# along with this program. If not, see <http://www.gnu.org/licenses/>. 20*8e4ffb4eSKevin Wolf# 21*8e4ffb4eSKevin Wolf 22*8e4ffb4eSKevin Wolf# creator 23*8e4ffb4eSKevin Wolfowner=kwolf@redhat.com 24*8e4ffb4eSKevin Wolf 25*8e4ffb4eSKevin Wolfseq="$(basename $0)" 26*8e4ffb4eSKevin Wolfecho "QA output created by $seq" 27*8e4ffb4eSKevin Wolf 28*8e4ffb4eSKevin Wolfstatus=1 # failure is the default! 29*8e4ffb4eSKevin Wolf 30*8e4ffb4eSKevin Wolf_cleanup() 31*8e4ffb4eSKevin Wolf{ 32*8e4ffb4eSKevin Wolf _cleanup_test_img 33*8e4ffb4eSKevin Wolf} 34*8e4ffb4eSKevin Wolftrap "_cleanup; exit \$status" 0 1 2 3 15 35*8e4ffb4eSKevin Wolf 36*8e4ffb4eSKevin Wolf# get standard environment, filters and checks 37*8e4ffb4eSKevin Wolf. ../common.rc 38*8e4ffb4eSKevin Wolf. ../common.filter 39*8e4ffb4eSKevin Wolf 40*8e4ffb4eSKevin Wolf# This tests qcow2-specific low-level functionality 41*8e4ffb4eSKevin Wolf_supported_fmt qcow2 42*8e4ffb4eSKevin Wolf_supported_proto file 43*8e4ffb4eSKevin Wolf_require_working_luks 44*8e4ffb4eSKevin Wolf 45*8e4ffb4eSKevin WolfIMG_SIZE=64M 46*8e4ffb4eSKevin Wolf 47*8e4ffb4eSKevin Wolfecho 48*8e4ffb4eSKevin Wolfecho "=== Create an encrypted image ===" 49*8e4ffb4eSKevin Wolfecho 50*8e4ffb4eSKevin Wolf 51*8e4ffb4eSKevin Wolf_make_test_img --object secret,id=sec0,data=123456 -o encrypt.format=luks,encrypt.key-secret=sec0 $IMG_SIZE 52*8e4ffb4eSKevin Wolf$PYTHON ../qcow2.py "$TEST_IMG" dump-header-exts 53*8e4ffb4eSKevin Wolf_img_info 54*8e4ffb4eSKevin Wolf$QEMU_IMG check \ 55*8e4ffb4eSKevin Wolf --object secret,id=sec0,data=123456 \ 56*8e4ffb4eSKevin Wolf --image-opts file.filename="$TEST_IMG",encrypt.key-secret=sec0 \ 57*8e4ffb4eSKevin Wolf | _filter_qemu_img_check 58*8e4ffb4eSKevin Wolf 59*8e4ffb4eSKevin Wolfecho 60*8e4ffb4eSKevin Wolfecho "=== Remove the header extension ===" 61*8e4ffb4eSKevin Wolfecho 62*8e4ffb4eSKevin Wolf 63*8e4ffb4eSKevin Wolf$PYTHON ../qcow2.py "$TEST_IMG" del-header-ext 0x0537be77 64*8e4ffb4eSKevin Wolf$PYTHON ../qcow2.py "$TEST_IMG" dump-header-exts 65*8e4ffb4eSKevin Wolf_img_info 66*8e4ffb4eSKevin Wolf$QEMU_IMG check \ 67*8e4ffb4eSKevin Wolf --object secret,id=sec0,data=123456 \ 68*8e4ffb4eSKevin Wolf --image-opts file.filename="$TEST_IMG",encrypt.key-secret=sec0 2>&1 \ 69*8e4ffb4eSKevin Wolf | _filter_qemu_img_check \ 70*8e4ffb4eSKevin Wolf | _filter_testdir 71*8e4ffb4eSKevin Wolf 72*8e4ffb4eSKevin Wolf# success, all done 73*8e4ffb4eSKevin Wolfecho "*** done" 74*8e4ffb4eSKevin Wolfrm -f $seq.full 75*8e4ffb4eSKevin Wolfstatus=0 76