예제 #1
0
	def load_database_file(self):
		Paths.create_paths()
		try:
			self.DEVICES = pickle.load(open(Paths.DATABASE_FILE, "rb"))
		except FileNotFoundError: # Create an empty database file if non exists
			pickle.dump([], open(Paths.DATABASE_FILE, "wb"))
			self.load_database_file()
예제 #2
0
	def load_log_filename(self):
		Paths.create_paths()
		try:
			with open(Paths.LOG_PATHNAME_FILE, "rb") as f:
				log_file = f.read().decode("UTF-8")
				f.close()
				return log_file
		except FileNotFoundError:
			return None
예제 #3
0
	def read_password_hash(self):
		Paths.create_paths()
		try:
			with open(Paths.PASSWORD_FILE, "rb") as f:
				password_hash = f.read()
				f.close()
				return password_hash
		except FileNotFoundError:
			if self.LOGGER is not None:
				self.LOGGER.log("Password file doesn't exist")
			return None
예제 #4
0
	def update_password_hash(self, cleartext_password):

		# Generate the hash
		salt_handler = SaltHandler()
		password_handler = PasswordHandler(salt_handler, cleartext_password)
		key = password_handler.generate()

		# Write the hash to the file
		Paths.create_paths()
		with open(Paths.PASSWORD_FILE, "wb") as f:
			f.write(key)
			f.close()

		# Log feedback
		if self.LOGGER is not None:
			self.LOGGER.log("Password was updated")
예제 #5
0
	def __init__(self, quiet):
		from os.path import isfile

		# Get a name for the log file
		log_file = self.load_log_filename()
		if log_file is None: # If no name is stored on the disk, generate a new one.
			log_file = Paths.LOG_DIR + self.generate_log_name()

		# Ensure that log file exists
		if not isfile(log_file):
			Paths.create_paths()
			open(log_file, "wb").close() # Initialize empty file

		self.LOG_FILE = log_file
		self.dump_log_filename()
		self.QUIET = quiet
예제 #6
0
파일: crypto.py 프로젝트: osneven/usbauth
	def dump_salt(self):
		Paths.create_paths()
		with open(Paths.SALT_FILE, "wb") as f:
			f.write(self.SALT)
			f.close()
예제 #7
0
	def dump_log_filename(self):
		Paths.create_paths()
		with open(Paths.LOG_PATHNAME_FILE, "wb") as f:
			f.write(self.LOG_FILE.encode("UTF-8"))
			f.close()