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; } }
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(); }