Esempio n. 1
0
        public X509Certificate2 Request(string name, string pass, bool canuse_clear = true, bool canuse_tor = false, bool canuse_i2p = false)
        {
            MessageBox.Show("Automated signing does not yet work, create an issue on github with your csr");
            TcpClient         client = new TcpClient();
            Socks5ProxyClient SPC;
            HttpProxyClient   HPC;
            string            servera = null;
            int i = 0;

            if (canuse_clear)
            {
                servera = SuperNodeDB.ClearSuperNodes[i];
            }
            else if (canuse_tor)
            {
                servera = SuperNodeDB.TorSuperNodes[i];
            }
            else if (canuse_i2p)
            {
                servera = SuperNodeDB.I2PSuperNodes[i];
            }
            try
            {
                if (canuse_i2p)
                {
                    HPC           = new HttpProxyClient();
                    HPC.ProxyHost = "127.0.0.1";
                    HPC.ProxyPort = 4444;
                    client        = HPC.CreateConnection("", 666);
                }
                else if (canuse_clear)
                {
                    client.Connect("127.0.0.1", 1);
                }
                else if (canuse_tor)
                {
                    SPC               = new Socks5ProxyClient();
                    SPC.ProxyHost     = "127.0.0.1";
                    SPC.ProxyPort     = 9050;
                    SPC.ProxyUserName = "";
                    SPC.ProxyPassword = "";
                    client            = SPC.CreateConnection("", 1);
                }
                NetworkStream stream = client.GetStream();

                return(new X509Certificate2());
            }
            catch (Exception ex)
            { return(new X509Certificate2()); }
        }
Esempio n. 2
0
        public void TestHttpCreateConnection(string proxyHost, int proxyPort, string destHost, int destPort)
        {
            HttpProxyClient p = new HttpProxyClient();

            p.ProxyHost = proxyHost;
            p.ProxyPort = proxyPort;
            TcpClient c = p.CreateConnection(destHost, destPort);

            byte[] sendBuf = System.Text.ASCIIEncoding.ASCII.GetBytes("GET / HTTP/1.1\n");
            c.GetStream().Write(sendBuf, 0, sendBuf.Length);
            byte[] recvBuf = new byte[1024];
            c.GetStream().Read(recvBuf, 0, recvBuf.Length);
            Console.Out.WriteLine(System.Text.ASCIIEncoding.ASCII.GetString(recvBuf));
            c.Close();
        }
Esempio n. 3
0
        async private void Go()
        {
            string proxy = "5.101.82.125:8000:Bj9BvB:fGtkgw";

            TcpClient TcpHandler(string address, int port)
            {
                string[] split      = proxy.Split(':');
                var      socksProxy = new HttpProxyClient(split[0], int.Parse(split[1]), split[2], split[3]);
                var      tcpClient  = socksProxy.CreateConnection(address, port);

                return(tcpClient);
            }

            if (File.Exists("session.dat"))
            {
                var client = new TelegramClient(apiId, apiHash, sessionUserId: "session", handler: TcpHandler);
                await client.ConnectAsync();

                FileSessionStore     store = new FileSessionStore();
                TLSharp.Core.Session s     = null; s = store.Load("session");
                //var hash = await client.SendCodeRequestAsync("79029828756");
                //string code = await GetCode();

                //var user = await client.MakeAuthAsync("79029828756", hash, code);
                var userByPhoneId = await client.SearchUserAsync("79029828756");
            }
            else
            {
                var client = new TelegramClient(apiId, apiHash, handler: TcpHandler);
                await client.ConnectAsync();

                var hash = await client.SendCodeRequestAsync("79029828756");

                string code = await GetCode();

                var user = await client.MakeAuthAsync("79029828756", hash, code);
            }
        }
