75 lines
2.1 KiB
C#
75 lines
2.1 KiB
C#
//----------------------------------------------------------------------------
|
|
//
|
|
// 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
|
|
{
|
|
/// <summary>
|
|
/// Static functions for validating certificate issues
|
|
/// </summary>
|
|
public static class CertificateUtils
|
|
{
|
|
#region - Members -
|
|
|
|
public static string header, description;
|
|
public static bool UnsecureConnection;
|
|
public static X509Certificate2 ServerCert;
|
|
|
|
#endregion
|
|
|
|
#region - Methods -
|
|
|
|
/// <summary>
|
|
/// Validate the certificate
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
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;
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// Display a pop up indicating the certificate has error,
|
|
/// and allow him to choose if he want to continue the connection wih this machine.
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
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
|
|
}
|
|
}
|