コード例 #1
0
ファイル: UtilsCore.cs プロジェクト: martin762/Eddie
        public static byte[] AssocToUtf8Bytes(Dictionary <string, byte[]> assoc)
        {
            string output = "";

            foreach (KeyValuePair <string, byte[]> kp in assoc)
            {
                output += ExtensionsString.Base64Encode(kp.Key.GetUtf8Bytes()) + ":" + ExtensionsString.Base64Encode(kp.Value) + "\n";
            }
            return(System.Text.Encoding.UTF8.GetBytes(output));
        }
コード例 #2
0
ファイル: UtilsCore.cs プロジェクト: martin762/Eddie
        public static string HashSHA256File(string path)
        {
            SHA256 Sha256 = SHA256.Create();

            using (FileStream stream = File.OpenRead(path))
            {
                byte[] bytes = Sha256.ComputeHash(stream);

                return(ExtensionsString.BytesToHex(bytes));
            }
        }
コード例 #3
0
ファイル: TorControl.cs プロジェクト: tendersoft-mjb/Eddie
        public static void Connect(TcpClient client, string host, int controlPort, string controlPassword)
        {
            if (client == null)
            {
                throw new Exception("Internal error (client is null)");
            }

            bool controlAuthenticate = Engine.Instance.Storage.GetBool("proxy.tor.control.auth");

            byte[] password = System.Text.Encoding.ASCII.GetBytes(controlPassword);

            if (controlAuthenticate)
            {
                if (controlPassword == "")
                {
                    Init();

                    if (m_torCookiePath == "")
                    {
                        throw new Exception(LanguageManager.GetText("TorControlNoPath"));
                    }

                    Engine.Instance.Logs.Log(LogType.Verbose, LanguageManager.GetText("TorControlAuth", "Cookie, from " + m_torCookiePath));

                    password = m_torCookiePassword;
                }
                else
                {
                    Engine.Instance.Logs.Log(LogType.Verbose, LanguageManager.GetText("TorControlAuth", "Password"));
                }
            }

            client.Connect(host, controlPort);

            if (controlAuthenticate)
            {
                Write(client, "AUTHENTICATE ");
                Write(client, ExtensionsString.BytesToHex(password));
                Write(client, "\n");

                string result = Read(client);

                if (result != "250 OK")
                {
                    throw new Exception(result);
                }
            }

            Flush(client);
        }
コード例 #4
0
ファイル: HttpResponse.cs プロジェクト: nir94/Eddie
        public void FromJson(Json jResponse)
        {
            if (jResponse.HasKey("headers"))
            {
                string[] lines = jResponse["headers"].ValueString.Split('\n');
                Status = "";
                foreach (string line in lines)
                {
                    string l = line.Trim();
                    if (l == "")
                    {
                        continue;
                    }

                    if (Status == "")
                    {
                        Status = l.Trim();
                    }
                    else
                    {
                        int posSep = l.IndexOfInv(":");
                        if (posSep != -1)
                        {
                            string k = "";
                            string v = "";
                            k = l.Substring(0, posSep).ToLowerInvariant().Trim();
                            v = l.Substring(posSep + 1).Trim();
                            if (k != "")
                            {
                                Headers.Add(new KeyValuePair <string, string>(k, v));
                            }
                        }
                    }
                }
            }

            if (jResponse.HasKey("body"))
            {
                BufferData = ExtensionsString.HexToBytes(jResponse["body"].ValueString);
            }

            if (jResponse.HasKey("response_code"))
            {
                ResponseCode = jResponse["response_code"].ValueInt;
            }
        }
コード例 #5
0
ファイル: TorControl.cs プロジェクト: tendersoft-mjb/Eddie
        public static void Init()
        {
            if (m_torDetection)
            {
                return;
            }

            ElevatedProcess.Command c = new ElevatedProcess.Command();
            c.Parameters["command"] = "tor-get-info";

            c.Parameters["name"] = "tor";
            string customPath = Engine.Instance.Storage.Get("proxy.tor.path");

            if (customPath != "")
            {
                c.Parameters["path"] = customPath;
            }
            c.Parameters["username"] = Environment.UserName;

            string torInfo = Engine.Instance.Elevated.DoCommandSync(c);

            foreach (string line in torInfo.Split('\n'))
            {
                if (line.StartsWithInv("Name:"))
                {
                    m_torProcessName = line.Substring("Name:".Length);
                }
                if (line.StartsWithInv("Path:"))
                {
                    m_torProcessPath = line.Substring("Path:".Length);
                }
                if (line.StartsWithInv("CookiePath:"))
                {
                    m_torCookiePath = line.Substring("CookiePath:".Length);
                }
                if (line.StartsWithInv("CookiePasswordHex:"))
                {
                    m_torCookiePassword = ExtensionsString.HexToBytes(line.Substring("CookiePasswordHex:".Length));
                }
            }

            m_torDetection = true;
        }