Commit 8caf0212 authored by Daniel P. Berrangé's avatar Daniel P. Berrangé Committed by Kevin Wolf
Browse files

qemu-io: prompt for encryption keys when required



The qemu-io tool does not check if the image is encrypted so
historically would silently corrupt the sectors by writing
plain text data into them instead of cipher text. The earlier
commit turns this mistake into a fatal abort, so check for
encryption and prompt for key when required.

This enables us to add unit tests to ensure we don't break
the ability of qemu-img to convert existing encrypted qcow2
files into a non-encrypted format.

Signed-off-by: default avatarDaniel P. Berrange <berrange@redhat.com>
Reviewed-by: default avatarEric Blake <eblake@redhat.com>
Signed-off-by: default avatarKevin Wolf <kwolf@redhat.com>
parent 6a11d518
Loading
Loading
Loading
Loading
+21 −0
Original line number Diff line number Diff line
@@ -52,6 +52,7 @@ static const cmdinfo_t close_cmd = {
static int openfile(char *name, int flags, QDict *opts)
{
    Error *local_err = NULL;
    BlockDriverState *bs;

    if (qemuio_blk) {
        fprintf(stderr, "file open already, try 'help close'\n");
@@ -68,7 +69,27 @@ static int openfile(char *name, int flags, QDict *opts)
        return 1;
    }

    bs = blk_bs(qemuio_blk);
    if (bdrv_is_encrypted(bs)) {
        char password[256];
        printf("Disk image '%s' is encrypted.\n", name);
        if (qemu_read_password(password, sizeof(password)) < 0) {
            error_report("No password given");
            goto error;
        }
        if (bdrv_set_key(bs, password) < 0) {
            error_report("invalid password");
            goto error;
        }
    }


    return 0;

 error:
    blk_unref(qemuio_blk);
    qemuio_blk = NULL;
    return 1;
}

static void open_help(void)