updated ASCII version also
[platform/upstream/cryptsetup.git] / FAQ
diff --git a/FAQ b/FAQ
index d3d1288..3e316ad 100644 (file)
--- a/FAQ
+++ b/FAQ
@@ -29,14 +29,55 @@ A. Contributors
 
   ATTENTION: If you are going to read just one thing, make it the
   section on Backup and Data Recovery. By far the most questions on
-  the cryptsetup mailing list are from people that just managed to
-  somehow format or overwrite the start of their LUKS partitions. In
+  the cryptsetup mailing list are from people that managed to damage
+  the start of their LUKS partitions, i.e. the LUKS header. In
   most cases, there is nothing that can be done to help these poor
   souls recover their data. Make sure you understand the problem and
-  limitations imposed by the LUKS security model BEFORE you face such
-  a disaster!
-
-  Specific warnings:
+  limitations imposed by the LUKS security model BEFORE you face
+  such a disaster! In particular, make sure you have a current header
+  backup before doing any potentially dangerous operations.
+
+  BACKUP: Yes, encrypted disks die, just as normal ones do. A full
+  backup is mandatory, see Section "6. Backup and Data Recovery" on
+  options for doing encrypted backup.
+
+  DISTRIBUTION INSTALLERS: Some distribution installers offer to
+  create LUKS containers in a way that can be mistaken as activation
+  of an existing container. Creating a new LUKS container on top of
+  an existing one leads to permanent, complete and irreversible data
+  loss. It is strongly recommended to only use distribution
+  installers after a complete backup of all LUKS containers has been
+  made.
+
+  NO WARNING ON NON-INERACTIVE FORMAT: If you feed cryptsetup from
+  STDIN (e.g. via GPG) on LUKS format, it does not give you the
+  warning that you are about to format (and e.g. will lose any
+  pre-existing LUKS container on the target), as it assumes it is
+  used form a script. In this scenario, the responsibility for
+  warning the user and possibly checking for an existing LUKS header
+  goes over to the script. This is a more general form of the
+  previous item.
+
+  LUKS PASSPHRASE IS NOT THE MASTER KEY: The LUKS passphrase is not
+  used in deriving the master key. It is used in decrypting a master
+  key that is randomly selected on header creation. This means that
+  if you create a new LUKS header on top of an old one with
+  exactly the same parameters and exactly the same passphrase as the
+  old one, it will still have a different master key and your data
+  will be permanently lost.
+
+  PASSPHRASE CHARACTER SET: Some people have had difficulties with
+  this when upgrading distributions. It is highly advisable to only
+  use the 94 printable characters from the first 128 characters of
+  the ASCII table, as they will always have the same binary
+  representation. Other characters may have different encoding
+  depending on system configuration and your passphrase will not
+  work with a different encoding. A table of the standardized first
+  128 ASCII caracters can, e.g. be found on
+  http://en.wikipedia.org/wiki/ASCII
+
+
+ * System Specific warnings
 
   - Ubuntu as of 4/2011: It seems the installer offers to create
   LUKS partitions in a way that several people mistook for an offer
@@ -192,6 +233,16 @@ A. Contributors
   new key-slot.
 
 
+ * Encrytion on top of RAID or the other way round?
+
+  Unless you have special needs, place encryption between RAID and
+  filesystem, i.e. encryption on top of RAID. You can do it the other
+  way round, but you have to be aware that you then need to give the
+  pasphrase for each individual disk and RAID autotetection will not
+  work anymore. Therefore it is better to encrypt the RAID device,
+  e.g. /dev/dm0 .
+
+
  * How do I read a dm-crypt key from file?
 
   Note that the file will still be hashed first, just like keyboard
@@ -363,10 +414,14 @@ A. Contributors
   However, this operation will not change volume key iteration count
   (MK iterations in output of "cryptsetup luksDump"). In order to
   change that, you will have to backup the data in the LUKS
-  container, luksFormat on the slow machine and restore the data.
-  Note that in the original LUKS specification this value was fixed
-  to 10, but it is now derived from the PBKDF2 benchmark as well and
-  set to iterations in 0.125 sec or 1000, whichever is larger.
+  container (i.e. your encrypted data), luksFormat on the slow
+  machine and restore the data. Note that in the original LUKS
+  specification this value was fixed to 10, but it is now derived
+  from the PBKDF2 benchmark as well and set to iterations in 0.125
+  sec or 1000, whichever is larger. Also note that MK iterations
+  are not very security relevant. But as each key-slot already takes
+  1 second, spending the additional 0.125 seconds really does not
+  matter.
 
 
  * "blkid" sees a LUKS UUID and an ext2/swap UUID on the same device.
@@ -395,6 +450,16 @@ A. Contributors
 4. Troubleshooting 
 
 
