public static LogonCredentials ReadFromStream(Stream source)
 {
     var reader = new BinaryReader(source);
     var res = new LogonCredentials();
     res.Login = reader.ReadString();
     res.Password = reader.ReadString();
     return res;
 }
Exemple #2
0
        public void LogonCredentialsConsistencyTest()
        {
            var creds = new LogonCredentials { Login = "******", Password = "******" };
            var serialized = creds.ToBytes();
            var deserialized = LogonCredentials.FromBytes(serialized);

            Assert.AreEqual("peter", deserialized.Login);
            Assert.AreEqual("secret", deserialized.Password);
        }
Exemple #3
0
        public static LogonCredentials ReadFromStream(Stream source)
        {
            var reader = new BinaryReader(source);
            var res    = new LogonCredentials();

            res.Login    = reader.ReadString();
            res.Password = reader.ReadString();
            return(res);
        }
Exemple #4
0
        public void LogonCredentialsConsistencyTest2()
        {
            var creds = new LogonCredentials { Login = "******", Password = "******" };
            var serializedCreds = creds.ToBytes();
            var serviceMessage = new ServiceMessage {MessageType = MessageType.Logon, Data = serializedCreds};
            var serializedServiceMessage = serviceMessage.ToBytes();

            var deserializedServiceMessage = ServiceMessage.FromBytes(serializedServiceMessage);
            Assert.AreEqual(MessageType.Logon, deserializedServiceMessage.MessageType);
            var deserializedCreds = LogonCredentials.FromBytes(deserializedServiceMessage.Data);

            Assert.AreEqual("peter", deserializedCreds.Login);
            Assert.AreEqual("secret", deserializedCreds.Password);
        }
Exemple #5
0
        public int LogOnInvalidMessage1()
        {
            try
            {
                var creds = new LogonCredentials { Login = this.Login, Password = this.password };
                var serializedCreds = creds.ToBytes();
                var serviceMessage = new ServiceMessage { MessageType = MessageType.Logon, Data = serializedCreds };

                var serviceMessageSerialized = serviceMessage.ToBytes();

                // Craft corrupted message
                var data = new byte[4 + 10];
                BitConverter.GetBytes(12).CopyTo(data, 0);
                this.stream.Write(data, 0, data.Length); // Send corrupted message

                var respData = this.cryptoWrapper.Receive();
                var smr = ServiceMessageResponse.FromBytes(respData);
                if (smr.IsSuccess)
                {
                    Logger.Debug(string.Format("Logon succeeded for user '{0}'", this.Login));
                    return 0;
                }
                else
                {
                    Logger.Debug(string.Format("Logon failed for user '{0}'. Reason: '{1}'", this.Login, smr.Message));
                    this.FreeClient();
                    return 1;
                }
            }
            catch (ArgumentNullException ex)
            {
                Logger.Error(ex.ToString);
                return 3;
            }
            catch (SocketException ex)
            {
                Logger.Error(ex.ToString);
                return 4;
            }
            catch (Exception ex)
            {
                Logger.Error(ex.ToString);
                return 5;
            }
        }
Exemple #6
0
 public int LogOn()
 {
     try
     {
         var creds = new LogonCredentials { Login = this.Login, Password = this.password };
         var serializedCreds = creds.ToBytes();
         var serviceMessage = new ServiceMessage { MessageType = MessageType.Logon, Data = serializedCreds };
         this.cryptoWrapper.Send(serviceMessage.ToBytes());
         var respData = this.cryptoWrapper.Receive();
         var smr = ServiceMessageResponse.FromBytes(respData);
         if (smr.IsSuccess)
         {
             Logger.Debug(string.Format("Logon succeeded for user '{0}'", this.Login));
             return 0;
         }
         else
         {
             Logger.Debug(string.Format("Logon failed for user '{0}'. Reason: '{1}'", this.Login, smr.Message));
             this.FreeClient();
             return 1;
         }
     }
     catch (ArgumentNullException ex)
     {
         Logger.Error(ex.ToString);
         return 3;
     }
     catch (SocketException ex)
     {
         Logger.Error(ex.ToString);
         return 4;
     }
     catch (Exception ex)
     {
         Logger.Error(ex.ToString);
         return 5;
     }
 }