aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/sign-file
diff options
context:
space:
mode:
authorRusty Russell <rusty@rustcorp.com.au>2012-10-18 21:23:15 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2012-10-19 11:27:43 -0400
commite2a666d52b4825c26c857cada211f3baac26a600 (patch)
treeb7e91bd10e8c1b2932ffd1716fde3abccd7c4dd8 /scripts/sign-file
parentc9623de4fc2f8320fe94316b46171683be3b1d59 (diff)
kbuild: sign the modules at install time
Linus deleted the old code and put signing on the install command, I fixed it to extract the keyid and signer-name within sign-file and cleaned up that script now it always signs in-place. Some enthusiast should convert sign-key to perl and pull x509keyid into it. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'scripts/sign-file')
-rw-r--r--scripts/sign-file44
1 files changed, 18 insertions, 26 deletions
diff --git a/scripts/sign-file b/scripts/sign-file
index e58e34e50ac5..095a953bdb8e 100644
--- a/scripts/sign-file
+++ b/scripts/sign-file
@@ -1,8 +1,8 @@
1#!/bin/sh 1#!/bin/bash
2# 2#
3# Sign a module file using the given key. 3# Sign a module file using the given key.
4# 4#
5# Format: sign-file <key> <x509> <src-file> <dst-file> 5# Format: sign-file <key> <x509> <keyid-script> <module>
6# 6#
7 7
8scripts=`dirname $0` 8scripts=`dirname $0`
@@ -15,8 +15,8 @@ fi
15 15
16key="$1" 16key="$1"
17x509="$2" 17x509="$2"
18src="$3" 18keyid_script="$3"
19dst="$4" 19mod="$4"
20 20
21if [ ! -r "$key" ] 21if [ ! -r "$key" ]
22then 22then
@@ -29,16 +29,6 @@ then
29 echo "Can't read X.509 certificate" >&2 29 echo "Can't read X.509 certificate" >&2
30 exit 2 30 exit 2
31fi 31fi
32if [ ! -r "$x509.signer" ]
33then
34 echo "Can't read Signer name" >&2
35 exit 2;
36fi
37if [ ! -r "$x509.keyid" ]
38then
39 echo "Can't read Key identifier" >&2
40 exit 2;
41fi
42 32
43# 33#
44# Signature parameters 34# Signature parameters
@@ -83,33 +73,35 @@ fi
83 73
84( 74(
85perl -e "binmode STDOUT; print pack(\"C*\", $prologue)" || exit $? 75perl -e "binmode STDOUT; print pack(\"C*\", $prologue)" || exit $?
86openssl dgst $dgst -binary $src || exit $? 76openssl dgst $dgst -binary $mod || exit $?
87) >$src.dig || exit $? 77) >$mod.dig || exit $?
88 78
89# 79#
90# Generate the binary signature, which will be just the integer that comprises 80# Generate the binary signature, which will be just the integer that comprises
91# the signature with no metadata attached. 81# the signature with no metadata attached.
92# 82#
93openssl rsautl -sign -inkey $key -keyform PEM -in $src.dig -out $src.sig || exit $? 83openssl rsautl -sign -inkey $key -keyform PEM -in $mod.dig -out $mod.sig || exit $?
94signerlen=`stat -c %s $x509.signer` 84
95keyidlen=`stat -c %s $x509.keyid` 85SIGNER="`perl $keyid_script $x509 signer-name`"
96siglen=`stat -c %s $src.sig` 86KEYID="`perl $keyid_script $x509 keyid`"
87keyidlen=${#KEYID}
88siglen=${#SIGNER}
97 89
98# 90#
99# Build the signed binary 91# Build the signed binary
100# 92#
101( 93(
102 cat $src || exit $? 94 cat $mod || exit $?
103 echo '~Module signature appended~' || exit $? 95 echo '~Module signature appended~' || exit $?
104 cat $x509.signer $x509.keyid || exit $? 96 echo -n "$SIGNER" || exit $?
97 echo -n "$KEYID" || exit $?
105 98
106 # Preface each signature integer with a 2-byte BE length 99 # Preface each signature integer with a 2-byte BE length
107 perl -e "binmode STDOUT; print pack(\"n\", $siglen)" || exit $? 100 perl -e "binmode STDOUT; print pack(\"n\", $siglen)" || exit $?
108 cat $src.sig || exit $? 101 cat $mod.sig || exit $?
109 102
110 # Generate the information block 103 # Generate the information block
111 perl -e "binmode STDOUT; print pack(\"CCCCCxxxN\", $algo, $hash, $id_type, $signerlen, $keyidlen, $siglen + 2)" || exit $? 104 perl -e "binmode STDOUT; print pack(\"CCCCCxxxN\", $algo, $hash, $id_type, $signerlen, $keyidlen, $siglen + 2)" || exit $?
112) >$dst~ || exit $? 105) >$mod~ || exit $?
113 106
114# Permit in-place signing 107mv $mod~ $mod || exit $?
115mv $dst~ $dst || exit $?