示例#1
0
        private void HandleProfileSaveForm(SingleLineEditForm slef)
        {
            if (slef == null)
            {
                return;
            }

            //SingleLineEditForm is used multiple times
            //Check whether it's called from with the PwGeneratorForm
            System.Diagnostics.StackTrace st = new System.Diagnostics.StackTrace();
            if (st.GetFrames().SingleOrDefault(x => x.GetMethod().Name.Contains("OnBtnProfileSave")) == null)
            {
                return;
            }

            ComboBox cb = Tools.GetField("m_cmbEdit", slef) as ComboBox;

            if (cb == null)
            {
                PluginDebug.AddError("Cound not add 'Save db-specific' checkbox", 0, "m_cmbEdit not found");
                return;
            }
            CheckBox cbDB = new CheckBox();

            cbDB.Left = cb.Left;
            cbDB.Top  = DpiUtil.ScaleIntX(146);
            Button bOK = Tools.GetField("m_btnOK", slef) as Button;

            if (bOK != null)
            {
                cbDB.Top = bOK.Top + (int)((bOK.Height - cbDB.Height) / 2);
            }
            cbDB.Text            = PluginTranslate.SaveProfileInDB;
            cbDB.AutoSize        = true;
            cbDB.Enabled         = (m_host.Database != null) && m_host.Database.IsOpen;
            cbDB.CheckedChanged += AdjustProfileName;
            cb.Parent.SuspendLayout();
            cb.Parent.Controls.Add(cbDB);
            cb.Parent.ResumeLayout();
            cb.Parent.PerformLayout();

            cb.TextChanged += (o, e) =>
            {
                cbDB.CheckedChanged -= AdjustProfileName;
                cbDB.Checked         = cbDB.Enabled && (cb.Text.EndsWith(Config.ProfileDBOnly));
                cbDB.CheckedChanged += AdjustProfileName;
            };
        }
示例#2
0
        public override void Import(PwDatabase pwStorage, Stream sInput,
                                    IStatusLogger slLogger)
        {
            SingleLineEditForm dlg = new SingleLineEditForm();

            dlg.InitEx(KPRes.Password, KPRes.Import + ": " + this.FormatName,
                       KPRes.PasswordPrompt, Properties.Resources.B48x48_KGPG_Key2,
                       string.Empty, null);
            if (UIUtil.ShowDialogNotValue(dlg, DialogResult.OK))
            {
                return;
            }
            string strPassword = dlg.ResultString;

            UIUtil.DestroyForm(dlg);

            byte[] pbPassword = Encoding.Default.GetBytes(strPassword);

            BinaryReader br = new BinaryReader(sInput, Encoding.Default);

            ushort usFileVersion = br.ReadUInt16();

            if (usFileVersion != 0x0100)
            {
                throw new Exception(KLRes.FileVersionUnsupported);
            }

            uint uEntries = br.ReadUInt32();
            uint uKeySize = br.ReadUInt32();

            Debug.Assert(uKeySize == 50);             // It's a constant

            byte btKeyArrayLen = br.ReadByte();

            byte[] pbKey = br.ReadBytes(btKeyArrayLen);

            byte btValidArrayLen = br.ReadByte();

            byte[] pbValid = br.ReadBytes(btValidArrayLen);

            if (pbPassword.Length > 0)
            {
                MangleSetKey(pbPassword);
                MangleDecode(pbKey);
            }

            MangleSetKey(pbKey);
            MangleDecode(pbValid);
            string strValid = Encoding.Default.GetString(pbValid);

            if (strValid != "aacaaaadaaeabaacyuioqaqqaaaaaertaaajkadaadaaxywqea")
            {
                throw new Exception(KLRes.InvalidCompositeKey);
            }

            for (uint uEntry = 0; uEntry < uEntries; ++uEntry)
            {
                PwEntry pe = new PwEntry(true, true);
                pwStorage.RootGroup.AddEntry(pe, true);

                pe.Strings.Set(PwDefs.TitleField, new ProtectedString(
                                   pwStorage.MemoryProtection.ProtectTitle, ReadString(br)));
                pe.Strings.Set(PwDefs.UserNameField, new ProtectedString(
                                   pwStorage.MemoryProtection.ProtectUserName, ReadString(br)));
                pe.Strings.Set(PwDefs.PasswordField, new ProtectedString(
                                   pwStorage.MemoryProtection.ProtectPassword, ReadString(br)));
                pe.Strings.Set("Hint", new ProtectedString(false, ReadString(br)));
                pe.Strings.Set(PwDefs.NotesField, new ProtectedString(
                                   pwStorage.MemoryProtection.ProtectNotes, ReadString(br)));
                pe.Strings.Set(PwDefs.UrlField, new ProtectedString(
                                   pwStorage.MemoryProtection.ProtectUrl, ReadString(br)));
            }

            br.Close();
            sInput.Close();
        }
