Esempio n. 1
0
        public override void OnBuildOvpn(ConnectionInfo connection, OvpnBuilder ovpn)
        {
            base.OnBuildOvpn(connection, ovpn);

            if (ovpn.ExistsDirective("auth-retry"))
            {
                ovpn.AppendDirective("auth-retry", "none", "");
            }
        }
Esempio n. 2
0
        public override void OnBuildOvpn(OvpnBuilder ovpn)
        {
            base.OnBuildOvpn(ovpn);

            if (GetDnsSwitchMode() == "resolvconf")
            {
                string dnsScriptPath = Software.FindResource("update-resolv-conf");
                if (dnsScriptPath != "")
                {
                    EnsureExecutablePermissions(dnsScriptPath);
                    Engine.Instance.Logs.Log(LogType.Verbose, Messages.DnsResolvConfScript);
                    ovpn.AppendDirective("script-security", "2", "");
                    ovpn.AppendDirective("up", dnsScriptPath, "");
                    ovpn.AppendDirective("down", dnsScriptPath, "");
                }
            }

            ovpn.AppendDirective("route-delay", "5", ""); // 2.8, to resolve some issue on some distro, ex. Fedora 21
        }
Esempio n. 3
0
        public override void OnBuildOvpnAuth(OvpnBuilder ovpn)
        {
            base.OnBuildOvpnAuth(ovpn);

            string key = Engine.Instance.Storage.Get("key");

            XmlNode nodeUser = User;

            ovpn.AppendDirective("<ca>", nodeUser.Attributes["ca"].Value, "");
            XmlElement xmlKey = nodeUser.SelectSingleNode("keys/key[@name='" + key + "']") as XmlElement;

            if (xmlKey == null)
            {
                throw new Exception(Messages.Format(Messages.KeyNotFound, key));
            }
            ovpn.AppendDirective("<cert>", xmlKey.Attributes["crt"].Value, "");
            ovpn.AppendDirective("<key>", xmlKey.Attributes["key"].Value, "");
            ovpn.AppendDirective("key-direction", "1", "");
            ovpn.AppendDirective("<tls-auth>", nodeUser.Attributes["ta"].Value, "");
        }
Esempio n. 4
0
        public override void OnBuildOvpnAuth(OvpnBuilder ovpn)
        {
            base.OnBuildOvpnAuth(ovpn);

            string key = Engine.Instance.Storage.Get("key");

            XmlNode nodeUser = User;
            ovpn.AppendDirective("<ca>", nodeUser.Attributes["ca"].Value, "");
            XmlElement xmlKey = nodeUser.SelectSingleNode("keys/key[@name='" + key + "']") as XmlElement;
            if (xmlKey == null)
                throw new Exception(MessagesFormatter.Format(Messages.KeyNotFound, key));
            ovpn.AppendDirective("<cert>", xmlKey.Attributes["crt"].Value, "");
            ovpn.AppendDirective("<key>", xmlKey.Attributes["key"].Value, "");
            ovpn.AppendDirective("key-direction","1", "");
            ovpn.AppendDirective("<tls-auth>", nodeUser.Attributes["ta"].Value, "");
        }
