//---------------------------------------------------------------------------- // // Copyright © 2009-2012, Intel Corporation. All rights reserved. // // File: CertificateUtils.cs // //---------------------------------------------------------------------------- using System; using UCT.Forms; using System.Windows.Forms; using System.Security.Cryptography.X509Certificates; namespace UCT.Utils { /// /// Static functions for validating certificate issues /// public static class CertificateUtils { #region - Members - public static string header, description; public static bool UnsecureConnection; public static X509Certificate2 ServerCert; #endregion #region - Methods - /// /// Validate the certificate /// /// public static bool ValidateCertificate() { UnsecureConnection = false; if (Configuration.HostNameMismatch == true) { header = "Hostname Mismatch"; description = "Mismatched Address.\nThe certificate you are using to connect is issued to a different address."; // Display the certificate error windows if (DisplayWarningWindow()) { return true; } return false; } return true; } /// /// Display a pop up indicating the certificate has error, /// and allow him to choose if he want to continue the connection wih this machine. /// /// private static bool DisplayWarningWindow() { using (CertWarning cw = new CertWarning(description)) { if (cw.ShowDialog() == DialogResult.Yes) { // Indicate if the connection has certificates issues UnsecureConnection = true; return true; } } return false; } #endregion } }