コード例 #1
0
        private void ShowPCAFormFromEntry(object sender, EventArgs e)
        {
            m_pcaForm = new PCADialog();
            m_pweForm.UpdateEntryStrings(true, true, true);
            PCAInitData        pcadata = new PCAInitData(m_pweForm.EntryRef);
            ExpiryControlGroup ecg     = (ExpiryControlGroup)Tools.GetField("m_cgExpiry", m_pweForm);

            pcadata.Strings = m_pweForm.EntryStrings;
            if (ecg != null)
            {
                pcadata.Expires   = ecg.Checked;
                pcadata.Expiry    = ecg.Value;
                pcadata.SetExpiry = (pcadata.Expires != m_pweForm.EntryRef.Expires) || (pcadata.Expiry != m_pweForm.EntryRef.ExpiryTime);
            }
            pcadata.URL2 = pcadata.Strings.ReadSafe(Config.PCAURLField);
            DerefStrings(pcadata, m_pweForm.EntryRef);
            m_pcaForm.Init(pcadata, ProfilesOpening);
            if (m_pcaForm.ShowDialog(m_pweForm) == DialogResult.OK)
            {
                m_pweForm.EntryStrings.Set(PwDefs.PasswordField, m_pcaForm.NewPassword);
                if (ecg != null)
                {
                    ecg.Checked = m_pcaForm.EntryExpiry.Checked;
                    if (ecg.Checked)
                    {
                        ecg.Value = m_pcaForm.EntryExpiry.Value.ToUniversalTime();
                    }
                }
                if (string.IsNullOrEmpty(m_pcaForm.Sequence))
                {
                    m_pweForm.EntryStrings.Remove(Config.PCASequence);
                }
                else
                {
                    m_pweForm.EntryStrings.Set(Config.PCASequence, new ProtectedString(false, m_pcaForm.Sequence));
                }
                if (string.IsNullOrEmpty(m_pcaForm.URL2))
                {
                    m_pweForm.EntryStrings.Remove(Config.PCAURLField);
                }
                else
                {
                    m_pweForm.EntryStrings.Set(Config.PCAURLField, new ProtectedString(false, m_pcaForm.URL2));
                }
                m_pweForm.UpdateEntryStrings(false, true, true);
            }
            m_pcaForm.CleanupEx();
            m_pcaForm = null;
        }
コード例 #2
0
ファイル: PEDCalcExt.cs プロジェクト: Rookiestyle/PEDCalc
        private void OnPEDMenuOpening(object sender, EventArgs e)
        {
            ToolStripMenuItem tsmi = sender as ToolStripMenuItem;

            if (tsmi == null)
            {
                return;
            }
            if (tsmi.DropDown == null)
            {
                return;
            }
            PEDValue_QuickAction pqaActions = tsmi.DropDown.Tag as PEDValue_QuickAction;

            if (pqaActions == null)
            {
                return;
            }
            if ((tsmi == m_ContextMenuEntry) || (tsmi == m_MainMenuEntry))
            {
                PwEntry[]    pe         = m_host.MainWindow.GetSelectedEntries();
                PEDCalcValue pcvInherit = pe[0].GetPEDValueInherit();
                pqaActions.SetInheritValue(pcvInherit);
                pqaActions.SetValue(pe[0].GetPEDValue(false));
            }
            else if ((tsmi == m_ContextMenuGroup) || (tsmi == m_MainMenuGroup))
            {
                PwGroup      pg         = m_host.MainWindow.GetSelectedGroup();
                PEDCalcValue pcvInherit = pg.GetPEDValueInherit();
                pqaActions.SetInheritValue(pcvInherit);
                pqaActions.SetValue(pg.GetPEDValue(false));
            }
            else if (m_pweForm != null)
            {
                PwEntry pe = m_pweForm.EntryRef;
                m_pweForm.UpdateEntryStrings(true, true);
                PEDCalcValue currentValue = m_pweForm.EntryStrings.ReadPEDCString();
                if (currentValue == null)
                {
                    currentValue = pe.GetPEDValue(false);
                }
                pqaActions.SetInheritValue(pe.GetPEDValueInherit());
                pqaActions.SetValue(currentValue);
            }
        }
