1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170
|
#!/bin/sh
set -e
PREREQ=""
prereqs()
{
echo "$PREREQ"
}
case $1 in
prereqs)
prereqs
exit 0
;;
esac
#Check whether loop-aes support is forced on or off
case "${INITRAMFS_LOOPAES}" in
0|no|off)
exit 0
;;
1|yes|on)
FORCE_LOOPAES=1
;;
auto|)
;;
*)
echo "WARNING! (loop-aes) ignoring invalid INITRAMFS_LOOPAES value ${INITRAMFS_LOOPAES}" 1>&2
esac
. /usr/share/initramfs-tools/hook-functions
exit_unless_forced() {
if [ -z "${FORCE_LOOPAES}" ]; then
exit $1
fi
}
get_root_device() {
[ -r /etc/fstab ] || return
grep '^[^#]' /etc/fstab | ( \
while read dev mount type options dump pass; do
if [ "$mount" = "/" ]; then
echo "rootdev=\"${dev}\" rootoptions=\"${options}\""
return
fi
done )
}
decode_cipher() {
local cipher
case "$1" in
twofish*)
echo twofish
;;
blowfish*)
echo blowfish
;;
serpent*)
echo serpent
;;
mars*|rc6*|tripleDES)
echo "WARNING| (loop-aes) Don't know how to handle encryption type $1" 1>&2
;;
NONE|XOR|AES*)
;;
*)
echo "WARNING| (loop-aes) Unknown encryption type $1" 1>&2
;;
esac
}
iterate_cipher_module() {
local cipher
local IFS=":"
for cipher in $2; do
$1 "loop_${cipher}"
done
}
get_root_opts() {
local opt cipher
local IFS=", "
for opt in $rootoptions; do
case "$opt" in
encryption=*)
cipher="$(decode_cipher \"${opt#encryption=}\")"
if [ -n "$cipher" ]; then
rootencryption="${rootencryption}${rootencryption:+:}${cipher}"
fi
loopaes_opts="${loopaes_opts},${opt}"
;;
offset=*)
loopaes_opts="${loopaes_opts},${opt}"
;;
sizelimit=*)
loopaes_opts="${loopaes_opts},${opt}"
;;
pseed=*)
loopaes_opts="${loopaes_opts},${opt}"
;;
phash=*)
loopaes_opts="${loopaes_opts},${opt}"
;;
loinit=*)
loopaes_opts="${loopaes_opts},${opt}"
;;
itercountk=*)
loopaes_opts="${loopaes_opts},${opt}"
;;
gpgkey=*)
rootgpgkey=${opt#gpgkey=}
;;
gpghome=*)
rootgpghome=${opt#gpghome=}
;;
loop=*)
rootloop=${opt#loop=}
;;
*)
# Presumably a non-supported or filesystem option
;;
esac
done
}
# Find out which device root is on
eval $(get_root_device)
[ -z "${rootdev}" ] && exit_unless_forced 0
# We now have set: rootdev rootoptions
get_root_opts
[ -z "${rootloop}" ] && exit_unless_forced 0
loopaes_opts="${loopaes_opts},loop=${rootloop}"
# Prepare the initramfs
if [ -n "${rootgpgkey}" ]; then
mkdir ${DESTDIR}/keys/
cp "${rootgpgkey}" ${DESTDIR}/keys/rootkeyfile.gpg
copy_exec /usr/bin/gpg /bin/
loopaes_opts="${loopaes_opts},gpgkey=/keys/rootkeyfile.gpg"
fi
if [ -n "${rootgpghome}" ]; then
cp -R "${rootgpghome}" ${DESTDIR}/.gnupg
else
mkdir ${DESTDIR}/.gnupg/
fi
loopaes_opts="${loopaes_opts},gpghome=/.gnupg"
echo "LOOPAESOPTS=\"$loopaes_opts\"" > ${DESTDIR}/conf/conf.d/loopaes
copy_exec /sbin/losetup /sbin/
# Allow the correct keymap to be loaded if possible
if [ -e /bin/loadkeys -a -r /etc/console/boottime.kmap.gz ]; then
copy_exec /bin/loadkeys /bin/
cp /etc/console/boottime.kmap.gz $DESTDIR/etc/
fi
manual_add_modules loop
if [ -z "${FORCE_LOOPAES}" ]; then
iterate_cipher_module "manual_add_modules" "$rootencryption"
else
iterate_cipher_module "manual_add_modules" "serpent:blowfish:twofish"
fi
# Done
exit 0
|