SECURITY dmcrypt
Uit Gentoo Linux Wiki
Inhoud |
[bewerken] Inleiding
dmcrypt is een manier om bestanden te crypteren en te decrypteren door gebruik te maken van een cryptografisch cijfer. dmcrypt staat toe deze bestanden te benaderen zoals een gewoon block device, dmcrypt is gemaakt om op een block device te zetten maar met een loopback device kunnen we gemakkelijk vermijden dat we een aparte partitie nodig hebben.
Er zijn andere manieren om bestanden te crypteren zoals Cryptoloop (afgekeurd, minder veilig en niet goed gecodeerd) of loopaes (veiliger en sneller, maar moeilijker in gebruik)
[bewerken] Loopback of partitie?
Een loopback betekend dat je een bestand hebt dat op een partitie staat die je mount met een speciaal apparaat, loopback genoemd. Het loop apparaat gedraagd zich dan als een normaal block device en transformeert je bestand gewoon naar nog een harde schijf
Dit is nuttig als je bijvoorbeeld al je ssh sleutels veilig wilt bewaren maar er geen partitie voor wilt aanmaken
[bewerken] Configuring your kernel for dmcrypt
You must configure your kernel to be able to use dmcrypt. Use your favourite kernel or emerge development-sources.
cd /usr/src/linux make mrproper make menuconfig
You must first enable the device mapper (dm):
| Linux Kernel Configuratie: Device Mapper |
Device Drivers --> RAID and LVM Support --> [*] Multiple devices driver support (RAID and LVM) <*> Device mapper support <*> Crypt target support Then you must enable the cipher (aes): Cryptographic Options --> <*> AES cipher algorithims (i586) And if your going to be using dmcrypt on a loopback file, not a partition: Device Drivers --> Block Devices --> <*> Loopback device support # Remember, cryptoloop is not dmcrypt |
If you wish you may enable all of the above as modules, but you must then modprobe them.
Now compile your kernel:
make && make modules_install
Now inform your bootloader of this change and reboot (or if you compiled them all as a module and do it right you can just modprobe)
[bewerken] Installing the tools needed
emerge sys-fs/cryptsetup
[bewerken] Using dmcrypt with a partition
If you wish to use dmcrypt on a partition then read this, otherwise see below for information on using it with a loopback device.
First we create a device mapper device called 'mycrypt' on a partition, say /dev/hda7 (we will use that throughout the guide)
cryptsetup -y create mycrypt /dev/hda7
Has it worked?
dmsetup ls
It should display 'mycrypt'
Now create a filesystem (replace mke2fs with whatever your filesystem creation tool is):
mke2fs /dev/mapper/mycrypt
Now mount it!
mount /dev/mapper/mycrypt /mnt/point
Test it worked, congratulations!
To bring it down:
umount /mnt/point cryptsetup remove mycrypt
[bewerken] Using dmcrypt with a loopback device
This is for using dmcrypt with a loopback device; see above for using it with a partition.
First, create our file:
touch protected shred -n1 -s50M protected
This creates a file called 'protected' in your current directory of 50MB. By prefilling it with random data, it's impossible to see afterwards how much has been used.
Now let's set a loopback device to use this file
losetup /dev/loop0 /path/to/protected
If loop0 is in use, try another
Now lets create an encrypted device mapper device using cryptsetup:
cryptsetup -y create mycrypt /dev/loop0
Check it worked:
dmsetup ls
You should see 'mycrypt' listed
Now create a filesystem (replace mke2fs with whatever your filesystem creation tool is):
mke2fs /dev/mapper/mycrypt
Now mount it:
mount /dev/mapper/mycrypt /mount/point
Check it works for a while, and be happy, then continue reading :)
To unmount it:
umount /mount/point cryptsetup remove mycrypt losetup -d /dev/loop0
To automate this process you could write your own script or use mine.
