From f6b8c2c5e6b805210a94727c0b05d8dd6ff35689 Mon Sep 17 00:00:00 2001 From: Johannes Berg Date: Tue, 27 May 2008 15:15:21 +0200 Subject: [PATCH] make db2bin take explicit arguments --- Makefile | 2 +- db2bin.py | 51 ++++++++++++++++++++++++++++++--------------------- 2 files changed, 31 insertions(+), 22 deletions(-) diff --git a/Makefile b/Makefile index fcb50ce..92051c9 100644 --- a/Makefile +++ b/Makefile @@ -8,7 +8,7 @@ all: regulatory.bin warn @$(MAKE) --no-print-directory -f Makefile verify regulatory.bin: db2bin.py key.priv.pem db.txt dbparse.py - @./db2bin.py + @./db2bin.py regulatory.bin db.txt key.priv.pem clean: @rm -f regulatory.bin dump *~ *.pyc keys-*.c diff --git a/db2bin.py b/db2bin.py index 98181df..e783b3a 100755 --- a/db2bin.py +++ b/db2bin.py @@ -4,10 +4,15 @@ from cStringIO import StringIO import struct import sha from dbparse import DBParser +import sys MAGIC = 0x52474442 VERSION = 19 +if len(sys.argv) < 3: + print 'Usage: %s output-file input-file [key-file]' % sys.argv[0] + sys.exit(2) + def create_rules(countries): result = {} for c in countries.itervalues(): @@ -44,7 +49,7 @@ class PTR(object): return self._offset p = DBParser() -countries = p.parse(file('db.txt')) +countries = p.parse(file(sys.argv[2])) power = [] bands = [] for c in countries.itervalues(): @@ -113,24 +118,28 @@ for alpha2 in countrynames: # struct regdb_file_reg_country output.write(struct.pack('>ccxxI', str(alpha2[0]), str(alpha2[1]), reg_rules_collections[coll.permissions])) -# Load RSA only now so people can use this script -# without having those libraries installed to verify -# their SQL changes -from M2Crypto import RSA - -# determine signature length -key = RSA.load_key('key.priv.pem') -hash = sha.new() -hash.update(output.getvalue()) -sig = key.sign(hash.digest()) -# write it to file -siglen.set(len(sig)) -# sign again -hash = sha.new() -hash.update(output.getvalue()) -sig = key.sign(hash.digest()) - -output.write(sig) - -outfile = open('regulatory.bin', 'w') + +if len(sys.argv) > 3: + # Load RSA only now so people can use this script + # without having those libraries installed to verify + # their SQL changes + from M2Crypto import RSA + + # determine signature length + key = RSA.load_key(sys.argv[3]) + hash = sha.new() + hash.update(output.getvalue()) + sig = key.sign(hash.digest()) + # write it to file + siglen.set(len(sig)) + # sign again + hash = sha.new() + hash.update(output.getvalue()) + sig = key.sign(hash.digest()) + + output.write(sig) +else: + siglen.set(0) + +outfile = open(sys.argv[1], 'w') outfile.write(output.getvalue()) -- 2.7.4