示例#1
0
        public async Task MessageEncodingDecodingTest_test()
        {
            //ARRANGE
            var source     = "Text to encode";
            var compressor = new DeflateCompressor();
            var encoder    = new MessageEncoding(compressor);
            //ACT
            var encoded = await encoder.EncodeMessage(source);

            var decoded = await encoder.DecodeMessage(encoded);

            //ASSERT
            Assert.AreEqual(decoded, source);
        }
示例#2
0
        public async Task MessageDecoding_test()
        {
            //ARRANGE
            var source     = "Text to encode";
            var compressor = new DeflateCompressor();
            var encoder    = new MessageEncoding(compressor);
            var encoded    = await Helper.DeflateCompress(System.Text.Encoding.UTF8.GetBytes(source), compressor);

            var toString64 = Convert.ToBase64String(encoded);
            //ACT
            var decoded = await encoder.DecodeMessage(toString64);

            //ASSERT
            Assert.AreEqual(decoded, source);
        }
示例#3
0
        public async Task GetPlainAsertion_Test()
        {
            //ARRANGE
            var foo             = "lVRLj9owEL5X6n%2BIfM87IWARVhRUCamtEKx66GXlOANrKbFT2wH239fOBsKyLdpex5%2F9PWbG04dTXTkHkIoJnqPQC9DD7POnqSJ11eB5q5%2F5Bn63oLRjgFxhe5CjVnIsiGIKc1KDwpri7fz7Nxx5ASZKgdTmOeSslGphxZUmXOcoCsLMDUM3TB%2FDBAchTjIvDbNxmsa%2FkLM0HIwT3el41rpR2PePUIStBzUQby9F23hEV0RR0VDhUVH7zMjxVaP81eaLb6VFgV%2BJPbPcyxwBJU%2BjXVJkUVy6WVyGblJA4o4hHLlBmk3CeFJGZQFPaVyMIoDCDYIxcZNxGblklyQuzUbJhMQBTUiEnJ%2FnmIxN5MzPPheCq7YGuQV5YNT4LeGUI4vQWrKi1fCKYHz%2FDvJVSApdzDnakUqBDW1tImQHuFSG5Jv70TdSaEFFhUwLHadrIu56IC1RTfT967bCSnfXQTFwzfQLml16cTx6JlCXcQ3ytVGksl2Y%2BldEA3ODf5j3Vsu1qBh9ceZVJY4LCUQPxv5flJaEK2akIce%2FMmkCLplVpLriuTxvS4OlsDGzJRm1gP78FvFhl5cLPY9%2Fl6g%2FvpHXx9MvFpRd%2Fw1Gw0k7C1E3RDJl5wxOhGp0Y2nALswuqA3sZnfXkWJqcaZs5%2BooZLk2YwLUED%2FaNBsh9cXGXx4ffPxD8rWnrdlNM%2BeOoTi9LERr9z5442B4RK6WH4397aVrRT2h%2FbP895%2FW7A8%3D";
            var unescaped       = Uri.UnescapeDataString(foo);
            var request         = "SAMLRequest=lVRLj9owEL5X6n%2BIfM87IWARVhRUCamtEKx66GXlOANrKbFT2wH239fOBsKyLdpex5%2F9PWbG04dTXTkHkIoJnqPQC9DD7POnqSJ11eB5q5%2F5Bn63oLRjgFxhe5CjVnIsiGIKc1KDwpri7fz7Nxx5ASZKgdTmOeSslGphxZUmXOcoCsLMDUM3TB%2FDBAchTjIvDbNxmsa%2FkLM0HIwT3el41rpR2PePUIStBzUQby9F23hEV0RR0VDhUVH7zMjxVaP81eaLb6VFgV%2BJPbPcyxwBJU%2BjXVJkUVy6WVyGblJA4o4hHLlBmk3CeFJGZQFPaVyMIoDCDYIxcZNxGblklyQuzUbJhMQBTUiEnJ%2FnmIxN5MzPPheCq7YGuQV5YNT4LeGUI4vQWrKi1fCKYHz%2FDvJVSApdzDnakUqBDW1tImQHuFSG5Jv70TdSaEFFhUwLHadrIu56IC1RTfT967bCSnfXQTFwzfQLml16cTx6JlCXcQ3ytVGksl2Y%2BldEA3ODf5j3Vsu1qBh9ceZVJY4LCUQPxv5flJaEK2akIce%2FMmkCLplVpLriuTxvS4OlsDGzJRm1gP78FvFhl5cLPY9%2Fl6g%2FvpHXx9MvFpRd%2Fw1Gw0k7C1E3RDJl5wxOhGp0Y2nALswuqA3sZnfXkWJqcaZs5%2BooZLk2YwLUED%2FaNBsh9cXGXx4ffPxD8rWnrdlNM%2BeOoTi9LERr9z5442B4RK6WH4397aVrRT2h%2FbP895%2FW7A8%3D&RelayState=tVFLi8IwEP4rEjx2oyvCYm5S9yGrWKi3IhjTUbOkSclMxSL%2B9013q%2B7jspe9TeZ7hjmxLtUlMMHSGgkKHjtjQJF2FvkzWPBa8Yn%2BWEhfrwdZ1hJT8truok6BynmjN6vogiw2b8HhC7K6zSxiW8jBy8YwkZ7qaR7Cx2Qkxq5ULhAkIvgGj0OJqgCfgj9oBcjE6S91ZxppfZ9lr%2BAtGP50zeNzIDmRJIPMbvWuatePNk%2BctsSnNocj5Jf3N1bU%2BeX342PdgzRV0zK71fz3DiFXNwom%2BmHCCWxlZYgJ8hVEbBOwcKVQpPJWOIkahZUFoCAl0vF8Jga8L1oWipflMrlLFukyuBqnPgME2xOVotdrNmbvkMRwNHoY9tosLrE8BoEHLMMZYHYV2sqY8%2Bp8fgc%3D&SigAlg=http%3A%2F%2Fwww.w3.org%2F2000%2F09%2Fxmldsig%23rsa-sha1&Signature=fSYSDEFSQs2E1lko89N6yhZWd9lptNVuKdI%2BdoKJ0nB%2FI13Mfwv2omvuaa0uaYKjF7hbBHCA1gYg7QTx1UXmyMEhbYk4c0thvvyF3HYlToQeiS9BD1tUTXA305bU0BRIf3kLTuRZzT6Rf5kS9XctAg1NZeBW02ro61YJ01E8Rxxt80GmHcQbEDkc7fIua31xqz%2FYxlz5fwIPmfQgH%2Fei2U7Cabf55GozXcffV7MefhbkyYPm9a2dpGo7Tb1t7THURBrwkUjIbYtcFSbTBVQ52nzGJ%2FoqR8SsJ7bIdgzXjKJdZqVZCxEBpXi69A1xL4llLVUrZmwKKDqplP1jkI9foA%3D%3D";
            var messageEncoding = new MessageEncoding(new DeflateCompressor());
            var decoded         = await messageEncoding.DecodeMessage(unescaped);

            var federationMetadataSerialiser = new FederationMetadataSerialiser(new CertificateValidatorMock(), new LogProviderMock());
            var metadataXml        = XmlReader.Create(@"D:\Dan\Software\ECA-Interenational\ECA_SPMetadata_20171114.xml");
            var metadata           = federationMetadataSerialiser.Deserialise(metadataXml) as EntityDescriptor;
            var spDescriptor       = metadata.RoleDescriptors.OfType <ServiceProviderSingleSignOnDescriptor>().First();
            var i                  = request.IndexOf("Signature");
            var data               = request.Substring(0, i - 1);
            var sgn                = Uri.UnescapeDataString(request.Substring(i + 10));
            var certificateManager = new CertificateManager(new LogProviderMock());


            //ACT
            var keyDescriptors = spDescriptor.Keys.Where(k => k.Use == KeyType.Signing);
            var validated      = false;

            foreach (var k in keyDescriptors.SelectMany(x => x.KeyInfo))
            {
                var binaryClause = k as BinaryKeyIdentifierClause;
                if (binaryClause == null)
                {
                    throw new InvalidOperationException(String.Format("Expected type: {0} but it was: {1}", typeof(BinaryKeyIdentifierClause), k.GetType()));
                }

                var certContent = binaryClause.GetBuffer();
                var cert        = new X509Certificate2(certContent);
                validated = this.VerifySignature(request, cert, certificateManager);
                if (validated)
                {
                    break;
                }
            }

            //ASSERT
            Assert.True(validated);
        }
