【发布时间】:2019-12-19 16:10:35
【问题描述】:
我在 uwp 中使用我的测试证书。我不知道哪里出了问题,所以这就是我在这里的原因。
我的步骤:
1、打开Package.appxmanifest,进入Capabilities,查看Shared User Certificates。
2,转到声明,选择证书并添加它。在右侧区域,单击 Add New,在 Store name 字段中,我选择了 Trusted Root Certifacte Authorities(其实我不知道这个字段是什么意思,选择哪个)。在内容字段中,我选择我的 pfx/p12 文件。
3、在mainpage.xaml.cs中,
StorageFile certificateFile = await Package.Current.InstalledLocation.GetFileAsync(@"client.p12");
IBuffer certificateBuffer = await FileIO.ReadBufferAsync(certificateFile);
string encodedCertificate = Windows.Security.Cryptography.CryptographicBuffer.EncodeToBase64String(certificateBuffer);
await CertificateEnrollmentManager.ImportPfxDataAsync(encodedCertificate, "000000", ExportOption.NotExportable, KeyProtectionLevel.NoConsent, InstallOptions.None, "Client Certificate");
var handler = new HttpClientHandler();
handler.ClientCertificateOptions = ClientCertificateOption.Manual;
handler.SslProtocols = System.Security.Authentication.SslProtocols.Tls12 | System.Security.Authentication.SslProtocols.Tls11 | System.Security.Authentication.SslProtocols.Tls;
handler.ServerCertificateCustomValidationCallback =
(httpRequestMessage, cert, cetChain, policyErrors) =>
{
return true;
};
HttpClient client = new HttpClient(handler);
//HttpResponseMessage response = await client.GetAsync("https://test.client.ssl/");
HttpResponseMessage response = await client.GetAsync("https://192.168.101.99/");
response.EnsureSuccessStatusCode();
string temp = await response.Content.ReadAsStringAsync();
4,构建并运行。
我收到错误:
Severity Code Description Project File Line Suppression State
Error DEP0700: Registration of the app failed. [0x80073CF6] AppxManifest.xml (41,10):
Error 0x80092009: Unable to register b17011a8-22d6-4a6a-bdb9-4a42390c9639_1.0.0.0_x86__701p3ryg2e8g6 package,
because trying to open and evaluate the client. When adding a p12 certificate to the root store,
I encountered the following error: The requested object could not be found.
【问题讨论】: