예제 #1
0
        private static XmlElement ResolveArtifact(
            string artifact,
            StoredRequestState storedRequestState,
            IOptions options)
        {
            var binaryArtifact = Convert.FromBase64String(artifact);
            var idp            = GetIdp(binaryArtifact, storedRequestState, options);
            var arsIndex       = (binaryArtifact[2] << 8) | binaryArtifact[3];
            var arsUri         = idp.ArtifactResolutionServiceUrls[arsIndex];

            var payload = new Saml2ArtifactResolve
            {
                Artifact = artifact,
                Issuer   = options.SPOptions.EntityId
            }.ToXml();

            var signingServiceCertificate = options.SPOptions.SigningServiceCertificate;
            var resolver = options.SPOptions.ArtifactResolver;

            options.SPOptions.Logger.WriteVerbose("Calling idp " + idp.EntityId.Id + " to resolve artifact\n" + artifact);

            var response =
                Saml2SoapBinding.SendSoapRequest(payload, arsUri, signingServiceCertificate, resolver);

            options.SPOptions.Logger.WriteVerbose("Artifact resolved returned\n" + response);

            return(new Saml2ArtifactResponse(response).GetMessage());
        }
예제 #2
0
        private static XmlElement ResolveArtifact(
            string artifact,
            string relayState,
            IOptions options)
        {
            var binaryArtifact = Convert.FromBase64String(artifact);
            var idp            = GetIdp(binaryArtifact, relayState, options);
            var arsIndex       = (binaryArtifact[2] << 8) | binaryArtifact[3];
            var arsUri         = idp.ArtifactResolutionServiceUrls[arsIndex];

            var payload = new Saml2ArtifactResolve()
            {
                Artifact = artifact,
                Issuer   = options.SPOptions.EntityId
            }.ToXml();

            if (options.SPOptions.SigningServiceCertificate != null)
            {
                var xmlDoc = new XmlDocument()
                {
                    PreserveWhitespace = true
                };

                xmlDoc.LoadXml(payload);
                xmlDoc.Sign(options.SPOptions.SigningServiceCertificate, true);
                payload = xmlDoc.OuterXml;
            }

            var response = Saml2SoapBinding.SendSoapRequest(payload, arsUri);

            return(new Saml2ArtifactResponse(response).Message);
        }
예제 #3
0
        private static XmlElement ResolveArtifact(
            string artifact,
            StoredRequestState storedRequestState,
            IOptions options)
        {
            var binaryArtifact = Convert.FromBase64String(artifact);
            var idp            = GetIdp(binaryArtifact, storedRequestState, options);
            var arsIndex       = (binaryArtifact[2] << 8) | binaryArtifact[3];
            var arsUri         = idp.ArtifactResolutionServiceUrls[arsIndex];

            var payload = new Saml2ArtifactResolve()
            {
                Artifact = artifact,
                Issuer   = options.SPOptions.EntityId
            }.ToXml();

            if (options.SPOptions.SigningServiceCertificate != null)
            {
                var xmlDoc = XmlHelpers.XmlDocumentFromString(payload);
                xmlDoc.Sign(options.SPOptions.SigningServiceCertificate, true);
                payload = xmlDoc.OuterXml;
            }

            options.SPOptions.Logger.WriteVerbose("Calling idp " + idp.EntityId.Id + " to resolve artifact\n" + artifact);

            var clientCertificates = options.SPOptions.ServiceCertificates
                                     .Where(sc => sc.Use.HasFlag(CertificateUse.TlsClient) && sc.Status == CertificateStatus.Current)
                                     .Select(sc => sc.Certificate);

            var response = Saml2SoapBinding.SendSoapRequest(payload, arsUri, clientCertificates);

            options.SPOptions.Logger.WriteVerbose("Artifact resolved returned\n" + response);

            return(new Saml2ArtifactResponse(response).GetMessage());
        }
        public void Saml2SoapBinding_SendSoapRequest_NullCheckDestination()
        {
            string payload = "Doesn't matter";

            Action a = () => Saml2SoapBinding.SendSoapRequest(payload, null, null, null);

            a.ShouldThrow <ArgumentNullException>()
            .And.ParamName.Should().Be("destination");
        }
        public void Saml2SoapBinding_SendSoapRequest_AllowsHttps()
        {
            var payload     = "Doesn't matter";
            var destination = new Uri("https://localhost/Endpoint");

            Action a = () => Saml2SoapBinding.SendSoapRequest(payload, destination, null, null);

            // Destination is not listening, but we should get an exception that shows it
            // at least tried to connect there.
            a.ShouldThrow <WebException>();
        }
        public void Saml2SoapBinding_SendSoapRequest_VerifiesUriIsRemote()
        {
            File.Exists("c:\\Kentor-Unit-Test.txt").Should().BeFalse(
                "a file c:\\Kentor-Unit-Test.txt already exists, preventing test from running");

            var payload     = "Doesn't matter";
            var destination = new Uri("file://c:/Kentor-Unit-Test.txt");

            Action a = () => Saml2SoapBinding.SendSoapRequest(payload, destination, null, null);

            a.ShouldThrow <ArgumentException>()
            .WithMessage("*file*");
        }