예제 #1
0
        public void TestBuildHash5()
        {
            var    info = XmppXElement.LoadXml(Resource.Get("Xmpp.Capabilities.discoinfo4.xml")).Cast <Info>();
            string hash = Caps.BuildHash(info);

            hash.ShouldBe("8ungGR8ouA8Bi9LIUp8r3+1tgbY=");
        }
예제 #2
0
        public void TestBuildHash2()
        {
            var    info = XmppXElement.LoadXml(Resource.Get("Xmpp.Capabilities.discoinfo3.xml")).Cast <Info>();
            string hash = Caps.BuildHash(info);

            hash.ShouldBe("XH3meI11JZj00/DhOlop7p7jKBE=");
        }
예제 #3
0
        public void TestBuildHash()
        {
            var info = XmppXElement.LoadXml(Resource.Get("Xmpp.Capabilities.discoinfo1.xml")).Cast <Info>();
            var hash = Caps.BuildHash(info);

            hash.ShouldBe("q07IKJEyjvHSyhy//CH0CxmKi8w=");
        }
예제 #4
0
        public void TestBuildHash6()
        {
            var    info = XmppXElement.LoadXml(Resource.Get("Xmpp.Capabilities.discoinfo5.xml")).Cast <Info>();
            string hash = Caps.BuildHash(info);

            hash.ShouldBe("KV4qaXUgvEqhWE7WEJoqvO6gTYA=");
        }
예제 #5
0
        public ClientCaps(ICapsStorage capsStorage)
        {
            var myDiscoInfo = DiscoInfo;

            capsHash = Caps.BuildHash(myDiscoInfo);

            // lets store our own caps as well
            if (!capsStorage.HasCapability(capsHash))
            {
                capsStorage.AddCapability(capsHash, myDiscoInfo.ToString());
            }
        }
        public CapsCollectionHandler(ICapsStorage capsStorage)
        {
            Handle(
                el =>
                el.OfType <Presence>(),

                async(context, xmppXElement) =>
            {
                var pres = xmppXElement.Cast <Presence>();
                var caps = pres.Caps;
                if (caps != null &&
                    caps.Hash != null &&        // old style caps has no hash attribute, we ignore old style caps
                    !capsStorage.HasCapability(caps.Version))
                {
                    try
                    {
                        var discoResult = await this.DiscoverInformationAsync(pres.From, caps.Node + "#" + caps.Version);

                        if (discoResult.Type == IqType.Result)
                        {
                            if (discoResult.Query.OfType <Info>())
                            {
                                var info = discoResult.Query as Info;
                                // check if Hash is correct
                                if (caps.HashAlgorithm != Matrix.Crypt.HashAlgorithms.Unknown)
                                {
                                    try
                                    {
                                        var validateHash = Caps.BuildHash(info, caps.HashAlgorithm);
                                        if (validateHash == caps.Version && !capsStorage.HasCapability(caps.Version))
                                        {
                                            capsStorage.AddCapability(caps.Version, info.ToString(true));
                                        }
                                        else
                                        {
                                            // wrong hash, malicious or broken client
                                            // ignore or log
                                        }
                                    }
                                    catch (Exception)
                                    {
                                        // could crash because of not supported Hash algorithm by the platform
                                        // ignore
                                    }
                                }
                                else
                                {
                                    if (caps.Version != null && !capsStorage.HasCapability(caps.Version))
                                    {
                                        capsStorage.AddCapability(caps.Version, info.ToString(true));
                                    }
                                }
                            }
                        }
                    }
                    catch (Exception)
                    {
                        // ignore, eg timeouts
                    }
                }
            });
        }