示例#3
0
        public override void Import(PwDatabase pwStorage, Stream sInput,
                                    IStatusLogger slLogger)
        {
            slLogger.SetText("> Spamex.com...", LogStatusType.Info);

            SingleLineEditForm dlgUser = new SingleLineEditForm();

            dlgUser.InitEx("Spamex.com", KPRes.WebSiteLogin + " - " + KPRes.UserName,
                           KPRes.UserNamePrompt, KeePass.Properties.Resources.B48x48_WWW,
                           string.Empty, null);
            if (UIUtil.ShowDialogNotValue(dlgUser, DialogResult.OK))
            {
                return;
            }
            string strUser = dlgUser.ResultString;

            UIUtil.DestroyForm(dlgUser);

            SingleLineEditForm dlgPassword = new SingleLineEditForm();

            dlgPassword.InitEx("Spamex.com", KPRes.WebSiteLogin + " - " + KPRes.Password,
                               KPRes.PasswordPrompt, KeePass.Properties.Resources.B48x48_WWW,
                               string.Empty, null);
            if (UIUtil.ShowDialogNotValue(dlgPassword, DialogResult.OK))
            {
                return;
            }
            string strPassword = dlgPassword.ResultString;

            UIUtil.DestroyForm(dlgPassword);

            RemoteCertificateValidationCallback pPrevCertCb =
                ServicePointManager.ServerCertificateValidationCallback;

            ServicePointManager.ServerCertificateValidationCallback =
                delegate(object sender, X509Certificate certificate, X509Chain chain,
                         SslPolicyErrors sslPolicyErrors)
            {
                return(true);
            };

            try
            {
                slLogger.SetText(KPRes.ImportingStatusMsg, LogStatusType.Info);

                string strPostData = @"toollogin=&MetaDomain=&LoginEmail=" +
                                     strUser + @"&LoginPassword="******"&Remember=1";

                List <KeyValuePair <string, string> > vCookies;
                string strMain = NetUtil.WebPageLogin(new Uri(UrlLoginPage),
                                                      strPostData, out vCookies);

                if (strMain.IndexOf("Welcome <b>" + strUser + "</b>") < 0)
                {
                    MessageService.ShowWarning(KPRes.InvalidUserPassword);
                    return;
                }

                string strIndexPage = NetUtil.WebPageGetWithCookies(new Uri(UrlIndexPage),
                                                                    vCookies, UrlDomain);

                ImportIndex(pwStorage, strIndexPage, vCookies, slLogger);

                int           nOffset   = 0;
                List <string> vSubPages = new List <string>();
                while (true)
                {
                    string strLink = StrUtil.GetStringBetween(strIndexPage, nOffset,
                                                              StrTabLinksStart, StrTabLinksEnd, out nOffset);
                    ++nOffset;

                    if (strLink.Length == 0)
                    {
                        break;
                    }

                    if (!strLink.StartsWith(StrTabLinkUrl))
                    {
                        continue;
                    }
                    if (vSubPages.IndexOf(strLink) >= 0)
                    {
                        continue;
                    }

                    vSubPages.Add(strLink);

                    string strSubPage = NetUtil.WebPageGetWithCookies(new Uri(
                                                                          UrlBase + strLink), vCookies, UrlDomain);

                    ImportIndex(pwStorage, strSubPage, vCookies, slLogger);
                }
            }
            finally
            {
                ServicePointManager.ServerCertificateValidationCallback = pPrevCertCb;
            }
        }