5 # Martin von Loewis - python 3 port
7 # See the LICENSE file for legal information regarding use of this file.
9 from __future__ import print_function
15 if __name__ != "__main__":
16 raise "This must be run as a command, not used as a module!"
20 from tlslite import __version__
22 if len(sys.argv) == 1 or (len(sys.argv)==2 and sys.argv[1].lower().endswith("help")):
24 print("Version: %s" % __version__)
26 print("RNG: %s" % prngName)
30 print(" M2Crypto : Loaded")
32 print(" M2Crypto : Not Loaded")
34 print(" pycrypto : Loaded")
36 print(" pycrypto : Not Loaded")
38 print(" GMPY : Loaded")
40 print(" GMPY : Not Loaded")
44 print(" createsrp <db>")
46 print(" add <db> <user> <pass> [<bits>]")
47 print(" del <db> <user>")
48 print(" check <db> <user> [<pass>]")
52 cmd = sys.argv[1].lower()
55 def __init__(self, argv):
58 if len(self.argv)<=index:
59 raise SyntaxError("Not enough arguments")
60 return self.argv[index]
61 def getLast(self, index):
62 if len(self.argv)>index+1:
63 raise SyntaxError("Too many arguments")
64 return self.get(index)
68 def reformatDocString(s):
69 lines = s.splitlines()
72 newLines.append(" " + line.strip())
73 return "\n".join(newLines)
77 command = args.getLast(2).lower()
78 if command == "valid":
81 print("Bad command: '%s'" % command)
83 elif cmd == "createsrp":
86 db = VerifierDB(dbName)
91 username = args.get(3)
92 password = args.get(4)
94 db = VerifierDB(dbName)
97 print("User already in database!")
99 bits = int(args.getLast(5))
100 N, g, salt, verifier = VerifierDB.makeVerifier(username, password, bits)
101 db[username] = N, g, salt, verifier
105 username = args.getLast(3)
106 db = VerifierDB(dbName)
112 username = args.get(3)
114 password = args.getLast(4)
118 db = VerifierDB(dbName)
123 print("Username exists")
126 if db.check(username, password):
127 print("Password is correct")
129 print("Password is wrong")
131 print("Username does not exist")
136 db = VerifierDB(dbName)
139 print("Verifier Database")
143 return int(math.floor(math.log(n, 2))+1)
144 for username in db.keys():
145 N, g, s, v = db[username]
146 print(numBits(N), username)
148 print("Bad command: '%s'" % cmd)