示例#1
0
        private Streamhost NegotiateProxy(SISession session, IEnumerable <Streamhost> proxies)
        {
            XmlElement e = Xml.Element("query", "http://jabber.org/protocol/bytestreams").Attr("sid", session.Sid);

            foreach (Streamhost streamhost in proxies)
            {
                e.Child(Xml.Element("streamhost", null).Attr("jid", streamhost.Jid.ToString()).Attr("host", streamhost.Host).Attr("port", streamhost.Port.ToString()));
            }
            Iq errorIq = base.im.IqRequest(IqType.Set, session.To, base.im.Jid, e, null, -1, "");

            if (errorIq.Type == IqType.Error)
            {
                throw Util.ExceptionFromError(errorIq, "The SOCKS5 negotiation failed.");
            }
            XmlElement element2 = errorIq.Data["query"];

            if ((element2 == null) || (element2.NamespaceURI != "http://jabber.org/protocol/bytestreams"))
            {
                throw new XmppException("Erroneous response.");
            }
            XmlElement element3 = element2["streamhost-used"];

            if (element3 == null)
            {
                throw new XmppException("Missing streamhost-used element.");
            }
            string     proxyJid    = element3.GetAttribute("jid");
            Streamhost streamhost2 = proxies.FirstOrDefault <Streamhost>(proxy => proxy.Jid == proxyJid);

            if (streamhost2 == null)
            {
                throw new XmppException("Invalid streamhost JID.");
            }
            return(streamhost2);
        }
示例#2
0
        private IEnumerable <Streamhost> GetProxyList()
        {
            ISet <Streamhost> set = new HashSet <Streamhost>();

            foreach (S22.Xmpp.Extensions.Item item in this.sdisco.GetItems(base.im.Jid.Domain))
            {
                foreach (Identity identity in this.sdisco.GetIdentities(item.Jid))
                {
                    if ((identity.Category == "proxy") && (identity.Type == "bytestreams"))
                    {
                        Streamhost networkAddress = this.GetNetworkAddress(item.Jid);
                        set.Add(networkAddress);
                    }
                }
            }
            return(set);
        }
示例#3
0
        private void MediatedTransfer(SISession session, IEnumerable <Streamhost> proxies)
        {
            Streamhost streamhost = this.NegotiateProxy(session, proxies);

            using (Socks5Client client = new Socks5Client(streamhost.Host, streamhost.Port, null, null))
            {
                string domain = this.Sha1(session.Sid + session.From + session.To);
                if (client.Request(SocksCommand.Connect, domain, 0).Status != ReplyStatus.Succeeded)
                {
                    CommonConfig.Logger.WriteInfo("SOCKS5 Connect request failed.");
                    throw new Socks5Exception("SOCKS5 Connect request failed.");
                }
                CommonConfig.Logger.WriteInfo("SOCKS5 Connect successed.");
                XmlElement data    = Xml.Element("query", "http://jabber.org/protocol/bytestreams").Attr("sid", session.Sid).Child(Xml.Element("activate", null).Text(session.To.ToString()));
                Iq         errorIq = base.im.IqRequest(IqType.Set, streamhost.Jid, base.im.Jid, data, null, -1, "");
                if (errorIq.Type == IqType.Error)
                {
                    throw Util.ExceptionFromError(errorIq, "Could not activate the bytestream.");
                }
                this.SendData(session, client.GetStream());
            }
        }