コード例 #3
0
        void UpdateKeyInfo()
        {
            if (hasSshKeyCheckBox.Checked)
            {
                switch (keyLocationPanel.KeyLocation.SelectedType)
                {
                case EntrySettings.LocationType.Attachment:
                case EntrySettings.LocationType.File:
                    try {
                        pwEntryForm.UpdateEntryStrings(true, false);
                        var context = new SprContext(pwEntryForm.EntryRef, pwEntryForm.EntryRef.GetDatabase(), SprCompileFlags.Deref);
                        using (var key = CurrentSettings.
                                         GetSshKey(pwEntryForm.EntryStrings, pwEntryForm.EntryBinaries, context)) {
                            commentTextBox.Text         = key.Comment;
                            fingerprintTextBox.Text     = key.GetMD5Fingerprint().ToHexString();
                            publicKeyTextBox.Text       = key.GetAuthorizedKeyString();
                            copyPublicKeybutton.Enabled = true;
                        }
                    } catch (Exception) {
                        string file = "attachment";
                        if (keyLocationPanel.KeyLocation.SelectedType == EntrySettings.LocationType.File)
                        {
                            try {
                                file = Path.GetFullPath(CurrentSettings.Location.FileName.ExpandEnvironmentVariables());
                            } catch (Exception) {
                                file = "file";
                            }
                        }
                        commentTextBox.Text = string.Format("<Error loading key from {0}>",
                                                            file);
                        fingerprintTextBox.Text     = string.Empty;
                        publicKeyTextBox.Text       = string.Empty;
                        copyPublicKeybutton.Enabled = false;
                    }
                    break;

                default:
                    commentTextBox.Text         = "No key selected";
                    fingerprintTextBox.Text     = string.Empty;
                    publicKeyTextBox.Text       = string.Empty;
                    copyPublicKeybutton.Enabled = false;
                    break;
                }
            }
            else
            {
                commentTextBox.Text     = string.Empty;
                fingerprintTextBox.Text = string.Empty;
                publicKeyTextBox.Text   = string.Empty;
            }
        }
コード例 #4
0
ファイル: MPAGen.cs プロジェクト: luelista/KeePassMPAGen
        public override ProtectedString Generate(PwProfile prf,
                                                 CryptoRandomStream crsRandomSource)
        {
            PwEntryForm entry = GetCurrentPwEntryForm();

            entry.UpdateEntryStrings(true, false);
            if (entry == null)
            {
                System.Windows.Forms.MessageBox.Show("No Current PwEntry found!");
                return(null);
            }

            MasterPasswordDlg dlg = new MasterPasswordDlg(keePass.Database);

            string site = "";

            site = entry.EntryStrings.ReadSafe("MPA Site");
            if (string.IsNullOrEmpty(site))
            {
                site = Regex.Replace(entry.EntryStrings.ReadSafe("URL"),
                                     @"^https?://(?:[^./]+\.)*([^./]+\.(?:[a-z.]{2,5}|[a-z]+))(?:[/].*)?$", "$1");
            }

            int counter;

            if (!Int32.TryParse(entry.EntryStrings.ReadSafe("MPA Counter"), out counter))
            {
                counter = 1;
            }

            dlg.SetSite(site, counter);

            if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                if (site != dlg.GetSiteName())
                {
                    entry.EntryStrings.Set("MPA Site", new ProtectedString(false, dlg.GetSiteName()));
                }
                if (counter.ToString() != dlg.GetSiteCounter())
                {
                    entry.EntryStrings.Set("MPA Counter", new ProtectedString(false, dlg.GetSiteCounter()));
                }
                entry.UpdateEntryStrings(false, false);

                return(new ProtectedString(true, dlg.PasswordResult));
            }
            return(null);

            /*
             *          if(prf == null) { Debug.Assert(false); }
             *          else
             *          {
             *                  Debug.Assert(prf.CustomAlgorithmUuid == Convert.ToBase64String(
             *                          m_uuid.UuidBytes, Base64FormattingOptions.None));
             *          }
             *
             *          PwProfile prfSub = new PwProfile();
             *          prfSub.GeneratorType = PasswordGeneratorType.CharSet;
             *          prfSub.CharSet = new PwCharSet(PwCharSet.UpperCase + PwCharSet.LowerCase +
             *                  PwCharSet.Digits + m_strSpecialCharSet);
             *          prfSub.CollectUserEntropy = false;
             *          prfSub.ExcludeCharacters = string.Empty;
             *          prfSub.ExcludeLookAlike = false;
             *          prfSub.Length = 11;
             *          prfSub.NoRepeatingCharacters = false;
             *
             *          string strPw;
             *          while(true)
             *          {
             *                  ulong u = crsRandomSource.GetRandomUInt64();
             *                  if(u >= 18446744073709551610UL) continue;
             *                  u %= 10UL;
             *
             *                  strPw = new string((char)('0' + (int)u), 1);
             *
             *                  byte[] pbEntropy = crsRandomSource.GetRandomBytes(32);
             *                  ProtectedString psSub;
             *                  if(PwGenerator.Generate(out psSub, prfSub, pbEntropy, null) !=
             *                          PwgError.Success) { Debug.Assert(false); continue; }
             *
             *                  strPw += psSub.ReadString();
             *                  if(Validate(strPw)) break;
             *          }
             *
             *          Debug.Assert(strPw.Length == 12);
             *          return new ProtectedString(false, strPw);*/
        }