+ * I get the error "LUKS keyslot x is invalid." What does that mean?
+
+  This means that the given keyslot has an offset that points
+  outside the valid keyslot area. Typically, the reason is a
+  corrupted LUKS header because something was written to the start of
+  the device the LUKS contaner is on. Refer to Section "Backup and
+  Data Recovery" and ask on the mailing list if you have trouble
+  diagnosing and (if still possible) repairing this.
+
+
  * Can a bad RAM module cause problems?
 
   LUKS and dm-crypt can give the RAM quite a workout, especially when
@@ -606,8 +671,8 @@ A. Contributors
   to the last stage ("Acceptance") and think about what to do now.
   There is one exception that I know of: If your LUKS container is
   still open, then it may be possible to extract the master key from
-  the running system. Ask on the mailing-list on how to do that and
-  make sure nobody switches off the machine.
+  the running system. See Item "How do I recover the master key from
+  a mapped LUKS container?" in Section "Backup and Data Recovery".
 
 
  * What is a "salt"?
@@ -640,6 +705,11 @@ A. Contributors
 
  * Is LUKS secure with a low-entropy (bad) passphrase?
 
+  Note: You should only use the 94 printable characters from 7 bit
+  ASCII code to prevent your passphrase from failing when the
+  character encoding changes, e.g. because of a system upgrade, see
+  also the note at the very start of this FAQ under "WARNINGS".
+
   This needs a bit of theory. The quality of your passphrase is
   directly related to its entropy (information theoretic, not
   thermodynamic). The entropy says how many bits of "uncertainty" or
@@ -969,7 +1039,7 @@ A. Contributors
  * Does a backup compromise security?
 
   Depends on how you do it. However if you do not have one, you are
-  going to eventually loseyour encrypted data.
+  going to eventually lose your encrypted data.
 
   There are risks introduced by backups. For example if you
   change/disable a key-slot in LUKS, a binary backup of the partition
@@ -1025,6 +1095,76 @@ A. Contributors
   damage the key-slots in part or in full. See also last item.
 
 
+ * How do I recover the master key from a mapped LUKS container?
+
+  This is typically only needed if you managed to damage your LUKS
+  header, but the container is still mapped, i.e. "luksOpen"ed. It
+  also helps if you have a mapped container that you forgot or do not
+  know a passphrase for (e.g. on a long running server.)
+
+  WARNING: Things go wrong, do a full backup before trying this!
+
+  WARNING: This exposes the master key of the LUKS container. Note
+  that both ways to recreate a LUKS header with the old master key
+  described below will write the master key to disk. Unless you are
+  sure you have securely erased it afterwards, e.g. by writing it to
+  an encrypted partition, RAM disk or by erasing the filesystem you
+  wrote it to by a complete overwrite, you should change the master
+  key afterwards.    Changing the master key requires a full data
+  backup, luksFormat and then restore of the backup.
+
+  First, there is a script by Milan that automatizes    the whole
+  process, except generating a new LUKS header with the old master
+  key (it prints the command for that though):
+
+http://code.google.com/p/cryptsetup/source/browse/trunk/misc/luks-header-from-active
+
+  You can also do this manually. Here is how:
+
+  - Get the master key from the device mapper. This is done by the
+  following command. Substitute c5 for whatever you mapped to:
+
+      # dmsetup table --target crypt --showkey /dev/mapper/c5
+      Result:
+      0 200704 crypt aes-cbc-essiv:sha256 
+      a1704d9715f73a1bb4db581dcacadaf405e700d591e93e2eaade13ba653d0d09 
+      0 7:0 4096
+  The result is actually one line, wrapped here for clarity. The long
+  hex string is the master key.
+
+  - Convert the master key to a binary file representation. You can
+  do this manually, e.g. with hexedit. You can also use the tool
+  "xxd" from vim like this:
+
+      echo "a1704d9....53d0d09" | xxd -r -p > <master-key-file>
+  - Do a luksFormat to create a new LUKS header.
+
+    NOTE: If your header is intact and you just forgot the
+  passphrase, you can just set a new passphrase, see next     subitem.
+
+  Unmap the device before you do that (luksClose). Then do
+
+      cryptsetup luksFormat --master-key-file=<master-key-file> <luks device>
+  Note that if the container was created with other than the default
+  settings of the cryptsetup version you are using, you need to give
+  additional parameters specifying the deviations. If in doubt, try
+  the script by Milan. It does recover the other parameters as well.
+
+  Side note: This is the way the decrypt_derived script gets at the
+  master key. It just omits the conversion and hashes the master key
+  string.
+
+  - If the header is intact and you just forgot the passphrase, just
+  set a new passphrase like this:
+
+      cryptsetup luksAddKey --master-key-file=<master-key-file> <luks device>
+  You may want to disable the old one afterwards.
+
+
  * What does the on-disk structure of dm-crypt look like?
 
   There is none. dm-crypt takes a block device and gives encrypted
