Esempio n. 1
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);
        }
Esempio n. 2
0
        private void ProcessLogon(ServiceMessage serviceMessage)
        {
            // Logon attempt
            var credentials = LogonCredentials.FromBytes(serviceMessage.Data);

            if (!this.dataContext.ValidateLoginPass(credentials.Login, credentials.Password))
            {
                this.ProcessConnectionInvalidCredentials();
                return;
            }

            // Check if user with same login is already logged in
            if (this.server.IsLoggedIn(credentials.Login))
            {
                var existingClient = this.server.GetChatClient(credentials.Login);
                if (existingClient.PokeForAlive())
                {
                    // Client with login <login> still alive -> new login attempt invalid
                    var resp = new ServiceMessageResponse {
                        Message = "This login is already used"
                    };
                    this.cryptoWrapper.Send(resp.ToBytes());
                    this.FreeTCPClient();
                    Log.DebugFormat(
                        "Logon from IP '{0}' failed: User '{1}' already logged on",
                        this.clientIpAddress,
                        credentials.Login);
                }
                else
                {
                    // Old client app which used current login is unresponsive -> dispose of it and add new
                    this.server.RemoveClient(credentials.Login);
                    Log.DebugFormat(
                        "Old client app which used login '{0}' is unresponsive -> dispose of it and add new",
                        credentials.Login);
                    this.server.AddLoggedInUser(credentials.Login, this);
                }
            }
            else
            {
                this.server.AddLoggedInUser(credentials.Login, this);
                this.cryptoWrapper.Send(ServiceMessageResponse.Success.ToBytes());
                Log.DebugFormat(
                    "Logon from IP '{0}' success: User '{1}' from IP  logged on",
                    this.clientIpAddress,
                    credentials.Login);
            }

            this.Login = credentials.Login;
        }
Esempio n. 3
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);
            }
        }
            /// <summary>
            /// Acquires the user token.
            /// </summary>
            /// <param name="userName">Name of the user.</param>
            /// <param name="password">The password of the user.</param>
            /// <param name="commerceAuthenticationParameters">The commerce authentication parameters.</param>
            /// <returns>The user commerce runtime token.</returns>
            internal override Task <UserToken> AcquireToken(string userName, string password, CommerceAuthenticationParameters commerceAuthenticationParameters)
            {
                ThrowIf.Null(commerceAuthenticationParameters, "commerceAuthenticationParameters");

                return(Execute <UserToken>(() =>
                {
                    CommerceRuntimeUserToken commerceUserToken;
                    CommerceIdentity originalIdentity = CommerceRuntimeManager.Identity;
                    ConnectionRequest connectionRequest = this.CreateAcquireTokenRequest(userName, password);
                    connectionRequest.Credential = commerceAuthenticationParameters.Credential;
                    connectionRequest.GrantType = commerceAuthenticationParameters.GrantType;
                    connectionRequest.AdditionalAuthenticationData = commerceAuthenticationParameters;

                    LogonCredentials credentials = null;

                    if (!commerceAuthenticationParameters.RetailOperation.HasValue)
                    {
                        try
                        {
                            CommerceIdentity commerceIdentity = new CommerceIdentity(string.Empty, 0, 0, new string[] { });
                            commerceIdentity.Roles.Add(CommerceRoles.Anonymous);

                            // Set anonymous identity from request.
                            CommerceRuntimeManager.Identity = commerceIdentity;

                            credentials = SecurityManager.Create(CommerceRuntimeManager.Runtime).LogOn(connectionRequest);

                            // Clear the commerce identity.
                            CommerceRuntimeManager.Identity = null;
                        }
                        catch (Exception)
                        {
                            CommerceRuntimeManager.Identity = originalIdentity;
                            throw;
                        }

                        commerceUserToken = new CommerceRuntimeUserToken(credentials.Identity);
                    }
                    else
                    {
                        credentials = SecurityManager.Create(CommerceRuntimeManager.Runtime).ElevateUser(connectionRequest, (RetailOperation)commerceAuthenticationParameters.RetailOperation);
                        commerceUserToken = new CommerceRuntimeUserToken(originalIdentity, credentials.Identity);
                    }

                    return commerceUserToken;
                }));
            }
Esempio n. 5
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);
        }
Esempio n. 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);
     }
 }
Esempio n. 7
0
 public QuickConnectTabPage(TabbedSettingsDialog dialog, LogonCredentials settings)
     : base(dialog, settings)
 {
 }