All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Willie" <tumbleweed@fastmail.net>
To: dm-crypt@saout.de
Subject: Re: [dm-crypt] How to gather LUKS parameters from active device (if LUKS header lost)
Date: Mon, 02 Aug 2010 10:33:26 -0700	[thread overview]
Message-ID: <1280770406.18055.1387939849@webmail.messagingengine.com> (raw)
In-Reply-To: <4C56CB65.1060804@redhat.com>


On Mon, 02 Aug 2010 15:43 +0200, "Milan Broz" <mbroz@redhat.com> wrote:
> 
> 
> On 08/02/2010 11:58 AM, Milan Broz wrote:
> > If you see dm-crypt mapping there mapped to proper drive, you can still recreate
> > LUKS header with some some magic.
> 
> Well, here is the idea how to reconstruct LUKS header from active mapping
> if header is lost but mapping is still active.
> (Note: if device is not active, recovery is impossible).
> 
> - it will change LUKS UUID!
> - no passphrase needed, it asks for new one (root access required of
> course)
> - cryptsetup 1.1.x required.
> 
> Do not save master key file (second param) to unencrypted filesystem!
> 
> I'll add something similar to cryptsetup distro into DOC install,
> for now take this as an idea - see attached script (it will not touch
> device,
> only saves master key to file and print required parameters for
> cryptsetup).
> 
> BEWARE: NO GUARANTEES AT ALL. NOT PROPERLY TESTED.
> 
> Example:
>   If you have mapped device named "luks_sdb", script will produce this:
> 
>   # <script> luks_sdb /mnt/safedisk/sdb_master_key
> 
>   Generating master key to file /mnt/safedisk/sdb_master_key.
>   You can now try to reformat LUKS device using:
>   cryptsetup luksFormat -c aes-cbc-essiv:sha256 -s 256
>   --align-payload=2056 --master-key-file=/mnt/safedisk/sdb_master_key
>   /dev/sdb
> 
> Milan
> 
> [---cut here---]
> #!/bin/bash
> 
> # Try to get LUKS info and master key from active mapping and prepare
> parameters for cryptsetup"
> # (C) 2010 Milan Broz <asi@ucw.cz>
> 
> 
> fail() { echo -e $1 ; exit 1 ; }
> field() { echo $(dmsetup table --target crypt --showkeys $DEVICE | cut
> -d' ' -f$1) ; }
> field_cryptsetup() { echo $(cryptsetup status $DEVICE | grep $1 | sed
> "s/.*$1:\s*//;s/\ .*//") ; }
> 
> which xxd >/dev/null || fail "You need xxd (part of vim package)
> installed to convert key."
> 
> [ -z "$2" ] && fail "LUKS header from active mapping, use:\n $0
> crypt_mapped_device mk_file_name";
> 
> DEVICE=$1
> MK_FILE=$2
> 
> [ -z "$(field 4)" ] && fail "Mapping $1 not active or it is not crypt
> target."
> 
> CIPHER=$(field_cryptsetup cipher)
> OFFSET=$(field_cryptsetup offset)
> REAL_DEVICE=$(field_cryptsetup device)
> KEY_SIZE=$(field_cryptsetup keysize)
> KEY=$(field 5)
> 
> [ -z "$CIPHER" -o -z "$OFFSET" -o "$OFFSET" -le 383 -o -z "$KEY" ] &&
> fail "Incompatible device, sorry."
> 
> echo "Generating master key to file $MK_FILE."
> echo -E -n $KEY| xxd -r -p >$MK_FILE
> 
> echo "You can now try to reformat LUKS device using:"
> echo "  cryptsetup luksFormat -c $CIPHER -s $KEY_SIZE
> --align-payload=$OFFSET --master-key-file=$MK_FILE $REAL_DEVICE"
> 


It gets worse and worse: I go to work, come back and my woman has turned
off the computer. Whatever I was seeing earlier today is no longer there
- just the iso image I wrote to the disk.

I think I'm stuffed, but very very grateful for the helpful replies
here.



-- 
http://www.fastmail.fm - Faster than the air-speed velocity of an
                          unladen european swallow

  reply	other threads:[~2010-08-02 17:34 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-08-01 21:11 [dm-crypt] Hosed encrypted drive. Is disaster recovery possible? Willie
2010-08-01 21:26 ` Christoph Anton Mitterer
2010-08-01 23:01 ` Arno Wagner
2010-08-01 23:20   ` Willie
2010-08-02  0:27     ` Arno Wagner
2010-08-02  8:38       ` Willie
2010-08-02  9:05         ` Arno Wagner
2010-08-02  9:58         ` Milan Broz
2010-08-02 10:21           ` Mikko Rauhala
2010-08-02 13:43           ` [dm-crypt] How to gather LUKS parameters from active device (if LUKS header lost) Milan Broz
2010-08-02 17:33             ` Willie [this message]
2010-08-02 17:36             ` Arno Wagner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1280770406.18055.1387939849@webmail.messagingengine.com \
    --to=tumbleweed@fastmail.net \
    --cc=dm-crypt@saout.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.