Esempio n. 5
0
        public override void OnBuildOvpn(OvpnBuilder ovpn)
        {
            base.OnBuildOvpn(ovpn);

            // Move here AirVPN specific of Session thread (protocol, remote, alt, port, proxy)

            ServerInfo CurrentServer = Engine.Instance.CurrentServer;

            string protocol = Engine.Instance.Storage.Get("mode.protocol").ToUpperInvariant();
            int port = Engine.Instance.Storage.GetInt("mode.port");
            int alt = Engine.Instance.Storage.GetInt("mode.alt");
            int proxyPort = 0;

            if (protocol == "AUTO")
            {
                protocol = CurrentServer.Provider.GetKeyValue("mode_protocol", "UDP");
                string proxyMode = Engine.Instance.Storage.GetLower("proxy.mode");
                if (proxyMode != "none")
                    protocol = "TCP";
                port = Conversions.ToInt32(CurrentServer.Provider.GetKeyValue("mode_port", "443"));
                alt = Conversions.ToInt32(CurrentServer.Provider.GetKeyValue("mode_alt", "0"));
            }

            if (protocol == "SSH")
            {
                proxyPort = Engine.Instance.Storage.GetInt("ssh.port");
                if (proxyPort == 0)
                    proxyPort = RandomGenerator.GetInt(1024, 64 * 1024);
            }
            else if (protocol == "SSL")
            {
                proxyPort = Engine.Instance.Storage.GetInt("ssl.port");
                if (proxyPort == 0)
                    proxyPort = RandomGenerator.GetInt(1024, 64 * 1024);
            }
            else
            {
                proxyPort = 0;
            }

            if (protocol == "UDP")
            {
                ovpn.AppendDirective("proto", "udp", "");
            }
            else // TCP, SSH, SSL, Tor
            {
                ovpn.AppendDirective("proto", "tcp", "");
            }

            string ip = CurrentServer.IpEntry;
            if (alt == 1)
                ip = CurrentServer.IpEntry2;

            if (protocol == "SSH")
                ovpn.AppendDirective("remote", "127.0.0.1 " + Conversions.ToString(proxyPort), "");
            else if (protocol == "SSL")
                ovpn.AppendDirective("remote", "127.0.0.1 " + Conversions.ToString(proxyPort), "");
            else
                ovpn.AppendDirective("remote", ip + " " + port.ToString(), "");

            string routesDefault = Engine.Instance.Storage.Get("routes.default");
            if (routesDefault == "in")
            {
                if ((protocol == "SSH") || (protocol == "SSL"))
                {
                    ovpn.AppendDirective("route", ip + " 255.255.255.255 net_gateway", "VPN Entry IP");
                }
            }

            ovpn.Protocol = protocol;
            ovpn.Address = ip;
            ovpn.Port = port;
            ovpn.ProxyPort = proxyPort;
        }
Esempio n. 6
0
        public override void OnBuildOvpn(OvpnBuilder ovpn)
        {
            base.OnBuildOvpn(ovpn);

            // Move here AirVPN specific of Session thread (protocol, remote, alt, port, proxy)

            ServerInfo CurrentServer = Engine.Instance.CurrentServer;

            string protocol  = Engine.Instance.Storage.Get("mode.protocol").ToUpperInvariant();
            int    port      = Engine.Instance.Storage.GetInt("mode.port");
            int    alt       = Engine.Instance.Storage.GetInt("mode.alt");
            int    proxyPort = 0;

            if (protocol == "AUTO")
            {
                protocol = CurrentServer.Provider.GetKeyValue("mode_protocol", "UDP");
                string proxyMode = Engine.Instance.Storage.GetLower("proxy.mode");
                if (proxyMode != "none")
                {
                    protocol = "TCP";
                }
                port = Conversions.ToInt32(CurrentServer.Provider.GetKeyValue("mode_port", "443"));
                alt  = Conversions.ToInt32(CurrentServer.Provider.GetKeyValue("mode_alt", "0"));
            }

            if (protocol == "SSH")
            {
                proxyPort = Engine.Instance.Storage.GetInt("ssh.port");
                if (proxyPort == 0)
                {
                    proxyPort = RandomGenerator.GetInt(1024, 64 * 1024);
                }
            }
            else if (protocol == "SSL")
            {
                proxyPort = Engine.Instance.Storage.GetInt("ssl.port");
                if (proxyPort == 0)
                {
                    proxyPort = RandomGenerator.GetInt(1024, 64 * 1024);
                }
            }
            else
            {
                proxyPort = 0;
            }

            if (protocol == "UDP")
            {
                ovpn.AppendDirective("proto", "udp", "");
            }
            else // TCP, SSH, SSL, Tor
            {
                ovpn.AppendDirective("proto", "tcp", "");
            }

            string ip = CurrentServer.IpEntry;

            if (alt == 1)
            {
                ip = CurrentServer.IpEntry2;
            }

            if (protocol == "SSH")
            {
                ovpn.AppendDirective("remote", "127.0.0.1 " + Conversions.ToString(proxyPort), "");
            }
            else if (protocol == "SSL")
            {
                ovpn.AppendDirective("remote", "127.0.0.1 " + Conversions.ToString(proxyPort), "");
            }
            else
            {
                ovpn.AppendDirective("remote", ip + " " + port.ToString(), "");
            }

            string routesDefault = Engine.Instance.Storage.Get("routes.default");

            if (routesDefault == "in")
            {
                if ((protocol == "SSH") || (protocol == "SSL"))
                {
                    ovpn.AppendDirective("route", ip + " 255.255.255.255 net_gateway", "VPN Entry IP");
                }
            }


            ovpn.Protocol  = protocol;
            ovpn.Address   = ip;
            ovpn.Port      = port;
            ovpn.ProxyPort = proxyPort;
        }
