void Sign(MemoryStream memoryStream)
    {
        memoryStream.Position = 0;

        SafeXmlDocument document = new SafeXmlDocument();

        document.PreserveWhitespace = true;
        document.Load(memoryStream);

        WSSecurityUtilityIdSignedXml signedXml = new WSSecurityUtilityIdSignedXml(document);

        signedXml.SignedInfo.CanonicalizationMethod = SignedXml.XmlDsigExcC14NTransformUrl;

        //signedXml.AddReference("/soap:Envelope/soap:Header/t:ExchangeImpersonation");
        signedXml.AddReference("/soap:Envelope/soap:Header/wsse:Security/wsu:Timestamp");

        signedXml.KeyInfo.AddClause(this.keyInfoNode);

        {
            signedXml.ComputeSignature(hashedAlgorithm);
        }

        XmlElement signature = signedXml.GetXml();

        XmlNode wssecurityNode = document.SelectSingleNode(
            "/soap:Envelope/soap:Header/wsse:Security",
            WSSecurityBasedCredentials.NamespaceManager);

        wssecurityNode.AppendChild(signature);

        memoryStream.Position = 0;
        document.Save(memoryStream);
    }
Example #2
0
        protected override void InternalProcessRecord()
        {
            TaskLogger.LogEnter();
            string text = null;

            try
            {
                string text2 = "Exchange-" + this.ShortNameForRole + ".xml";
                string text3 = Path.Combine(ConfigurationContext.Setup.BinPath, text2);
                string text4 = Path.Combine(ConfigurationContext.Setup.SetupLoggingPath, this.ShortNameForRole + "Prereqs.log");
                string text5 = text3;
                if (this.ADToolsNeeded)
                {
                    SafeXmlDocument safeXmlDocument = new SafeXmlDocument();
                    safeXmlDocument.Load(text3);
                    XmlNode    documentElement = safeXmlDocument.DocumentElement;
                    XmlElement xmlElement      = safeXmlDocument.CreateElement("Feature", documentElement.NamespaceURI);
                    xmlElement.SetAttribute("Id", "RSAT-ADDS");
                    documentElement.AppendChild(xmlElement);
                    string text6 = Path.Combine(ConfigurationContext.Setup.SetupLoggingPath, "temp" + text2);
                    safeXmlDocument.Save(text6);
                    text5 = text6;
                    text  = text6;
                }
                base.Args = string.Concat(new string[]
                {
                    "-inputPath \"",
                    text5,
                    "\" -logPath \"",
                    text4,
                    "\""
                });
                base.InternalProcessRecord();
            }
            catch (IOException exception)
            {
                base.WriteError(exception, ErrorCategory.InvalidOperation, null);
            }
            catch (UnauthorizedAccessException exception2)
            {
                base.WriteError(exception2, ErrorCategory.SecurityError, null);
            }
            finally
            {
                if (text != null)
                {
                    try
                    {
                        File.Delete(text);
                    }
                    catch
                    {
                    }
                }
            }
            TaskLogger.LogExit();
        }
        private bool UpdateSetting(string filePath)
        {
            Exception ex     = null;
            bool      result = false;

            try
            {
                SafeXmlDocument safeXmlDocument = new SafeXmlDocument();
                safeXmlDocument.Load(filePath);
                XmlNode documentElement = safeXmlDocument.DocumentElement;
                if (documentElement == null)
                {
                    TaskLogger.Trace("The aspnet.config file at {0} does not contain a root element. Skipping the file.", new object[]
                    {
                        filePath
                    });
                    return(result);
                }
                XmlNode xmlNode = documentElement.SelectSingleNode("descendant::runtime/legacyImpersonationPolicy");
                if (xmlNode == null || xmlNode.Attributes == null || xmlNode.Attributes.Count <= 0)
                {
                    TaskLogger.Trace("The aspnet.config file at {0} does not contain a valid legacyImpersonationPolicy setting. Skipping the file.", new object[]
                    {
                        filePath
                    });
                    return(result);
                }
                xmlNode.Attributes[0].Value = "false";
                safeXmlDocument.Save(filePath);
                TaskLogger.Trace("Successfully changed the legacyImpersonationPolicy setting to false in aspnet.config file at {0}.", new object[]
                {
                    filePath
                });
                result = true;
            }
            catch (XPathException ex2)
            {
                ex = ex2;
            }
            catch (XmlException ex3)
            {
                ex = ex3;
            }
            if (ex != null)
            {
                TaskLogger.Trace("Failed to parse the aspnet.config file at {0}. Skipping the file. Exception: {1}.", new object[]
                {
                    filePath,
                    ex
                });
            }
            return(result);
        }
