Ejemplo n.º 1
0
        protected internal virtual void Read(string xml, bool validateXmlSignature)
        {
#if DEBUG
            Debug.WriteLine("Saml2P: " + xml);
#endif

            XmlDocument = xml.ToXmlDocument();

            if (XmlDocument.DocumentElement.NamespaceURI != Schemas.Saml2Constants.ProtocolNamespace.OriginalString)
            {
                throw new Saml2RequestException("Not SAML2 Protocol.");
            }

            ValidateElementName();

            Id = XmlDocument.DocumentElement.Attributes[Schemas.Saml2Constants.Message.Id].GetValueOrNull <Saml2Id>();

            Version = XmlDocument.DocumentElement.Attributes[Schemas.Saml2Constants.Message.Version].GetValueOrNull <string>();
            if (Version != Schemas.Saml2Constants.VersionNumber)
            {
                throw new Saml2RequestException("Invalid SAML2 version.");
            }

            IssueInstant = XmlDocument.DocumentElement.Attributes[Schemas.Saml2Constants.Message.IssueInstant].GetValueOrNull <DateTimeOffset>();

            Issuer = XmlDocument.DocumentElement[Schemas.Saml2Constants.Message.Issuer, Schemas.Saml2Constants.AssertionNamespace.OriginalString].GetValueOrNull <string>();
            if (!string.IsNullOrEmpty(Config.AllowedIssuer) && !Config.AllowedIssuer.Equals(Issuer, StringComparison.Ordinal))
            {
                throw new Saml2RequestException($"Invalid Issuer. Actually '{Issuer}', allowed '{Config.AllowedIssuer}'");
            }

            Destination = XmlDocument.DocumentElement.Attributes[Schemas.Saml2Constants.Message.Destination].GetValueOrNull <Uri>();

            var extensionsData = XmlDocument.DocumentElement[Schemas.Saml2Constants.Message.Extensions, Schemas.Saml2Constants.ProtocolNamespace.OriginalString].GetValueOrNull <string>();
            if (extensionsData != null)
            {
                Extensions = new Schemas.Extensions {
                    Data = extensionsData
                };
            }

            var documentValidationResult = MustValidateXmlSignature(validateXmlSignature) ? ValidateXmlSignature(XmlDocument.DocumentElement) : SignatureValidation.NotPresent;

            DecryptMessage();

            if (MustValidateXmlSignature(validateXmlSignature))
            {
                ValidateXmlSignature(documentValidationResult);
            }
        }
Ejemplo n.º 2
0
        protected internal virtual void Read(string xml, bool validateXmlSignature)
        {
#if DEBUG
            Debug.WriteLine("Saml2P: " + xml);
#endif

            XmlDocument = xml.ToXmlDocument();

            if (XmlDocument.DocumentElement.NamespaceURI != Saml2Constants.ProtocolNamespace.OriginalString)
            {
                throw new Saml2RequestException("Not SAML2 Protocol.");
            }

            ValidateElementName();

            Id = XmlDocument.DocumentElement.Attributes[Saml2Constants.Message.Id].GetValueOrNull <Saml2Id>();

            Version = XmlDocument.DocumentElement.Attributes[Saml2Constants.Message.Version].GetValueOrNull <string>();
            if (Version != Saml2Constants.VersionNumber)
            {
                throw new Saml2RequestException("Invalid SAML2 version.");
            }

            IssueInstant = XmlDocument.DocumentElement.Attributes[Saml2Constants.Message.IssueInstant].GetValueOrNull <DateTime>();

            Issuer = XmlDocument.DocumentElement[Saml2Constants.Message.Issuer, Saml2Constants.AssertionNamespace.OriginalString].GetValueOrNull <Uri>();

            Destination = XmlDocument.DocumentElement.Attributes[Saml2Constants.Message.Destination].GetValueOrNull <Uri>();

            var extensionsData = XmlDocument.DocumentElement[Saml2Constants.Message.Extensions, Saml2Constants.ProtocolNamespace.OriginalString].GetValueOrNull <string>();
            if (extensionsData != null)
            {
                Extensions = new Schemas.Extensions {
                    Data = extensionsData
                };
            }

            DecryptMessage();

            if (!(this is Saml2AuthnRequest) && validateXmlSignature)
            {
                ValidateXmlSignature();
            }
        }