protected Task InitializeTrustedCertsAsync() { if (!string.IsNullOrEmpty(this.trustedCACertificateFileName)) { // Since Windows will pop up security warning when add certificate to current user store location; // Therefore we will use CustomCertificateValidator instead. if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { Console.WriteLine("Hook up callback on device transport settings to validate with given certificate"); CustomCertificateValidator.Create(new List <X509Certificate2> { this.GetTrustedCertificate() }, this.deviceTransportSettings); } else { Console.WriteLine("Install trusted CA certificates"); InstallTrustedCACerts(new List <X509Certificate2> { this.GetTrustedCertificate() }); } } // for dotnet runtime, in order to provide the entire client certificate chain when // authenticating with a server it is required that these chain CA certificates // are installed as trusted CAs. this.clientCertificateChain.ForEach(certs => InstallTrustedCACerts(certs)); return(Task.CompletedTask); }
public static CustomCertificateValidator Create( IList <X509Certificate2> certs, ITransportSettings[] transportSettings) { var instance = new CustomCertificateValidator(certs, transportSettings); instance.SetupCertificateValidation(); return(instance); }