Esempio n. 1
0
        public Task Connect(VpnConnectionRequestContract connectionRequest)
        {
            Ensure.NotNull(connectionRequest, nameof(connectionRequest));

            _logger.Info("Connect requested");

            _serviceSettings.Apply(connectionRequest.Settings);

            var endpoints   = Map(connectionRequest.Servers);
            var protocol    = Map(connectionRequest.Protocol);
            var credentials = Map(connectionRequest.Credentials);
            var config      = Map(connectionRequest.VpnConfig);
            NetworkSettingsConfig settingsConfig = new NetworkSettingsConfig
            {
                AddDefaultGatewayForTap = !connectionRequest.Settings.PortForwardingEnabled
            };

            if (_networkSettings.ApplyNetworkSettings(settingsConfig))
            {
                _vpnConnection.Connect(
                    endpoints,
                    config,
                    protocol,
                    credentials);
            }
            else
            {
                CallbackStateChanged(new VpnState(VpnStatus.Disconnected, VpnError.NoTapAdaptersError));
            }

            return(Task.CompletedTask);
        }
Esempio n. 2
0
        public async Task Connect(VpnConnectionRequest request)
        {
            Ensure.NotNull(request, nameof(request));

            VpnConnectionRequestContract contract = Map(request);

            await _vpnService.Connect(contract);
        }
        public void ItShouldThrowWhenKeysAreIncorrect()
        {
            // Arrange
            VpnConnectionRequestContract contract = GetConnectionRequestContract();

            // Act
            IList <ValidationResult> result = contract.Validate(new ValidationContext(this)).ToList();

            // Assert
            result.Should().Contain(c => c.ErrorMessage.Contains("Invalid server IP address"));
            result.Should().Contain(c => c.ErrorMessage.Contains($"Incorrect key length {PublicKey.Length}"));
            result.Should().Contain(c => c.ErrorMessage.Contains($"Incorrect key length {PrivateKey.Length}"));
            result.Should().Contain(c => c.ErrorMessage.Contains($"Incorrect key length {ServerPublicKey.Length}"));
        }
Esempio n. 4
0
        public Task Connect(VpnConnectionRequestContract connectionRequest)
        {
            Ensure.NotNull(connectionRequest, nameof(connectionRequest));

            _logger.Info("Connect requested");

            _serviceSettings.Apply(connectionRequest.Settings);

            var endpoints   = Map(connectionRequest.Servers);
            var protocol    = Map(connectionRequest.Protocol);
            var credentials = Map(connectionRequest.Credentials);
            var config      = Map(connectionRequest.VpnConfig);

            _vpnConnection.Connect(
                endpoints,
                config,
                protocol,
                credentials);

            return(Task.CompletedTask);
        }