示例#1
0
	def __init__(self, filename, log=None):
		""" initialise dictionary of valid properties and list of all file entries
		"""
		self.log = log
		try:
			pFile = open(filename, "r")
		except:
			self.report("error opening " + filename, "e")
			raise
		self.properties = {}
		self.allEntries = pFile.readlines()
		pFile.close()
		ep = EncryptedPassword()
		for entry in self.allEntries:
			if entry.strip().startswith("#"):
				# comment line
				pass
			elif entry.strip() == "":
				# blank line
				pass
			else:	
				pos = entry.find("=")
				if pos < 0:
					key = entry.strip()
					value = ""
				else:
					key = entry[:pos]
					if key.find("password") > 0:
						try:
							value = ep.decrypt(entry[pos + 1:].rstrip())
						except:
							value = entry[pos + 1:].rstrip()
					else:
						value = entry[pos + 1:].rstrip()
				self.properties[key] = value
示例#2
0
	def __init__(self, fileName):
		ep = EncryptedPassword()
		self.rep = SimpleReporter()
		self.fileName = fileName
		try:
			inf = open(fileName, "r")
		except:
			self.rep.report("problem opening %s" % (fileName), "e")
		self.origProps = inf.readlines()
		inf.close()
		newLines = []
		dirtyFile = 0
		for line in self.origProps:
			if line.strip().startswith("#"):
				newLines.append(line)
				continue
			lineBits = line.split("=")
			if len(lineBits) < 2:
				newLines.append(line)
				continue
			if not lineBits[0].find("password") > -1:
				newLines.append(line)
				continue
			key = lineBits[0]
			origVal = "=".join(lineBits[1:]).rstrip()
			try:
				ep.decrypt(origVal)
				newLines.append(line)
			except:
				newVal = ep.encrypt(origVal)
				newLines.append(key + "=" + newVal + "\n")
				dirtyFile = 1
		if dirtyFile:
			outf = open(fileName, "w")
			outf.writelines(newLines)
			outf.close()
示例#3
0
import os, sys
from crypto import EncryptedPassword
from crypto import MaskingPassword
MaskingThread = MaskingPassword("-")
MaskingThread.start()
input = raw_input("Enter the password: "******"[INFO] original password is : %s" % (password)
ep = EncryptedPassword()
encrypted = ep.encrypt(password)
print "[INFO] encrypted password is : %s" % (encrypted)
decrypted = ep.decrypt(encrypted)
print "[INFO] when \t\t\t %s\nis decrypted we get\t\t %s\nwhich ought to be the same as\t %s" % (encrypted, decrypted, password)
示例#4
0
 def testEncrypt(self):
     print "TestEmbeddedPassword : testEncrypt"
     ep = EncryptedPassword()
     self.assertEqual("r5ISHXLXSgbYhhLqhtj+Mg==", ep.encrypt("password"))
示例#5
0
 def testRoundTrip(self):
     print "TestEmbeddedPassword : testRoundTrip"
     ep = EncryptedPassword()
     self.assertEqual(ep.decrypt(ep.encrypt("Password123")), "Password123")
示例#6
0
import os, sys
from crypto import EncryptedPassword
from crypto import MaskingPassword

while true:
    MaskingThread = MaskingPassword("-")
    MaskingThread.start()
    input1 = raw_input("Enter the password: "******"Confirm password: "******"[WARN] confirmation does not match the original password"
password = input1.strip()
ep = EncryptedPassword()
encrypted = ep.encrypt(password)
print "[INFO] encrypted password is : %s" % (encrypted)
示例#7
0
import os, sys
from crypto import EncryptedPassword
from crypto import MaskingPassword
while true:
	MaskingThread = MaskingPassword("-")
	MaskingThread.start()
	input1 = raw_input("Enter the password: "******"Confirm password: "******"[WARN] confirmation does not match the original password"
password = input1.strip()
ep = EncryptedPassword()
try:
	decrypted = ep.decrypt(input1)
	print "[INFO] decrypted password is : %s" % (decrypted)
except:
	print "[ERROR] cannot decrypt password %s" % (input1)