Debian Codegraph @

debian/block_signed_deb

raw
1 #!/bin/sh
2 #
3 # Helper script for generating dbx entries for the Debian shim package
4 #
5 # GPL v2+
6 #
7 # Copyright 2020- Steve McIntyre <[email protected]>
8
9 REASON=""
10
11 usage () {
12 echo "$0 <options> <deb1> ... <debN>"
13 echo
14 echo "generate hashes for the signed binaries in deb file(s) in"
15 echo "the correct format to go in the dbx.hashes file"
16 echo
17 echo " -r <reason> - the reason for the blacklisting, required for dbx"
18 echo
19 echo "and a list of .deb files to scan"
20 }
21
22 while getopts ":r:" o; do
23 case "${o}" in
24 r)
25 REASON=${OPTARG}
26 ;;
27 *)
28 echo "Unknown option ${o}"
29 usage
30 exit 1
31 ;;
32 esac
33 done
34 shift $((OPTIND-1))
35
36 if [ "$REASON"x = ""x ]; then
37 echo "$0: Needs a reason to be specified"
38 echo
39 usage
40 exit 1
41 fi
42
43 for DEB in $@; do
44 DIR=$(mktemp -d)
45 if [ -f $DEB ]; then
46 BASEDEB=$(basename $DEB)
47 echo "###############################"
48 echo "# Files from $BASEDEB"
49 echo "# ($REASON)"
50 dpkg -x $DEB $DIR
51 for EFI in $(find $DIR -name *.signed); do
52 BASE=$(basename $EFI)
53 case $BASE in
54 *aa64*efi.signed)
55 EFIARCH=aa64;;
56 *x64*efi.signed)
57 EFIARCH=x64;;
58 *ia32*efi.signed)
59 EFIARCH=ia32;;
60 *)
61 echo "Can't determine EFI arch from $BASE. Abort"
62 exit 1
63 ;;
64 esac
65 echo "# $BASE"
66 HASH=$(pesign --hash --padding --in $EFI | awk '{print $2}')
67 echo "$HASH $EFIARCH"
68 done
69 echo "###############################"
70 echo
71 fi
72 rm -rf $DIR
73 done