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));
        }
Example #2
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));
        }
Example #3
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);
        }
Example #5
0
        public CreateAndVerifyOTP()
        {
            InitializeComponent();

            _qrCodeGenerator   = new QRCodeGenerator();
            _timeAuthenticator = new TimeAuthenticator();
            txtOTPSecret.Text  = "";
        }
        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");
        }
Example #7
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");
        }
        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));
        }
Example #9
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));
        }
Example #10
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);
        }
        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);
        }
Example #14
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);
        }