def _publicKey(self, path, databasePath): if os.path.exists(path): key = BasicFunctions.binaryReader(path) else: raise PathDoesNotExist(self.username) importpath = os.path.join(databasePath, '{}.pem'.format(self.username)) BasicFunctions.binaryWriter(importpath, key) return importpath
def _init_GUI(self): template = BasicFunctions.reader( os.path.join(self.folderPath, 'GUI.py')) GUI = template.format(self.port, self.ip, self.password, self.username, self.pubKeyPath, self.privKeyPath, self.privKeyPassword, self.client_name, self.c_pubkeypath) path = os.path.join(self.createPath, 'GUI.py') BasicFunctions.writer(path, GUI)
def export(self, privpath, pubpath, password=0000): priv = self.private.exportKey('PEM', password) pub = self.public.exportKey('PEM') privpath = privpath pubpath = pubpath BasicFunctions.binaryWriter(privpath, priv) BasicFunctions.binaryWriter(pubpath, pub)
def sign(self, message, privKeyPath, password): if type(message) is str: message = message.encode('utf-8') key = RSA.importKey(BasicFunctions.binaryReader(privKeyPath), password) Hash = SHA3_512.new(message) signature = pss.new(key).sign(Hash) return signature
def verify(self, message, pubKeyPath, signature): if type(message) is str: message = message.encode('utf-8') key = RSA.importKey(BasicFunctions.binaryReader(pubKeyPath)) Hash = SHA3_512.new(message) verifier = pss.new(key) try: verifier.verify(Hash, signature) except (ValueError, TypeError): return False return True
def GUICleaner(self): BasicFunctions.writer('Files/GUI.py', '#!/usr/bin/python3')
def _pathFinder(self): Folder, head = BasicFunctions.headTail(self.folderPath) return head
def decrypt(self, message, privKeyPath, password): key = RSA.importKey(BasicFunctions.binaryReader(privKeyPath), password) cipher = PKCS1_OAEP.new(key) plaintext = cipher.decrypt(message) return plaintext
def encrypt(self, message, pubKeyPath): key = RSA.importKey(BasicFunctions.binaryReader(pubKeyPath)) cipher = PKCS1_OAEP.new(key) ciphertext = cipher.encrypt(message) return ciphertext
Major: Telecommunication Engineering <*****@*****.**> https://www.mahdibaghbanii.wordpress.com https://www.github.com/MahdiBaghbani Company: 17London78 Inc. https://www.17London78.ir https://www.github.com/17London78 ========================================= """ import os from Files.Server import ServerUtil from Files.Assests import BasicFunctions MAIN_PATH = os.path.dirname(os.path.abspath(__file__)) File, head = BasicFunctions.headTail(MAIN_PATH) DATA_PATH = os.path.join(head, 'Data') USER_DB_PATH = os.path.join(DATA_PATH, 'User Database') SM_DATA_PATH = os.path.join(USER_DB_PATH, 'serverMDB.txt') SU_DATA_PATH = os.path.join(USER_DB_PATH, 'serverUDB.txt') class SManager: def __init__(self, path): self.path = path self.serverU = self._SERVERU_init(self.path) def _SERVERU_init(self, path): server = ServerUtil.ServerUtil(path) return server