Ejemplo n.º 1
0
 public ClientMessage[] SetPromptForCredentialReply(string userName, char[] password)
 {
     ClientMessage[] clientMessages;
     PowwaEvents.PowwaEVENT_DEBUG_LOG0("SetPromptForCredentialReply(): Enter");
     try
     {
         lock (this.clientRequestLock)
         {
             lock (this.sessionStateLock)
             {
                 PromptForCredentialMessage promptForCredentialMessage = this.ValidateSessionStateForMessageReply <PromptForCredentialMessage>();
                 if (promptForCredentialMessage.DomainCredentials)
                 {
                     StringBuilder stringBuilder  = new StringBuilder(0x202);
                     StringBuilder stringBuilder1 = new StringBuilder(0x152);
                     uint          num            = PowwaSession.CredUIParseUserName(userName, stringBuilder, stringBuilder.Capacity, stringBuilder1, stringBuilder1.Capacity);
                     if (num != 0)
                     {
                         PowwaEvents.PowwaEVENT_DEBUG_LOG2("SetPromptForCredentialReply(): Invalid UserName", "userName", userName, "errorCode", num.ToString(CultureInfo.InvariantCulture));
                         throw PowwaException.CreateValidationErrorException(Resources.InvalidUserNameInDomainCredentials);
                     }
                 }
                 PSCredential pSCredential = new PSCredential(userName, PowwaSession.ToSecureString(password));
                 this.messageQueue.SetInputMessageReply(pSCredential);
             }
             clientMessages = this.GetClientMessages();
         }
     }
     finally
     {
         PowwaEvents.PowwaEVENT_DEBUG_LOG0("SetPromptForCredentialReply(): Exit");
     }
     return(clientMessages);
 }
Ejemplo n.º 2
0
        private static void ValidateCharactersInString(string s)
        {
            char[] chrArray  = new char[] { '\0', '\uFFF9', '\uFFFA', '\uFFFB', '\uFFFC', '\uFFFD', '\uFFFE', '\uFFFF' };
            char[] chrArray1 = chrArray;
            char[] chrArray2 = chrArray1;
            int    num       = 0;

            while (num < (int)chrArray2.Length)
            {
                char chr = chrArray2[num];
                if (s.IndexOf(chr) < 0)
                {
                    num++;
                }
                else
                {
                    object[] objArray = new object[1];
                    objArray[0] = (int)chr;
                    throw PowwaException.CreateValidationErrorException(string.Format(CultureInfo.CurrentUICulture, Resources.LogonError_InvalidCharacterFormat, objArray));
                }
            }
        }
Ejemplo n.º 3
0
        private void CreateSession(LogOn.FormInfo formInfo)
        {
            string str;
            string applicationName;
            string str1;
            string originalString;
            WSManConnectionInfo wSManConnectionInfo = null;

            if (formInfo.ConfigurationName.Length == 0)
            {
                str = null;
            }
            else
            {
                str = string.Concat("http://schemas.microsoft.com/powershell/", formInfo.ConfigurationName);
            }
            string       str2         = str;
            PSCredential pSCredential = new PSCredential(formInfo.DestinationUserName, formInfo.DestinationPassword);

            if (!formInfo.IsUriConnection)
            {
                if (string.Compare(formInfo.ApplicationName, "WSMAN", StringComparison.OrdinalIgnoreCase) == 0)
                {
                    applicationName = null;
                }
                else
                {
                    applicationName = formInfo.ApplicationName;
                }
                string str3 = applicationName;
                try
                {
                    wSManConnectionInfo = new WSManConnectionInfo(formInfo.UseSsl, formInfo.ComputerName, formInfo.Port, str3, str2, pSCredential);
                }
                catch (UriFormatException uriFormatException)
                {
                    throw PowwaException.CreateValidationErrorException(Resources.LogonError_InvalidComputerNameUriFormat);
                }
                wSManConnectionInfo.AuthenticationMechanism = formInfo.AuthenticationType;
                PowwaEvents.PowwaEVENT_DEBUG_CONNECT_USING_COMPUTERNAME(formInfo.DestinationUserName, wSManConnectionInfo.ComputerName, wSManConnectionInfo.Port, wSManConnectionInfo.AppName, wSManConnectionInfo.ShellUri, wSManConnectionInfo.AuthenticationMechanism.ToString());
            }
            else
            {
                wSManConnectionInfo = new WSManConnectionInfo(formInfo.ConnectionUri, str2, pSCredential);
                if (!formInfo.AllowRedirection)
                {
                    wSManConnectionInfo.MaximumConnectionRedirectionCount = 0;
                }
                PowwaEvents.PowwaEVENT_DEBUG_CONNECT_USING_URI(formInfo.DestinationUserName, wSManConnectionInfo.ConnectionUri.AbsoluteUri, wSManConnectionInfo.ShellUri);
            }
            string sourceIPAddressRemoteAddr        = SessionHelper.GetSourceIPAddressRemoteAddr();
            string sourceIPAddressHttpXForwardedFor = SessionHelper.GetSourceIPAddressHttpXForwardedFor();

            if (formInfo.IsUriConnection)
            {
                str1 = null;
            }
            else
            {
                str1 = PswaHelper.TranslateLocalComputerName(formInfo.ComputerName);
            }
            string str4 = str1;

            PowwaAuthorizationManager.Instance.CheckLogOnCredential(formInfo.UserName, formInfo.Password, str4, formInfo.ConnectionUri, formInfo.ConfigurationName, sourceIPAddressRemoteAddr, sourceIPAddressHttpXForwardedFor);
            ClientInfo   clientInfo   = new ClientInfo(HttpContext.Current.Request.UserAgent, CultureInfo.CurrentCulture, CultureInfo.CurrentUICulture);
            PowwaSession powwaSession = PowwaSessionManager.Instance.CreateSession(this.Session.SessionID, wSManConnectionInfo, clientInfo, formInfo.UserName);
            string       name         = powwaSession.Name;
            string       userName     = formInfo.UserName;
            string       str5         = sourceIPAddressRemoteAddr;
            string       str6         = sourceIPAddressHttpXForwardedFor;

            if (formInfo.IsUriConnection)
            {
                originalString = wSManConnectionInfo.ConnectionUri.OriginalString;
            }
            else
            {
                originalString = wSManConnectionInfo.ComputerName;
            }
            PowwaEvents.PowwaEVENT_SESSION_START(name, userName, str5, str6, originalString, formInfo.DestinationUserName, wSManConnectionInfo.Port, wSManConnectionInfo.AppName, wSManConnectionInfo.ShellUri);
            HttpCookie item = base.Request.Cookies["ASP.NET_SessionId"];

            if (FormsAuthentication.RequireSSL && item != null)
            {
                item.Secure = true;
            }
            FormsAuthentication.SetAuthCookie(formInfo.UserName, false, "/");
            base.Response.Redirect("~/default.aspx");
            //FormsAuthentication.RedirectFromLoginPage(formInfo.UserName, false);
        }
