Dernier commit
This commit is contained in:
parent
93aace85cb
commit
e0c0f5e3da
@ -89,7 +89,8 @@ NAME = b"client1"
|
|||||||
VERSION = b"EICP2P2 V1"
|
VERSION = b"EICP2P2 V1"
|
||||||
|
|
||||||
REQUEST_TYPE = [
|
REQUEST_TYPE = [
|
||||||
b'ping', b'pingACK', b'updateAsk', b'updateBack', b'transfer', b'register_client', b'registerACK', b'send', b'sendACK',
|
b'ping', b'pingACK', b'updateAsk', b'updateBack', b'transfer', b'register_client', b'registerACK', b'send',
|
||||||
|
b'sendACK',
|
||||||
b'exit', b'RSASend', b'init', b'getUsers', b'getUsersACK',
|
b'exit', b'RSASend', b'init', b'getUsers', b'getUsersACK',
|
||||||
]
|
]
|
||||||
|
|
||||||
@ -108,7 +109,12 @@ class MainThread(threading.Thread):
|
|||||||
self.rsa = None
|
self.rsa = None
|
||||||
self.aes_key = None
|
self.aes_key = None
|
||||||
self.clientSocket = None
|
self.clientSocket = None
|
||||||
self.users = {}
|
self.users = {
|
||||||
|
# id: rsa
|
||||||
|
}
|
||||||
|
self.connected_users = {
|
||||||
|
# id: (rsa, aes, nick)
|
||||||
|
}
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
rsa = RsaGenThread(self)
|
rsa = RsaGenThread(self)
|
||||||
@ -124,7 +130,7 @@ class MainThread(threading.Thread):
|
|||||||
try:
|
try:
|
||||||
type = bytes(input("Type: "), "ascii")
|
type = bytes(input("Type: "), "ascii")
|
||||||
contenu = bytes(input("Contenu: "), "ascii")
|
contenu = bytes(input("Contenu: "), "ascii")
|
||||||
self.send_aes(self.gen_header(type_=type)+contenu)
|
self.send_aes(self.gen_header(type_=type) + contenu)
|
||||||
print(self.receive_aes())
|
print(self.receive_aes())
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(e)
|
print(e)
|
||||||
@ -195,7 +201,9 @@ class MainThread(threading.Thread):
|
|||||||
header = self.extract_header(back)
|
header = self.extract_header(back)
|
||||||
contenu = back[BUFFER_SIZE:]
|
contenu = back[BUFFER_SIZE:]
|
||||||
if header[b"type"] == b"getUsersACK":
|
if header[b"type"] == b"getUsersACK":
|
||||||
self.users = [(contenu.split(b"%!!%")[i], i) for i in range(len(contenu.split(b"%!!%")))]
|
self.users = {i: contenu.split(b"%!!%")[i] for i in range(len(contenu.split(b"%!!%")))}
|
||||||
|
|
||||||
|
################################################ COMMUNICATION WITH AES ############################################
|
||||||
|
|
||||||
def send_aes(self, to_send, key=None):
|
def send_aes(self, to_send, key=None):
|
||||||
"""Send message with aes encryption
|
"""Send message with aes encryption
|
||||||
@ -229,7 +237,7 @@ class MainThread(threading.Thread):
|
|||||||
:type key: bytes
|
:type key: bytes
|
||||||
"""
|
"""
|
||||||
to_decrypt = self.receive()
|
to_decrypt = self.receive()
|
||||||
debug(b"Received in aes "+to_decrypt)
|
debug(b"Received in aes " + to_decrypt)
|
||||||
if key is None:
|
if key is None:
|
||||||
key = self.aes_key
|
key = self.aes_key
|
||||||
if key is None:
|
if key is None:
|
||||||
@ -304,6 +312,7 @@ class MainThread(threading.Thread):
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
client = MainThread(NAME)
|
client = MainThread(NAME)
|
||||||
client.start()
|
client.start()
|
||||||
|
@ -380,7 +380,6 @@ class ClientThread(threading.Thread):
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
def send_users(self):
|
def send_users(self):
|
||||||
print(self.server.clients.keys())
|
|
||||||
self.send_aes(self.gen_header(type_=b"getUsersACK")+b"%!!%".join(list(self.server.clients.keys())))
|
self.send_aes(self.gen_header(type_=b"getUsersACK")+b"%!!%".join(list(self.server.clients.keys())))
|
||||||
|
|
||||||
def register_client(self):
|
def register_client(self):
|
||||||
@ -433,6 +432,7 @@ class ClientThread(threading.Thread):
|
|||||||
self.register_client()
|
self.register_client()
|
||||||
elif header[b"type"] == b"getUsers":
|
elif header[b"type"] == b"getUsers":
|
||||||
self.send_users()
|
self.send_users()
|
||||||
|
elif
|
||||||
self.client.close()
|
self.client.close()
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user