Example #4
0
 protected override void InternalProcessRecord()
 {
     TaskLogger.LogEnter();
     try
     {
         string text = Path.Combine(Path.Combine(this.ExchangeInstallPath, this.XmlFileRelativePath), this.XmlFileName);
         base.WriteVerbose(Strings.VerboseTaskParameters(this.ExchangeInstallPath, this.XmlFileRelativePath, text, this.XmlNodeNameToRemove));
         SafeXmlDocument safeXmlDocument = new SafeXmlDocument();
         safeXmlDocument.Load(text);
         XmlNode xmlNode = safeXmlDocument.DocumentElement.SelectSingleNode(this.XmlNodeNameToRemove);
         if (xmlNode != null)
         {
             safeXmlDocument.DocumentElement.RemoveChild(xmlNode);
             safeXmlDocument.Save(text);
         }
     }
     catch (XmlException exception)
     {
         base.WriteError(exception, ErrorCategory.InvalidOperation, null);
     }
     catch (XPathException exception2)
     {
         base.WriteError(exception2, ErrorCategory.InvalidOperation, null);
     }
     catch (IOException exception3)
     {
         base.WriteError(exception3, ErrorCategory.InvalidOperation, null);
     }
     catch (UnauthorizedAccessException exception4)
     {
         base.WriteError(exception4, ErrorCategory.InvalidOperation, null);
     }
     catch (NotSupportedException exception5)
     {
         base.WriteError(exception5, ErrorCategory.InvalidOperation, null);
     }
     catch (SecurityException exception6)
     {
         base.WriteError(exception6, ErrorCategory.InvalidOperation, null);
     }
     catch (ArgumentException exception7)
     {
         base.WriteError(exception7, ErrorCategory.InvalidArgument, null);
     }
     TaskLogger.LogExit();
 }
Example #5
0
        protected override void InternalProcessRecord()
        {
            TaskLogger.LogEnter();
            SafeXmlDocument safeXmlDocument = new SafeXmlDocument();

            try
            {
                int num = 0;
                try
                {
IL_0D:
                    safeXmlDocument.Load(this.ConfigFileFullPath);
                    XmlElement xmlElement = this.FindOrCreateElement(safeXmlDocument, base.ParameterSetName != "Remove");
                    if (xmlElement == null)
                    {
                        if (base.ParameterSetName == "Remove")
                        {
                            this.WriteWarning(Strings.ElementNotFound(this.Element));
                        }
                        return;
                    }
                    string parameterSetName;
                    if ((parameterSetName = base.ParameterSetName) != null)
                    {
                        if (parameterSetName == "AppSettingKey")
                        {
                            this.AddAppSettingEntry(xmlElement);
                            goto IL_F3;
                        }
                        if (parameterSetName == "Attribute")
                        {
                            this.AddAttribute(xmlElement);
                            goto IL_F3;
                        }
                        if (parameterSetName == "ListValues")
                        {
                            this.AddListValues(xmlElement);
                            goto IL_F3;
                        }
                        if (parameterSetName == "Remove")
                        {
                            this.RemoveElementOrAppSettingEntry(xmlElement);
                            goto IL_F3;
                        }
                        if (parameterSetName == "XmlNode")
                        {
                            this.SetXmlNode(safeXmlDocument, xmlElement);
                            goto IL_F3;
                        }
                    }
                    base.WriteError(new InvalidOperationException("invalid parameter set name"), (ErrorCategory)1003, null);
IL_F3:
                    safeXmlDocument.Save(this.ConfigFileFullPath);
                }
                catch (IOException exception)
                {
                    num++;
                    if (num > 3)
                    {
                        base.WriteError(exception, (ErrorCategory)1003, null);
                    }
                    else
                    {
                        this.WriteWarning(Strings.AppConfigIOException(this.ConfigFileFullPath, 3, 3));
                        Thread.Sleep(3000);
                    }
                    goto IL_0D;
                }
            }
            catch (XmlException exception2)
            {
                base.WriteError(exception2, (ErrorCategory)1003, null);
            }
            catch (ArgumentException exception3)
            {
                base.WriteError(exception3, (ErrorCategory)1003, null);
            }
            catch (UnauthorizedAccessException exception4)
            {
                base.WriteError(exception4, (ErrorCategory)1003, null);
            }
            catch (NotSupportedException exception5)
            {
                base.WriteError(exception5, (ErrorCategory)1003, null);
            }
            catch (SecurityException exception6)
            {
                base.WriteError(exception6, (ErrorCategory)1003, null);
            }
            TaskLogger.LogExit();
        }