Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 380729 - [patch] sys-kernel/genkernel-3.4.16 sys-kernel/genkernel-3.4.16 initrd.scripts tries to decrypt (gpg) all key files, even unencrypted
Summary: [patch] sys-kernel/genkernel-3.4.16 sys-kernel/genkernel-3.4.16 initrd.script...
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: [OLD] Core system (show other bugs)
Hardware: All Linux
: Normal normal (vote)
Assignee: Gentoo Genkernel Maintainers
URL:
Whiteboard:
Keywords: InVCS
Depends on:
Blocks:
 
Reported: 2011-08-26 09:20 UTC by Axel Bringenberg
Modified: 2011-10-30 13:55 UTC (History)
0 users

See Also:
Package list:
Runtime testing required: ---


Attachments
Patch for /usr/share/genkernel/defaults/initrd.scripts (initrd.scripts.patch,644 bytes, patch)
2011-08-26 09:25 UTC, Axel Bringenberg
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Axel Bringenberg 2011-08-26 09:20:58 UTC
The initrd.scripts from genkernel package always use gpg for key file given by boot parameter root_key or swap_key. But normally it should use gpg just on key files with extension ".gpg"

Example:
root_key=key.bin

Reproducible: Always

Steps to Reproduce:
1. create key-file on usb.stick, e.g. dd if=/dev/urandom of=/mnt/usb/key.bin bs=512 count=4
2. setup root volume with LUKS, e.g.  cryptsetup --cipher aes-cbc-essiv:sha256 --key-file /mnt/key/key.bin --key-size 256 luksFormat /dev/sdNN
3. add LUKS mount options crypt_root=/dev/sdNN root_key=key.bin
Actual Results:  
The scripts will not work if gpg is not included in initrd or it will ask for passphrase which will not work too,
because key file is not an encrypted gpg file.

Expected Results:  
The scripts should recognize extensions other than ".gpg" and use the key file as-is.
Comment 1 Axel Bringenberg 2011-08-26 09:25:56 UTC
Created attachment 284693 [details, diff]
Patch for /usr/share/genkernel/defaults/initrd.scripts

This patch corrects a bug in detection of the ".gpg" extension for boot parameter root_key and swap_key
Comment 2 Axel Bringenberg 2011-08-29 07:29:52 UTC
bug summary changed (sorry for confusion).
patch works for me.
Comment 3 Sebastian Pipping gentoo-dev 2011-08-30 14:23:34 UTC
Please explain how addition of quotes has an effect here.  I don't see it myself, yet.
Comment 4 Axel Bringenberg 2011-08-30 14:39:16 UTC
If LUKS_KEY doesn't contain '.gpg' (what is my case), an "[: =: unary operator expected" error occurs, because left side of '=' is nothing.

With addition of the quotes you have at least an empty string "".
Comment 5 Sebastian Pipping gentoo-dev 2011-08-30 14:41:32 UTC
Alright.  But the body of if-then is still entered?
Comment 6 Axel Bringenberg 2011-08-30 14:52:06 UTC
(In reply to comment #5)
> Alright.  But the body of if-then is still entered?

Yes, if LUKS_KEY contains '.gpg' and /sbin/gpg is availabe.

Short example (without the gpg executable test):

for LUKS_KEY in 'root.bin' 'root.gpg'; do
  if [ "$(echo ${LUKS_KEY} | grep -o '.gpg$')" = ".gpg" ]; then
    echo Yep, it is gpg;
  else
    echo No, it is raw;
  fi;
done
Comment 7 Sebastian Pipping gentoo-dev 2011-08-30 14:56:10 UTC
If I add '' to the loop and remove the quotes like this

=============================================================
for LUKS_KEY in '' 'root.bin' 'root.gpg'; do
  if [ $(echo ${LUKS_KEY} | grep -o '.gpg$') = ".gpg" ]; then
    echo Yep, it is gpg;
  else
    echo No, it is raw;
  fi;
done
=============================================================

I get

=============================================================
bash: [: =: unary operator expected
No, it is raw
bash: [: =: unary operator expected
No, it is raw
Yep, it is gpg
=============================================================

for the output.  So the if-then part is _not_ entered.  That's what I have trouble understanding.  To apply decrpytion it would have to enter it, right?  What am I missing?
Comment 9 Axel Bringenberg 2011-08-31 07:23:37 UTC
> [...] So the if-then part is _not_ entered.  That's what I have
> trouble understanding.  To apply decrpytion it would have to enter it, right? 

You are right. I reverted the patch on my test system and "suddenly" it works - with a little hiccup "sh: .gpg: unknown operand", but anyway it starts successfully, since it falls through the if-else part. And what ever forced me before into the gpg passphrase input ... I can't reproduce it :-(

So my patch just solve the error "sh: .gpg: unknown operand". Sorry for the noise.
Comment 10 Sebastian Pipping gentoo-dev 2011-08-31 11:56:25 UTC
Don't worry - you did fix a bug.