Exemplo n.º 1
0
        public void Connect(IReadOnlyList <VpnHost> servers, VpnConfig config, VpnProtocol protocol,
                            VpnCredentials credentials)
        {
            ApplyNetworkSettings();

            _origin.Connect(servers, config, protocol, credentials);
        }
Exemplo n.º 2
0
        public virtual bool Changed(VpnProtocol vpnProtocol)
        {
            bool childChanged = false;

            foreach (Setting child in GetChildren())
            {
                if (child.Changed(vpnProtocol))
                {
                    childChanged = true;
                    break;
                }
            }

            if (childChanged)
            {
                if (_appSettings.GetType().GetProperty(Name)?.PropertyType == typeof(bool))
                {
                    return(!_reverted);
                }

                return(true);
            }

            return(Value != GetSettingValueSerialized());
        }
Exemplo n.º 3
0
        public void Connect(IReadOnlyList <VpnHost> servers, VpnConfig config, VpnProtocol protocol,
                            VpnCredentials credentials)
        {
            AddDefaultGateway();

            _origin.Connect(servers, config, protocol, credentials);
        }
Exemplo n.º 4
0
 public VpnState(VpnStatus status, string entryIp, VpnProtocol protocol, string label = "")
 {
     Status   = status;
     EntryIp  = entryIp;
     Protocol = protocol;
     Label    = label;
 }
Exemplo n.º 5
0
        private static VpnStateChangedEventArgs Map(VpnStateContract contract)
        {
            VpnStatus   status   = Map(contract.Status);
            VpnError    error    = Map(contract.Error);
            VpnProtocol protocol = Map(contract.VpnProtocol);

            return(new(status, error, contract.EndpointIp, contract.NetworkBlocked, protocol, contract.OpenVpnAdapterType, contract.Label));
        }
Exemplo n.º 6
0
        private static VpnStateChangedEventArgs Map(VpnStateContract contract)
        {
            VpnStatus   status   = Map(contract.Status);
            VpnError    error    = Map(contract.Error);
            VpnProtocol protocol = Map(contract.Protocol);

            return(new VpnStateChangedEventArgs(status, error, contract.EndpointIp, contract.NetworkBlocked, protocol));
        }
Exemplo n.º 7
0
 public VpnState(VpnStatus status, string entryIp, VpnProtocol vpnProtocol, OpenVpnAdapter?networkAdapterType = null, string label = "")
 {
     Status             = status;
     EntryIp            = entryIp;
     NetworkAdapterType = networkAdapterType;
     VpnProtocol        = vpnProtocol;
     Label = label;
 }
Exemplo n.º 8
0
 public VpnState(VpnStatus status, VpnError error, string localIp, string remoteIp, VpnProtocol protocol = VpnProtocol.Auto)
 {
     Status   = status;
     Error    = error;
     LocalIp  = localIp;
     RemoteIp = remoteIp;
     Protocol = protocol;
 }
Exemplo n.º 9
0
        private ProtocolType MapProtocolType(VpnProtocol protocol)
        {
            if (protocol == VpnProtocol.OpenVpnTcp)
            {
                return(ProtocolType.Tcp);
            }

            return(ProtocolType.Udp);
        }
