fedora core 6 1.2949 + vserver 2.2.0
[linux-2.6.git] / scripts / modsign / modsign.sh
1 #!/bin/bash
2 ###############################################################################
3 #
4 # Copyright (C) 2004 Red Hat, Inc. All Rights Reserved.
5 # Written by David Howells (dhowells@redhat.com)
6 #
7 # This program is free software; you can redistribute it and/or
8 # modify it under the terms of the GNU General Public License
9 # as published by the Free Software Foundation; either version
10 # 2 of the License, or (at your option) any later version.
11 #
12 ###############################################################################
13
14 verbose=
15
16 if [ $# -gt 1 -a "x$1" = "x-v" ]
17     then
18     verbose=-v
19     shift
20 fi
21
22 if [ $# = 0 ]
23     then
24         echo
25         echo "usage: $0 [-v] <module_to_sign> [<key_name>]"
26         echo
27         exit 1
28 fi
29
30 module=$1
31
32 if [ -z "$KEYFLAGS" ]
33     then
34     KEYFLAGS="--no-default-keyring --secret-keyring ../kernel.sec --keyring ../kernel.pub"
35 fi
36
37 if [ $# -eq 2 ]
38     then
39     KEYFLAGS="$KEYFLAGS --default-key $2"
40 fi
41
42 # strip out only the sections that we care about
43 scripts/modsign/mod-extract $verbose $module $module.out || exit $?
44 # dd if=/dev/zero of=$module.out bs=1 count=1 # inject fault
45
46 # sign the sections
47 gpg --no-greeting $KEYFLAGS -b $module.out || exit $?
48
49 # check the signature
50 #gpg --verify rxrpc.ko.out.sig rxrpc.ko.out
51
52 ## sha1 the sections
53 #sha1sum $module.out | awk "{print \$1}" > $module.sha1
54
55 # add the encrypted data to the module
56 objcopy --add-section .module_sig=$module.out.sig $module $module.signed || exit $?
57 objcopy --set-section-flags .module_sig=alloc $module.signed || exit $?
58 rm -f $module.out*