From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43097) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Yvor2-00057h-99 for qemu-devel@nongnu.org; Fri, 22 May 2015 11:27:21 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Yvor1-00073a-1X for qemu-devel@nongnu.org; Fri, 22 May 2015 11:27:20 -0400 From: Kevin Wolf Date: Fri, 22 May 2015 17:26:37 +0200 Message-Id: <1432308400-13958-20-git-send-email-kwolf@redhat.com> In-Reply-To: <1432308400-13958-1-git-send-email-kwolf@redhat.com> References: <1432308400-13958-1-git-send-email-kwolf@redhat.com> Subject: [Qemu-devel] [PULL 19/22] qemu-io: prompt for encryption keys when required List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-block@nongnu.org Cc: kwolf@redhat.com, qemu-devel@nongnu.org From: "Daniel P. Berrange" 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: Daniel P. Berrange Reviewed-by: Eric Blake Signed-off-by: Kevin Wolf --- qemu-io.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/qemu-io.c b/qemu-io.c index ae5e274..9bc83c6 100644 --- a/qemu-io.c +++ b/qemu-io.c @@ -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) -- 1.8.3.1