How do I unlock my LUKS disks on Ubuntu 26.04 from a Live USB (if my computer is ubootable)?

Sorry, I should have been more clear:

$ snap-tpmctl get-luks-key --escaped
Enter recovery key: *****-*****-*****-*****-*****-*****-*****-*****
"kLR\r\x95c#}\x05\xcd\xc1\x8b\xb9v\x81\xac"
$ printf "kLR\r\x95c#}\x05\xcd\xc1\x8b\xb9v\x81\xac" >/tmp/keyfile
$ sudo cryptsetup luksOpen --test-passphrase --key-file=/tmp/keyfile /dev/disk/by-id/ata-QEMU_HARDDISK_QM00003-part5 && echo SUCCESS
SUCCESS

I was able to emulate get-luks-key by this:

printf "%.4x" $(sed -E -e 's/-/ /g' -e 's/\b0*//g' <recovery-key.txt) | sed -E 's/([0-9a-f]{2})([0-9a-f]{2})/\2\1/g' | xxd -r -p

(sed -E 's/\b0*//g' to strip leading 0’s so as to not accidentally have the number interpreted as octal)
[EDIT: trimmed down version; xxd does not allow concatenating option like -rp, which is why p was ignored and thus the first byte was interpreted as offset; removed redundat tr – incorporated into sed command]

1 Like

Thank you!

By the way, you don’t need sudo with snap-tpmctl when getting the LUKS key, because it’s merely manipulating strings.

1 Like

As for the length of the recovery key, I think it might be misleading. When you look at the luksDump output, you’ll find that all slots are populated with 512 bit keys. They are derived by PBKDF2 from the passphrase, which is just a raw byte string in case of the recovery key. Key derivation functions add extra computational costs — it takes a moment for --test-passphrase to return —, so brute-forcing a recovery key is probably equally or even more computationally expensive than doing the same with the 512 bits volume key.

At least that’s what I came up with for an explanation.

1 Like

Replying to myself to confirm that this is what happens. The cryptsetup FAQ has all the info — great (re)read, BTW.

Unlocking with Key File

Salt by the Shovel

(emphasis added)
Note how key derivation takes about 1 sec by design — the number of iterations for PBKDF is chosen at creation time, depending on the target machine —, to slow down brute force attacks. So now, thanks to the salt, the attacker cannot make any use of rainbow tables and needs to go through the key derivation function on every try, so 1 sec per, which is an eternity: 2128 seconds are ~1031 years; or they’d need 2256 rainbow tables, because the slot keys are rather salty — 32 bytes (256 bits). Even if an attacker had 1000x the computing power of your machine, to get through the iterations 1000x quicker (see 5.10), it’d take them 1028 (CPU) years — or, IOW, if they had 100,000 trillion trillion CPU’s, each 1000x as fast as yours, to do it in parallel, they’d pull it off in one year. :grin: :smiling_face_with_sunglasses: :beach_with_umbrella:

About Entropy

It’s probably worth noting that the TPM/FDE setup of Ubuntu doesn’t use Argon2 but PDKBF2 (see 5.11).

(emphasis added)

By that standard, Ubuntu’s 128 bit recovery key is extremely rich in entropy.

From memory, I also think that 128 bit symmetric keys are still considered pretty secure. Or let’s just do the math; suppose we only had a 128 bit volume (master) key; brute-forcing it cannot be slowed down by PDKDF, since the attacker only needs to try decrypting stuff and see if the output is not obvious gibberish. Suppose further that a single attempt only takes 1 microsecond; that only shifts the decimal point 6 digits to the left, so the attacker would now only need 0.1 trillion trillion machines to do it in one year — :disguised_face: :detective: :older_person:: any day now…

1 Like

Peter, that was informative and interesting, thank you!

I always knew that a salt was important, but I hadn’t bothered to find out why. Now I know.

According to this documentation, 26.04 uses Argon2, not PDKBF2; unless you use FIPS mode.

However, I checked this on my installation. It uses PBKDF2, not Argon2, as you correctly stated.

$ lsblk --fs | grep -F crypto_LUKS
├─sda4  crypto_LUKS 2  ubuntu-save-enc [redacted]
└─sda5  crypto_LUKS 2  ubuntu-data-enc [redacted]

sda4 is the “save” partition, and sda5 the “data” partition.

$ sudo cryptsetup luksDump /dev/sda4 | grep -Fi argon
$ sudo cryptsetup luksDump /dev/sda4 | grep -F PBKDF:
	PBKDF:      pbkdf2
	PBKDF:      pbkdf2
	PBKDF:      pbkdf2

The same for sda5.

Apparently, this is because TPM-backed encryption uses “PBKDF2 for maximum system initialization speed and stability,” and doesn’t need the higher security of Argon2 because “a TPM-backed setup relies on the hardware’s built-in anti-hammering (rate-limiting) logic to protect against brute-force attacks. The physical TPM chip itself prevents quick guesses.”

So, it’s all good.

I have been learning so much in the past few days!

2 Likes

This topic was automatically closed after 30 days. New replies are no longer allowed.