1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
|
public partial class MainForm : Form
{
bool verifssl;
DateTime time, time1;
public MainForm()
{
InitializeComponent();
verifssl = false;
}
//sur click du bouton start
void Bt_StartClick(object sender, EventArgs e)
{
ServicePointManager.ServerCertificateValidationCallback = ServerCertificateValidationCallback;
time = DateTime.Now;
timer.Start(); //on demarre les
timer1.Start(); //deux timers
lb_Start.Text = time.ToString("hh:mm:ss");
lb_Timer.Text = time.ToString("hh:mm:ss");
}
//sur click du bouton stop
void Bt_StopClick(object sender, EventArgs e)
{
timer.Stop();
timer1.Stop();
lb_Timer.Text = "";
lb_Start.Text = "";
lb_SSL.Text = "";
}
//le timer1 -> 1sec
void Timer1Tick(object sender, EventArgs e)
{
time1 = DateTime.Now;
lb_Timer.Text = time1.ToString("hh:mm:ss");
}
//le timer -> 5sec
void TimerTick(object sender, EventArgs e)
{
lb_SSL.Text = "checking . . .";
verifssl = ssl();// verification du ssl
if(verifssl)
lb_SSL.Text = "ca fonctionne";
else
lb_SSL.Text = "ca ne fonctionne pas";
}
bool ssl()
{
try
{
var request = WebRequest.Create("https://exemple.com:443");
var response = request.GetResponse();
return true;
}
catch
{
return false;
}
}
//callback du SSL
bool ServerCertificateValidationCallback(object sender, X509Certificate certificate,
X509Chain chain, SslPolicyErrors sslPolicyErrors)
{
string sN = certificate.GetSerialNumberString();
string Iss = certificate.Issuer.ToString();
string exp = certificate.GetExpirationDateString();
string serialNumber = "XXXXXXXXXXXXXXXXXXXXX";
string issuer = "CN=XXXXXXXXX CA, O=XXXX, C=XX";
string expiration = "XX/XX/XXXX XX:XX:XX";
if(sN != serialNumber || Iss != issuer || exp != expiration)
{
MessageBox.Show("probleme de certificat");
return false;
}
else
{
return true;
}
}
} |
Partager