From 73c6317b3e6a55b8ffb6841a1fd85c77581f79b3 Mon Sep 17 00:00:00 2001 From: Jeff Leung Date: Wed, 8 Jul 2020 15:48:59 -0700 Subject: [PATCH] Verify with a NTP time source before continuing --- MFACodeGenerator/MFACodeGenerator.csproj | 39 ++++++++++++++++++++++++ MFACodeGenerator/Program.cs | 24 +++++++++++++++ MFACodeGenerator/packages.config | 1 + 3 files changed, 64 insertions(+) diff --git a/MFACodeGenerator/MFACodeGenerator.csproj b/MFACodeGenerator/MFACodeGenerator.csproj index 1ec9a3d..dc041af 100644 --- a/MFACodeGenerator/MFACodeGenerator.csproj +++ b/MFACodeGenerator/MFACodeGenerator.csproj @@ -13,6 +13,22 @@ true true + C:\Users\curriegrad2004\Desktop\MFAGenerator\ + true + Disk + false + Foreground + 7 + Days + false + false + true + 0 + 1.0.0.%2a + false + false + true + true AnyCPU @@ -33,7 +49,22 @@ prompt 4 + + 25959F1C21FCA9FFDED624C1BC14F6D1248B0FDD + + + MFACodeGenerator_TemporaryKey.pfx + + + true + + + true + + + ..\packages\NtpClient.1.0.14\lib\net40\NtpClient.dll + ..\packages\Otp.NET.1.2.2\lib\net45\Otp.NET.dll @@ -70,6 +101,7 @@ True Resources.resx + SettingsSingleFileGenerator @@ -84,5 +116,12 @@ + + + False + .NET Framework 3.5 SP1 + false + + \ No newline at end of file diff --git a/MFACodeGenerator/Program.cs b/MFACodeGenerator/Program.cs index e4bbe3d..664756d 100644 --- a/MFACodeGenerator/Program.cs +++ b/MFACodeGenerator/Program.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using System.Windows.Forms; +using NtpClient; namespace MFACodeGenerator { @@ -14,6 +15,29 @@ namespace MFACodeGenerator [STAThread] static void Main() { + try + { + NtpClient.NtpConnection client + = new NtpConnection("pool.ntp.org"); + var NetDate = client.GetUtc(); + + var diff = NetDate - DateTime.UtcNow; + + if (Math.Abs(diff.Seconds) >= 60) + { + MessageBox.Show("Time difference is greater than 60 seconds. Please check your local clock settings!", + "Clock Drift Detected", + MessageBoxButtons.OK, + MessageBoxIcon.Error); + return; + } + } catch + { + MessageBox.Show("Since we can't verify your PC's clock to a reliable time source, this application may not work properly. Please ensure the time on your PC is set correctly.", + "No Reliable Time Source Found" + , MessageBoxButtons.OK + , MessageBoxIcon.Warning); + } Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new Form1()); diff --git a/MFACodeGenerator/packages.config b/MFACodeGenerator/packages.config index 14fe04a..720b61c 100644 --- a/MFACodeGenerator/packages.config +++ b/MFACodeGenerator/packages.config @@ -1,4 +1,5 @@  + \ No newline at end of file