Ejemplo n.º 4
0
        private LogOn.FormInfo ValidateForm()
        {
            string           value;
            HtmlInputControl htmlInputControl;

            LogOn.FormInfo formInfo = new LogOn.FormInfo();
            LogOn.ValidateCharactersInString(this.userNameTextBox.Value);
            LogOn.ValidateCharactersInString(this.passwordTextBox.Value);
            LogOn.ValidateCharactersInString(this.altUserNameTextBox.Value);
            LogOn.ValidateCharactersInString(this.passwordTextBox.Value);
            LogOn.ValidateCharactersInString(this.connectionUriTextBox.Value);
            LogOn.ValidateCharactersInString(this.targetNodeTextBox.Value);
            LogOn.ValidateCharactersInString(this.configurationNameTextBox.Value);
            LogOn.ValidateCharactersInString(this.applicationNameTextBox.Value);
            formInfo.UserName = PswaHelper.TranslateLocalAccountName(this.userNameTextBox.Value);
            formInfo.Password = this.passwordTextBox.Value;
            LogOn.FormInfo formInfo1 = formInfo;
            if (this.altUserNameTextBox.Value.Length > 0)
            {
                value = this.altUserNameTextBox.Value;
            }
            else
            {
                value = formInfo.UserName;
            }
            formInfo1.DestinationUserName = value;
            if (this.altPasswordTextBox.Value.Length > 0)
            {
                htmlInputControl = this.altPasswordTextBox;
            }
            else
            {
                htmlInputControl = this.passwordTextBox;
            }
            char[] charArray = htmlInputControl.Value.ToCharArray();
            formInfo.DestinationPassword = new SecureString();
            for (int i = 0; i < (int)charArray.Length; i++)
            {
                formInfo.DestinationPassword.AppendChar(charArray[i]);
                charArray[i] = '*';
            }
            formInfo.IsUriConnection = string.Compare(this.connectionTypeSelection.Value, "connection-uri", StringComparison.OrdinalIgnoreCase) == 0;
            if (!formInfo.IsUriConnection)
            {
                formInfo.ComputerName = this.targetNodeTextBox.Value;
                formInfo.UseSsl       = this.useSslSelection.Value == "1";
                if (this.portTextBox.Value.Length != 0)
                {
                    if (!int.TryParse(this.portTextBox.Value, out formInfo.Port))
                    {
                        throw PowwaException.CreateValidationErrorException(Resources.LogonError_InvalidPort);
                    }
                }
                else
                {
                    formInfo.Port = 0x1761;
                }
                formInfo.ApplicationName = this.applicationNameTextBox.Value;
            }
            else
            {
                try
                {
                    formInfo.ConnectionUri = new Uri(this.connectionUriTextBox.Value);
                }
                catch (UriFormatException uriFormatException1)
                {
                    UriFormatException uriFormatException = uriFormatException1;
                    object[]           message            = new object[1];
                    message[0] = uriFormatException.Message;
                    throw PowwaException.CreateValidationErrorException(string.Format(CultureInfo.CurrentUICulture, Resources.LogonError_InvalidUri, message));
                }
                formInfo.AllowRedirection = this.allowRedirectionSelection.Value == "1";
            }
            formInfo.ConfigurationName = this.configurationNameTextBox.Value;
            string str  = this.authenticationTypeSelection.Value;
            string str1 = str;

            if (str != null)
            {
                if (str1 == "0")
                {
                    formInfo.AuthenticationType = AuthenticationMechanism.Default;
                }
                else if (str1 == "1")
                {
                    formInfo.AuthenticationType = AuthenticationMechanism.Basic;
                }
                else if (str1 == "2")
                {
                    formInfo.AuthenticationType = AuthenticationMechanism.Negotiate;
                }
                else if (str1 == "4")
                {
                    formInfo.AuthenticationType = AuthenticationMechanism.Credssp;
                }
                else if (str1 == "5")
                {
                    formInfo.AuthenticationType = AuthenticationMechanism.Digest;
                }
                else if (str1 == "6")
                {
                    formInfo.AuthenticationType = AuthenticationMechanism.Kerberos;
                }
                else
                {
                    throw PowwaException.CreateValidationErrorException(Resources.InternalError_InvalidAuthenticationMechanism);
                }
                return(formInfo);
            }
            throw PowwaException.CreateValidationErrorException(Resources.InternalError_InvalidAuthenticationMechanism);
        }