From 9d66d9bb5ef6f053cd191107534eb31943df8824 Mon Sep 17 00:00:00 2001 From: XuefengHuang Date: Tue, 28 Oct 2014 00:27:36 -0400 Subject: [PATCH 1/2] fix issue #95 Add a command line options specifying the files from which public keys should be read. --- nminit.py | 36 ++++++++++++++++++++++++++++++------ 1 file changed, 30 insertions(+), 6 deletions(-) diff --git a/nminit.py b/nminit.py index 312d512..23cb368 100644 --- a/nminit.py +++ b/nminit.py @@ -34,6 +34,7 @@ import glob +import optparse # embedded here. Is this really the right thing to do? justinpubkey = {'e':22599311712094481841033180665237806588790054310631222126405381271924089573908627143292516781530652411806621379822579071415593657088637116149593337977245852950266439908269276789889378874571884748852746045643368058107460021117918657542413076791486130091963112612854591789518690856746757312472362332259277422867, 'n':12178066700672820207562107598028055819349361776558374610887354870455226150556699526375464863913750313427968362621410763996856543211502978012978982095721782038963923296750730921093699612004441897097001474531375768746287550135361393961995082362503104883364653410631228896653666456463100850609343988203007196015297634940347643303507210312220744678194150286966282701307645064974676316167089003178325518359863344277814551559197474590483044733574329925947570794508677779986459413166439000241765225023677767754555282196241915500996842713511830954353475439209109249856644278745081047029879999022462230957427158692886317487753201883260626152112524674984510719269715422340038620826684431748131325669940064404757120601727362881317222699393408097596981355810257955915922792648825991943804005848347665699744316223963851263851853483335699321871483966176480839293125413057603561724598227617736944260269994111610286827287926594015501020767105358832476708899657514473423153377514660641699383445065369199724043380072146246537039577390659243640710339329506620575034175016766639538091937167987100329247642670588246573895990251211721839517713790413170646177246216366029853604031421932123167115444834908424556992662935981166395451031277981021820123445253} @@ -73,8 +74,8 @@ # This is the public key of the person who will control most of the resources. -controllerpubkey = {'e': 1515278400394037168869631887206225761783197636247636149274740854708478416229147500580877416652289990968676310353790883501744269103521055894342395180721167L, 'n': 8811850224687278929671477591179591903829730117649785862652866020803862826558480006479605958786097112503418194852731900367494958963787480076175614578652735061071079458992502737148356289391380249696938882025028801032667062564713111819847043202173425187133883586347323838509679062142786013585264788548556099117804213139295498187634341184917970175566549405203725955179602584979965820196023950630399933075080549044334508921319264315718790337460536601263126663173385674250739895046814277313031265034275415434440823182691254039184953842629364697394327806074576199279943114384828602178957150547925812518281418481896604655037L} - +#controllerpubkey = {'e': 1515278400394037168869631887206225761783197636247636149274740854708478416229147500580877416652289990968676310353790883501744269103521055894342395180721167L, 'n': 8811850224687278929671477591179591903829730117649785862652866020803862826558480006479605958786097112503418194852731900367494958963787480076175614578652735061071079458992502737148356289391380249696938882025028801032667062564713111819847043202173425187133883586347323838509679062142786013585264788548556099117804213139295498187634341184917970175566549405203725955179602584979965820196023950630399933075080549044334508921319264315718790337460536601263126663173385674250739895046814277313031265034275415434440823182691254039184953842629364697394327806074576199279943114384828602178957150547925812518281418481896604655037L} +controllerpubkey = {} offcutresourcedata ="""# BUG: How do we come up with these values dynamically? @@ -292,7 +293,7 @@ def initialize_state(): # NOTE: I chose these randomly (they will be uniform across all NMs)... # Was this wise? - configuration['ports'] = [, 2888, 9625, 10348, 39303, 48126, 52862, 57344, 64310] + configuration['ports'] = [2888, 9625, 10348, 39303, 48126, 52862, 57344, 64310] print "Generating key..." keys = rsa_gen_pubpriv_keys(100) @@ -328,8 +329,31 @@ def initialize_state(): # write out the vessel dictionary... persist.commit_object(vesseldict,"vesseldict") - - +def main(): + # Parse the options provided. + helpstring = "python nminit.py [-s] " + parser = optparse.OptionParser(usage=helpstring) + + parser.add_option("-s", "--specifyfiles", action = "store_true", + dest="specify_files", default=False, + help="specifying the files from which public keys should be read") + + (options, args) = parser.parse_args() + if len(args) == 1: + controllerpubkeypath = os.path.realpath(args[0]) + else: + print "Please input user public keys " + return 0 + + #Set variables according to the provided options. + specify = options.specify_files + + if specify: + controllerpubkey = rsa_file_to_publickey(controllerpubkeypath) + else: + print helpstring + return 0 + initialize_state() @@ -338,4 +362,4 @@ def initialize_state(): if __name__ == '__main__': - initialize_state() + main() From 7a9b9c6c7fa2e27482ff2a5a56c39992fec0890e Mon Sep 17 00:00:00 2001 From: XuefengHuang Date: Mon, 10 Nov 2014 09:01:29 -0500 Subject: [PATCH 2/2] added to print usage details Thank you for @asm582 suggestion. Add to print usage details when we enter command incorrect or partial --- nminit.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nminit.py b/nminit.py index 23cb368..3a3476e 100644 --- a/nminit.py +++ b/nminit.py @@ -342,7 +342,7 @@ def main(): if len(args) == 1: controllerpubkeypath = os.path.realpath(args[0]) else: - print "Please input user public keys " + print "Please input user public key"+" "+helpstring return 0 #Set variables according to the provided options.