Exemplo n.º 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());
        }
Exemplo n.º 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));
        }
Exemplo n.º 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));
        }
Exemplo n.º 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));
        }
Exemplo n.º 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());
        }
Exemplo n.º 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));
        }