I am creating a Portable Class Library which means I must use System.Net.Http.HttpClient to call my web APIs as far as I understand. The challenge is that for my Universal Windows App, I cannot figure out how to ignore the error that is returned due to the fact the fact the API server can have a self signed certificate. Any suggestions would be greatly appreciated.
UPDATE: I cannot import any certificates as this will be an application that runs on various devices in various organizations and is not practical to have them import a self signed certificate onto every device running the application.
We configure a custom HttpClient. We begin by setting up an SSLContext using the SSLContextBuilder and use the TrustSelfSignedStrategy class to allow self signed certificates. Using the NoopHostnameVerifier essentially turns hostname verification off.
If you use Windows.Web.Http.HttpClient instead, then you can ignore self signed certificates. In a second thought, you can ignore self signed certificate errors if you add it to the root certificates of the app.
Not an option since System.Net.ServicePointManager.CertificatePolicy is not available in UWP. If you use Windows.Web.Http.HttpClient instead, then you can ignore self signed certificates. In a second thought, you can ignore self signed certificate errors if you add it to the root certificates of the app.
In this guide, you'll cover using self-signed certificates with dotnet dev-certs, and other options like PowerShell and OpenSSL. You can then validate that the certificate will load using an example such as an ASP.NET Core app hosted in a container.
Not an option since System.Net.ServicePointManager.CertificatePolicy
is not available in UWP. If you use Windows.Web.Http.HttpClient
instead, then you can ignore self signed certificates.
UPDATE:
In a second thought, you can ignore self signed certificate errors if you add it to the root certificates of the app.
Two options:
Install it with APIs:
IBuffer buffer = await FileIO.ReadBufferAsync(file);
Certificate rootCert = new Certificate(buffer);
CertificateStore rootStore = CertificateStores.TrustedRootCertificationAuthorities;
rootStore.Add(rootCert);
Include it in you Package.appxmanifest > Declarations > Certificates > Add and set:
With any of both options, you will stop getting:
System.Net.WebException: The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel. ---> System.Security.Authentication.AuthenticationException: The remote certificate is invalid according to the validation procedure.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With