Esempio n. 1
0
        public void Serialize_metadata_from_configuration_signed()
        {
            var cert = _context.Sts_Dev_cetificate;

            var metadata = new Saml20MetadataDocument().Load(_context.Config);


            Assert.NotEmpty(metadata.ToXml(null, _context.Config.ServiceProvider.SigningCertificate, _context.Config.SigningAlgorithm));
        }
        public void TestSigning_01()
        {
            Saml20MetadataDocument doc = new Saml20MetadataDocument(true);

            EntityDescriptor entity = doc.CreateDefaultEntity();

            entity.validUntil = DateTime.Now.AddDays(14);

            Console.WriteLine(doc.ToXml());
        }
Esempio n. 3
0
        private void CreateMetadataDocument(HttpContext context, bool sign)
        {
            SAML20FederationConfig configuration = ConfigurationReader.GetConfig<SAML20FederationConfig>();

            KeyInfo keyinfo = new KeyInfo();
            KeyInfoX509Data keyClause = new KeyInfoX509Data(ConfigurationReader.GetConfig<FederationConfig>().SigningCertificate.GetCertificate(), X509IncludeOption.EndCertOnly);
            keyinfo.AddClause(keyClause);

            Saml20MetadataDocument doc = new Saml20MetadataDocument(configuration, keyinfo, sign);

            context.Response.Write(doc.ToXml( context.Response.ContentEncoding ));
        }
        private void CreateMetadataDocument(HttpContext context, bool sign)
        {
            SAML20FederationConfig configuration = SAML20FederationConfig.GetConfig();

            KeyInfo         keyinfo   = new KeyInfo();
            KeyInfoX509Data keyClause = new KeyInfoX509Data(FederationConfig.GetConfig().SigningCertificate.GetCertificate(), X509IncludeOption.EndCertOnly);

            keyinfo.AddClause(keyClause);

            Saml20MetadataDocument doc = new Saml20MetadataDocument(configuration, keyinfo, sign);

            context.Response.Write(doc.ToXml(context.Response.ContentEncoding));
        }
Esempio n. 5
0
        /// <summary>
        /// Creates the metadata document.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="sign">if set to <c>true</c> sign the document.</param>
        public string CreateMetadataDocument(Encoding encoding, bool sign)
        {
            logger.Debug(TraceMessages.MetadataDocumentBeingCreated);

            var keyinfo = new System.Security.Cryptography.Xml.KeyInfo();
            var keyClause = new System.Security.Cryptography.Xml.KeyInfoX509Data(configuration.ServiceProvider.SigningCertificate, X509IncludeOption.EndCertOnly);
            keyinfo.AddClause(keyClause);

            var doc = new Saml20MetadataDocument(configuration, keyinfo, sign);

            logger.Debug(TraceMessages.MetadataDocumentCreated);
            return doc.ToXml(encoding, configuration.ServiceProvider.SigningCertificate);
        }
Esempio n. 6
0
        /// <summary>
        /// Creates the metadata document.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="sign">if set to <c>true</c> sign the document.</param>
        public string CreateMetadataDocument(Encoding encoding, bool sign)
        {
            logger.Debug(TraceMessages.MetadataDocumentBeingCreated);

            var keyinfo   = new System.Security.Cryptography.Xml.KeyInfo();
            var keyClause = new System.Security.Cryptography.Xml.KeyInfoX509Data(configuration.ServiceProvider.SigningCertificate, X509IncludeOption.EndCertOnly);

            keyinfo.AddClause(keyClause);

            var doc = new Saml20MetadataDocument(configuration, keyinfo, sign);

            logger.Debug(TraceMessages.MetadataDocumentCreated);
            return(doc.ToXml(encoding, configuration.ServiceProvider.SigningCertificate));
        }
