lfs-uefi: fix efivar-37 FTBFS
[linux_from_scratch_hints.git] / eswap.txt
blobcfaa9af37a08302193d1473dfe9c9f2be2ee8682
1 AUTHOR: Jerome Pinot <ngc891@gmail.com>
3 DATE: 2005-12-01
5 LICENSE: GNU Free Documentation License Version 1.2
7 SYNOPSIS: Encrypting swap partition
9 DESCRIPTION:
10 Here is a way to enable disk encryption on HLFS system. Aim is to provide native
11 swap encryption and possibility to encrypt the root partition later, with
12 third-part software.
14 ATTACHMENTS:
15 * ftp://ngc891.blogdns.net/pub/hlfs/hlfs-607-eswap-1.patch
16 * http://www.linuxfromscratch.org/patches/downloads/util-linux/util-linux-2.12r-loop_AES-3.1b.patch 
17 * http://www.linuxfromscratch.org/patches/downloads/linux/linux-2.6.14.3-loop_AES-3.1b.patch
18 * http://www.linuxfromscratch.org/patches/downloads/gnupg/gnupg-1.4.2-loop_AES-3.1b.patch
20 PREREQUISITES:
21 This hint is written for HLFS but can be easily applied to LFS. You should have 
22 some basic knowledge about devices and using swap.
24 HINT:
26 I. About encrypting disk
27 ------------------------
29 A Linux system already provides some basic security environment including users 
30 and groups, passwords, permissions, and n
31 ow access control via SELinux project.
33 However, this could be not enough in some cases like attackers with physical
34 access. If someone can physically access your hard drive and mount it in an 
35 other computer, he overpasses the system and can read whatever he wants.
37 The problem is the same with the swap partition. It stores short lifetime data 
38 including most of the things you have just done with the computer and that 
39 didn't fit in the RAM. The system continously overwrite this partition and there
40 is no easy structure inside but an attacker could seek in for passwords and 
41 other data you just typed.
43 One protection against this kind of attack is swap encryption. It means cipher 
44 your data with an algorithm, so you need a passphrase and/or a key to access 
45 clearly to it. Even, some ciphers like AES provide you "plausible deniability".
46 It means there is no way to know that the partition is actually encrypted 
47 because it looks just like trash, like an empty partition. So, there is no 
48 more problem for the syst
49 em being overpassed by physical access.
51 Encrypting your partitions could increase drastically your data security.
53 II. How to do?
54 --------------
56 There is several ways to encrypt disk on Linux, including cryptoloop, dm-crypt,
57 loop-AES and StegFS.
59 StegFS is a special encrypted file system. It's sounds really great but is still
60 under development and needs big modifications of the base system.
62 Cryptoloop was a special loop device included in the kernel that provides access
63 to encrypted device by loopback. Everybody was happy to have such an easy way to 
64 access encrypted device, but unfortunately, it was found that cryptoloop has a 
65 flaw and cannot be trust. If you can find cryptoloop in some linux distribution,
66 it was actually removed from the official Linux kernel source code [1].
68 dm-crypt is an encrypted device mapper created to replace cryptoloop [2]. You 
69 can find it in the official source, under the device mapper sub-section. It is
70 supposed to avoid the flaw of cryptoloop, but actually, it fails. You ca
71 n find 
72 on the web more informations about that [3]. So even if it's available natively 
73 in the kernel it should be avoid for more security.
75 *UPDATE* It seems that dm-crypt could be use now, and the flaw corrected in the
76 kernel. It uses a definitly different process which may be explain in an other
77 LFS hint.
79 So there is loop-AES. It is stable and modular and needs few modifications to 
80 the base system. It consists of patches to apply to the kernel (2.4 and 2.6) and
81 some utilities. Using multi-key with loop-AES avoids the flaw of cryptoloop and 
82 dm-crypt. It uses the AES algorithm which is known to be one of the strongest 
83 available. Moreover, there is already an LFS hint for encrypting root partition 
84 using loop-AES [4].
86 You can find loop-AES here:
87 http://sourceforge.net/projects/loop-aes/ 
89 [1] http://lwn.net/Articles/67216/ 
90 [2] http://kerneltrap.org/node/2433 
91 [3] http://mareichelt.de/pub/texts.cryptoloop.php 
92 [4] http://linuxfromscratch.org/~devine/erfs-howto.html 
94 III. Encrypting swap
95 ---------------
96 -----
98 It's a matter of applying 2 patches and changing a little the /etc/fstab file.
99 The easiest way is to patch the svn version of the book like this:
101 -- Optional --
103  wget ftp://ngc891.blogdns.net/pub/hlfs/hlfs-607-eswap-1.patch
104  cd HLFS
105  patch -Np1 -i ../hlfs-607-eswap-1.patch
107 -- Optional --
109 Unfortunatly, it can be out of date so you have choice to follow the other way:
111 1. First you need to apply the util-linux-2.12r-loop_AES-3.1b.patch to the
112 util-linux before building it during chapter 6. This patch enables the use of 
113 mount, umount, and swapon for encrypted devices.
115  $ patch -Np1 -i ../util-linux-2.12r-loop_AES-3.1b.patch
117 2. You need to change the line about swap file in the /etc/fstab (chapter 7)
119 from:   /dev/[yyy]      swap    swap    pri=1   0       0
120 to:     /dev/[yyy]      swap    swap    sw,loop=/dev/loop7,encryption=AES128,pri=1      0       0
122 The swap will be mount using a loopback device with a multikeys AES encryption. 
123 It uses the last loop device so you will be able to use from /dev/loop0 to 
124 /dev/loop6 for other purpose.
126 3. 
127 Finally, you must patch your kernel source before "make menuconfig" in
128 chapter 7:
130  patch -Np1 -i ../linux-2.6.14.3-loop_AES-3.1b.patch
132 Then, during "make menuconfig", you MUST select loop-AES under loop item of the
133 block sub-section or your swap partition may not be available. You should enable
134 BLK_DEV_LOOP_AES and BLK_DEV_LOOP_KEYSCRUB.
136 IV. Setting up third-part software
137 ----------------------------------
139 You can find the following packages in ftp://ngc891.blogdns.net/pub/hlfs/packages 
141 1. GnuPG 1.4.2
143 The build process of GnuPG is explained at the end of the HLFS book, security section.
145 2. Sharutils 4.3.81
147 We need sharutils for uuencode to convert randon binary data from /dev/urandom
148 to random ascii data for keys generation.
150  sed -e 's/^CFLAGS .*$/& -pie -fpie/' -i `find . -name Makefile.in` &&
151  ./configure --prefix=/usr &&
152  make && make install
154 3. Aespipe 2.3b
156 Add some flags and build aespipe:
158  sed -e 's/^LINK .*$/& -nointl/' -i Makefile.in
159  sed -e '10,0s/^/CFLAGS+=-pie -fpie\n&/' -i Makefile.in
160  &&
161  ./configure --prefix=/usr &&
162  make && make install
164 ACKNOWLEDGEMENTS:
165 Thanks to the author of loop-AES, Jari Ruusu
167 CHANGELOG:
168 [2005-12-01]
169   * updated for Linux 2.6.14.3, util-linux 2.12r, loop-AES 3.1b, sharutils 4.81
170   * removed GnuPG section, it's in the HLFS book now
171   * added a note about dm-crypt
172 [2005-07-12]
173   * new URLs
174   * kernel 2.6.11.12, loop-AES 3.0d, sharutils 4.3.80
175   * patch for HLFS r534
176 [2005-04-14]
177   * updated for Linux 2.6.11.7
178   * update the HLFS patch to r461
179 [2005-03-27]
180   * updated for loop-AES 3.0c
181 [2005-03-18]
182   * updated for Linux 2.6.11.4 and GnuPG 1.4.1
183   * added hlfs book patch
184   * some fixes
185 [2005-02-27]
186   * Added Sharutils and aespipe
187   * Some fixes
188 [2005-02-19]
189   * Added GnuPG compilation guide
190   * Few fixes
191 [2005-02-13]
192   * Initial version