private static void client_MessageReceived(object sender, MessageEventArgs e) { if (e.Message is ServerConnectionResponse) { HandleServerConnectResponse(e); } else if (e.Message is EnableEncryptionResponse) { HandleEnableEncryptionResponse(e); } //throw new NotImplementedException(); }
private static void HandleServerConnectResponse(MessageEventArgs e) { //ServerConnectionResponse response = e.Message as ServerConnectionResponse; //sa = new ServerAuthority(new BigInteger(response.DiffieHellmanInfo.P, 16), new BigInteger(response.DiffieHellmanInfo.G, 16)); //serverPublicKey = response.DiffieHellmanInfo.PublicKeyInfo; //// now enable encryption //e.ClientConnection.Send( // new EnableEncryptionMessage() // { // MessageID = "EnableEncryptionMessage", // Enable = true, // PublicKeyInfo = sa.GenerateEncodedPublicKeyInfo() // }); }
private static void HandleEnableEncryptionResponse(MessageEventArgs e) { EnableEncryptionResponse response = e.Message as EnableEncryptionResponse; encryptionEnabled = response.Success; if (encryptionEnabled) { e.ClientConnection.Envelope = new EncryptedMessageEnvelope((ICrypto) new SharedKeyCrypto( sa.Parameters, sa.KeyPair, serverPublicKey ) ); } }
void connection_MessageReceived(object sender, MessageEventArgs e) { }
private void ProcessMessages() { running = true; try { while (running) { using (StreamWrapper wrapper = new StreamWrapper(client.Stream)) { IMessage message = Envelope.Deserialize(wrapper) as IMessage; MessageEventArgs args = new MessageEventArgs(this, message, wrapper.GetInputBytes()); OnMessageReceived(args); } } } catch (Exception ex) { logger.Error(ex); client.Disconnect(true); } }
protected void OnMessageSent(MessageEventArgs args) { var function = MessageSent; if (function != null) { function(this, args); } }
protected void OnMessageReceived(MessageEventArgs args) { var function = MessageReceived; if (function != null) { function(this, args); } }