Exemple #1
0
        private void StartSshProcess()
        {
            Providers.Service service = Engine.CurrentServer.Provider as Providers.Service;
            if (service == null) // Unexpected
                return;

            if (m_processProxy != null) // Unexpected
                return;

            string fileKeyExtension = "";
            if (Platform.Instance.IsUnixSystem())
                fileKeyExtension = "key";
            else
                fileKeyExtension = "ppk";

            m_fileSshKey = new TemporaryFile(fileKeyExtension);
            Platform.Instance.FileContentsWriteText(m_fileSshKey.Path, Utils.XmlGetAttributeString(service.User, "ssh_" + fileKeyExtension, ""));

            if (Platform.Instance.IsUnixSystem())
            {
                // under OS X, SSH change it's UID to normal user.
                if (Platform.Instance.GetCode() != "OSX")
                {
                    string cmd = "chmod 600 \"" + m_fileSshKey.Path + "\"";
                    Platform.Instance.ShellCmd(cmd);
                }
            }

            string arguments = "";

            arguments += " -i \"" + m_fileSshKey.Path + "\" -L " + Conversions.ToString(m_ovpn.ProxyPort) + ":127.0.0.1:2018 sshtunnel@" + m_ovpn.Address;
            if (Platform.Instance.IsUnixSystem())
                arguments += " -p " + m_ovpn.Port; // ssh use -p
            else
                arguments += " -P " + m_ovpn.Port; // plink use -P

            if (Platform.Instance.IsUnixSystem())
                arguments += " -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no"; // TOOPTIMIZE: To bypass key confirmation. Not the best approach.
            arguments += " -N -T -v";

            m_programScope = new ProgramScope(Software.SshPath, "SSH Tunnel");

            m_processProxy = new Process();
            m_processProxy.StartInfo.FileName = Software.SshPath;
            m_processProxy.StartInfo.Arguments = arguments;
            m_processProxy.StartInfo.WorkingDirectory = Utils.GetTempPath();

            m_processProxy.StartInfo.Verb = "run";
            m_processProxy.StartInfo.CreateNoWindow = true;
            m_processProxy.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
            m_processProxy.StartInfo.UseShellExecute = false;
            m_processProxy.StartInfo.RedirectStandardInput = true;
            m_processProxy.StartInfo.RedirectStandardError = true;
            m_processProxy.StartInfo.RedirectStandardOutput = true;

            m_processProxy.ErrorDataReceived += new DataReceivedEventHandler(ProcessSshOutputDataReceived);
            m_processProxy.OutputDataReceived += new DataReceivedEventHandler(ProcessSshOutputDataReceived);
            m_processProxy.Exited += new EventHandler(ProcessSshExited);

            m_processProxy.Start();

            m_processProxy.BeginOutputReadLine();
            m_processProxy.BeginErrorReadLine();
        }
