public static PeerHashToken CreateHashTokenFrom(Message message)
        {
            PeerHashToken invalid = PeerHashToken.Invalid;
            RequestSecurityTokenResponse response = RequestSecurityTokenResponse.CreateFrom(message.GetReaderAtBodyContents(), MessageSecurityVersion.Default, new PeerSecurityTokenSerializer());

            if (string.Compare(response.TokenType, "http://schemas.microsoft.com/net/2006/05/peer/peerhashtoken", StringComparison.OrdinalIgnoreCase) == 0)
            {
                XmlElement requestSecurityTokenResponseXml = response.RequestSecurityTokenResponseXml;
                if (requestSecurityTokenResponseXml == null)
                {
                    return(invalid);
                }
                foreach (XmlElement element2 in requestSecurityTokenResponseXml.ChildNodes)
                {
                    if (PeerRequestSecurityToken.CompareWithNS(element2.LocalName, element2.NamespaceURI, "Status", "http://schemas.xmlsoap.org/ws/2005/02/trust"))
                    {
                        if (element2.ChildNodes.Count == 1)
                        {
                            XmlElement element = element2.ChildNodes[0] as XmlElement;
                            if (PeerRequestSecurityToken.CompareWithNS(element.LocalName, element.NamespaceURI, "Code", "http://schemas.xmlsoap.org/ws/2005/02/trust") && (string.Compare(XmlHelper.ReadTextElementAsTrimmedString(element), "http://schemas.xmlsoap.org/ws/2005/02/trust/status/valid", StringComparison.OrdinalIgnoreCase) != 0))
                            {
                                return(invalid);
                            }
                        }
                    }
                    else if (PeerRequestSecurityToken.CompareWithNS(element2.LocalName, element2.NamespaceURI, "RequestedSecurityToken", "http://schemas.xmlsoap.org/ws/2005/02/trust"))
                    {
                        return(PeerHashToken.CreateFrom(element2));
                    }
                }
            }
            return(invalid);
        }
Example #2
0
 internal static PeerHashToken CreateFrom(XmlElement child)
 {
     byte[] authenticator = null;
     foreach (System.Xml.XmlNode node in child.ChildNodes)
     {
         XmlElement element = (XmlElement)node;
         if ((element != null) && PeerRequestSecurityToken.CompareWithNS(element.LocalName, element.NamespaceURI, "PeerHashToken", "http://schemas.microsoft.com/net/2006/05/peer"))
         {
             if (element.ChildNodes.Count != 1)
             {
                 break;
             }
             XmlElement element2 = element.ChildNodes[0] as XmlElement;
             if ((element2 == null) || !PeerRequestSecurityToken.CompareWithNS(element2.LocalName, element2.NamespaceURI, "Authenticator", "http://schemas.microsoft.com/net/2006/05/peer"))
             {
                 break;
             }
             try
             {
                 authenticator = Convert.FromBase64String(XmlHelper.ReadTextElementAsTrimmedString(element2));
                 break;
             }
             catch (ArgumentNullException exception)
             {
                 DiagnosticUtility.ExceptionUtility.TraceHandledException(exception, TraceEventType.Information);
             }
             catch (FormatException exception2)
             {
                 DiagnosticUtility.ExceptionUtility.TraceHandledException(exception2, TraceEventType.Information);
             }
         }
     }
     return(new PeerHashToken(authenticator));
 }
Example #3
0
        public static PeerHashToken CreateHashTokenFrom(Message message)
        {
            PeerHashToken token = PeerHashToken.Invalid;
            RequestSecurityTokenResponse response = RequestSecurityTokenResponse.CreateFrom(message.GetReaderAtBodyContents(), MessageSecurityVersion.Default, new PeerSecurityTokenSerializer());

            if (String.Compare(response.TokenType, PeerHashToken.TokenTypeString, StringComparison.OrdinalIgnoreCase) != 0)
            {
                return(token);
            }
            XmlElement responseXml = response.RequestSecurityTokenResponseXml;

            if (responseXml != null)
            {
                foreach (XmlElement child in responseXml.ChildNodes)
                {
                    if (PeerRequestSecurityToken.CompareWithNS(child.LocalName, child.NamespaceURI, StatusString, TrustFeb2005Strings.Namespace))
                    {
                        if (child.ChildNodes.Count == 1)
                        {
                            XmlElement desc = (child.ChildNodes[0] as XmlElement);
                            if (PeerRequestSecurityToken.CompareWithNS(desc.LocalName, desc.NamespaceURI, CodeString, TrustFeb2005Strings.Namespace))
                            {
                                string code = XmlHelper.ReadTextElementAsTrimmedString(desc);
                                if (String.Compare(code, ValidString, StringComparison.OrdinalIgnoreCase) != 0)
                                {
                                    break;
                                }
                            }
                        }
                    }
                    else if (PeerRequestSecurityToken.CompareWithNS(child.LocalName, child.NamespaceURI, TrustFeb2005Strings.RequestedSecurityToken, TrustFeb2005Strings.Namespace))
                    {
                        token = PeerHashToken.CreateFrom(child);
                        break;
                    }
                }
            }
            return(token);
        }
Example #4
0
        public static PeerHashToken CreateHashTokenFrom(Message message)
        {
            PeerHashToken        token  = PeerHashToken.Invalid;
            XmlReader            reader = message.GetReaderAtBodyContents();
            RequestSecurityToken rst    = RequestSecurityToken.CreateFrom(reader);
            XmlElement           rstXml = rst.RequestSecurityTokenXml;

            if (rstXml != null)
            {
                //find the wrapper element
                foreach (XmlNode node in rst.RequestSecurityTokenXml.ChildNodes)
                {
                    XmlElement element = (XmlElement)node;
                    if (element == null || !PeerRequestSecurityToken.CompareWithNS(element.LocalName, element.NamespaceURI, PeerRequestSecurityToken.RequestedSecurityTokenElementName, TrustFeb2005Strings.Namespace))
                    {
                        continue;
                    }
                    token = PeerHashToken.CreateFrom(element);
                }
            }
            return(token);
        }
Example #5
0
        internal static PeerHashToken CreateFrom(XmlElement child)
        {
            byte[] auth = null;
            foreach (XmlNode node in child.ChildNodes)
            {
                XmlElement element = (XmlElement)node;

                if (element == null || !PeerRequestSecurityToken.CompareWithNS(element.LocalName, element.NamespaceURI, PeerTokenElementName, PeerNamespace))
                {
                    continue;
                }
                if (element.ChildNodes.Count != 1)
                {
                    break;
                }
                XmlElement authElement = element.ChildNodes[0] as XmlElement;
                if (authElement == null || !PeerRequestSecurityToken.CompareWithNS(authElement.LocalName, authElement.NamespaceURI, PeerAuthenticatorElementName, PeerNamespace))
                {
                    break;
                }
                try
                {
                    auth = Convert.FromBase64String(XmlHelper.ReadTextElementAsTrimmedString(authElement));
                    break;
                }
                catch (ArgumentNullException e)
                {
                    DiagnosticUtility.TraceHandledException(e, TraceEventType.Information);
                }
                catch (FormatException e)
                {
                    DiagnosticUtility.TraceHandledException(e, TraceEventType.Information);
                }
            }
            return(new PeerHashToken(auth));
        }