22 lines
786 B
Python
22 lines
786 B
Python
from source import packets
|
|
from source.behaviors import roles
|
|
from source.behaviors.events import base
|
|
from source.utils.crypto.type import CipherType
|
|
|
|
|
|
class RequestKeyEvent(base.BaseTrustedEvent):
|
|
"""
|
|
Event reacting to a machine trying to get our secret symmetric key for secure communication
|
|
"""
|
|
|
|
def handle(self, packet: packets.RequestKeyPacket, address: tuple):
|
|
super().handle(packet, address)
|
|
|
|
# check if we are a master
|
|
if not isinstance(self.manager.role.current, roles.MasterRole):
|
|
return
|
|
|
|
# create a packet containing our secret key
|
|
packet = packets.KeyPacket(self.manager.role.current.secret_key)
|
|
# send it back to the slave
|
|
self.manager.communication.send(packet, CipherType.RSA, address)
|