/// <summary>
        /// Called when a message has been received from the server
        /// </summary>
        /// <param name="bytes">The message as a byte array</param>
        protected override void OnMessageReceived(byte[] bytes)
        {
            //base.OnMessageReceived(bytes);
            if (_remotePublicKey != null) //then we're secure
            {
                base.OnMessageReceived(bytes);
                //var obj = FormatReceived(bytes);
                //MessageReceived?.Invoke(this, obj);
            }
            else
            {
                try
                {
                    var json = bytes.AsString();//.FromBase64();
                    if (IsBase64Encoded(json))
                    {
                        System.Diagnostics.Debug.WriteLine("Remote public key is curiously Base64 encoded");
                        json = json.FromBase64(); //still not sure how this gets base64 encoded in the first place
                    }
                    _remotePublicKey = Newtonsoft.Json.JsonConvert.DeserializeObject <RSAParameters>(json);

                    System.Diagnostics.Debug.WriteLine("{0} received {1}'s public Key", IsServerSide ? "Server" : "Client", IsServerSide ? "client" : "server");
                    //bytes = null; //not a real message, so set it to null
                    IsConnectedResetEvent.Set();
                    Connected?.Invoke(this, Socket.RemoteEndPoint);
                }
                catch (Exception e)
                {
                    //Log.e(e);
                    System.Diagnostics.Debug.WriteLine(e.ToString());
                    System.Diagnostics.Debugger.Break();
                }
            }
        }
Exemple #2
0
 /// <summary>
 /// Constructs a new SecureStringClient
 /// </summary>
 /// <param name="client">An existing connected TcpClient</param>
 public Client(TcpClient client)
 {
     IsServerSide = true;
     _client      = new Sockets.Socket(client);
     IsConnectedResetEvent.Set();
     InitializeConnection();
 }
Exemple #3
0
 /// <summary>
 /// Called when a connection has been established with the server
 /// </summary>
 /// <param name="remoteEndPoint">The IPEndPoint of the server</param>
 protected virtual void OnConnected(IPEndPoint remoteEndPoint)
 {
     IsConnectedResetEvent.Set();
     Connected?.Invoke(this, remoteEndPoint);
 }