示例#1
0
 private void SprEngine_FilterCompile(object sender, SprEventArgs e)
 {
     if ((e.Context.Flags & SprCompileFlags.ExtActive) != SprCompileFlags.ExtActive)
     {
         return;
     }
     if (e.Text.IndexOf(Config.Placeholder, StringComparison.InvariantCultureIgnoreCase) >= 0)
     {
         OTPDAO.EnsureOTPUsagePossible(e.Context.Entry);
         KPOTP myOTP = OTPDAO.GetOTP(e.Context.Entry);
         if (!myOTP.Valid)
         {
             PluginDebug.AddError("Auto-Type OTP failed", 0, "Uuid: " + e.Context.Entry.Uuid.ToHexString());
         }
         else
         {
             PluginDebug.AddInfo("Auto-Type OTP success", 0, "Uuid: " + e.Context.Entry.Uuid.ToHexString());
         }
         e.Text = StrUtil.ReplaceCaseInsensitive(e.Text, Config.Placeholder, myOTP.GetOTP(false, true));
         if (myOTP.Valid && (myOTP.Type == KPOTPType.HOTP))
         {
             var newOTP = myOTP.Clone();
             newOTP.HOTPCounter++;
             OTPDAO.SaveOTP(newOTP, e.Context.Entry);
         }
     }
 }
示例#2
0
 /// <summary>
 /// Auto-Type Function.
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void SprEngine_FilterCompile(object sender, SprEventArgs e)
 {
     if ((e.Context.Flags & SprCompileFlags.ExtActive) == SprCompileFlags.ExtActive)
     {
         if (e.Text.IndexOf(m_host.CustomConfig.GetString(setname_string_AutoType_FieldName, setdef_string_AutoType_FieldName).ExtWithBrackets(), StringComparison.InvariantCultureIgnoreCase) >= 0)
         {
             if (SettingsCheck(e.Context.Entry) && SeedCheck(e.Context.Entry))
             {
                 bool ValidInterval = false; bool ValidLength = false; bool ValidUrl = false;
                 if (SettingsValidate(e.Context.Entry, out ValidInterval, out ValidLength, out ValidUrl))
                 {
                     bool     NoTimeCorrection = false;
                     string[] Settings         = SettingsGet(e.Context.Entry);
                     var      TotpGenerator    = new Totp_Provider(Convert.ToInt16(Settings[0]), Convert.ToInt16(Settings[1]));
                     if (ValidUrl)
                     {
                         var CurrentTimeCorrection = TimeCorrections[Settings[2]];
                         if (CurrentTimeCorrection != null)
                         {
                             TotpGenerator.TimeCorrection = CurrentTimeCorrection.TimeCorrection;
                         }
                         else
                         {
                             TotpGenerator.TimeCorrection = TimeSpan.Zero;
                             NoTimeCorrection             = true;
                         }
                     }
                     string InvalidCharacters;
                     if (SeedValidate(e.Context.Entry, out InvalidCharacters))
                     {
                         e.Context.Entry.Touch(false);
                         e.Text = StrUtil.ReplaceCaseInsensitive(e.Text, m_host.CustomConfig.GetString(setname_string_AutoType_FieldName, setdef_string_AutoType_FieldName).ExtWithBrackets(), TotpGenerator.Generate(Base32.Decode(SeedGet(e.Context.Entry).ReadString().ExtWithoutSpaces())));
                     }
                     else
                     {
                         e.Text = string.Empty;
                         MessageService.ShowWarning(TrayTotp_Plugin_Localization.strWarningBadSeed + InvalidCharacters.ExtWithParenthesis().ExtWithSpaceBefore());
                     }
                     if (NoTimeCorrection)
                     {
                         MessageService.ShowWarning(TrayTotp_Plugin_Localization.strWarningBadUrl);
                     }
                 }
                 else
                 {
                     e.Text = string.Empty;
                     MessageService.ShowWarning(TrayTotp_Plugin_Localization.strWarningBadSet);
                 }
             }
             else
             {
                 e.Text = string.Empty;
                 MessageService.ShowWarning(TrayTotp_Plugin_Localization.strWarningNotSet);
             }
         }
     }
 }
