private bool EncryptionRegisterFromWire(Peer toPassTo, PacketBase packet) { EncryptionRequest eq = packet as EncryptionRequest; if (eq == null) { ClassLogger.LogError("Recieved encryption request with null packet."); return(false); } if (!EncryptionFactory.ContainsKey(eq.EncryptionByteType)) { ClassLogger.LogError("Failed to establish encryption from Peer ID: " + toPassTo.UniqueConnectionId + " with EncryptionByte: " + eq.EncryptionByteType); return(false); } EncryptionBase newEncryptionObj = EncryptionFactory[eq.EncryptionByteType](); toPassTo.EncryptionRegister.Register(newEncryptionObj, eq.EncryptionByteType); bool result = toPassTo.EncryptionRegister[eq.EncryptionByteType] .SetNetworkInitRequiredData(eq.EncryptionInitInfo); if (result) { EncryptionRequest encryptionResponse = new EncryptionRequest(eq.EncryptionByteType, newEncryptionObj.NetworkInitRequiredData()); toPassTo.SendMessage(Packet.OperationType.Response, encryptionResponse, (byte)InternalPacketCode.EncryptionRequest, Packet.DeliveryMethod.ReliableUnordered, 0, 0, true); } return(false); }
private bool ProcessEncryptionResponse(Peer peer, PacketBase packet) { EncryptionRequest eq = packet as EncryptionRequest; if (eq == null) { ClassLogger.LogError("Recieved encryption request with null packet."); return(false); } if (!peer.EncryptionRegister.HasKey(eq.EncryptionByteType)) { ClassLogger.LogError("Recieved an encryption request response from the server for ByteType: {0} but the client is unaware of that type." , eq.EncryptionByteType); return(false); } //TODO: Verify that this is working. Callback at one point was not working. //This will set the server's init info. In the case of the default, for example, it will set the Diffiehelmman public key. //With this the server and client have established a shared secret and can now pass messages, with the IV, to eachother securely. //In the case of a custom method it is User defined and should be referenced. bool result = peer.EncryptionRegister[eq.EncryptionByteType].SetNetworkInitRequiredData(eq.EncryptionInitInfo); Action callback = peer.EncryptionRegister[eq.EncryptionByteType].OnEstablished; if (callback != null) { callback(); } return(result); }