Exemple #1
0
        public async Task Connect(VPNConnection conn)
        {
            VpnManagementAgent mgr = new VpnManagementAgent();

            VpnNativeProfile profile = new VpnNativeProfile()
            {
                AlwaysOn                   = true,
                NativeProtocolType         = VpnNativeProtocolType.Pptp,
                ProfileName                = conn.ConnectionName,
                RememberCredentials        = true,
                RequireVpnClientAppUI      = false,
                RoutingPolicyType          = VpnRoutingPolicyType.ForceAllTrafficOverVpn,
                TunnelAuthenticationMethod = VpnAuthenticationMethod.PresharedKey,
                UserAuthenticationMethod   = VpnAuthenticationMethod.PresharedKey
            };

            profile.Servers.Add(conn.ServerName);

            VpnManagementErrorStatus profileStatus = await mgr.AddProfileFromObjectAsync(profile);

            PasswordCredential credentials = new PasswordCredential
            {
                UserName = conn.UserName,
                Password = conn.Password,
            };

            VpnManagementErrorStatus connectStatus = await mgr.ConnectProfileWithPasswordCredentialAsync(profile, credentials);

            activeProfile = profile;
        }
Exemple #2
0
        public async Task <VpnManagementConnectionStatus> Connect(Server server)
        {
            VpnNativeProfile profile = new VpnNativeProfile()
            {
                AlwaysOn                   = true,
                NativeProtocolType         = VpnNativeProtocolType.IpsecIkev2,
                ProfileName                = Constants.connectionProfileName,
                RememberCredentials        = false,
                RequireVpnClientAppUI      = false,
                RoutingPolicyType          = VpnRoutingPolicyType.ForceAllTrafficOverVpn,
                TunnelAuthenticationMethod = VpnAuthenticationMethod.Eap,
                UserAuthenticationMethod   = VpnAuthenticationMethod.Eap,
                //load eap from xml placed at assembly folder
                EapConfiguration = File.ReadAllText(Path.Combine(Windows.ApplicationModel.Package.Current.Installed­Location.Path, @"profile.xml"))
            };

            profile.Servers.Add(server.serverAddress);

            PasswordCredential credentials = new PasswordCredential
            {
                UserName = server.eap_name,
                Password = server.eap_secret
            };

            VpnManagementErrorStatus profileStatus = await ManagementAgent.AddProfileFromObjectAsync(profile);

            if (profileStatus == VpnManagementErrorStatus.Ok)
            {
                VpnManagementErrorStatus connectStatus = await ManagementAgent.ConnectProfileWithPasswordCredentialAsync(profile, credentials);

                if (connectStatus == VpnManagementErrorStatus.Ok)
                {
                    ActiveProfile = profile;
                    return(profile.ConnectionStatus);
                }
                else
                {
                    throw new Exception("Connetion failed");
                }
            }
            else
            {
                throw new Exception("VPN profile add failed");
            }
        }
Exemple #3
0
        private async void OnAutoCheck(object sender, RoutedEventArgs e)
        {
            CheckBox checkBox = sender as CheckBox;

            if (checkBox.IsChecked.HasValue)
            {
                if (Profile.AlwaysOn == checkBox.IsChecked.Value)
                {
                    // It's already the right way around; ust return.
                    return;
                }
                Profile.AlwaysOn = checkBox.IsChecked.Value;
                VpnManagementAgent vpnManagementAgent = new VpnManagementAgent();
                var result = await vpnManagementAgent.UpdateProfileFromObjectAsync(Profile);

                VpnManagementErrorStatus errorStatus = result;
                var f = string.Format("{0} / {1}", errorStatus, errorStatus.ToString());
                Log($"{errorStatus}");
            }
        }
        public async Task DoConnect(Config.Server server)
        {
            profile.Servers.Add(server.serverAddress);

            VpnManagementErrorStatus status = await manager.AddProfileFromObjectAsync(profile);

            if (status != VpnManagementErrorStatus.Ok)
            {
                throw new Exception("VPN profile add failed. Status is " + status);
            }

            PasswordCredential credentials = new PasswordCredential
            {
                UserName = server.eap_name,
                Password = server.eap_secret,
            };

            status = await manager.ConnectProfileWithPasswordCredentialAsync(profile, credentials);

            if (status != VpnManagementErrorStatus.Ok)
            {
                throw new Exception("VPN profile delete failed. Status is " + status);
            }
        }