Mar-10-2021, 06:09 PM
(Mar-10-2021, 05:57 PM)buran Wrote: Please, post the full traceback you get, verbatim, not just the last line.
Also the full code, e.g. what isnew_pass
?
Okay.
Server:
import socket from cryptotools import RSA, PrivateKey hashed = None Content = None Password = None File = None f = None feil = None FileLoc = None UUID = None AccountExists = None rawUUID = None key = PrivateKey.random() pkey = key.to_public() def server_program(): # get the hostname global hashed, Content, Password, f, File, feil, FileLoc, rawUUID, AccountExists, UUID host = "127.0.0.1" port = 65432 # initiate port no above 1024 server_socket = socket.socket() # get instance # look closely. The bind() function takes tuple as argument server_socket.bind((host, port)) # bind host address and port together # configure how many client the server can listen simultaneously server_socket.listen(2) conn, address = server_socket.accept() # accept new connection print("Connection from: " + str(address)) while True: # receive data stream. it won't accept data packet greater than 1024 bytes data = conn.recv(1024).decode() if data != "": print(data) if not data: break if data[0:4] == "PSWD": # PSWD Password = data.split("PSWD")[1] try: AccountExists = open("logins.txt", 'w+').read().split(Password)[1] except IndexError as e: conn.sendall(RSA.Message.from_hex(b'AccountDoesntExist').encrypt(UUID)) print(e) continue PSWD = AccountExists.split("\n")[0] if PSWD == Password: conn.sendall(RSA.Message.from_hex(b'True').encrypt(UUID)) else: conn.sendall(RSA.Message.from_hex(b'False').encrypt(UUID)) elif data[0:4] == "UUID": # UUID Content = data.split("UUID")[1] UUID = Content msg = f'{pkey}' conn.sendall(msg.encode()) server_socket.close() server_program() if __name__ == '__main__': server_program()Client:
import socket from cryptotools import PrivateKey, RSA HOST = "127.0.0.1" PORT = 65432 private = PrivateKey.random() public = private.to_public() s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.connect((HOST, PORT)) msg = f'UUID{public}' s.sendall(msg.encode()) serverkey = s.recv(1024).decode() new_pass = input('Please enter a password: ') msg = f'PSWD{RSA.Message.from_hex(new_pass).encrypt((serverkey[0], serverkey[1]))}' s.sendall(msg.encode()) rawdata = s.recv(1024).decode() Recieved = RSA.Message.from_hex(rawdata).decrypt(private) s.close() print(Recieved)