Exemplo n.º 1
0
        private void addWebsiteToListView(KP2faC_Website website)
        {
            ListViewItem lvi = new ListViewItem(website.name);

            if (website.is2faPosssible())
            {
                lvi.BackColor = Color.LightGreen;
                lvi.SubItems.Add("Yes - " + website.getTfa());
                lvi.ImageIndex  = (int)PwIcon.Checked;
                lvi.ToolTipText = "URL: " + website.url;

                if (!string.IsNullOrEmpty(website.exception))
                {
                    lvi.ImageIndex  = (int)PwIcon.Warning;
                    lvi.ToolTipText = lvi.ToolTipText + "\nException: " + website.exception;
                }
            }
            else
            {
                lvi.BackColor = Color.LightSalmon;
                lvi.SubItems.Add("No");
                lvi.ImageIndex  = (int)PwIcon.Expired;
                lvi.ToolTipText = "Tell them to support 2fa:\n (Double click)";
            }
            lvi.Tag = website;
            lv_Websites.Items.Add(lvi);
        }
Exemplo n.º 2
0
        public void InitEx(PwEntry pe)
        {
            btn_Reload.Enabled = false;
            btn_Reload.Visible = false;

            RichTextBuilder rb = new RichTextBuilder();

            string strItemSeperator = Environment.NewLine;

            EvAppendEntryFieldProtectedString(rb, strItemSeperator, "Title", PwDefs.TitleField, pe);
            EvAppendEntryFieldProtectedString(rb, strItemSeperator, "Username", PwDefs.UserNameField, pe);
            EvAppendEntryFieldProtectedString(rb, strItemSeperator, "URL", PwDefs.UrlField, pe);

            this.Text = this.Text + " - " + pe.Strings.ReadSafe(PwDefs.TitleField);


            string         r           = "";
            string         totpAlready = "No";
            KP2faC_Website curWebsite  = null;
            bool           bPossible   = false;

            if ((pe.Strings.Exists("otp") && pe.Strings.Get("otp") != null) ||
                (pe.Strings.Exists("TOTP Seed") && pe.Strings.Get("TOTP Seed") != null))
            {
                totpAlready = "Yes";
            }
            string url = pe.Strings.ReadSafe(PwDefs.UrlField);

            pb_trafficlight.Image = Properties.Resources.trafficlight_orange;
            if (String.IsNullOrEmpty(url))
            {
                r = "No Url set. A Url is needed to check for 2fa support";
            }
            else
            {
                if (KP2faCheckerExt.dictKp2fac_WebsiteByDomain.Count > 0)
                {
                    string   prettifiedUrl = KP2faCheckerExt.prettifyUrl(url, KP2faCheckerExt.prettifyMode.AllWithoutTld);
                    string[] domainArray   = prettifiedUrl.Split('.').Reverse().ToArray();

                    var curDict = KP2faCheckerExt.dictKp2fac_WebsiteByDomain;
                    for (int i = 0; i < domainArray.Length; i++)
                    {
                        if (curDict.ContainsKey(domainArray[i]))
                        {
                            if (curDict[domainArray[i]] is KP2faC_Website)
                            {
                                if (((KP2faC_Website)curDict[domainArray[i]]).is2faPosssible())
                                {
                                    if (i == domainArray.Length - 1)
                                    {
                                        r                     = "Yes" + r;
                                        bPossible             = true;
                                        pb_trafficlight.Image = Properties.Resources.trafficlight_green;
                                    }
                                }
                                else
                                {
                                    r = "No" + r;
                                    pb_trafficlight.Image = Properties.Resources.trafficlight_red;
                                }
                                curWebsite = (KP2faC_Website)curDict[domainArray[i]];
                            }
                            else
                            {
                                curDict = (Dictionary <string, object>)curDict[domainArray[i]];
                                if (i == domainArray.Length - 1)
                                {
                                    if (curDict.ContainsKey("*") && curDict["*"] is KP2faC_Website)
                                    {
                                        if (((KP2faC_Website)curDict["*"]).is2faPosssible())
                                        {
                                            r                     = "Yes" + r;
                                            bPossible             = true;
                                            pb_trafficlight.Image = Properties.Resources.trafficlight_green;
                                        }
                                        else
                                        {
                                            r = "No" + r;
                                            pb_trafficlight.Image = Properties.Resources.trafficlight_red;
                                        }
                                        curWebsite = (KP2faC_Website)curDict["*"];
                                    }
                                }
                            }
                        }
                        else if (curDict.ContainsKey("*"))
                        {
                            if (curDict["*"] is KP2faC_Website)
                            {
                                if (((KP2faC_Website)curDict["*"]).is2faPosssible())
                                {
                                    r                     = "Yes" + r;
                                    bPossible             = true;
                                    pb_trafficlight.Image = Properties.Resources.trafficlight_green;
                                }
                                else
                                {
                                    r = "No" + r;
                                    pb_trafficlight.Image = Properties.Resources.trafficlight_red;
                                }
                                curWebsite = (KP2faC_Website)curDict["*"];
                            }
                            break;
                        }
                    }
                }
                else
                {
                    r = "Unknown. API Error!";
                    btn_Reload.Enabled = true;
                    btn_Reload.Visible = true;
                    btn_Reload.Tag     = pe;
                }
                if (string.IsNullOrEmpty(r))
                {
                    r = "Dont know!";
                }
            }
            EvAppendEntryFieldString(rb, strItemSeperator, "2FA already configured", totpAlready);
            rb.Build(rtb_Entry);

            rb = new RichTextBuilder();
            EvAppendEntryFieldString(rb, strItemSeperator, "2FA supported", r);
            if (bPossible && curWebsite != null)
            {
                rb.AppendLine();
                EvAppendEntryFieldString(rb, strItemSeperator, "Websitename", curWebsite.name);
                EvAppendEntryFieldString(rb, strItemSeperator, "2FA Options", curWebsite.getTfa());
                EvAppendEntryFieldString(rb, strItemSeperator, "Documentation", curWebsite.doc);
                if (!String.IsNullOrEmpty(curWebsite.exception))
                {
                    EvAppendEntryFieldString(rb, strItemSeperator, "Exception", curWebsite.exception);
                }
            }
            else if (!bPossible && curWebsite != null)
            {
                EvAppendEntryFieldString(rb, strItemSeperator, "This is wrong?", "Give a hint! https://toasted.top/kp2fac/");
                rb.AppendLine();
                EvAppendEntryFieldString(rb, strItemSeperator, "Tell them to support 2FA!", " ");
                if (!String.IsNullOrEmpty(curWebsite.email_address))
                {
                    EvAppendEntryFieldString(rb, strItemSeperator, "Email address", curWebsite.email_address);
                }
                if (!String.IsNullOrEmpty(curWebsite.facebook))
                {
                    EvAppendEntryFieldString(rb, strItemSeperator, "Facebook", curWebsite.facebook);
                }
                if (!String.IsNullOrEmpty(curWebsite.twitter))
                {
                    EvAppendEntryFieldString(rb, strItemSeperator, "Twitter", curWebsite.twitter);
                }
            }
            else
            {
                rb.AppendLine();
                EvAppendEntryFieldString(rb, strItemSeperator, "Is 2fa supported?", "Give a hint! https://toasted.top/kp2fac/");
            }

            rb.Build(rtb_2FA);
        }