@@ -1056,25 +1196,78 @@ A. Contributors
   0xc1000-0xe0400. The space to the next full sector address is
   padded with zeros. Never used key-slots are filled with what the
   disk originally contained there, a key-slot removed with
-  "luksRemoveKey" or "luksKillSlot" gets filled with 0xff. Start of
-  bulk data is at 0x101000, i.e. at 1'052'672 bytes, i.e. at 1MiB
-  + 4096 bytes from the start of   the partition. This is also the
-  value given by command "luksDump" with   "Payload offset: 2056",
-  just multiply by the sector size (512 bytes). Incidentally,
-  "luksHeaderBackup" for a LUKS container created with default
-  parameters dumps exactly the first 1'052'672 bytes to file and
-  "luksHeaderRestore"   restores them.
+  "luksRemoveKey" or "luksKillSlot" gets filled with 0xff. Due to
+  2MiB default alignment, start of the data area for cryptsetup 1.3
+  and later is at 2MiB, i.e. at 0x200000. For older versions, it is
+  at 0x101000, i.e. at 1'052'672 bytes, i.e. at 1MiB + 4096 bytes
+  from the start of the partition. Incidentally, "luksHeaderBackup"
+  for a LUKS container created with default parameters dumps exactly
+  the first 2MiB (or 1'052'672 bytes for   headers created with
+  cryptsetup versions < 1.3) to file and "luksHeaderRestore" restores
+  them.
 
   For non-default parameters, you have to figure out placement
-  yourself. "luksDump" helps. For the most common non-default
-  settings, namely aes-xts-plain with 512 bit key, the offsets are:
-  1st keyslot 0x1000-0x3f800, 2nd keyslot 0x40000-0x7e000, 3rd
-  keyslot 0x7e000-0xbd800, ..., and start of bulk data at 0x200000.
+  yourself. "luksDump" helps. See also next item. For the most common
+  non-default settings, namely aes-xts-plain with 512 bit key, the
+  offsets are: 1st keyslot 0x1000-0x3f800, 2nd keyslot
+  0x40000-0x7e000, 3rd keyslot 0x7e000-0xbd800, ..., and start of
+  bulk data at 0x200000.
 
   The exact specification of the format is here:
   http://code.google.com/p/cryptsetup/wiki/Specification
 
 
+ * What is the smallest possible LUKS container?
+
+  Note: From cryptsetup 1.3 onwards, alignment is set to 1MB. With
+  modern Linux partitioning tools that also align to 1MB, this will
+  result in aligmnet to 2k secors and typical Flash/SSD sectors,
+  which is highly desirable for a number of reasons. Changing the
+  alignment is not recomended.
+
+  That said, with default parameters, the data area starts at
+  exactly 2MB offset (at 0x101000 for crptsetup versions before 1.3).
+  The smallest data area you can have is one sector of 512 bytes.
+  Data areas of 0 bytes can be created, but fail on mapping.
+
+  While you cannot put a filesystem into something this small, it may
+  still be used to contain, for eamcple, key. Note that with current
+  formatting tools, a partition for a container this size will be
+  3MiB anyways. If you put the LUKS container into a file (via
+  losetup and a loopback device), the file needs to be 2097664 bytes
+  in size, i.e. 2MiB + 512B.
+
+  The two ways to influence the start of the data area are key-size
+  and alignment.
+
+  For alignment, you can go down to 1 on the parameter. This will
+  still leave you with a data-area starting at 0x101000, i.e.
+  1MiB+4096B (default parameters) as alignment will be rounded up to
+  the next multiple of 8 (i.e. 4096 bytes) (TODO: need to verify
+  this).
+
+  For key-size, you can use 128 bit (e.g. AES-128 with CBC), 256 bit
+  (e.g. AES-256 with CBC) or 512 bit (e.g. AES-256 with XTS mode).
+  You can do 64 bit (e.g. blofish-64 with CBC), but anything below
+  128 bit has to be considered insecure today.
+
+  Example 1 - AES 128 bit with CBC:
+
+      cryptsetup luksFormat -s 128 --align-payload=8 <device>
+  This results in a data offset of 0x81000, i.e. 516KiB or 528384
+  bytes. Add one 512 byte sector and the smallest LUKS container size
+  with these parameters is 516KiB + 512B or 528896 bytes.
+
+  Example 2 - Blowfish 64 bit with CBC (WARNING: insecure):
+
+      cryptsetup luksFormat -c blowfish -s 64 --align-payload=8 /dev/loop0
+  This results in a data offset of 0x41000, i.e. 260kiB or 266240
+  bytes, with a minimal LUKS conatiner size of 260kiB + 512B or
+  266752 bytes.
+
+
  * I think this is overly complicated. Is there an alternative?
 
   Not really. Encryption comes at a price. You can use plain