dex6 / sed-opal-unlocker

Micro-utility for unlocking TCG-OPAL encrypted disks
Apache License 2.0
33 stars 4 forks source link

Custom PBA Image #1

Open leonardohn opened 4 years ago

leonardohn commented 4 years ago

Considering that sedutil is weird (e.g. linuxpba suddenly reboots after writing a password which is not "debug") and it's PBA is quite slow to boot, it would be nice to have a PBA image based on sed-opal-unlocker available for the public.

I would like to propose to build a minimal linux kernel containing only sed-opal-unlocker and busybox embedded on the initramfs, compressed using a faster algorithm than lzma (lz4, perhaps?), so that it could boot instantly on NVMe devices (and maybe on SATA).

What do you think about it?

dex6 commented 4 years ago

Thanks for your interest in this project.

The idea is great and to be honest, I'm already using something like that for a few months... a PBA image in form of EFI system partition containing multiplicated EFI executable (very minimal kernel with embedded initramfs with busybox + sed-opal-unlocker + plymouth + efibootmgr + kexec + somescripts; all lz4-ed) and I find it working really well.

It's probably as far from being general as you can possibly get, though. The image must be built on user's computer (embeds encrypted secrets and depends on /boot/efi/ structure); it's Gentoo-based (unlikely to build on other distros); it assumes user replaced vendor's Secure Boot keys with his/her own (everything is signed with custom keys). Even the Plymouth theme is acceptable only for Thinkpad users ;-)

But I guess that's a good starting point. I promise I'll publish it someday in my laptop-notes repo; it already contains some design notes. I did finish the scripts, however I chronically lack time (and some motivation as well) to clean them out and publish... I hope this will happen in a month or two, but I cannot guarantee anything.

leonardohn commented 4 years ago

Although I'm not having spare time to help right now, I've already tried some options to automate the PBA image generation using petitboot. They already provide some useful packages out of the box, so it won't take time to have a working image. My suggestion would be to use the initramfs outside the kernel (as a cpio.lz4), so the user can modify it as needed.

Are you currently building your PBA using gentoo-sources or vanilla-sources?

gitthangbaby commented 4 years ago

Nice ideas! I also don't like the existing PBA as it

Tronic commented 3 years ago

@leonardohn @gitthangbaby If you are still interested, I got it working on initramfs via normal EFI system partition: no PBA/ShadowMBR, no extra reboot after unlocking, and even Secure Boot all the way. This still needs polishing before it can be released, but it certainly is working on my server, can even ssh in to type the password. See #3 for updates.

gitthangbaby commented 3 years ago

See #3 for updates.

interesting. does this mean the parts of disk can stay unencrypted? because i 've had an initram or post-init solution with such convenience (however using 2nd non TCG drive for execution), but i realized i'd love Windows to unlock parts of the target drive too (which doesn't work without some expensive tools like Winmagic(?); wouldn't survive resume; and Bitlocker also didn't provide hardware support despite manufacturer claim). But if partitions can be locked, then i could simply mark Windows and LinuxBoot partition as unecnrypted. That'd be pretty cool!

Tronic commented 3 years ago

@gitthangbaby Well, technically all data is always encrypted, but yes, anything not included in your enabled LockingRanges can stays unlocked after power loss.

Do note that setupLockingRange may destroy data, so migrate your data elsewhere while setting this up:

sedutil-cli --setupLockingRange 1 [Admin1 password] [start sector] [sector COUNT] /dev/nvme0n1
sedutil-cli --enableLockingRange 1 [Admin1 password] /dev/nvme0n1

# Unlock immediately (e.g. on initramfs)
sedutil-cli --setLockingRange 1 RW [Admin1 password] /dev/nvme0n1

# Lock immediately (not safe on a running system, locking happens automatically on power loss anyway)
sedutil-cli --setLockingRange 1 LK [Admin1 password] /dev/nvme0n1

Since sed-opal-unlocker is currently hardcoded to use LockingRange 0, i.e. the whole disk, you will need to edit source code to enable what was done with sedutil-cli --setLockingRange in the commands above.