I'm trying to design a firmware update system for an embedded Linux system. My plan is to send an image that can be mounted on the target system, so I don't need to unpack the entire file. I also want to encrypt the image, and optionally compress it as well. Since the build system for creating this image is going to be deployed on several computers I also want the build system to require minimal amount of setup, i.e., avoid avoid requiring root privileges.
I've created a working model where I mount an image file using
losetup as such:
dd if=/dev/zero of=image_file bs=1M count=10 losetup -e aes loop0 image_file mkfs.ext2 /dev/loop0 losetup -d loop0 mount -t ext2 -o loop,encryption=aes image_file some_working_folder/ # Add files to some_working_folder umount some_working_folder # Send encrypted image to the target system
Now, since this is a bit cumbersome to set up on some machines, and I want to avoid creating fixed sized images. So I want to replace the
losetup commands with something else. I found the command
virt-make-fs, which can create a mountable image with the
ext2 filesystem. So now I only need to encrypt the image file in a way that is decryptable by the linux kernel. I've tried to use OpenSSL, but I haven't been able to find the correct algorithm, or maybe I'm missing something. Does anybody know how to do this? Basically I want something like the script below.
tar -cf archive.tar some files virt-make-fs archive.tar image.ext2 # the below command need to be fixed/replaced openssl enc -aes192 -in image.ext2 -out image.ext2.aes
On the target system I want be able to use the following command, or at least something similar.
# The next command should be done on the target mount -t ext2 -o loop,encryption=aes image.ext2.aes /mnt/upgrade # work with files in /mnt/upgrade
So, just to clarify: How can I create an encrypted mountable image file without being root?
Feel free to comment if I'm trying to reinvent the wheel, or if there is some other well established solution for this problem. Even though there are better solutions, I'm still interested in the command to solve the encryption problem.
Edit: As been pointed out cryptoloop is unsecure, see http://lwn.net/Articles/67216/. So I will probably look around for another solution as well. I've found to util
aespipe, which I might be able to use.
Edit 2: I've dug into the source code in the AES module of the Linux kernel, and I've concluded that it is probably the hashing of the password that is causing the problem. Both
aespipe and the AES module are using an AES-256-CBC encryption. As far as I can see the linux kernel uses the given password as key, and
aespipe hashes the incoming password. Since the "no root" part is very important to me I've started looking for other solutions, and my current plan is to use something like the following on the development computer:
tar -cf - file0 file1 ... | gzip -c | aespipe -e aes256 > arhive_file
And then on the target system run
rm -rf /tmp/update ; mkdir -p /tmp/update aespipe -d -e aes256 < archive.mbl | gzip -cd | tar -C /tmp/update -xf -