如何信任 Windows 商店应用程序中的自签名证书 [英] How to trust a self-signed certificate in a windows store app

查看:54
本文介绍了如何信任 Windows 商店应用程序中的自签名证书的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试覆盖 Windows 应用商店应用中的证书验证以接受两个外部服务(使用 HttpClient)上的自签名证书,以允许 Windows 8 应用接受证书并为 SSL 建立信任关系

我实现了这里记录的方法:安装证书使用应用程序清单

并将相关的 .cer 文件添加到我的应用程序中,并确保它们是内容"和始终复制".

我的 package.appxmanifest Extensions 部分如下所示:

 <扩展><扩展类别="windows.certificates"><证书><Certificate StoreName="TrustedPeople" Content="Assets\ReportingServices.cer"/><Certificate StoreName="TrustedPeople" Content="Assets\Crm.cer"/><Certificate StoreName="CA" Content="Assets\DigiCertHighAssurance.cer"/><TrustFlags ExclusiveTrust="true"/><SelectionCriteria AutoSelect="true"/></证书></扩展>

但这仍然不起作用.

我尝试将应用程序证书放在根"StoreName 中,但仍然没有成功.有没有人知道为什么这可能不起作用?

解决方案

只是为了节省您的时间.我必须通过 2 天的反复试验来解决这个问题.在这里你可以解决它.将 .cer 文件添加到您的项目中,将构建操作设为内容",复制为较新然后将此添加到您的应用清单

<能力名称="sharedUserCertificates"/><Capability Name="enterpriseAuthentication"/><Capability Name="privateNetworkClientServer"/><能力名称="internetClient"/></能力><扩展><扩展类别="windows.certificates"><证书><Certificate StoreName="Root" Content="Certificates\vibeapi.cer"/><TrustFlags ExclusiveTrust="true"/><SelectionCriteria AutoSelect="true"/></证书></扩展></扩展>

和你后面的代码,你现在可以使用这个访问文件

//测试https连接HttpClientHandler msgHandler = new HttpClientHandler();使用 (System.Net.Http.HttpClient httpClient = new System.Net.Http.HttpClient(msgHandler, true)){var HTTPSURL = new Uri("https://www.sample.net/");var response = await httpClient.GetAsync(HTTPSURL);var responseStr = await response.Content.ReadAsStringAsync();}

见链接以供参考帮助

I am trying to override the certificate validation in a Windows Store App to accept a self-signed certificate on two external services (using HttpClient) to allow the Windows 8 app to accept the certificates and establish a trust relationship for SSL

EDIT: I implemented the approach documented here : Installing certs by using the appmanifest

and added the relevant .cer files to my application and ensured they are 'Content' and 'Copy Always'.

My package.appxmanifest Extensions section looks like this:

  <Extensions>
<Extension Category="windows.certificates">
  <Certificates>
    <Certificate StoreName="TrustedPeople" Content="Assets\ReportingServices.cer" />
    <Certificate StoreName="TrustedPeople" Content="Assets\Crm.cer" />
    <Certificate StoreName="CA" Content="Assets\DigiCertHighAssurance.cer" />
    <TrustFlags ExclusiveTrust="true" />
    <SelectionCriteria AutoSelect="true" />
  </Certificates>
</Extension>

but this still does not work.

I have tried putting the app certificates in the 'Root' StoreName but still no success. Does anyone have any ideas why this might not work please?

解决方案

Just to save your time. I got to resolve this for 2 days of trial and error. Here you can solve it. Add the .cer file to your project, Make the build action as "Content", copy as newer then add this to your app manifest

<Capabilities>
    <Capability Name="sharedUserCertificates" />
    <Capability Name="enterpriseAuthentication" />
    <Capability Name="privateNetworkClientServer" />
    <Capability Name="internetClient" />
</Capabilities>


<Extensions>
<Extension Category="windows.certificates">
  <Certificates>
    <Certificate StoreName="Root" Content="Certificates\vibeapi.cer" />
      <TrustFlags ExclusiveTrust="true" />
       <SelectionCriteria AutoSelect="true" />
    </Certificates>
  </Extension>
</Extensions>

and to your code behind you can now access the file using this

//Testing https connection
HttpClientHandler msgHandler = new HttpClientHandler();

using (System.Net.Http.HttpClient httpClient = new System.Net.Http.HttpClient(msgHandler, true))
       {
          var HTTPSURL = new Uri("https://www.sample.net/");


       var response = await httpClient.GetAsync(HTTPSURL);
       var responseStr = await response.Content.ReadAsStringAsync();

       }

see link for reference help

这篇关于如何信任 Windows 商店应用程序中的自签名证书的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