Пример #1
0
        protected override void Validate()
        {
            switch (Type)
            {
            case "string":
                if (InvalidCharacters != string.Empty && Value != null)
                {
                    foreach (var c in InvalidCharacters.ToCharArray())
                    {
                        if (c == ',' && Multiple)
                        {
                            continue;
                        }
                        if (Value.IndexOf(c) > -1)
                        {
                            Error($"The {Name} parameter contains an invalid '{c}' character");
                        }
                    }
                }
                break;

            default:
                if (!string.IsNullOrEmpty(Value) && !Constants.CanConvert()[Type](Value))
                {
                    Error($"The parameter {Name} is supposed to be a {Type}, but it can not be parsed as such.");
                }
                break;
            }
            if (string.IsNullOrEmpty(Label))
            {
                Label = Name;
            }
        }
Пример #2
0
            public TotpData GetTotpData(IDictionary <string, string> entryFields)
            {
                TotpData res = new TotpData();

                if (SettingsCheck(entryFields) && SeedCheck(entryFields))
                {
                    bool ValidInterval; bool ValidLength; bool ValidUrl;
                    if (SettingsValidate(entryFields, out ValidInterval, out ValidLength, out ValidUrl))
                    {
                        bool     NoTimeCorrection = false;
                        string[] Settings         = SettingsGet(entryFields);
                        res.Duration = Settings[0];
                        res.Length   = Settings[1];
                        if (res.Length == "S")
                        {
                            res.Encoder = TotpData.EncoderSteam;
                        }
                        if (ValidUrl)
                        {
                            NoTimeCorrection      = true;
                            res.TimeCorrectionUrl = Settings[2];

                            /*var CurrentTimeCorrection = TimeCorrections[Settings[2]];
                             * if (CurrentTimeCorrection != null)
                             * {
                             *      TotpGenerator.TimeCorrection = CurrentTimeCorrection.TimeCorrection;
                             * }
                             * else
                             * {
                             *      TotpGenerator.TimeCorrection = TimeSpan.Zero;
                             *      NoTimeCorrection = true;
                             * }*/
                        }
                        string InvalidCharacters;
                        if (SeedValidate(entryFields, out InvalidCharacters))
                        {
                            res.IsTotpEntry = true;
                            res.TotpSeed    = SeedGet(entryFields).ExtWithoutSpaces();
                        }
                        else
                        {
                            ShowWarning("Bad seed!" + InvalidCharacters.ExtWithParenthesis().ExtWithSpaceBefore());
                        }
                        if (NoTimeCorrection)
                        {
                            ShowWarning("Warning: TOTP Time correction not implemented!");
                        }
                    }
                    else
                    {
                        ShowWarning("Bad settings!");
                    }
                }
                else
                {
                    //no totp entry
                }
                return(res);
            }
 Generate
 (
     OpenApiParameter
     parameter,
     IEnumerable <OpenApiParameter>
     parameters
 )
 => InvalidCharacters.RemoveAndReplace(parameter.Name);
Пример #4
0
        public void LoadNonPlayerCharacters()
        {
            string match = @"^c\d{4}[.]anibnd([.]dcx)?$";
            IEnumerable <string> chrFiles = Directory.GetFiles($"{GameDir}chr");

            chrFiles = chrFiles.Select(f => Path.GetFileName(f)).Where(f => Regex.IsMatch(f, match));
            foreach (string file in chrFiles)
            {
                int id = int.Parse(file.Substring(1, 4));
                if (InvalidCharacters.Contains(id) || id == 0)
                {
                    continue;  // skip invalid/unused characters and player character (c0000)
                }
                Characters[id] = new ChrHandler(id, this);
            }
        }
        /// <summary>
        /// Copies the specified entry's generated TOTP to the clipboard using the KeePass's clipboard function.
        /// </summary>
        /// <param name="pe">Password Entry.</param>
        private void TOTPCopyToClipboard(PwEntry pe)
        {
            if (SettingsCheck(pe) && SeedCheck(pe))
            {
                bool ValidInterval; bool ValidLength; bool ValidUrl;
                if (SettingsValidate(pe, out ValidInterval, out ValidLength, out ValidUrl))
                {
                    string[] Settings = SettingsGet(pe);

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

                    string InvalidCharacters;
                    if (SeedValidate(pe, out InvalidCharacters))
                    {
                        pe.Touch(false);

                        string totp = TOTPGenerator.Generate(SeedGet(pe).ReadString().ExtWithoutSpaces());

                        ClipboardUtil.CopyAndMinimize(totp, true, m_host.MainWindow, pe, m_host.MainWindow.ActiveDatabase);
                        m_host.MainWindow.StartClipboardCountdown();
                    }
                    else
                    {
                        MessageService.ShowWarning(TrayTOTP_Plugin_Localization.strWarningBadSeed + InvalidCharacters.ExtWithParenthesis().ExtWithSpaceBefore());
                    }
                    if (TOTPGenerator.TimeCorrectionError)
                    {
                        MessageService.ShowWarning(TrayTOTP_Plugin_Localization.strWarningBadUrl);
                    }
                }
                else
                {
                    MessageService.ShowWarning(TrayTOTP_Plugin_Localization.strWarningBadSet);
                }
            }
            else
            {
                MessageService.ShowWarning(TrayTOTP_Plugin_Localization.strWarningNotSet);
            }
        }
        /// <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);
                    }
                }
            }
        }
Пример #7
0
 /// <summary>
 /// Copies the specified entry's generated TOTP to the clipboard using the KeePass's clipboard function.
 /// </summary>
 /// <param name="pe">Password Entry.</param>
 private void TotpCopyToClipboard(PwEntry pe)
 {
     if (SettingsCheck(pe) && SeedCheck(pe))
     {
         bool ValidInterval; bool ValidLength; bool ValidUrl;
         if (SettingsValidate(pe, out ValidInterval, out ValidLength, out ValidUrl))
         {
             bool     NoTimeCorrection = false;
             string[] Settings         = SettingsGet(pe);
             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(pe, out InvalidCharacters))
             {
                 pe.Touch(false);
                 ClipboardUtil.CopyAndMinimize(TotpGenerator.Generate(Base32.Decode(SeedGet(pe).ReadString().ExtWithoutSpaces())), true, m_host.MainWindow, pe, m_host.MainWindow.ActiveDatabase);
                 m_host.MainWindow.StartClipboardCountdown();
             }
             else
             {
                 MessageService.ShowWarning(TrayTotp_Plugin_Localization.strWarningBadSeed + InvalidCharacters.ExtWithParenthesis().ExtWithSpaceBefore());
             }
             if (NoTimeCorrection)
             {
                 MessageService.ShowWarning(TrayTotp_Plugin_Localization.strWarningBadUrl);
             }
         }
         else
         {
             MessageService.ShowWarning(TrayTotp_Plugin_Localization.strWarningBadSet);
         }
     }
     else
     {
         MessageService.ShowWarning(TrayTotp_Plugin_Localization.strWarningNotSet);
     }
 }
Пример #8
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);
             }
         }
     }
 }