Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to trust a self-signed certificate in a windows store app

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?

like image 571
Redeemed1 Avatar asked Oct 29 '12 10:10

Redeemed1


People also ask

How do I trust a self-signed certificate in Windows?

Import the self-signed certificate to the client Windows computer. On the Windows computer, start MMC (mmc.exe). Add the Certificates snap-in for the computer account and manage certificates for the local computer. Import the self-signed certificate into Trusted Root Certification Authorities > Certificates.

Can self-signed certificate be trusted?

Self-signed certificates are safe in a testing environment, and you can use them while you are waiting for your certificates officially signed by CAs. But, using them in a production environment leaves the systems exposed to vulnerabilities and security breaches.

Why is a self-signed certificate not trustworthy?

Self-signed certificates aren't trusted by browsers because they are generated by your server, not by a CA. You can tell if a certificate is self-signed if a CA is not listed in the issuer field in our SSL Certificate tester.


1 Answers

This is a bit of old one, but seeing as there are quite a few watchers I will give my solution.

// 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);
like image 134
Ne0 Avatar answered Sep 24 '22 10:09

Ne0