Esempio n. 7
0
        /// <summary>
        /// Creates the metadata document.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="sign">if set to <c>true</c> sign the document.</param>
        private void CreateMetadataDocument(HttpContext context, bool sign)
        {
            Logger.Debug(TraceMessages.MetadataDocumentBeingCreated);

            var configuration = Saml2Config.Current;

            var keyinfo   = new KeyInfo();
            var keyClause = new KeyInfoX509Data(configuration.ServiceProvider.SigningCertificate.GetCertificate(), X509IncludeOption.EndCertOnly);

            keyinfo.AddClause(keyClause);

            var doc = new Saml20MetadataDocument(configuration, keyinfo, sign);

            Logger.Debug(TraceMessages.MetadataDocumentCreated);

            context.Response.Write(doc.ToXml(context.Response.ContentEncoding));
        }
            public void SignsXml()
            {
                // Arrange
                var doc    = new Saml20MetadataDocument(true);
                var entity = doc.CreateDefaultEntity();

                entity.ValidUntil = DateTime.Now.AddDays(14);

                // Act
                var metadata = doc.ToXml();
                var document = new XmlDocument {
                    PreserveWhitespace = true
                };

                document.LoadXml(metadata);
                var result = XmlSignatureUtils.CheckSignature(document);

                // Assert
                Assert.That(result);
            }
Esempio n. 9
0
            public void SignsXml()
            {
                // Arrange
                var doc    = new Saml20MetadataDocument(true);
                var entity = doc.CreateDefaultEntity();

                entity.ValidUntil = DateTime.Now.AddDays(14);

                var certificate = new X509Certificate2(FileEmbeddedResource("SAML2.Tests.Certificates.sts_dev_certificate.pfx"), "test1234");
                // Act
                var metadata = doc.ToXml(null, certificate);
                var document = new XmlDocument {
                    PreserveWhitespace = true
                };

                document.LoadXml(metadata);
                var result = XmlSignatureUtils.CheckSignature(document);

                // Assert
                Assert.That(result);
            }
            public void SignsXml()
            {
                // Arrange
                var doc = new Saml20MetadataDocument(true);
                var entity = doc.CreateDefaultEntity();
                entity.ValidUntil = DateTime.Now.AddDays(14);

                var certificate = new X509Certificate2(FileEmbeddedResource("SAML2.Tests.Certificates.sts_dev_certificate.pfx"), "test1234");
                // Act
                var metadata = doc.ToXml(null, certificate);
                var document = new XmlDocument { PreserveWhitespace = true };
                document.LoadXml(metadata);
                var result = XmlSignatureUtils.CheckSignature(document);

                // Assert
                Assert.That(result);
            }
            public void SignsXml()
            {
                // Arrange
                var doc = new Saml20MetadataDocument(true);
                var entity = doc.CreateDefaultEntity();
                entity.ValidUntil = DateTime.Now.AddDays(14);

                // Act
                var metadata = doc.ToXml();
                var document = new XmlDocument { PreserveWhitespace = true };
                document.LoadXml(metadata);
                var result = XmlSignatureUtils.CheckSignature(document);

                // Assert
                Assert.That(result);
            }
Esempio n. 12
0
        /// <summary>
        /// Creates the metadata document.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="sign">if set to <c>true</c> sign the document.</param>
        private void CreateMetadataDocument(HttpContext context, bool sign)
        {
            Logger.Debug(TraceMessages.MetadataDocumentBeingCreated);

            var configuration = Saml2Config.GetConfig();

            var keyinfo = new KeyInfo();
            var keyClause = new KeyInfoX509Data(Saml2Config.GetConfig().ServiceProvider.SigningCertificate.GetCertificate(), X509IncludeOption.EndCertOnly);
            keyinfo.AddClause(keyClause);

            var doc = new Saml20MetadataDocument(configuration, keyinfo, sign);

            Logger.Debug(TraceMessages.MetadataDocumentCreated);

            context.Response.Write(doc.ToXml(context.Response.ContentEncoding));
        }
Esempio n. 13
0
        public void Serialize_metatdata_from_configuration_not_signed()
        {
            var metadata = new Saml20MetadataDocument().Load(_context.Config);

            Assert.NotEmpty(metadata.ToXml());
        }
Esempio n. 14
0
        public void Serialize_metadata_to_xml_empty_constructor_should_throw_exception()
        {
            var metadata = new Saml20MetadataDocument();

            Assert.Throws <System.InvalidOperationException>(() => metadata.ToXml());
        }