Exemple #1
0
        private void buttonQuery_Click(object sender, EventArgs e)
        {
            string  profile;
            JObject j;
            bool    verified = false;
            string  owner    = textBoxAccount.Text;

            if (owner.Contains("@"))
            {
                owner    = ProfileContractHelper.QueryOwner(owner);
                verified = true;
            }
            j       = ProfileContractHelper.QueryByAccount(owner);
            profile = j.ToString();
            string email = j["email"].AsString();

            if (email != "" && !verified)
            {
                JObject j1     = ProfileContractHelper.Query(email);
                string  email1 = j1["email"].AsString();
                verified = email1.Equals(email);
            }
            textBoxProfile.Text          = profile;
            labelVerificationStatus.Text = verified ? "Yes" : "No";
            textBoxAddress.Text          = owner;
        }
        private void RefreshCurrentAccountProfile()
        {
            string  owner    = comboBoxAccounts.Text;
            JObject j        = ProfileContractHelper.QueryByAccount(owner);
            string  profile  = j.ToString();
            string  email    = j["email"].AsString();
            bool    verified = false;

            if (email != "")
            {
                JObject j1     = ProfileContractHelper.Query(email);
                string  email1 = j1["email"].AsString();
                verified = email1.Equals(email);
            }
            textBoxProfile.Text          = profile;
            labelVerificationStatus.Text = verified ? "Yes" : "No";
            linkLabelVerifyLink.Visible  = !verified && email != "";
            if (linkLabelVerifyLink.Visible)
            {
                emailVerifyReqParams = new Dictionary <string, string>()
                {
                    { "email", email },
                    { "owner", owner },
                };
            }
        }
        private string CheckCurrentAccountProfile()
        {
            JObject profile = ProfileContractHelper.QueryByAccount(comboBoxAccounts.Text);
            string  email   = profile["email"].AsString();

            if (email == "")
            {
                MessageBox.Show("Your current account has no valid email binding yet, register one first", "Error!");
                return("");
            }
            return(email);
        }
        private void buttonVerifyResponse_Click(object sender, EventArgs e)
        {
            if (!CheckEmailAddressInput())
            {
                return;
            }
            string  myEmail = CheckCurrentAccountProfile();
            JObject j       = ParseChallengeMessageSend(textBoxChallengeSend.Text.Trim(), myEmail);

            if (j == null)
            {
                return;
            }
            string challenge = j["challenge"].AsString();
            string message   = textBoxResponseReceived.Text.Trim();

            string[] parts = message.Split('\n');
            if (parts.Length != 2)
            {
                MessageBox.Show("Received response message is invalid", "Error!");
                return;
            }
            try
            {
                JObject j1       = JObject.Parse(parts[0]);
                string  purpose  = j1["purpose"].AsString();
                string  from     = j1["from"].AsString();
                string  to       = j1["to"].AsString();
                string  address  = j1["address"].AsString();
                string  response = j1["response"].AsString();
                if (purpose != "NEO email address verification response" || response.Length != 16)
                {
                    MessageBox.Show("Received response message is invalid", "Error!");
                    return;
                }
                if (from != textBoxPeerEmail.Text)
                {
                    MessageBox.Show("Received response message is not send from email addree to be verified", "Error!");
                    return;
                }
                if (to != myEmail)
                {
                    MessageBox.Show("Received response message is not send to current selected account", "Error!");
                    return;
                }
                JObject j2        = ProfileContractHelper.QueryByAccount(address);
                string  peerEmail = j2["email"].AsString();
                if (peerEmail != from)
                {
                    MessageBox.Show("Received response message is send from email address different than its profile", "Error!");
                    return;
                }
                string pubkey = j2["pubkey"].AsString();
                if (!VerifySignature(parts[0], parts[1], pubkey))
                {
                    MessageBox.Show("Received response message has invalid signature!", "Error!");
                    return;
                }
                if (response != challenge)
                {
                    MessageBox.Show("Received response message has invalid response code than your original generated challenge code", "Error!");
                    return;
                }
                MessageBox.Show("The email address has pass all verication test successfully");
            }
            catch (Exception)
            {
                MessageBox.Show("Received challenge message is invalid", "Error!");
                return;
            }
        }