Return-Path: Received: from mail-wr1-x42a.google.com (mail-wr1-x42a.google.com [IPv6:2a00:1450:4864:20::42a]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.server123.net (Postfix) with ESMTPS for ; Mon, 6 Aug 2018 10:26:55 +0200 (CEST) Received: by mail-wr1-x42a.google.com with SMTP id h15-v6so11488051wrs.7 for ; Mon, 06 Aug 2018 01:26:55 -0700 (PDT) References: <3a015c32-03d0-fe2f-41c3-7c445e7efa8a@gmail.com> From: Milan Broz Message-ID: Date: Mon, 6 Aug 2018 10:26:53 +0200 MIME-Version: 1.0 In-Reply-To: <3a015c32-03d0-fe2f-41c3-7c445e7efa8a@gmail.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Subject: Re: [dm-crypt] Recreation of LUKS header when the master key is known List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Mikhail Morfikov , dm-crypt@saout.de There was a script in cryptsetup repo, that did exactly this task (re-create LUKS header according to active device parameters). See misc/luks-header-from-active in git. But it is probably no longer working (definitely not with LUKS2 where we store dm-crypt key in keyring), but some parts can be useful still. I will need to fix it later... Patches welcome :) Milan On 05/08/18 23:53, Mikhail Morfikov wrote: > My friend zeroed out the first 3 GiB of a drive, including the partition table, > LUKSv1 header, and EXT4 superblock + some data of the first partition. He > realized what he did, and before rebooting the system, he recovered the master > key via the following command: > > ----------------------------- > # dmsetup table --showkeys /dev/mapper/encrypted | awk '{ print $5 }' | xxd -r > -p > /tmp/master_key > ----------------------------- > > He saved the key and later on (offline) he wanted to recreate the LUKS header > using the following command: > > ----------------------------- > # cryptsetup luksFormat -v -y -c aes-xts-plain64 > --master-key-file=/tmp/master_key /dev/sdd1 > ----------------------------- > > But he was unable to decrypt the data (I know the ext4 superblock is damaged, > but the volume can be tested whether it is decrypted or not, and in this case it > wasn't). > > He said that the original container was created (probably) using this command: > > # cryptsetup -v -y -c aes-xts-plain64 -s 512 -h sha512 -i 5000 --use-random > luksFormat /dev/sdd1 > > He ultimately found the header backup and everything went well, but I have a > question -- what parameters are needed in order to recreate the header when the > master key is known? > _______________________________________________ > dm-crypt mailing list > dm-crypt@saout.de > https://www.saout.de/mailman/listinfo/dm-crypt >