UWP:无法创建新的 VPN 配置文件

UWP: Can't create a new VPN profile

我正在尝试在通用 windows 应用程序中创建新的 VPN 配置文件。 我正在使用 this api.

有两种记录的方法可以做到这一点。 AddProfileFromXmlAsync 和 AddProfileFromObjectAsync。对我来说不幸的是 none 它们都可以正常工作。

当我使用 AddProfileFromXmlAsync 时,我总是遇到 AccessDenied 错误。我在这个 thread that somehow it could be related to bad xml syntax but I get the same error also when I am using the exact xml in the Microsoft example.

上看到了

如果您仅提供 ProfileName,AddProfileFromObjectAsync 工作正常。否则它会失败并出现错误 Other。这对我来说还不够,因为我还需要配置 NativeProtocolType 属性。在我尝试添加新配置文件之前,我正在检查该配置文件是否已经存在,因此可以肯定我不会收到其他错误,因为该配置文件已经存在。

我正在将这些功能添加到我的应用清单中:

    <Capabilities>
        <Capability Name="internetClient" />
        <Capability Name="internetClientServer" />
        <Capability Name="privateNetworkClientServer" />
       <rescap:Capability Name="networkingVpnProvider" />
  </Capabilities>

有人知道问题出在哪里吗?

这是一个至少在 15063 上可用的示例(请注意,周年纪念更新中存在一个错误,导致 API 无法正常工作,因此请尝试使用 15063 或确保您拥有所有更新周年更新)

// Install key and cert
await 
CertificateEnrollmentManager.UserCertificateEnrollmentManager.ImportPfxDataAsync(PEMKey,
Password,
ExportOption.NotExportable,
KeyProtectionLevel.NoConsent,
InstallOptions.None,
"Test VPN");

VpnNativeProfile profile = new VpnNativeProfile();
profile.AlwaysOn = true;
profile.NativeProtocolType = VpnNativeProtocolType.IpsecIkev2;
profile.ProfileName = "Test VPN";
profile.RememberCredentials = false;
profile.RequireVpnClientAppUI = true;
profile.RoutingPolicyType = VpnRoutingPolicyType.ForceAllTrafficOverVpn;
profile.Servers.Add(Constants.ConcentratorDNSName);
profile.UserAuthenticationMethod = VpnAuthenticationMethod.Eap;
profile.EapConfiguration = File.ReadAllText("profile.xml");
VpnManagementAgent agent = new VpnManagementAgent();
await agent.AddProfileFromObjectAsync(profile);
VpnManagementErrorStatus status = await agent.ConnectProfileAsync(profile);

示例 EAP XML 配置可以在@ https://docs.microsoft.com/en-us/windows/client-management/mdm/eap-configuration

找到

同样不幸的是,VPNv2 CSP 中的 XML 与 API 中的不同。此外,在 Microsoft 的内部检查中,AddProfileFromXMLAsync 似乎存在错误,导致它无法工作。