File: usbcrypto.mkinitrd

package info (click to toggle)
cryptsetup 2%3A1.0.4%2Bsvn26-1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 3,572 kB
  • ctags: 418
  • sloc: sh: 10,706; ansic: 3,187; makefile: 329; python: 90; perl: 40; sed: 16
file content (65 lines) | stat: -rw-r--r-- 1,738 bytes parent folder | download
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
#!/bin/bash

# An example script which when placed in /etc/mkinitrd/scripts will enable
# the use of a USB stick to provide keys at boot time.

modules="usb-storage sd-mod nls_cp437 ehci-hcd uhci-hcd nls_iso8859-1"

mkdir $INITRDDIR/keys
cp /boot/keys/* $INITRDDIR/keys

for mod in $modules; do
  for ko in `modprobe --set-version $VERSION --show-depends $mod | cut -b8-`; do
    install -d $INITRDDIR/${ko%/*}
    install $ko $INITRDDIR/$ko
  done
done

cat <<EOF >$INITRDDIR/bin/xor
perl -e 'open(F2,@ARGV[0]) && open(F1,@ARGV[1]) or die "
Usage: $0 <file1> <file2>\n"; print $buf1 ^ $buf2 while (read (F1, $buf1,65536) &
& read (F2,$buf2,65536));' -- $STICKMNT/$STICKKEYDIR/$KEYNAME $HOSTKEYDIR/$HOSTKEY | $CRYPTSETUP create $CRYPTVOLNAME $CRYPTRAWVOL
EOF

cat <<EOF >$INITRDDIR/bin/delay
/bin/sleep 0.5s
EOF

cat <<EOF >$INITRDDIR/keyscripts/usbkeys
modprobe uhci-hcd
modprobe ehci-hcd
modprobe usb-storage
modprobe sd-mod

#read old nil < /proc/sys/kernel/printk
#echo 0 > /proc/sys/kernel/printk

echo
echo
echo "Root disk is encrypted. Please provide keys on a usb stick."
echo
echo -n "Waiting for keys "
while [ ! -f /dev2/rootkey ]; do
  echo -n "."
  /bin/delay
  for d in	/devfs/scsi/host*/bus*/target*/lun*/part1 \\
		/devfs/scsi/host*/bus*/target*/lun*/disc; do
    if ! mount -n \$d /mnt -o ro -t vfat 2>/dev/null >/dev/null; then continue; fi
    for i in keys/*; do
      if [ -f /mnt/\${i%.*}.key ]; then
        /bin/xor /mnt/\${i%.*}.key \$i > /dev2/rootkey
      fi
    done
    umount -n /mnt
  done
done

echo " Found"
#echo $old > /proc/sys/kernel/printk

if [ -f /dev2/rootkey ]; then
  /sbin/cryptsetup -v -d /dev2/rootkey -c \$cipher_mode create \$dmname \$device
fi
EOF

chmod +x $INITRDDIR/keyscripts/usbkeys