From c95b421924fde0d6a1acbbf4efeaace312c732c1 Mon Sep 17 00:00:00 2001 From: John Cardinal Date: Mon, 8 Jul 2019 18:01:36 +0000 Subject: [PATCH] --- Controllers/OpsController.cs | 3 ++- util/OpsDiagnostics.cs | 47 ++++++++++++++++++++++++++++++++++++ util/RfMail.cs | 3 +++ 3 files changed, 52 insertions(+), 1 deletion(-) diff --git a/Controllers/OpsController.cs b/Controllers/OpsController.cs index 27dfc96..a77be77 100644 --- a/Controllers/OpsController.cs +++ b/Controllers/OpsController.cs @@ -39,6 +39,7 @@ namespace rockfishCore.Controllers break; case "AyaNovaSite": Ret.Status = OpsDiagnostics.CheckWebsite("https://www.ayanova.com/", "Ground Zero Tech-Works Inc."); + bool bssl = OpsDiagnostics.IsSSLCertAboutToExpire("https://www.ayanova.com"); break; case "APISite": Ret.Status = OpsDiagnostics.CheckWebsite("https://api.ayanova.com/", "WorkorderTypes Enumeration"); @@ -56,7 +57,7 @@ namespace rockfishCore.Controllers Ret.Status = OpsDiagnostics.CheckWebsite("http://svn.ayanova.com:3343/csvn/login/auth", "Subversion Edge"); break; case "Forum": - Ret.Status = OpsDiagnostics.CheckWebsite("http://forum.ayanova.com/", "AyaNova support resources"); + Ret.Status = OpsDiagnostics.CheckWebsite("http://forum.ayanova.com/", "AyaNova Known Issues & Updates"); break; case "DevOps": Ret.Status = OpsDiagnostics.CheckWebsite("https://test.helloayanova.com/api/v8/", "AyaNova server"); diff --git a/util/OpsDiagnostics.cs b/util/OpsDiagnostics.cs index c8cb9fd..2b771fd 100644 --- a/util/OpsDiagnostics.cs +++ b/util/OpsDiagnostics.cs @@ -4,6 +4,10 @@ using System.Linq; using System.Net.Http; using Amazon.S3; +//for ssl certs +using System.Security.Cryptography.X509Certificates; +using System.Threading.Tasks; + namespace rockfishCore.Util { public static class OpsDiagnostics @@ -36,6 +40,49 @@ namespace rockfishCore.Util } + /// + /// check if an ssl cert is within 10 days of expiry + /// + /// + /// + public static bool IsSSLCertAboutToExpire(string url) + { + var expires = GetServerCertificateExpiryAsync(url).Result; + //In 10 days will we be past the expiry date + var deadline = DateTime.Now.AddDays(10); + if (expires < deadline) + { + return true; + } + + return false; + } + + + + static async Task GetServerCertificateExpiryAsync(string url) + { + DateTime ret = DateTime.MinValue; + var httpClientHandler = new HttpClientHandler + { + ServerCertificateCustomValidationCallback = (_, cert, __, ___) => + { + ret = cert.NotAfter; + return true; + } + }; + + var httpClient = new HttpClient(httpClientHandler); + await httpClient.SendAsync(new HttpRequestMessage(HttpMethod.Head, url)); + + return ret; + } + + + + + + public static List GetFileListFromSpacesBackupStorage() { AmazonS3Config ClientConfig = new AmazonS3Config(); diff --git a/util/RfMail.cs b/util/RfMail.cs index 51e2897..b976c40 100644 --- a/util/RfMail.cs +++ b/util/RfMail.cs @@ -766,6 +766,9 @@ namespace rockfishCore.Util { // Accept all SSL certificates client.ServerCertificateValidationCallback = (s, c, h, e) => true; + //case 3667 fix for intermittent cert issue hopefully + //https://github.com/jstedfast/MailKit/issues/515#issuecomment-439438242 + client.CheckCertificateRevocation = false; //client.Connect(MAIL_IMAP_ADDRESS, MAIL_IMAP_PORT, true); if (mirrorServer) client.Connect(MAIL_MIRROR_IMAP_ADDRESS, MAIL_IMAP_PORT);