Esempio n. 7
0
        public override void OnBuildConnectionActive(ConnectionInfo connection, ConnectionActive connectionActive)
        {
            base.OnBuildConnectionActive(connection, connectionActive);

            OvpnBuilder    ovpn = connectionActive.OpenVpnProfileStartup;
            ConnectionMode mode = GetMode();

            if (mode.Protocol == "SSH")
            {
                connectionActive.SshLocalPort       = Engine.Instance.Storage.GetInt("ssh.port");
                connectionActive.SshRemotePort      = mode.Port;
                connectionActive.SshPortDestination = mode.SshPortDestination;
                if (connectionActive.SshLocalPort == 0)
                {
                    connectionActive.SshLocalPort = RandomGenerator.GetInt(1024, 64 * 1024);
                }
            }
            else if (mode.Protocol == "SSL")
            {
                connectionActive.SslLocalPort  = Engine.Instance.Storage.GetInt("ssl.port");
                connectionActive.SslRemotePort = mode.Port;
                if (connectionActive.SslLocalPort == 0)
                {
                    connectionActive.SslLocalPort = RandomGenerator.GetInt(1024, 64 * 1024);
                }
            }

            {
                string modeDirectives    = mode.Directives;
                string paramUserTA       = "";
                string paramUserTlsCrypt = "";
                if (User != null)
                {
                    paramUserTA       = UtilsXml.XmlGetAttributeString(User, "ta", "");
                    paramUserTlsCrypt = UtilsXml.XmlGetAttributeString(User, "tls_crypt", "");
                }
                modeDirectives = modeDirectives.Replace("{@user-ta}", paramUserTA);
                modeDirectives = modeDirectives.Replace("{@user-tlscrypt}", paramUserTlsCrypt);
                ovpn.AppendDirectives(modeDirectives, "Mode level");
            }

            // Pick the IP
            IpAddress ip           = null;
            string    entryIpLayer = Engine.Instance.Storage.Get("network.entry.iplayer");

            if (entryIpLayer == "ipv6-ipv4")
            {
                ip = connection.IpsEntry.GetV6ByIndex(mode.EntryIndex);
                if (ip == null)
                {
                    ip = connection.IpsEntry.GetV4ByIndex(mode.EntryIndex);
                }
            }
            else if (entryIpLayer == "ipv4-ipv6")
            {
                ip = connection.IpsEntry.GetV4ByIndex(mode.EntryIndex);
                if (ip == null)
                {
                    ip = connection.IpsEntry.GetV6ByIndex(mode.EntryIndex);
                }
            }
            else if (entryIpLayer == "ipv6-only")
            {
                ip = connection.IpsEntry.GetV6ByIndex(mode.EntryIndex);
            }
            else if (entryIpLayer == "ipv4-only")
            {
                ip = connection.IpsEntry.GetV4ByIndex(mode.EntryIndex);
            }

            if (ip != null)
            {
                IpAddress remoteAddress = ip.Clone();
                int       remotePort    = mode.Port;

                if (mode.Protocol == "SSH")
                {
                    remoteAddress = "127.0.0.1";
                    remotePort    = connectionActive.SshLocalPort;
                }
                else if (mode.Protocol == "SSL")
                {
                    remoteAddress = "127.0.0.1";
                    remotePort    = connectionActive.SslLocalPort;
                }

                ovpn.AppendDirective("remote", remoteAddress.Address + " " + remotePort.ToString(), "");

                // Adjust the protocol
                OvpnBuilder.Directive dProto = ovpn.GetOneDirective("proto");
                if (dProto != null)
                {
                    dProto.Text = dProto.Text.ToLowerInvariant();
                    if (dProto.Text == "tcp")
                    {
                        if (remoteAddress.IsV6)
                        {
                            dProto.Text = "tcp6";
                        }
                    }
                    else if (dProto.Text == "udp")
                    {
                        if (remoteAddress.IsV6)
                        {
                            dProto.Text = "udp6";
                        }
                    }
                }

                if ((mode.Protocol == "SSH") || (mode.Protocol == "SSL"))
                {
                    if (Constants.FeatureIPv6ControlOptions)
                    {
                        if (((ip.IsV4) && (connectionActive.TunnelIPv4)) ||
                            ((ip.IsV6) && (connectionActive.TunnelIPv6)))
                        {
                            connectionActive.AddRoute(ip, "net_gateway", "VPN Entry IP");
                        }
                    }
                    else
                    {
                        string routesDefault = Engine.Instance.Storage.Get("routes.default");
                        if (routesDefault == "in")
                        {
                            connectionActive.AddRoute(ip, "net_gateway", "VPN Entry IP");
                        }
                    }
                }
            }

            connectionActive.Protocol = mode.Protocol;
            if (ip != null)
            {
                connectionActive.Address = ip.Clone();
            }
        }