示例#3
0
文件: Plugin.cs 项目: aXe1/KeeYaOtp
 private void SprEngine_FilterCompile(object sender, SprEventArgs e)
 {
     if (((e.Context.Flags & SprCompileFlags.ExtActive) == SprCompileFlags.ExtActive) &&
         e.Text.Contains(yaotpPlaceholder) &&
         e.Context.Entry.Strings.Exists(OtpDataUtils.Key) &&
         OtpDataUtils.TryParseOtpData(e.Context.Entry.Strings.Get(OtpDataUtils.Key).ReadString(), out var secret, out var pin))
     {
         var otpString = (new Yaotp(secret, pin, () => DateTime.UtcNow)).ComputeOtp();
         e.Text = StrUtil.ReplaceCaseInsensitive(e.Text, yaotpPlaceholder, otpString);
     }
 }
        /// <summary>
        /// Auto-Type Function.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void SprEngine_FilterCompile(object sender, SprEventArgs e)
        {
            if ((e.Context.Flags & SprCompileFlags.ExtActive) == SprCompileFlags.ExtActive)
            {
                if (e.Text.IndexOf(m_host.CustomConfig.GetString(setname_string_AutoType_FieldName, setdef_string_AutoType_FieldName).ExtWithBrackets(), StringComparison.InvariantCultureIgnoreCase) >= 0)
                {
                    if (SettingsCheck(e.Context.Entry) && SeedCheck(e.Context.Entry))
                    {
                        bool ValidInterval = false; bool ValidLength = false; bool ValidUrl = false;
                        if (SettingsValidate(e.Context.Entry, out ValidInterval, out ValidLength, out ValidUrl))
                        {
                            string[] Settings = SettingsGet(e.Context.Entry);

                            TOTPProvider TOTPGenerator = new TOTPProvider(Settings, ref this.TimeCorrections);

                            string InvalidCharacters;

                            if (SeedValidate(e.Context.Entry, out InvalidCharacters))
                            {
                                e.Context.Entry.Touch(false);
                                string totp = TOTPGenerator.GenerateByByte(Base32.Decode(SeedGet(e.Context.Entry).ReadString().ExtWithoutSpaces()));
                                e.Text = StrUtil.ReplaceCaseInsensitive(e.Text, m_host.CustomConfig.GetString(setname_string_AutoType_FieldName, setdef_string_AutoType_FieldName).ExtWithBrackets(), totp);
                            }
                            else
                            {
                                e.Text = string.Empty;
                                MessageService.ShowWarning(TrayTOTP_Plugin_Localization.strWarningBadSeed + InvalidCharacters.ExtWithParenthesis().ExtWithSpaceBefore());
                            }
                            if (TOTPGenerator.TimeCorrectionError)
                            {
                                MessageService.ShowWarning(TrayTOTP_Plugin_Localization.strWarningBadUrl);
                            }
                        }
                        else
                        {
                            e.Text = string.Empty;
                            MessageService.ShowWarning(TrayTOTP_Plugin_Localization.strWarningBadSet);
                        }
                    }
                    else
                    {
                        e.Text = string.Empty;
                        MessageService.ShowWarning(TrayTOTP_Plugin_Localization.strWarningNotSet);
                    }
                }
            }
        }
示例#5
0
        void SprEngine_FilterCompile(object sender, SprEventArgs e)
        {
            if ((e.Context.Flags & SprCompileFlags.ExtActive) == SprCompileFlags.ExtActive)
            {
                if (e.Text.IndexOf(totpPlaceHolder, StringComparison.InvariantCultureIgnoreCase) >= 0)
                {
                    if (e.Context.Entry.Strings.Exists(OtpAuthData.StringDictionaryKey))
                    {
                        var data = OtpAuthData.FromString(e.Context.Entry.Strings.Get(OtpAuthData.StringDictionaryKey).ReadString());
                        var totp = new Totp(data.Key, step: data.Step, mode: data.OtpHashMode, totpSize: data.Size);
                        var text = totp.ComputeTotp().ToString().PadLeft(data.Size, '0');

                        e.Text = StrUtil.ReplaceCaseInsensitive(e.Text, "{TOTP}", text);
                    }
                }
            }
        }
        /// <summary>
        /// Auto-Type Function.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void SprEngine_FilterCompile(object sender, SprEventArgs e)
        {
            if ((e.Context.Flags & SprCompileFlags.ExtActive) == SprCompileFlags.ExtActive && e.Text.IndexOf(Settings.AutoTypeFieldName.ExtWithBrackets(), StringComparison.InvariantCultureIgnoreCase) >= 0)
            {
                if (TOTPEntryValidator.HasSeed(e.Context.Entry))
                {
                    if (TOTPEntryValidator.SettingsValidate(e.Context.Entry))
                    {
                        string[] settings = TOTPEntryValidator.SettingsGet(e.Context.Entry);

                        TOTPProvider totpGenerator = new TOTPProvider(settings, this.TimeCorrections);

                        string invalidCharacters;

                        if (TOTPEntryValidator.SeedValidate(e.Context.Entry, out invalidCharacters))
                        {
                            e.Context.Entry.Touch(false);
                            string totp = totpGenerator.GenerateByByte(Base32.Decode(TOTPEntryValidator.SeedGet(e.Context.Entry).ReadString().ExtWithoutSpaces()));
                            e.Text = StrUtil.ReplaceCaseInsensitive(e.Text, Settings.AutoTypeFieldName.ExtWithBrackets(), totp);
                        }
                        else
                        {
                            e.Text = string.Empty;
                            MessageService.ShowWarning(Localization.Strings.ErrorBadSeed + invalidCharacters.ExtWithParenthesis().ExtWithSpaceBefore());
                        }
                        if (totpGenerator.TimeCorrectionError)
                        {
                            MessageService.ShowWarning(Localization.Strings.WarningBadURL);
                        }
                    }
                    else
                    {
                        e.Text = string.Empty;
                        MessageService.ShowWarning(Localization.Strings.ErrorBadSettings);
                    }
                }
                else
                {
                    e.Text = string.Empty;
                    MessageService.ShowWarning(Localization.Strings.ErrorNoSeed);
                }
            }
        }
