Beispiel #1
0
        public void Signing()
        {
            const string xml =
                @"<!-- root comment -->
                <root>
                    <child>content</child>
                </root>";

            var xDocument      = XDocument.Parse(xml);
            var signedDocument = new SignedXDocument(xDocument);

            Assert.AreNotEqual(xDocument.ToString(), signedDocument.Sign().ToString());
        }
Beispiel #2
0
        public void Verification()
        {
            const string xml =
                @"<!-- root comment -->
                <root>
                    <child>content</child>
                </root>";

            var xDocument      = XDocument.Parse(xml);
            var signedDocument = new SignedXDocument(xDocument);
            var withSignature  = signedDocument.Sign();

            Assert.IsTrue(SignedXDocument.Verify(withSignature));
        }
Beispiel #3
0
        public void VerificationAltered()
        {
            const string xml =
                @"<!-- root comment -->
                <root>
                    <child>content</child>
                </root>";

            var xDocument      = XDocument.Parse(xml);
            var signedDocument = new SignedXDocument(xDocument);
            var withSignature  = signedDocument.Sign();
            var altered        = new XDocument(withSignature);

            altered.Root?.Add(new XElement(@"dummy"));

            Assert.IsFalse(SignedXDocument.Verify(altered));
        }
Beispiel #4
0
        public void VerificationWithProperties()
        {
            const string xml =
                @"<!-- root comment -->
                <root>
                    <child>content</child>
                </root>";

            var xDocument      = XDocument.Parse(xml);
            var signedDocument = new SignedXDocument(xDocument)
            {
                SignatureProperties = new List <XElement>
                {
                    new XElement(@"SomeProperty", @"SomeValue")
                }
            };
            var withSignature = signedDocument.Sign();

            Assert.IsTrue(SignedXDocument.Verify(withSignature));
        }
Beispiel #5
0
        public void SigningWithProperties()
        {
            const string xml =
                @"<!-- root comment -->
                <root>
                    <child>content</child>
                </root>";

            var xDocument      = XDocument.Parse(xml);
            var signedDocument = new SignedXDocument(xDocument)
            {
                SignatureProperties = new List <XElement>
                {
                    new XElement(@"Property1", @"SomeValue1"),
                    new XElement(@"Property2", @"SomeValue2")
                }
            };

            Assert.AreNotEqual(xDocument.ToString(), signedDocument.Sign().ToString());
        }
Beispiel #6
0
        public void VerificationWithPropertiesAltered()
        {
            const string xml =
                @"<!-- root comment -->
                <root>
                    <child>content</child>
                </root>";

            var xDocument      = XDocument.Parse(xml);
            var signedDocument = new SignedXDocument(xDocument)
            {
                SignatureProperties = new List <XElement>
                {
                    new XElement(@"SomeProperty", @"SomeValue", new [] { new XAttribute(@"Id", @"property") })
                }
            };
            var withSignature = signedDocument.Sign();
            var altered       = new XDocument(withSignature);
            var propertyNode  = altered.XPathSelectElement(@"//*[@Id='property']");

            propertyNode?.SetValue(@"SomeAlteredValue");

            Assert.IsFalse(SignedXDocument.Verify(altered));
        }