public void Prevent_code_reuse()
        {
            var date = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
            var usedCodesManager = new UsedCodesManager();
            var authenticator = new TimeAuthenticator(usedCodesManager, () => date);
            var secret = Authenticator.GenerateKey();
            var code = authenticator.GetCode(secret);

            Assert.IsTrue(authenticator.CheckCode(secret, code));
            Assert.IsFalse(authenticator.CheckCode(secret, code));
        }
Esempio n. 2
0
        public void Prevent_code_reuse()
        {
            var date             = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
            var usedCodesManager = new UsedCodesManager();
            var authenticator    = new TimeAuthenticator(usedCodesManager, () => date);
            var secret           = Authenticator.GenerateKey();
            var code             = authenticator.GetCode(secret);

            Assert.IsTrue(authenticator.CheckCode(secret, code));
            Assert.IsFalse(authenticator.CheckCode(secret, code));
        }
        public void VerifyKeys(string secret, string timeString, string code)
        {
            var date = DateTime.Parse(timeString);

            var authenticator = new TimeAuthenticator(mockUsedCodesManager, () => date);
            Assert.IsTrue(authenticator.CheckCode(secret, code));
        }
Esempio n. 4
0
        public void VerifyKeys(string secret, string timeString, string code)
        {
            var date = DateTime.Parse(timeString);

            var authenticator = new TimeAuthenticator(mockUsedCodesManager, () => date);

            Assert.IsTrue(authenticator.CheckCode(secret, code));
        }
Esempio n. 5
0
        public void CreateKey()
        {
            var authenticator = new TimeAuthenticator(mockUsedCodesManager);
            var secret        = Authenticator.GenerateKey();
            var code          = authenticator.GetCode(secret);

            Assert.IsTrue(authenticator.CheckCode(secret, code, "dummyuser"), "Generated Code doesn't verify");
        }
        private bool PerformTOTPAuthentication(string totpCode)
        {
            var secret        = AppSettings.TOTPSecret;
            var authenticator = new TimeAuthenticator();
            var ok            = authenticator.CheckCode(secret, totpCode, null);

            return(ok);
        }
        public void CreateKey()
        {
            var authenticator = new TimeAuthenticator(mockUsedCodesManager);
            var secret = Authenticator.GenerateKey();
            var code = authenticator.GetCode(secret);

            Assert.IsTrue(authenticator.CheckCode(secret, code, "dummyuser"), "Generated Code doesn't verify");
        }
Esempio n. 8
0
        public void TimeAuthenticatorTest()
        {
            var    authenticator = new TimeAuthenticator();
            string secret        = Authenticator.GenerateKey(Authenticator.SecretKeyLength.n16Bytes);
            string code          = authenticator.GetCode(secret);

            Assert.IsTrue(authenticator.CheckCode(secret, code), "OTP Time Authentication failed");
        }
Esempio n. 9
0
        public void UsesUsedCodesManager()
        {
            var date          = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
            var authenticator = new TimeAuthenticator(mockUsedCodesManager, () => date);
            var secret        = Authenticator.GenerateKey();
            var code          = authenticator.GetCode(secret);

            authenticator.CheckCode(secret, code, "dummyuser");

            Assert.AreEqual(mockUsedCodesManager.LastChallenge, 0uL);
            Assert.AreEqual(mockUsedCodesManager.LastCode, code);
        }
        public void VerifyKeyRange(string secret, string timeString, string code)
        {
            var date = DateTime.Parse(timeString).AddMinutes(5);

            var defaultAuthenticator = new TimeAuthenticator(mockUsedCodesManager, () => date);

            Assert.IsFalse(defaultAuthenticator.CheckCode(secret, code, new object()));

            var wideRangeAuthenticator = new TimeAuthenticator(mockUsedCodesManager, () => date, verificationRange: 10);

            Assert.IsTrue(wideRangeAuthenticator.CheckCode(secret, code, new object()));
        }
        public void UsesUsedCodesManager()
        {
            var date = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
            var authenticator = new TimeAuthenticator(mockUsedCodesManager, () => date);
            var secret = Authenticator.GenerateKey();
            var code = authenticator.GetCode(secret);

            authenticator.CheckCode(secret, code, "dummyuser");

            Assert.AreEqual(mockUsedCodesManager.LastChallenge, 0uL);
            Assert.AreEqual(mockUsedCodesManager.LastCode, code);
        }
Esempio n. 12
0
        public void VerifyUsedTime()
        {
            var date          = DateTime.Parse("2013-12-05 17:23:50 +0100");
            var authenticator = new TimeAuthenticator(mockUsedCodesManager, () => date);

            DateTime usedTime;

            Assert.True(authenticator.CheckCode("H22Q7WAMQYFZOJ2Q", "696227", null, out usedTime));

            // 17:23:50 - 30s
            Assert.AreEqual(usedTime.Hour, 17);
            Assert.AreEqual(usedTime.Minute, 23);
            Assert.AreEqual(usedTime.Second, 20);
        }
Esempio n. 13
0
 private void btnVerifyCode_Click(object sender, EventArgs e)
 {
     if (!_initialized)
     {
         return;
     }
     OTPVerificationCompleted = _timeAuthenticator.CheckCode(_googleAuthenticator.Secret, txtOTPCodeToVerify.Text);
     if (OTPVerificationCompleted)
     {
         txtVerifyResult.Text = "Code verified successfully";
         if (CodeVerified != null)
         {
             CodeVerified.Invoke(this, new EventArgs());
         }
     }
     else
     {
         txtVerifyResult.Text = "The code is incorrect";
     }
 }
Esempio n. 14
0
        private void btnVerifyCode_Click(object sender, EventArgs e)
        {
            if (!_initialized)
            {
                return;
            }
            OTPVerificationCompleted = _timeAuthenticator.CheckCode(_googleAuthenticator.Secret, txtOTPCodeToVerify.Text);
            if (OTPVerificationCompleted)
            {
                txtVerifyResult.Text = "Code verified successfully";
                CodeVerified?.Invoke(this, EventArgs.Empty);
            }
            else
            {
                txtVerifyResult.Text = "The code is incorrect";
                CodeVerificationFailed?.Invoke(this, EventArgs.Empty);
            }

#if _SHOW_FULL_DATE_TIME_
            txtVerifyResult.Text += $"\r\n{DateTime.Now:yyyy-MM-dd / HH:mm:ss}";
#else
            txtVerifyResult.Text += $"\r\n{DateTime.Now:HH:mm:ss}";
#endif
        }
        public void VerifyUsedTime()
        {
            var date = DateTime.Parse("2013-12-05 17:23:50 +0100");
            var authenticator = new TimeAuthenticator(mockUsedCodesManager, () => date);

            DateTime usedTime;

            Assert.True(authenticator.CheckCode("H22Q7WAMQYFZOJ2Q", "696227", null, out usedTime));

            // 17:23:50 - 30s
            var sameDate = date.AddSeconds(-30);
            Assert.AreEqual(usedTime.Hour, sameDate.Hour);
            Assert.AreEqual(usedTime.Minute, sameDate.Minute);
            Assert.AreEqual(usedTime.Second, sameDate.Second);
        }