示例#4
0
        public async Task DecodeTest()
        {
            string url      = String.Empty;
            var    builders = new List <IRedirectClauseBuilder>();

            var requestUri = new Uri("http://localhost:59611/");
            var federationPartyContextBuilder = new FederationPartyContextBuilderMock();
            var federationContex = federationPartyContextBuilder.BuildContext("local");
            var spDescriptor     = federationContex.MetadataContext.EntityDesriptorConfiguration.SPSSODescriptors.First();
            var certContext      = spDescriptor.KeyDescriptors.Where(x => x.Use == KeyUsage.Signing && x.IsDefault)
                                   .Select(x => x.CertificateContext)
                                   .First();
            var supportedNameIdentifierFormats = new List <Uri> {
                new Uri(NameIdentifierFormats.Transient)
            };
            var authnRequestContext = new AuthnRequestContext(requestUri, new Uri("http://localhost"), federationContex, supportedNameIdentifierFormats);

            authnRequestContext.RelyingState.Add("relayState", "Test state");
            var xmlSerialiser = new XMLSerialiser();
            var compressor    = new DeflateCompressor();
            var encoder       = new MessageEncoding(compressor);
            var logger        = new LogProviderMock();
            var serialiser    = new RequestSerialiser(xmlSerialiser, encoder, logger);

            RequestHelper.GetAuthnRequestBuilders = AuthnRequestBuildersFactoryMock.GetAuthnRequestBuildersFactory();
            var authnBuilder = new SamlRequestBuilder(serialiser);

            builders.Add(authnBuilder);

            //request compression builder
            var encodingBuilder = new RequestEncoderBuilder(encoder);

            builders.Add(encodingBuilder);

            //relay state builder
            var jsonSerialiser       = new NSJsonSerializer(new DefaultSettingsProvider());
            var relayStateSerialiser = new RelaystateSerialiser(jsonSerialiser, encoder, logger) as IRelayStateSerialiser;
            var relayStateBuilder    = new RelayStateBuilder(relayStateSerialiser);

            builders.Add(relayStateBuilder);

            //signature builder
            var certificateManager = new CertificateManager(logger);
            var signatureBuilder   = new SignatureBuilder(certificateManager, logger);

            builders.Add(signatureBuilder);
            var bindingContext = new RequestBindingContext(authnRequestContext);

            foreach (var b in builders)
            {
                await b.Build(bindingContext);
            }
            var decoder = new RedirectBindingDecoder(logger, encoder);
            //ACT
            var message = await decoder.Decode(bindingContext.GetDestinationUrl());

            var stateFromResult    = message.Elements[HttpRedirectBindingConstants.RelayState];
            var requestFromContext = bindingContext.RequestParts[HttpRedirectBindingConstants.SamlRequest];
            var decoded            = await encoder.DecodeMessage(requestFromContext);

            //ASSERT
            Assert.IsNotNull(stateFromResult);
            Assert.AreEqual(bindingContext.RequestParts[HttpRedirectBindingConstants.RelayState], message.Elements[HttpRedirectBindingConstants.RelayState]);
            Assert.AreEqual(decoded, message.Elements[HttpRedirectBindingConstants.SamlRequest]);
        }