Ejemplo n.º 1
0
        public async void InitExAsync()
        {
            buildListView();
            bRetrievingJson = true;
            doSearchAsync();

            startAnimation("Loading");
            btn_Search.Enabled = false;
            btn_Reload.Enabled = false;

            KP2faC_FileloaderAsync fileloader = new KP2faC_FileloaderAsync(KP2faCheckerExt.getKP2faC_Config());
            string json = await fileloader.GetJsonAsync();

            stopAnimation();

            if (!json.Equals("KP2faC API error"))
            {
                listKP2faC_Website = JsonConvert.DeserializeObject <List <KP2faC_Website> >(json);
                doSearchAsync();
            }
            else
            {
                btn_Search.Enabled = true;
                btn_Reload.Enabled = true;
            }
            bRetrievingJson = false;
        }
Ejemplo n.º 2
0
 private void btn_Reload_Click(object sender, EventArgs e)
 {
     KP2faCheckerExt.init(true);
     if (btn_Reload.Tag is PwEntry)
     {
         InitEx((PwEntry)btn_Reload.Tag);
     }
 }
Ejemplo n.º 3
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);
        }