Esempio n. 8
0
        public override void OnBuildOvpn(OvpnBuilder ovpn)
        {
            base.OnBuildOvpn(ovpn);

            ovpn.AppendDirective("route-delay", "5", "");             // 2.8, to resolve some issue on some distro, ex. Fedora 21
        }
Esempio n. 9
0
        public override void OnBuildOvpn(ConnectionInfo connection, OvpnBuilder ovpn)
        {
            base.OnBuildOvpn(connection, ovpn);

            ConnectionMode mode = GetMode();

            int proxyPort = 0;

            if (mode.Protocol == "SSH")
            {
                proxyPort = Engine.Instance.Storage.GetInt("ssh.port");
                if (proxyPort == 0)
                {
                    proxyPort = RandomGenerator.GetInt(1024, 64 * 1024);
                }
            }
            else if (mode.Protocol == "SSL")
            {
                proxyPort = Engine.Instance.Storage.GetInt("ssl.port");
                if (proxyPort == 0)
                {
                    proxyPort = RandomGenerator.GetInt(1024, 64 * 1024);
                }
            }
            else
            {
                proxyPort = 0;
            }

            {
                string modeDirectives = mode.Directives;
                string paramUserTA    = "";
                if (User != null)
                {
                    paramUserTA = Utils.XmlGetAttributeString(User, "ta", "");
                }
                modeDirectives = modeDirectives.Replace("{@user-ta}", paramUserTA);
                ovpn.AppendDirectives(modeDirectives, "Mode level");
            }

            // Pick the IP
            IpAddress ip            = null;
            string    protocolEntry = Engine.Instance.Storage.Get("protocol.ip.entry");

            if (protocolEntry == "ipv6-ipv4")
            {
                ip = connection.IpsEntry.GetV6ByIndex(mode.EntryIndex);
                if (ip == null)
                {
                    ip = connection.IpsEntry.GetV4ByIndex(mode.EntryIndex);
                }
            }
            else if (protocolEntry == "ipv4-ipv6")
            {
                ip = connection.IpsEntry.GetV4ByIndex(mode.EntryIndex);
                if (ip == null)
                {
                    ip = connection.IpsEntry.GetV6ByIndex(mode.EntryIndex);
                }
            }
            else if (protocolEntry == "ipv6-only")
            {
                ip = connection.IpsEntry.GetV6ByIndex(mode.EntryIndex);
            }
            else if (protocolEntry == "ipv4-only")
            {
                ip = connection.IpsEntry.GetV4ByIndex(mode.EntryIndex);
            }

            if (ip != null)
            {
                if (mode.Protocol == "SSH")
                {
                    ovpn.AppendDirective("remote", "127.0.0.1 " + Conversions.ToString(proxyPort), "");
                }
                else if (mode.Protocol == "SSL")
                {
                    ovpn.AppendDirective("remote", "127.0.0.1 " + Conversions.ToString(proxyPort), "");
                }
                else
                {
                    ovpn.AppendDirective("remote", ip.AddressQ + " " + mode.Port.ToString(), "");
                }

                string routesDefault = Engine.Instance.Storage.Get("routes.default");
                if (routesDefault == "in")
                {
                    if ((mode.Protocol == "SSH") || (mode.Protocol == "SSL"))
                    {
                        ovpn.AppendDirective("route", ip.ToOpenVPN() + " net_gateway", "VPN Entry IP");                         // ClodoIPv6 // ToFix
                    }
                }
            }

            ovpn.Protocol  = mode.Protocol; // TOCLEAN
            ovpn.Address   = ip;
            ovpn.Port      = mode.Port;
            ovpn.ProxyPort = proxyPort;
        }