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);
        }
Esempio n. 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));
 }
Esempio n. 3
0
        public Message ProcessRst(Message message, Claim claim)
        {
            IPeerNeighbor neighbor = host;
            PeerRequestSecurityTokenResponse response = null;
            Message reply = null;

            lock (ThisLock)
            {
                if (this.state != PeerAuthState.Created || neighbor == null || neighbor.IsInitiator || neighbor.State != PeerNeighborState.Opened)
                {
                    OnFailed(neighbor);
                    return(null);
                }
            }

            try
            {
                PeerHashToken receivedToken = PeerRequestSecurityToken.CreateHashTokenFrom(message);
                PeerHashToken expectedToken = securityManager.GetExpectedTokenForClaim(claim);

                if (!expectedToken.Equals(receivedToken))
                {
                    OnFailed(neighbor);
                }
                else
                {
                    this.state = PeerAuthState.Authenticated;
                    PeerHashToken selfToken = securityManager.GetSelfToken();
                    response = new PeerRequestSecurityTokenResponse(selfToken);
                    reply    = Message.CreateMessage(MessageVersion.Soap12WSAddressing10, TrustFeb2005Strings.RequestSecurityTokenResponse, response);
                    OnAuthenticated();
                }
            }
            catch (Exception e)
            {
                if (Fx.IsFatal(e))
                {
                    throw;
                }
                DiagnosticUtility.TraceHandledException(e, TraceEventType.Information);
                OnFailed(neighbor);
            }
            return(reply);
        }
Esempio n. 4
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);
        }
Esempio n. 5
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);
        }
Esempio n. 6
0
        public Message ProcessRst(Message message, Claim claim)
        {
            IPeerNeighbor host = this.host;
            PeerRequestSecurityTokenResponse response = null;
            Message message2 = null;

            lock (this.ThisLock)
            {
                if (((this.state != PeerAuthState.Created) || (host == null)) || (host.IsInitiator || (host.State != PeerNeighborState.Opened)))
                {
                    this.OnFailed(host);
                    return(null);
                }
            }
            try
            {
                PeerHashToken token = PeerRequestSecurityToken.CreateHashTokenFrom(message);
                if (!this.securityManager.GetExpectedTokenForClaim(claim).Equals(token))
                {
                    this.OnFailed(host);
                    return(message2);
                }
                this.state = PeerAuthState.Authenticated;
                response   = new PeerRequestSecurityTokenResponse(this.securityManager.GetSelfToken());
                message2   = Message.CreateMessage(MessageVersion.Soap12WSAddressing10, "RequestSecurityTokenResponse", (BodyWriter)response);
                this.OnAuthenticated();
            }
            catch (Exception exception)
            {
                if (Fx.IsFatal(exception))
                {
                    throw;
                }
                DiagnosticUtility.ExceptionUtility.TraceHandledException(exception, TraceEventType.Information);
                this.OnFailed(host);
            }
            return(message2);
        }
Esempio n. 7
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));
        }
Esempio n. 8
0
 public static bool AuthenticateRequest(Claim claim, string password, Message message)
 {
     return(PeerRequestSecurityToken.CreateHashTokenFrom(message).Validate(claim, password));
 }