You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
51 lines
1.9 KiB
51 lines
1.9 KiB
# -*- coding: utf-8 -*-
|
|
|
|
import tkinter as tk
|
|
from Interface import Interface, puissance_mod_rapide
|
|
|
|
|
|
class InterfaceServeur(Interface):
|
|
def __init__(self):
|
|
Interface.__init__(self, "serveur")
|
|
self.n = 870567544966633301
|
|
self.e = 42205
|
|
self.d = 769020235650503533
|
|
# à compléter
|
|
self.waitForHelloButton = tk.Button(self, text="Serveur Hello", command=self.hello)
|
|
self.waitForHelloButton.pack()
|
|
self.finishedButton = tk.Button(self, text="Finished", command=self.finish, state="disabled")
|
|
self.finishedButton.pack()
|
|
|
|
def hello(self):
|
|
"""attend la réception du message HELLO depuis le client, puis envoie en
|
|
clair sa clé publique"""
|
|
self.receive()
|
|
if self.message.get() == "HELLO":
|
|
self.entree.set(str(self.e)+";"+str(self.n))
|
|
self.send()
|
|
self.waitForHelloButton['state'] = 'disabled'
|
|
self.finishedButton['state'] = 'enabled'
|
|
else:
|
|
print("HELLO n'a pas été reçu.")
|
|
|
|
def finish(self):
|
|
"""attend la réception de la clé symétrique, la déchiffre avec sa clé privée, la
|
|
mémorise et envoie le message Finished chiffré avec cette clé"""
|
|
self.receive()
|
|
cleSym = int(self.message.get())
|
|
cleSym_dechiffree = self.dechiffre_RSA(cleSym).to_bytes(7, "big")
|
|
self.set_cleSymetrique(cleSym_dechiffree)
|
|
self.entree.set("Finished")
|
|
self.send()
|
|
self.finishedButton['state'] = "disabled"
|
|
self.sendButton['state'] = "enabled"
|
|
self.recvButton['state'] = "enabled"
|
|
|
|
def dechiffre_RSA(self, msg):
|
|
"""déchiffre un message avec sa clé privée"""
|
|
return puissance_mod_rapide(msg, self.d, self.n)
|
|
|
|
|
|
|
|
It = InterfaceServeur()
|
|
It.mainloop()
|
|
|