Exemplo n.º 10
0
 private static VpnProtocolContract Map(VpnProtocol protocol)
 {
     return(protocol switch
     {
         VpnProtocol.OpenVpnUdp => VpnProtocolContract.OpenVpnUdp,
         VpnProtocol.OpenVpnTcp => VpnProtocolContract.OpenVpnTcp,
         VpnProtocol.WireGuard => VpnProtocolContract.WireGuard,
         VpnProtocol.Smart => VpnProtocolContract.Smart,
     });
Exemplo n.º 11
0
        public VpnStateChangedEventArgs(VpnState state, VpnError error, bool networkBlocked, VpnProtocol protocol = VpnProtocol.Auto)
        {
            Ensure.NotNull(state, nameof(state));

            State          = state;
            Error          = error;
            NetworkBlocked = networkBlocked;
            Protocol       = protocol;
        }
Exemplo n.º 12
0
        private SocketType MapSocketType(VpnProtocol protocol)
        {
            if (protocol == VpnProtocol.OpenVpnUdp)
            {
                return(SocketType.Dgram);
            }

            return(SocketType.Stream);
        }
        private void OnVpnProtocolChanged(VpnProtocol vpnProtocol)
        {
            bool isPreviousProtocolObfuscated;

            if ((isPreviousProtocolObfuscated = UserSettings.IsObfuscationProtocolEnabled(vpnProtocol)) ^ this._isPreviousProtocolObfuscated)
            {
                this.ReverseHandlersUrls();
            }
            this._isPreviousProtocolObfuscated = isPreviousProtocolObfuscated;
        }
Exemplo n.º 14
0
 public VpnState(VpnStatus status, VpnError error, string localIp, string remoteIp, VpnProtocol vpnProtocol, OpenVpnAdapter?openVpnAdapter = null, string label = "")
 {
     Status         = status;
     Error          = error;
     LocalIp        = localIp;
     RemoteIp       = remoteIp;
     OpenVpnAdapter = openVpnAdapter;
     VpnProtocol    = vpnProtocol;
     Label          = label;
 }
Exemplo n.º 15
0
 public void OnAppSettingsChanged(PropertyChangedEventArgs e)
 {
     if (e.PropertyName == nameof(IAppSettings.OvpnProtocol) &&
         _lastVpnProtocol == VpnProtocol.WireGuard && _appSettings.GetProtocol() != VpnProtocol.WireGuard ||
         _lastVpnProtocol != VpnProtocol.WireGuard && _appSettings.GetProtocol() == VpnProtocol.WireGuard)
     {
         _updateAction.Run();
         _lastVpnProtocol = _appSettings.GetProtocol();
     }
 }
Exemplo n.º 16
0
 public VpnConnectionRequest(
     IReadOnlyList <VpnHost> servers,
     VpnProtocol protocol,
     VpnConfig config,
     VpnCredentials credentials)
 {
     Servers     = servers;
     Protocol    = protocol;
     Config      = config;
     Credentials = credentials;
 }
Exemplo n.º 17
0
        public void Enumerable_ShouldThrow_WhenProtocolIsNotSupported(VpnProtocol protocol)
        {
            // Arrange
            var endpoint = new VpnEndpoint(new VpnHost("abc.com", "1.2.3.4", string.Empty), protocol, 54321);
            var subject  = new EndpointArguments(endpoint);

            // Act
            Action action = () => subject.ToList();

            // Assert
            action.Should().Throw <ArgumentException>();
        }
Exemplo n.º 18
0
        public void Enumerable_ShouldMap_VpnProtocol(VpnProtocol protocol, string expected)
        {
            // Arrange
            var endpoint = new VpnEndpoint(new VpnHost("abc.com", "7.7.7.7", string.Empty), protocol, 44444);
            var subject  = new EndpointArguments(endpoint);

            // Act
            var result = subject.ToList();

            // Assert
            result.Should().Contain($"--remote {endpoint.Server.Ip} {endpoint.Port} {expected}");
        }
Exemplo n.º 19
0
        public void Connect(IReadOnlyList <VpnHost> servers, VpnConfig config, VpnProtocol protocol, VpnCredentials credentials)
        {
            _servers     = servers;
            _config      = config;
            _protocol    = protocol;
            _credentials = credentials;

            _connectRequested     = true;
            _disconnectedReceived = false;

            Queued(Connect);
        }
Exemplo n.º 20
0
        public INetworkInterface GetByVpnProtocol(VpnProtocol vpnProtocol, OpenVpnAdapter?openVpnAdapter)
        {
            if (vpnProtocol == VpnProtocol.WireGuard)
            {
                return(GetWireGuardTunInterface());
            }

            return(openVpnAdapter switch
            {
                OpenVpnAdapter.Tap => GetOpenVpnTapInterface(),
                OpenVpnAdapter.Tun => GetOpenVpnTunInterface(),
                _ => new NullNetworkInterface()
            });
Exemplo n.º 21
0
        private async Task Connect(IEnumerable <Server> servers, VpnProtocol protocol)
        {
            var request = new VpnConnectionRequest(
                Servers(servers),
                protocol,
                VpnConfig(),
                _vpnCredentialProvider.Credentials());

            await _vpnServiceManager.Connect(request);

            _logger.Info("Connect requested");
            _modals.CloseAll();
        }
Exemplo n.º 22
0
        private string OpenVpnProtocol(VpnProtocol protocol)
        {
            switch (protocol)
            {
            case VpnProtocol.OpenVpnUdp:
                return("udp");

            case VpnProtocol.OpenVpnTcp:
                return("tcp");
            }

            throw new ArgumentException(nameof(protocol));
        }
Exemplo n.º 23
0
        public override bool Changed(VpnProtocol vpnProtocol)
        {
            bool changed = base.Changed(vpnProtocol);

            if (_customDnsIpSetting.GetSettingValueSerialized() != _customDnsIpSetting.Value)
            {
                if (_appSettings.CustomDnsIps.Length == 0)
                {
                    return(true);
                }
            }

            return(_appSettings.CustomDnsIps.Length != 0 && changed);
        }
Exemplo n.º 24
0
        private void ApplyNetworkSettings(VpnProtocol vpnProtocol, OpenVpnAdapter?openVpnAdapter)
        {
            uint interfaceIndex = _networkInterfaceLoader.GetByVpnProtocol(vpnProtocol, openVpnAdapter).Index;

            try
            {
                _logger.Info("Setting interface metric...");
                NetworkUtil.SetLowestTapMetric(interfaceIndex);
                _logger.Info("Interface metric set.");
            }
            catch (NetworkUtilException e)
            {
                _logger.Error("Failed to apply network settings. Error code: " + e.Code);
            }
        }
Exemplo n.º 25
0
        public void Connect(IReadOnlyList <VpnHost> servers, VpnConfig config, VpnProtocol protocol, VpnCredentials credentials)
        {
            _reconnectPending = false;
            _reconnecting     = false;
            _disconnecting    = false;
            _protocol         = protocol;
            _credentials      = credentials;
            _config           = config;

            _candidates.Set(servers);
            _candidates.Reset();
            _endpoint = _candidates.Next(_protocol);

            _origin.Connect(_endpoint, credentials, config);
        }
Exemplo n.º 26
0
        private async Task <VpnEndpoint> BestEndpoint(VpnHost server, VpnProtocol protocol, CancellationToken cancellationToken)
        {
            switch (protocol)
            {
            case VpnProtocol.Auto:
                var bestEndpoint = await BestEndpoint(EndpointCandidates(server, VpnProtocol.OpenVpnUdp));

                if (bestEndpoint.Port == 0 && !cancellationToken.IsCancellationRequested)
                {
                    bestEndpoint = await BestEndpoint(EndpointCandidates(server, VpnProtocol.OpenVpnTcp));
                }
                return(bestEndpoint);

            default:
                return(await BestEndpoint(EndpointCandidates(server, protocol)));
            }
        }
Exemplo n.º 27
0
        public VpnEndpoint Next(VpnProtocol protocol)
        {
            if (!string.IsNullOrEmpty(Current.Server.Ip))
            {
                _skippedIps[protocol].Add(Current.Server.Ip);
            }

            var server = _all.FirstOrDefault(i => !_skippedIps[protocol].Contains(i.Ip));

            if (server.IsEmpty())
            {
                _skippedIps[protocol].Clear();
                server = _all.FirstOrDefault();
            }

            Current = Endpoint(server, protocol);

            return(Current);
        }
        private string GetVpnProtocol(VpnProtocol protocol)
        {
            switch (protocol)
            {
            case 0:
                return("udp");

            case 1:
                return("tcp");

            case 2:
                return("xorudp");

            case 3:
                return("xortcp");

            default:
                throw new NotSupportedException();
            }
        }
Exemplo n.º 29
0
        private void RestoreNetworkSettings(VpnProtocol vpnProtocol, OpenVpnAdapter?openVpnAdapter)
        {
            uint interfaceIndex = _networkInterfaceLoader.GetByVpnProtocol(vpnProtocol, openVpnAdapter).Index;

            if (interfaceIndex == 0)
            {
                return;
            }

            try
            {
                _logger.Info("Restoring interface metric...");
                NetworkUtil.RestoreDefaultTapMetric(interfaceIndex);
                _logger.Info("Interface metric restored.");
            }
            catch (NetworkUtilException e)
            {
                _logger.Error("Failed restore network settings. Error code: " + e.Code);
            }
        }
 public Task <string> GetConfigAsync(string domain, VpnProtocol protocol)
 {
     OpenVpnConfigsDownloadManager.< GetConfigAsync > d__7 <GetConfigAsync> d__;