Exemple #2
0
        private void StartSslProcess()
        {
            Providers.Service service = Engine.CurrentServer.Provider as Providers.Service;
            if (service == null) // Unexpected
                return;

            if (m_processProxy != null) // Unexpected
                return;

            m_fileSslCrt = new TemporaryFile("crt");
            Platform.Instance.FileContentsWriteText(m_fileSslCrt.Path, Utils.XmlGetAttributeString(service.User, "ssl_crt", ""));

            m_fileSslConfig = new TemporaryFile("ssl");

            string sslConfig = "";

            if (Platform.Instance.IsUnixSystem())
            {
                //sslConfig += "output = /dev/stdout\n"; // With this, with new stunnel 5.01, we have duplicated output dump.
                //sslConfig += "pid = /tmp/stunnel4.pid\n";
                sslConfig += "foreground = yes\n"; // Without this, the process fork and it's exit can't be detected.
                sslConfig += "pid = /tmp/" + RandomGenerator.GetHash() + ".pid\n"; // 2.2
            }
            if(Engine.Instance.Storage.Get("ssl.options") != "")
                sslConfig += "options = " + Engine.Instance.Storage.Get("ssl.options") + "\n";
            sslConfig += "client = yes\n";
            sslConfig += "debug = 6\n";
            sslConfig += "\n";
            sslConfig += "[openvpn]\n";
            sslConfig += "accept = 127.0.0.1:" + Conversions.ToString(m_ovpn.ProxyPort) + "\n";
            sslConfig += "connect = " + m_ovpn.Address + ":" + m_ovpn.Port + "\n";
            sslConfig += "TIMEOUTclose = 0\n";
            sslConfig += "verify = 3\n";
            //sslConfig += "CAfile = \"" + m_fileSslCrt.Path + "\"\n";
            sslConfig += "CAfile = " + m_fileSslCrt.Path + "\n";
            sslConfig += "\n";

            string sslConfigPath = m_fileSslConfig.Path;
            Platform.Instance.FileContentsWriteText(sslConfigPath, sslConfig);

            m_programScope = new ProgramScope(Software.SslPath, "SSL Tunnel");

            m_processProxy = new Process();
            m_processProxy.StartInfo.FileName = Software.SslPath;
            m_processProxy.StartInfo.Arguments = "\"" + sslConfigPath + "\"";
            m_processProxy.StartInfo.WorkingDirectory = Utils.GetTempPath();

            m_processProxy.StartInfo.Verb = "run";
            m_processProxy.StartInfo.CreateNoWindow = true;
            m_processProxy.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
            m_processProxy.StartInfo.UseShellExecute = false;
            m_processProxy.StartInfo.RedirectStandardInput = true;
            m_processProxy.StartInfo.RedirectStandardError = true;
            m_processProxy.StartInfo.RedirectStandardOutput = true;

            m_processProxy.ErrorDataReceived += new DataReceivedEventHandler(ProcessSslOutputDataReceived);
            m_processProxy.OutputDataReceived += new DataReceivedEventHandler(ProcessSslOutputDataReceived);
            m_processProxy.Exited += new EventHandler(ProcessSslExited);

            m_processProxy.Start();

            m_processProxy.BeginOutputReadLine();
            m_processProxy.BeginErrorReadLine();
        }
Exemple #3
0
        private void StartOpenVpnProcess()
        {
            if (m_processOpenVpn != null) // Unexpected
                return;

            m_fileOvpn = new TemporaryFile("ovpn");
            string ovpnPath = m_fileOvpn.Path;
            Platform.Instance.FileContentsWriteText(ovpnPath, Engine.ConnectedOVPN);

            if(m_processProxy == null)
                m_programScope = new ProgramScope(Software.OpenVpnPath, "OpenVPN Tunnel");

            m_processOpenVpn = new Process();
            m_processOpenVpn.StartInfo.FileName = Software.OpenVpnPath;
            m_processOpenVpn.StartInfo.Arguments = "";
            m_processOpenVpn.StartInfo.WorkingDirectory = Utils.GetTempPath();

            if (Storage.Simulate)
            {
                m_processOpenVpn.StartInfo.FileName = "Simulate.exe";
                Sleep(1000);
                Engine.SetConnected(true);
            }

            m_processOpenVpn.StartInfo.Arguments = "--config \"" + ovpnPath + "\" ";

            m_processOpenVpn.StartInfo.Verb = "run";
            m_processOpenVpn.StartInfo.CreateNoWindow = true;
            m_processOpenVpn.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
            m_processOpenVpn.StartInfo.UseShellExecute = false;
            m_processOpenVpn.StartInfo.RedirectStandardInput = true;
            m_processOpenVpn.StartInfo.RedirectStandardError = true;
            m_processOpenVpn.StartInfo.RedirectStandardOutput = true;
            m_processOpenVpn.StartInfo.StandardErrorEncoding = Encoding.UTF8; // 2.11.10
            m_processOpenVpn.StartInfo.StandardOutputEncoding = Encoding.UTF8; // 2.11.10

            m_processOpenVpn.OutputDataReceived += new DataReceivedEventHandler(ProcessOpenVpnOutputDataReceived);
            m_processOpenVpn.ErrorDataReceived += new DataReceivedEventHandler(ProcessOpenVpnOutputDataReceived);
            m_processOpenVpn.Exited += new EventHandler(ProcessOpenVpnExited);

            m_processOpenVpn.Start();

            m_processOpenVpn.BeginOutputReadLine();
            m_processOpenVpn.BeginErrorReadLine();
        }