Ejemplo n.º 1
0
            private XDocument DeserializeMceConfig()
            {
                XmlReaderSettings xmlReaderSettings = ClassificationDefinitionUtils.CreateSafeXmlReaderSettings();

                xmlReaderSettings.IgnoreComments = true;
                xmlReaderSettings.ValidationType = ValidationType.None;
                XDocument result;

                using (Stream stream = this.OpenSourceStream())
                {
                    using (XmlReader xmlReader = XmlReader.Create(stream, xmlReaderSettings))
                    {
                        result = XDocument.Load(xmlReader);
                    }
                }
                return(result);
            }
Ejemplo n.º 2
0
        internal static XDocument ValidateRulePackageXmlContentsLite(byte[] dataToValidate)
        {
            ArgumentValidator.ThrowIfNull("dataToValidate", dataToValidate);
            XmlReaderSettings xmlReaderSettings = ClassificationDefinitionUtils.CreateSafeXmlReaderSettings();

            xmlReaderSettings.IgnoreComments   = true;
            xmlReaderSettings.ValidationFlags |= XmlSchemaValidationFlags.ProcessIdentityConstraints;
            xmlReaderSettings.ValidationType   = ValidationType.Schema;
            xmlReaderSettings.Schemas          = XmlProcessingUtils.RulePackageSchemaInstance;
            XDocument xdocument;

            try
            {
                using (Stream stream = new MemoryStream(dataToValidate))
                {
                    using (XmlReader xmlReader = XmlReader.Create(stream, xmlReaderSettings))
                    {
                        xdocument = XDocument.Load(xmlReader);
                    }
                }
                if (xdocument.Root == null)
                {
                    throw new XmlSchemaValidationException(Strings.ClassificationRuleCollectionMissingRootElementViolation, null, 1, 1);
                }
                XNamespace defaultNamespace = xdocument.Root.GetDefaultNamespace();
                if (!string.Equals(defaultNamespace.NamespaceName, "http://schemas.microsoft.com/office/2011/mce", StringComparison.OrdinalIgnoreCase))
                {
                    throw new XmlSchemaValidationException(Strings.ClassificationRuleCollectionIncorrectDocumentNamespaceViolation(defaultNamespace.NamespaceName, "http://schemas.microsoft.com/office/2011/mce"), null, 1, 1);
                }
            }
            catch (XmlSchemaValidationException ex)
            {
                throw new ClassificationRuleCollectionSchemaValidationException(ex.Message, ex.LineNumber, ex.LinePosition);
            }
            catch (XmlException ex2)
            {
                throw new ClassificationRuleCollectionSchemaValidationException(ex2.Message, ex2.LineNumber, ex2.LinePosition);
            }
            return(xdocument);
        }
Ejemplo n.º 3
0
            public InternalRulePackageDecrypter(byte[] inputRulePackageData)
            {
                this.inputRulePackageData = inputRulePackageData;
                XmlReader reader = XmlReader.Create(new MemoryStream(this.inputRulePackageData), ClassificationDefinitionUtils.CreateSafeXmlReaderSettings());

                this.document.Load(reader);
                this.nsmgr = new XmlNamespaceManager(this.document.NameTable);
                this.nsmgr.AddNamespace("ns", this.document.DocumentElement.NamespaceURI);
            }
Ejemplo n.º 4
0
            private byte[] ReplaceSymmetricAlgorithmParameters(byte[] symmetricKey, byte[] initializationVector)
            {
                XmlDocument xmlDocument = new XmlDocument();
                XmlReader   reader      = XmlReader.Create(new MemoryStream(this.inputRulePackageData), ClassificationDefinitionUtils.CreateSafeXmlReaderSettings());

                xmlDocument.Load(reader);
                XmlNode xmlNode = RulePackageDecrypter.InternalRulePackageDecrypter.SelectAndEnsureSingleNode(xmlDocument, this.nsmgr, "/ns:RulePackage/ns:RulePack/ns:Encryption/ns:Key");

                if (xmlNode == null)
                {
                    throw new XmlException("Encryption key node not found");
                }
                xmlNode.InnerText = Convert.ToBase64String(symmetricKey);
                XmlNode xmlNode2 = RulePackageDecrypter.InternalRulePackageDecrypter.SelectAndEnsureSingleNode(xmlDocument, this.nsmgr, "/ns:RulePackage/ns:RulePack/ns:Encryption/ns:IV");

                if (xmlNode2 == null)
                {
                    throw new XmlException("Encryption IV node not found");
                }
                xmlNode2.InnerText = Convert.ToBase64String(initializationVector);
                return(XmlProcessingUtils.XmlDocumentToUtf16EncodedBytes(xmlDocument));
            }