11 cryptoIDlibLoaded = True
13 cryptoIDlibLoaded = False
16 if __name__ != "__main__":
17 raise "This must be run as a command, not used as a module!"
20 from tlslite.api import *
22 if len(sys.argv) == 1 or (len(sys.argv)==2 and sys.argv[1].lower().endswith("help")):
24 print "Version: 0.3.8"
26 print "RNG: %s" % prngName
30 print " cryptlib_py : Loaded"
32 print " cryptlib_py : Not Loaded"
34 print " M2Crypto : Loaded"
36 print " M2Crypto : Not Loaded"
38 print " pycrypto : Loaded"
40 print " pycrypto : Not Loaded"
42 print " GMPY : Loaded"
44 print " GMPY : Not Loaded"
46 print " cryptoIDlib : Loaded"
48 print " cryptoIDlib : Not Loaded"
52 print " createsrp <db>"
53 print " createsharedkey <db>"
55 print " add <db> <user> <pass> [<bits>]"
56 print " del <db> <user>"
57 print " check <db> <user> [<pass>]"
61 cmd = sys.argv[1].lower()
64 def __init__(self, argv):
67 if len(self.argv)<=index:
68 raise SyntaxError("Not enough arguments")
69 return self.argv[index]
70 def getLast(self, index):
71 if len(self.argv)>index+1:
72 raise SyntaxError("Too many arguments")
73 return self.get(index)
77 def reformatDocString(s):
78 lines = s.splitlines()
81 newLines.append(" " + line.strip())
82 return "\n".join(newLines)
86 command = args.getLast(2).lower()
87 if command == "valid":
90 print "Bad command: '%s'" % command
92 elif cmd == "createsrp":
95 db = VerifierDB(dbName)
98 elif cmd == "createsharedkey":
99 dbName = args.getLast(2)
101 db = SharedKeyDB(dbName)
106 username = args.get(3)
107 password = args.get(4)
110 db = VerifierDB(dbName)
113 print "User already in database!"
115 bits = int(args.getLast(5))
116 N, g, salt, verifier = VerifierDB.makeVerifier(username, password, bits)
117 db[username] = N, g, salt, verifier
119 db = SharedKeyDB(dbName)
122 print "User already in database!"
125 db[username] = password
129 username = args.getLast(3)
132 db = VerifierDB(dbName)
135 db = SharedKeyDB(dbName)
142 username = args.get(3)
144 password = args.getLast(4)
149 db = VerifierDB(dbName)
152 db = SharedKeyDB(dbName)
157 print "Username exists"
160 if db.check(username, password):
161 print "Password is correct"
163 print "Password is wrong"
165 print "Username does not exist"
172 db = VerifierDB(dbName)
175 db = SharedKeyDB(dbName)
178 if isinstance(db, VerifierDB):
179 print "Verifier Database"
183 return int(math.floor(math.log(n, 2))+1)
184 for username in db.keys():
185 N, g, s, v = db[username]
186 print numBits(N), username
188 print "Shared Key Database"
189 for username in db.keys():
192 print "Bad command: '%s'" % cmd