Skip to contentSkip to conversation

qemu-img: set encrypted disk image password

PATCH In review Laurent Vivier 4 participants 6 messages Jul 30, 2008

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 qemu-img: set encrypted disk image password

This patch modify qemu-img to ask and set a password when an encrypted disk image is created.

Laurent

Signature · 3 lines
----------------- [email protected]  ------------------
  "La perfection est atteinte non quand il ne reste rien à
ajouter mais quand il ne reste rien à enlever." Saint Exupéry
---
 qemu-img.c |    5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
qemu-img.c +4 -1
Index: qemu/qemu-img.c
===================================================================
@@ -208,6 +208,7 @@ static int img_create(int argc, char **a
     uint64_t size;
     const char *p;
     BlockDriver *drv;
+    BlockDriverState *bs;
 
     flags = 0;
     for(;;) {
@@ -237,7 +238,6 @@ static int img_create(int argc, char **a
     filename = argv[optind++];
     size = 0;
     if (base_filename) {
-        BlockDriverState *bs;
         bs = bdrv_new_open(base_filename, NULL);
         bdrv_get_geometry(bs, &size);
         size *= 512;
@@ -279,6 +279,9 @@ static int img_create(int argc, char **a
             error("Error while formatting");
         }
     }
+    /* to set password */
+    bs = bdrv_new_open(filename, NULL);
+    bdrv_delete(bs);
     return 0;
 }
 
#1 lore raw
Quoted 2 lines · Laurent Vivier

This patch modify qemu-img to ask and set a password when an encrypted disk image is created.

Well, this one is stupid, the other one is good...

Sorry,
Laurent

Signature · 3 lines
----------------- [email protected]  ------------------
  "La perfection est atteinte non quand il ne reste rien à
ajouter mais quand il ne reste rien à enlever." Saint Exupéry
#3 lore raw
Quoted 9 lines · Sebastian Herbszt
Quoted 3 lines · Laurent Vivier
Quoted 2 lines

This patch modify qemu-img to ask and set a password when an encrypted disk image is created.

Well, this one is stupid, the other one is good...

Back when nuitari-qemu posted about this problem [1], i came up with almost exactly the same patch. Why is it "stupid" ?

[1] http://lists.gnu.org/archive/html/qemu-devel/2008-06/msg00344.html

* For the first point:

Qemu-img doesn't need a password when it creates the disk image because there is nothing to encrypt in an empty image and the password is never stored in it.

When qemu reads an encrypted image it uses the given password (the key) to decrypt the data, if it is not the key given to encrypt it, the data will be invalid.

It's why this patch is stupid...

You can test this:
- qemu-img create -f qcow2 -e encrypted.qcow2
- qemu -hda boot.img -hdb encrypted.qcow2
type a password (you need my last patch)

# mkfs /dev/hdb
# fsck -f /dev/hdb
-> OK
# halt

- qemu -hda boot.img -hdb encrypted.qcow2
type a different password

# fsck -f /dev/hdb
-> NOT OK

- qemu -hda boot.img -hdb encrypted.qcow2
type the good password

# fsck -f /dev/hdb
-> OK

Qemu-img needs the password to convert an image because there are encrypted data to read an convert.

* For the second point:

it's what my other patch try to solve.

Regards,
Laurent
----------------------- Laurent Vivier ---------------------- "The best way to predict the future is to invent it."
- Alan Kay

#4 lore raw
Quoted 1 line

Qemu-img doesn't need a password when it creates the disk image because there is nothing to encrypt in an empty image and the password is never stored in it.

Okay... this might be better documented.

I somewhat expected that most of the meta data for an encrypted disk would also be encrypted, maybe with the execption of a simple signature at the start.

#5 lore raw
Quoted 5 lines · Le 30 juil. 08 à 22:18, [email protected] a écrit :
Quoted 1 line

Qemu-img doesn't need a password when it creates the disk image because there is nothing to encrypt in an empty image and the password is never stored in it.

Okay... this might be better documented.

I somewhat expected that most of the meta data for an encrypted disk would also be encrypted, maybe with the execption of a simple signature at the start.

Meta-data are not encrypted, only data.

Meta-data cannot give any information about data, allowing someone to crack the key. So encrypting data is enough.

For instance, when you encrypt a file on ext3, you don't encrypt the filesystem metadata (like inode and block pointers). Meta-data of qcow2 are like meta-data of ext3.

Regards,
Laurent
----------------------- Laurent Vivier ---------------------- "The best way to predict the future is to invent it."
- Alan Kay