cid = circ.cid.encode("hex") if circ.is_pf: self.cur.execute("DELETE FROM pfs WHERE id = (?);", (cid, )) else: self.cur.execute("DELETE FROM circuits WHERE id = (?);", (cid, )) cdb_logger.debug("Removed circuit " + repr(circ.name)) if __name__ == "__main__": cid = urandom(8) symkey = Crypt().generate_key() k1 = Crypt().generate_key() k2 = Crypt().generate_key() c_client = Crypt(public_key=k1.publickey(), private_key=k2) c_router = Crypt(public_key=k2.publickey(), private_key=k1) pkt = c_client.sign_and_encrypt("CLNT" + cid + symkey) data, hash = c_router.decrypt(pkt) cd = CircuitDatabase(db_path="circuitdb_1234.db") c = ClientCircuit(cid, cid, c_router) cd.add(c) # cd.get(data, hash, c_router) # cd.remove(c) # cd.remove(c) # try: # cd.get('ABCD') # print "BAD" # except: # print "GOOD" # cd.add(c)
class Lokr(tk.Tk): ver = 1.2 def __init__(self): # init main window tk.Tk.__init__(self) self.lokr_file = "" self.user_file = self.resource_path(".lokrdata/usrs.ulokr") self.user = "" self.iconbitmap(self.resource_path("assets/closedlock.ico")) self.logo = tk.PhotoImage(file=self.resource_path("assets/lock.png")) self.title("LOKR LOGIN") self.minsize(350, 200) plain_text_file = open(self.resource_path(".lokrdata/cset.dlokr"), "rb") cipher_text_file = open(self.resource_path(".lokrdata/cpcset.dlokr"), "rb") plain_text = pickle.load(plain_text_file) cipher_text = pickle.load(cipher_text_file) plain_text_file.close() cipher_text_file.close() self.crypt = Crypt(cipher_text, plain_text) LoginFrame(self) self.mainloop() # PASSWORD MANIPULATION METHODS def savePassword(self, label, pwd, key): # appends encrypted pass, key, lbl to user's .lokr file encrypted_label = self.crypt.encrypt(label, key) encrypted_password = self.crypt.encrypt(pwd, key) file = open(self.resource_path(self.lokr_file), "rb") file.seek(0) whatsinside = pickle.load(file) file.close() whatsinside[encrypted_label] = {str(key): encrypted_password} file = open(self.resource_path(self.lokr_file), "wb") pickle.dump(whatsinside, file) file.close() def editPassword(self, index, label, pwd): # edits password: delete and resaves with new info keys = self.parseLokrFile("keys") self.deletePassword(index) self.savePassword(label, pwd, int(keys[index])) def deletePassword(self, index): # delete password from user's .lokr labels = self.parseLokrFile("labels") file = open(self.resource_path(self.lokr_file), "rb") file.seek(0) contents = pickle.load(file) file.close() del contents[labels[index]] file = open(self.resource_path(self.lokr_file), "wb") pickle.dump(contents, file) file.close() # USER MANAGEMENT METHODS def setUserLokrFile(self, username): # set user's lokr file self.user = username for file in os.listdir(self.resource_path(".lokrdata")): if file == (self.crypt.encrypt(username, 11) + ".lokr"): self.lokr_file = ".lokrdata/" + file def readUsersFile(self): # reads USR file, returns: decrypted usr info as a dict in format: usr:pwd file = open(self.resource_path(self.user_file), "rb") user_data = pickle.load(file) file.close() decrypted_user_data = {} for user, pwd in user_data.items(): decrypted_user_data[self.crypt.decrypt(user, 7)] = self.crypt.decrypt( pwd, 7) return decrypted_user_data def saveUser(self, usr, pwd): # appends usr and pwd to USR file file = open(self.resource_path(self.user_file), "rb") user_data = pickle.load(file) file.close() user_data[self.crypt.encrypt(usr, 7)] = self.crypt.encrypt(pwd, 7) file = open(self.resource_path(self.user_file), "wb") pickle.dump(user_data, file) file.close() def authenticate(self, usr, pwd): # checks if usr and pwd match USR file, returns True if correct for user, password in self.readUsersFile().items(): if user == usr and password == pwd: return True return False # LOKR FILE METHODS def parseLokrFile(self, call): # reads .lokr, input: call('keys', 'labels, or 'pwds'), returns: requested info as a list file = open(self.resource_path(self.lokr_file), "rb") file.seek(0) lokr_data = pickle.load(file) labels = list(lokr_data.keys()) keys = [] pwds = [] file.close() for k, i in enumerate(list(lokr_data.keys())): keys.append((list(list(lokr_data.values())[k].keys())[0])) for k, i in enumerate(list(lokr_data.keys())): pwds.append((list(list(lokr_data.values())[k].values())[0])) if call == "keys": return keys if call == "labels": return labels if call == "pwds": return pwds def decryptLokr(self, info): # decrypts .lokr file, input: info('labels' or 'pwds'), returns: requested info as a list keys = self.parseLokrFile("keys") labels = self.parseLokrFile("labels") pwds = self.parseLokrFile("pwds") newlabels = [ self.crypt.decrypt(labels[x], keys[x]) for x in range(len(keys)) ] newpwds = [ self.crypt.decrypt(pwds[x], keys[x]) for x in range(len(keys)) ] if info == "labels": return newlabels if info == "pwds": return newpwds def createLokr(self, name): # creates new .lokr file for user with defaults file = open( self.resource_path(".lokrdata/" + self.crypt.encrypt(name, 11) + ".lokr"), "wb", ) pickle.dump({"ExampleLabel": {5: "ExamplePassword"}}, file) file.close() # HELPER METHODS def resource_path(self, relative_path): # PyInstaller creates a temp folder and stores path in _MEIPASS current_file_path = __file__ current_file_dir = os.path.dirname(__file__) # os.path.join(current_file_dir, try: base_path = sys._MEIPASS except Exception: base_path = os.path.abspath(".") return os.path.join(current_file_dir, relative_path)
def MainConfig(cls): logger.info("Initializing Xml configuration") try: configurationDetails = ET.parse( 'configuration.xml' ) #This file may not exist, introduce fatal error except Exception as err: logger.critical("Cannot parse configuration.xml") ConfigDict = {} if configurationDetails is not None: #Checking the log level logger.info("configuration.xml parsed successfully") ConfigDict["loggingLevel"] = configurationDetails.find( 'loggingLevel').text if ConfigDict["loggingLevel"] != "DEBUG": level = Log.getLogLevel(ConfigDict["loggingLevel"]) Log.loggingLevel = level logger.setLevel(level) for handler in logger.handlers: handler.setLevel(level) # Check if Email notifications are Enabled ConfigDict["EmailNotifications"] = configurationDetails.find( 'EmailNotifications').text ConfigDict["JarvisEmail"] = configurationDetails.find( 'JarvisEmail').text encPassword = configurationDetails.find('JarvisPasscode').text ConfigDict["JarvisPasscode"] = encPassword # Performing the Password decryption only if Email notifications are enabled if ConfigDict["EmailNotifications"] == 'Enabled': logger.debug("Performing the Password decryption") key = Crypt.loadKeyFile() if key is not "KO": logger.debug("Password decryption key is found") c = Crypt() decPassword = c.decrypt(encPassword.strip(), key) if decPassword != "": ConfigDict["JarvisPasscode"] = decPassword else: logger.critical("Error decrypting password" ) # Raise Fatal Error here else: logger.critical( "Error fetching key") # Raise Fatal Error here ConfigDict["PrimaryCustEmail"] = configurationDetails.find( 'PrimaryCustEmail').text ConfigDict["smtpHost"] = configurationDetails.find('smtpHost').text ConfigDict["smtpPort"] = configurationDetails.find('smtpPort').text ConfigDict["IdentifierFile"] = configurationDetails.find( 'IdentifierFile').text ConfigDict["BackupDirName"] = configurationDetails.find( 'BackupDirName').text ConfigDict["CheckedPathsFileName"] = configurationDetails.find( 'CheckedPathsFileName').text ConfigDict["BackupSummaryFileName"] = configurationDetails.find( 'BackupSummaryFileName').text ConfigDict["NotificationEmailSubject"] = configurationDetails.find( 'NotificationEmailSubject').text logger.info("Finished reading configuration.xml") return ConfigDict