I just don't know how to describe anything, because I'm too confused, But all I know is it's supposed to make it into a string but it didn't work. Here is the server code:
god bless buran for this code <3
Client (just in case):
god bless buran for this code <3
import json import socket import os from _thread import * from pathlib import Path from cryptotools import RSA UUID = None lastClient = False key, pkey = RSA.generate_keypair(1024) ServerSideSocket = socket.socket() host = '192.168.1.14' port = 2004 ThreadCount = 0 response = "NotExists" try: ServerSideSocket.bind((host, port)) except socket.error as e: print(str(e)) print('Socket is listening..') ServerSideSocket.listen(5) def multi_threaded_client(connection): global UUID, lastClient, ThreadCount, key, pkey, response while True: try: data = connection.recv(1024).decode() if data != "": print(f'Decoded raw data: {data}') if data[0:4] == "UUID": # PKEY key, pkey = RSA.generate_keypair(1024) Content = data.split("UUID")[1] UUID = json.loads(Content) msg = json.dumps(pkey) connection.sendall(msg.encode()) else: if data == "quit": ThreadCount = ThreadCount - 1 break data = RSA.Message.from_hex(data) data.decrypt(key) data = data.str() if data[0:4] == "USER": # USER User = data.split("USER")[1] Users = Path("C:/Users/####/PycharmProjects/pythonProject2/logins.txt") Users = Users.open('r').read().splitlines() for line in Users: if not any(a in line for a in User): response = line response = RSA.Message.from_str(response) response.encrypt(UUID) connection.sendall(response.hex().encode()) if data[0:4] == "PSWD": # PSWD Password = data.split("PSWD")[1] PSWD = response.split(":")[1] response = 'Correct' if PSWD == Password else 'Incorrect' message = RSA.Message.from_str(response) message.encrypt(UUID) connection.sendall(message.hex().encode()) except KeyboardInterrupt: print("Exiting") while True: if lastClient: break try: Client, address = ServerSideSocket.accept() except KeyboardInterrupt: exit(0) print('Connected to: ' + address[0] + ':' + str(address[1])) start_new_thread(multi_threaded_client, (Client,)) ThreadCount += 1 print('Thread Number: ' + str(ThreadCount)) ServerSideSocket.close()I know I know, the error speaks for itself, but here is the thing, I already converted the Message object to str
Client (just in case):
import atexit import socket import json from time import sleep import _thread from cryptotools import RSA import sys sys.stdout.write("\rSending public key") msg = f'UUID{json.dumps(public)}' s.sendall(msg.encode()) sys.stdout.write("\rWaiting for server public key to be recieved.") serverkey = json.loads(s.recv(1024).decode()) while True: sys.stdout.write("\rPlease Enter your username: \n") user = "USER" + input() user = RSA.Message.from_str(user) user.encrypt(serverkey) s.sendall(user.hex().replace(' ', '').encode()) Recieved = s.recv(1024).decode() Recieved = RSA.Message.from_hex(Recieved) Recieved.decrypt(private) Recieved = Recieved.str() print(Recieved) if Recieved != "NotExists": R = Recieved.split(":")[2].split(",") contacts.extend(R) sys.stdout.seek(0) sys.stdout.write("\rPlease Enter A Password: \n") new_pass = input() new_pass = f'PSWD{new_pass}' msg = RSA.Message.from_str(new_pass) msg.encrypt(serverkey) s.sendall(msg.hex().replace(' ', '').encode()) rawdata = s.recv(1024).decode() recieved = RSA.Message.from_hex(rawdata) recieved.decrypt(private) if str(recieved).split("b'")[1].split("'")[0].find("Correct") != -1: loggedin = True else: loggedin = False if loggedin: sys.stdout.write("Correct login.") for item in contacts: if item == "" and counter == 0: sys.stdout.write("no blins :(") sys.stdout.write(item + "\n") counter = counter + 1 else: sys.stdout.write("Wrong Username! Try again") continue
Error:Traceback (most recent call last):
File "C:\Users\####\PycharmProjects\pythonProject2\server.py", line 58, in multi_threaded_client
Password = data.split("PSWD")[1]
AttributeError: 'Message' object has no attribute 'split'