History

MODSIGN: Specify the hash algorithm on sign-file command line

Make the script usable without a .config file.

Michal Marek committed 13 years ago

Commit 4bc94101 parent 22753672 files · +17 −38Browse files

Unified · Split

2 files
  1. Makefile +1 −1
  2. scripts/sign-file +16 −37
Makefile+1−1
@@ -723,7 +723,7 @@ ifeq ($(CONFIG_MODULE_SIG),y) · 722 unmodified lines
723723 MODSECKEY = ./signing_key.priv
724724 MODPUBKEY = ./signing_key.x509
725725 export MODPUBKEY
726−mod_sign_cmd = perl $(srctree)/scripts/sign-file $(MODSECKEY) $(MODPUBKEY)
726+mod_sign_cmd = perl $(srctree)/scripts/sign-file $(CONFIG_MODULE_SIG_HASH) $(MODSECKEY) $(MODPUBKEY)
727727 else
728728 mod_sign_cmd = true
729729 endif
scripts/sign-file+16−37
@@ -4,7 +4,7 @@ · 3 unmodified lines
44 #
55 # Format:
66 #
7−# ./scripts/sign-file [-v] <key> <x509> <module> [<dest>]
7+# ./scripts/sign-file [-v] <hash algo> <key> <x509> <module> [<dest>]
88 #
99 #
1010 use strict;
@@ -17,35 +17,19 @@ if ($#ARGV >= 0 && $ARGV[0] eq "-v") { · 6 unmodified lines
1717 shift;
1818 }
1919
20−die "Format: ./scripts/sign-file [-v] <key> <x509> <module> [<dest>]\n"
21− if ($#ARGV != 2 && $#ARGV != 3);
20+die "Format: ./scripts/sign-file [-v] <hash algo> <key> <x509> <module> [<dest>]\n"
21+ if ($#ARGV != 3 && $#ARGV != 4);
2222
23−my $private_key = $ARGV[0];
24−my $x509 = $ARGV[1];
25−my $module = $ARGV[2];
26−my $dest = ($#ARGV == 3) ? $ARGV[3] : $ARGV[2] . "~";
23+my $dgst = $ARGV[0];
24+my $private_key = $ARGV[1];
25+my $x509 = $ARGV[2];
26+my $module = $ARGV[3];
27+my $dest = ($#ARGV == 4) ? $ARGV[4] : $ARGV[3] . "~";
2728
2829 die "Can't read private key\n" unless (-r $private_key);
2930 die "Can't read X.509 certificate\n" unless (-r $x509);
3031 die "Can't read module\n" unless (-r $module);
3132
32−#
33−# Read the kernel configuration
34−#
35−my %config = (
36− CONFIG_MODULE_SIG_SHA512 => 1
37− );
38−
39−if (-r ".config") {
40− open(FD, "<.config") || die ".config";
41− while (<FD>) {
42− if ($_ =~ /^(CONFIG_.*)=[ym]/) {
43− $config{$1} = 1;
44− }
45− }
46− close(FD);
47−}
48−
4933 #
5034 # Function to read the contents of a file into a variable.
5135 #
@@ -321,51 +305,46 @@ my $id_type = 1; # Identifier type: X.509 · 269 unmodified lines
321305 #
322306 # Digest the data
323307 #
324−my ($dgst, $prologue) = ();
325−if (exists $config{"CONFIG_MODULE_SIG_SHA1"}) {
308+my $prologue;
309+if ($dgst eq "sha1") {
326310 $prologue = pack("C*",
327311 0x30, 0x21, 0x30, 0x09, 0x06, 0x05,
328312 0x2B, 0x0E, 0x03, 0x02, 0x1A,
329313 0x05, 0x00, 0x04, 0x14);
330− $dgst = "-sha1";
331314 $hash = 2;
332−} elsif (exists $config{"CONFIG_MODULE_SIG_SHA224"}) {
315+} elsif ($dgst eq "sha224") {
333316 $prologue = pack("C*",
334317 0x30, 0x2d, 0x30, 0x0d, 0x06, 0x09,
335318 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x04,
336319 0x05, 0x00, 0x04, 0x1C);
337− $dgst = "-sha224";
338320 $hash = 7;
339−} elsif (exists $config{"CONFIG_MODULE_SIG_SHA256"}) {
321+} elsif ($dgst eq "sha256") {
340322 $prologue = pack("C*",
341323 0x30, 0x31, 0x30, 0x0d, 0x06, 0x09,
342324 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x01,
343325 0x05, 0x00, 0x04, 0x20);
344− $dgst = "-sha256";
345326 $hash = 4;
346−} elsif (exists $config{"CONFIG_MODULE_SIG_SHA384"}) {
327+} elsif ($dgst eq "sha384") {
347328 $prologue = pack("C*",
348329 0x30, 0x41, 0x30, 0x0d, 0x06, 0x09,
349330 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x02,
350331 0x05, 0x00, 0x04, 0x30);
351− $dgst = "-sha384";
352332 $hash = 5;
353−} elsif (exists $config{"CONFIG_MODULE_SIG_SHA512"}) {
333+} elsif ($dgst eq "sha512") {
354334 $prologue = pack("C*",
355335 0x30, 0x51, 0x30, 0x0d, 0x06, 0x09,
356336 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x03,
357337 0x05, 0x00, 0x04, 0x40);
358− $dgst = "-sha512";
359338 $hash = 6;
360339 } else {
361− die "Can't determine hash algorithm";
340+ die "Unknown hash algorithm: $dgst\n";
362341 }
363342
364343 #
365344 # Generate the digest and read from openssl's stdout
366345 #
367346 my $digest;
368−$digest = readpipe("openssl dgst $dgst -binary $module") || die "openssl dgst";
347+$digest = readpipe("openssl dgst -$dgst -binary $module") || die "openssl dgst";
369348
370349 #
371350 # Generate the binary signature, which will be just the integer that comprises

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t