Esempio n. 4
0
        public void Connect(Reconnect reconnect, string proxyHost = null, int proxyport = 0)
        {
            bool useProxy = (proxyHost != null && proxyport != 0);

            OnDisconnectHasBeenCalled = false;

            _incomingEncryption = new RC4(Utility.HexStringToBytes(IncomingKey));
            _outgoingEncryption = new RC4(Utility.HexStringToBytes(OutgoingKey));

            try
            {
                if (useProxy)
                {
                    Log.Info("Connecting using HTTP proxy client...");
                    HttpProxyClient proxyClient = new HttpProxyClient(proxyHost, proxyport);
                    TcpClient       client      = proxyClient.CreateConnection(reconnect.Host, reconnect.Port);
                    _socket = client.Client;
                }
                else
                {
                    Log.Info("Connecting no using proxy!");
                    _socket = new Socket(SocketType.Stream, ProtocolType.Tcp);
                    _socket.Connect(new IPEndPoint(IPAddress.Parse(reconnect.Host), reconnect.Port));
                }

                _socket.NoDelay        = true;
                _socket.ReceiveTimeout = 5000;
                _socket.SendTimeout    = 5000;
                Disconnected           = false;
                Start();
                _onConnect?.Invoke();
            }
            catch (Exception e)
            {
                Log.Error("Disconnecting due to error : " + e.Message);
                Disconnect(DisconnectReason.ExceptionOnConnection.SetDetails(e.Message));
            }
        }