示例#7
0
 // If built-in {TIMEOTP} placeholder is used, but KeeOtp1 Save Mode is used
 private void SprEngine_FilterCompilePre(object sender, SprEventArgs e)
 {
     if ((e.Context.Flags & SprCompileFlags.ExtActive) == SprCompileFlags.ExtActive)
     {
         string currentPlaceHolder = null;
         if (e.Text.IndexOf(BuiltInTotpPlaceHolder, StringComparison.InvariantCultureIgnoreCase) >= 0)
         {
             currentPlaceHolder = BuiltInTotpPlaceHolder;
         }
         else if (e.Text.IndexOf(BuiltInHotpPlaceHolder, StringComparison.InvariantCultureIgnoreCase) >= 0)
         {
             currentPlaceHolder = BuiltInHotpPlaceHolder;
         }
         if (!string.IsNullOrEmpty(currentPlaceHolder))
         {
             PwEntry     entry = e.Context.Entry;
             OtpAuthData data  = OtpAuthUtils.loadData(entry);
             if (data != null)
             {
                 if (!OtpAuthUtils.checkBuiltInMode(entry) ||
                     (OtpAuthUtils.checkEntry(entry) && OtpTime.getOverrideBuiltInTime() && (OtpTime.getTimeType() == OtpTimeType.FixedOffset || OtpTime.getTimeType() == OtpTimeType.CustomNtpServer)) ||
                     !data.Proprietary)
                 {
                     OtpBase otp = OtpAuthUtils.getOtp(data);
                     if (data.Type == OtpType.Totp || data.Type == OtpType.Steam)
                     {
                         e.Text = StrUtil.ReplaceCaseInsensitive(e.Text, currentPlaceHolder, otp.getTotpString(OtpTime.getTime()));
                     }
                     else if (data.Type == OtpType.Hotp)
                     {
                         e.Text = StrUtil.ReplaceCaseInsensitive(e.Text, currentPlaceHolder, otp.getHotpString(data.Counter));
                         OtpAuthUtils.increaseHotpCounter(host, data, entry);
                     }
                 }
             }
         }
     }
 }
示例#8
0
 private void SprEngine_FilterCompile(object sender, SprEventArgs e)
 {
     if ((e.Context.Flags & SprCompileFlags.ExtActive) == SprCompileFlags.ExtActive)
     {
         if (e.Text.IndexOf(KeeOtp1PlaceHolder, StringComparison.InvariantCultureIgnoreCase) >= 0)
         {
             PwEntry     entry = e.Context.Entry;
             OtpAuthData data  = OtpAuthUtils.loadData(entry);
             if (data != null)
             {
                 OtpBase otp = OtpAuthUtils.getOtp(data);
                 if (data.Type == OtpType.Totp || data.Type == OtpType.Steam)
                 {
                     e.Text = StrUtil.ReplaceCaseInsensitive(e.Text, KeeOtp1PlaceHolder, otp.getTotpString(OtpTime.getTime()));
                 }
                 else if (data.Type == OtpType.Hotp)
                 {
                     e.Text = StrUtil.ReplaceCaseInsensitive(e.Text, KeeOtp1PlaceHolder, otp.getHotpString(data.Counter));
                     OtpAuthUtils.increaseHotpCounter(host, data, entry);
                 }
             }
         }
     }
 }