/usr/bin/tlsdb is in python-tlslite 0.3.8-1.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 | #!/usr/bin/python
import sys
import os
import socket
import thread
import math
try:
import cryptoIDlib
cryptoIDlibLoaded = True
except:
cryptoIDlibLoaded = False
if __name__ != "__main__":
raise "This must be run as a command, not used as a module!"
from tlslite.api import *
if len(sys.argv) == 1 or (len(sys.argv)==2 and sys.argv[1].lower().endswith("help")):
print ""
print "Version: 0.3.8"
print ""
print "RNG: %s" % prngName
print ""
print "Modules:"
if cryptlibpyLoaded:
print " cryptlib_py : Loaded"
else:
print " cryptlib_py : Not Loaded"
if m2cryptoLoaded:
print " M2Crypto : Loaded"
else:
print " M2Crypto : Not Loaded"
if pycryptoLoaded:
print " pycrypto : Loaded"
else:
print " pycrypto : Not Loaded"
if gmpyLoaded:
print " GMPY : Loaded"
else:
print " GMPY : Not Loaded"
if cryptoIDlibLoaded:
print " cryptoIDlib : Loaded"
else:
print " cryptoIDlib : Not Loaded"
print ""
print "Commands:"
print ""
print " createsrp <db>"
print " createsharedkey <db>"
print ""
print " add <db> <user> <pass> [<bits>]"
print " del <db> <user>"
print " check <db> <user> [<pass>]"
print " list <db>"
sys.exit()
cmd = sys.argv[1].lower()
class Args:
def __init__(self, argv):
self.argv = argv
def get(self, index):
if len(self.argv)<=index:
raise SyntaxError("Not enough arguments")
return self.argv[index]
def getLast(self, index):
if len(self.argv)>index+1:
raise SyntaxError("Too many arguments")
return self.get(index)
args = Args(sys.argv)
def reformatDocString(s):
lines = s.splitlines()
newLines = []
for line in lines:
newLines.append(" " + line.strip())
return "\n".join(newLines)
try:
if cmd == "help":
command = args.getLast(2).lower()
if command == "valid":
print ""
else:
print "Bad command: '%s'" % command
elif cmd == "createsrp":
dbName = args.get(2)
db = VerifierDB(dbName)
db.create()
elif cmd == "createsharedkey":
dbName = args.getLast(2)
db = SharedKeyDB(dbName)
db.create()
elif cmd == "add":
dbName = args.get(2)
username = args.get(3)
password = args.get(4)
try:
db = VerifierDB(dbName)
db.open()
if username in db:
print "User already in database!"
sys.exit()
bits = int(args.getLast(5))
N, g, salt, verifier = VerifierDB.makeVerifier(username, password, bits)
db[username] = N, g, salt, verifier
except ValueError:
db = SharedKeyDB(dbName)
db.open()
if username in db:
print "User already in database!"
sys.exit()
args.getLast(4)
db[username] = password
elif cmd == "del":
dbName = args.get(2)
username = args.getLast(3)
try:
db = VerifierDB(dbName)
db.open()
except ValueError:
db = SharedKeyDB(dbName)
db.open()
del(db[username])
elif cmd == "check":
dbName = args.get(2)
username = args.get(3)
if len(sys.argv)>=5:
password = args.getLast(4)
else:
password = None
try:
db = VerifierDB(dbName)
db.open()
except ValueError:
db = SharedKeyDB(dbName)
db.open()
try:
db[username]
print "Username exists"
if password:
if db.check(username, password):
print "Password is correct"
else:
print "Password is wrong"
except KeyError:
print "Username does not exist"
sys.exit()
elif cmd == "list":
dbName = args.get(2)
try:
db = VerifierDB(dbName)
db.open()
except ValueError:
db = SharedKeyDB(dbName)
db.open()
if isinstance(db, VerifierDB):
print "Verifier Database"
def numBits(n):
if n==0:
return 0
return int(math.floor(math.log(n, 2))+1)
for username in db.keys():
N, g, s, v = db[username]
print numBits(N), username
else:
print "Shared Key Database"
for username in db.keys():
print username
else:
print "Bad command: '%s'" % cmd
except:
raise
|