Esempio n. 5
0
        public ConnectionBase CreateConnection(string uri)
        {
            Socket         socket     = null;
            ConnectionBase connection = null;

            try
            {
                if (this.ConnectionType == ConnectionType.Tcp)
                {
#if !DEBUG
                    {
                        Regex regex = new Regex(@"(.*?):(.*):(\d*)");
                        var   match = regex.Match(uri);
                        Uri   url   = new Uri(string.Format("{0}://{1}:{2}", match.Groups[1], match.Groups[2], match.Groups[3]));

                        if (url.HostNameType == UriHostNameType.IPv4)
                        {
                            var myIpAddress = IPAddress.Parse(url.Host);

                            if (IPAddress.Any.ToString() == myIpAddress.ToString() ||
                                IPAddress.Loopback.ToString() == myIpAddress.ToString() ||
                                IPAddress.Broadcast.ToString() == myIpAddress.ToString())
                            {
                                return(null);
                            }
                            if (Collection.Compare(myIpAddress.GetAddressBytes(), IPAddress.Parse("10.0.0.0").GetAddressBytes()) >= 0 &&
                                Collection.Compare(myIpAddress.GetAddressBytes(), IPAddress.Parse("10.255.255.255").GetAddressBytes()) <= 0)
                            {
                                return(null);
                            }
                            if (Collection.Compare(myIpAddress.GetAddressBytes(), IPAddress.Parse("172.16.0.0").GetAddressBytes()) >= 0 &&
                                Collection.Compare(myIpAddress.GetAddressBytes(), IPAddress.Parse("172.31.255.255").GetAddressBytes()) <= 0)
                            {
                                return(null);
                            }
                            if (Collection.Compare(myIpAddress.GetAddressBytes(), IPAddress.Parse("127.0.0.0").GetAddressBytes()) >= 0 &&
                                Collection.Compare(myIpAddress.GetAddressBytes(), IPAddress.Parse("127.255.255.255").GetAddressBytes()) <= 0)
                            {
                                return(null);
                            }
                            if (Collection.Compare(myIpAddress.GetAddressBytes(), IPAddress.Parse("192.168.0.0").GetAddressBytes()) >= 0 &&
                                Collection.Compare(myIpAddress.GetAddressBytes(), IPAddress.Parse("192.168.255.255").GetAddressBytes()) <= 0)
                            {
                                return(null);
                            }
                        }
                        else if (url.HostNameType == UriHostNameType.IPv6)
                        {
                            var myIpAddress = IPAddress.Parse(url.Host);

                            if (IPAddress.IPv6Any.ToString() == myIpAddress.ToString() ||
                                IPAddress.IPv6Loopback.ToString() == myIpAddress.ToString() ||
                                IPAddress.IPv6None.ToString() == myIpAddress.ToString())
                            {
                                return(null);
                            }
                            if (myIpAddress.ToString().ToLower().StartsWith("fe80:"))
                            {
                                return(null);
                            }
                        }
                    }
#endif

                    connection = new TcpConnection(SessionManager.Connect(SessionManager.GetIpEndPoint(uri), new TimeSpan(0, 0, 10)), SessionManager.MaxReceiveCount, _bufferManager);
                }
                else if (this.ConnectionType == ConnectionType.Socks4Proxy)
                {
                    Regex regex = new Regex(@"(.*?):(.*):(\d*)");
                    var   match = regex.Match(uri);
                    if (!match.Success)
                    {
                        return(null);
                    }

                    socket = SessionManager.Connect(SessionManager.GetIpEndPoint(this.ProxyUri), new TimeSpan(0, 0, 10));
                    var proxy = new Socks4ProxyClient(socket, match.Groups[2].Value, int.Parse(match.Groups[3].Value));

                    connection = new TcpConnection(proxy.CreateConnection(new TimeSpan(0, 0, 10)), SessionManager.MaxReceiveCount, _bufferManager);
                }
                else if (this.ConnectionType == ConnectionType.Socks4aProxy)
                {
                    Regex regex = new Regex(@"(.*?):(.*):(\d*)");
                    var   match = regex.Match(uri);
                    if (!match.Success)
                    {
                        return(null);
                    }

                    socket = SessionManager.Connect(SessionManager.GetIpEndPoint(this.ProxyUri), new TimeSpan(0, 0, 10));
                    var proxy = new Socks4aProxyClient(socket, match.Groups[2].Value, int.Parse(match.Groups[3].Value));

                    connection = new TcpConnection(proxy.CreateConnection(new TimeSpan(0, 0, 10)), SessionManager.MaxReceiveCount, _bufferManager);
                }
                else if (this.ConnectionType == ConnectionType.Socks5Proxy)
                {
                    Regex regex = new Regex(@"(.*?):(.*):(\d*)");
                    var   match = regex.Match(uri);
                    if (!match.Success)
                    {
                        return(null);
                    }

                    socket = SessionManager.Connect(SessionManager.GetIpEndPoint(this.ProxyUri), new TimeSpan(0, 0, 10));
                    var proxy = new Socks5ProxyClient(socket, match.Groups[2].Value, int.Parse(match.Groups[3].Value));

                    connection = new TcpConnection(proxy.CreateConnection(new TimeSpan(0, 0, 10)), SessionManager.MaxReceiveCount, _bufferManager);
                }
                else if (this.ConnectionType == ConnectionType.HttpProxy)
                {
                    Regex regex = new Regex(@"(.*?):(.*):(\d*)");
                    var   match = regex.Match(uri);
                    if (!match.Success)
                    {
                        return(null);
                    }

                    socket = SessionManager.Connect(SessionManager.GetIpEndPoint(this.ProxyUri), new TimeSpan(0, 0, 10));
                    var proxy = new HttpProxyClient(socket, match.Groups[2].Value, int.Parse(match.Groups[3].Value));

                    connection = new TcpConnection(proxy.CreateConnection(new TimeSpan(0, 0, 10)), SessionManager.MaxReceiveCount, _bufferManager);
                }

                var secureConnection = new SecureClientConnection(connection, null, _bufferManager);
                secureConnection.Connect(new TimeSpan(0, 0, 20));

                return(new CompressConnection(secureConnection, SessionManager.MaxReceiveCount, _bufferManager));
            }
            catch (Exception)
            {
                if (socket != null)
                {
                    socket.Close();
                }
                if (connection != null)
                {
                    connection.Dispose();
                }
            }

            return(null);
        }