Example #1
0
        public void FromTotpUrl_Sha512AndStepSizeFifteenDigitsEight()
        {
            var url = string.Format("otpauth://totp/user/?secret={0}&algorithm=Sha512&period=15&digits=8", Base32Encoder.Encode(OtpCalculationTests.RfcTestKey));
            var otp = KeyUrl.FromUrl(url);

            Assert.IsTrue(otp is Totp);
            var totp = (Totp)otp;

            CollectionAssert.AreEqual(OtpCalculationTests.RfcTestKey, totp.GetKey(), "Key's don't match");
            Assert.AreEqual(8, totp.GetDigitLength(), "Digits don't match");
            Assert.AreEqual(15, totp.GetTimeStep(), "Step size doesn't match");
            Assert.AreEqual(OtpHashMode.Sha512, totp.GetHashMode(), "Hash mode doesn't match");
        }
Example #2
0
        public void FromTotpUrl_Sha256()
        {
            var url = string.Format("otpauth://totp/user?secret={0}&algorithm=Sha256", Base32Encoder.Encode(OtpCalculationTests.RfcTestKey));
            var otp = KeyUrl.FromUrl(url);

            Assert.IsTrue(otp is Totp);
            var totp = (Totp)otp;

            CollectionAssert.AreEqual(OtpCalculationTests.RfcTestKey, totp.GetKey(), "Key's don't match");
            Assert.AreEqual(6, totp.GetDigitLength(), "Digits don't match");
            Assert.AreEqual(30, totp.GetTimeStep(), "Step size doesn't match");
            Assert.AreEqual(OtpHashMode.Sha256, totp.GetHashMode(), "Hash mode doesn't match");
        }
Example #3
0
        void SetupTotp()
        {
            if (this.CustomData != null && this.CustomData.Exists(PassXYZLib.PxDefs.PxCustomDataOtpUrl))
            {
                var rawUrl = this.CustomData.Get(PassXYZLib.PxDefs.PxCustomDataOtpUrl);
                var otp    = KeyUrl.FromUrl(rawUrl);
                if (otp is Totp totp)
                {
                    var url = new Uri(rawUrl);
                    m_TotpDescription = url.LocalPath.Substring(1);

                    Totp  = totp;
                    Token = totp.ComputeTotp();
                }
            }
        }
Example #4
0
        public void FromUrl_InvalidProtocol()
        {
            var url = string.Format("otp://totp/user?secret={0}", Base32Encoder.Encode(OtpCalculationTests.RfcTestKey));

            new Action(() => KeyUrl.FromUrl(url)).ShouldThrow <ArgumentException>().WithMessage("invalid scheme otp. Must be otpauth://");
        }
Example #5
0
        public void FromUrl_InvalidType()
        {
            var url = string.Format("otpauth://sotp/user?secret={0}", Base32Encoder.Encode(OtpCalculationTests.RfcTestKey));

            new Action(() => KeyUrl.FromUrl(url)).ShouldThrow <ArgumentException>().WithMessage("rawUrl contains an invalid operation sotp. Must be hotp or totp");
        }
Example #6
0
        public void FromHotpUrl_WithPeriod()
        {
            var url = string.Format("otpauth://Hotp/user?secret={0}&period=15", Base32Encoder.Encode(OtpCalculationTests.RfcTestKey));

            new Action(() => KeyUrl.FromUrl(url)).ShouldThrow <ArgumentException>().WithMessage("Invalid parameter in query string");
        }
Example #7
0
        public void FromTotpUrl_NoQueryString()
        {
            var url = "otpauth://totp/user";

            new Action(() => KeyUrl.FromUrl(url)).ShouldThrow <ArgumentException>().WithMessage("Must have a query string");
        }
Example #8
0
        public void FromTotpUrl_NoSecret()
        {
            var url = "otpauth://totp/user?period=30";

            new Action(() => KeyUrl.FromUrl(url)).ShouldThrow <ArgumentException>().WithMessage("must contain secret");
        }
Example #9
0
        public void FromTotpUrl_InvalidScheme()
        {
            var url = string.Format("otp://totp/user?secret={0}&algorithm=Sha512&period=15&digits=8", Base32Encoder.Encode(OtpCalculationTests.RfcTestKey));

            new Action(() => KeyUrl.FromUrl(url)).ShouldThrow <ArgumentException>().WithMessage("invalid scheme otp. Must be otpauth://");
        }
Example #10
0
        public void FromTotpUrl_MalFormattedUrl_ExtraArgumentWithSlash()
        {
            var url = string.Format("otpauth://totp/user/extra/?secret={0}&algorithm=Sha512&period=15&digits=8", Base32Encoder.Encode(OtpCalculationTests.RfcTestKey));

            new Action(() => KeyUrl.FromUrl(url)).ShouldThrow <ArgumentException>().WithMessage("rawUrl is invalid");
        }
Example #11
0
        public void FromTotpUrl_InvalidQueryString()
        {
            var url = string.Format("otpauth://totp/user?secret={0}&algorithm=Sha512&period=15&digits=8&blah=b", Base32Encoder.Encode(OtpCalculationTests.RfcTestKey));

            new Action(() => KeyUrl.FromUrl(url)).ShouldThrow <ArgumentException>().WithMessage("Invalid parameter in query string");
        }
Example #12
0
 public void FromTotpUrl_NullUrl()
 {
     new Action(() => KeyUrl.FromUrl(null)).ShouldThrow <ArgumentNullException>().WithMessage("Value cannot be null.\r\nParameter name: rawUrl");
 }
Example #13
0
        public void FromTotpUrl_DigitsInvalid()
        {
            var url = string.Format("otpauth://totp/user?secret={0}&digits=a", Base32Encoder.Encode(OtpCalculationTests.RfcTestKey));

            new Action(() => KeyUrl.FromUrl(url)).ShouldThrow <ArgumentException>().WithMessage("Invalid digits a, must be a number");
        }
Example #14
0
        public void FromTotpUrl_ExplicitHashModeInvalid()
        {
            var url = string.Format("otpauth://totp/user?secret={0}&algorithm=Garbage", Base32Encoder.Encode(OtpCalculationTests.RfcTestKey));

            new Action(() => KeyUrl.FromUrl(url)).ShouldThrow <ArgumentException>().WithMessage("Invalid Algorithm Garbage");
        }
Example #15
0
        public void FromTotpUrl_ZeroStep()
        {
            var url = string.Format("otpauth://totp/user?secret={0}&period=0", Base32Encoder.Encode(OtpCalculationTests.RfcTestKey));

            new Action(() => KeyUrl.FromUrl(url)).ShouldThrow <ArgumentException>().WithMessage("Invalid Period 0, must be at least 1");
        }