【问题标题】:How to trust a self-signed certificate in a windows store app如何信任 Windows 商店应用程序中的自签名证书
【发布时间】:2023-04-11 00:27:01
【问题描述】:

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

编辑: 我实现了此处记录的方法:Installing certs by using the appmanifest

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

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

  <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>

但这仍然不起作用。

我已尝试将应用程序证书放入“根”StoreName,但仍然没有成功。请问有谁知道为什么这可能不起作用?

【问题讨论】:

  • 我也想知道这个问题的解决方法。我也尝试在 appxmanifest 中添加公共 .cer 文件,但没有任何运气。
  • @pkumar0 这是一个不同的问题

标签: windows-store-apps


【解决方案1】:

这个有点老了,但是看到有很多观察者我会给出我的解决方案。

// Create the httpClient and send the request
HttpBaseProtocolFilter aHBPF = new HttpBaseProtocolFilter();
// If you want to ignore expired Certs
aHBPF.IgnorableServerCertificateErrors.Add(ChainValidationResult.Expired);
// Untrused because this is a self signed cert that is not installed
aHBPF.IgnorableServerCertificateErrors.Add(ChainValidationResult.Untrusted);
// Host names and certs names may not match
aHBPF.IgnorableServerCertificateErrors.Add(ChainValidationResult.InvalidName);

HttpClient httpClient = new HttpClient(aHBPF);
HttpResponseMessage response = await httpClient.SendRequestAsync(httpRequest, HttpCompletionOption.ResponseHeadersRead).AsTask(cts.Token);

【讨论】:

  • NeO 感谢这一点,它看起来是一个有趣的解决方案,并且很好地使用了框架。我既没有这个项目也没有时间对此做任何事情。如果其他人可以尝试确认它是否有效,那么我可以将其标记为答案。
【解决方案2】:

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

<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>

您现在可以使用它访问您背后的代码

//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();

       }

查看链接以供参考 help

【讨论】:

    【解决方案3】:

    如果您将 cer 文件放到项目根目录并将清单文件中的 Content 部分更改为 Content="file.cer" ,它将起作用

    【讨论】:

    • 我没有可用的项目,所以我无法对此进行测试。也许其他人可以试试这个看看
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-12-23
    • 2011-07-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-06-04
    相关资源
    最近更新 更多