コード例 #1
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            NetworkMessage nm = new NetworkMessage(MessageType.AssociatePluginToToken);

            if (cboTokens.SelectedItem.ToString() == "")
            {
                MessageBox.Show("Select a token to register");
                return;
            }
            else
            {
                nm.Token = cboTokens.SelectedItem.ToString().Split('-')[1].Trim();
            }
            if (cboPlugins.SelectedItem.ToString() == "")
            {
                MessageBox.Show("Select a plugin to register an event for.");
                return;
            }
            else
            {
                nm.PluginName = cboPlugins.SelectedItem.ToString();
            }
            foreach (DataGridViewRow dgvr in dgvParameters.Rows)
            {
                if ((bool)dgvr.Cells["dgcIsOptional"].Value == false)
                {
                    if (dgvr.Cells["dgcValue"].Value.ToString() == "")
                    {
                        MessageBox.Show("Fill in the required paramters or go home");
                        return;
                    }
                    else
                    {
                        if (dgvr.Cells["dgcName"].Value.ToString() == "Username")
                        {
                            nm.Username = dgvr.Cells["dgcValue"].Value.ToString(); // this should be a list instead of specific properties
                        }
                        else if (dgvr.Cells["dgcName"].Value.ToString() == "Password")
                        {
                            nm.Password = actualPassword;//dgvr.Cells["dgcValue"].Value.ToString(); // make this a single-hashed version of the token
                        }
                    }
                }
            }
            if (!string.IsNullOrEmpty(nm.Password))
            {
                lblSwipeEncrypt.Visible  = true;
                pgbAwaitingToken.Visible = true;
                // need to do a progress bar and ask for a ring to encrypt credential
                if (ServiceCommunication.SendNetworkMessage(ref client, JsonConvert.SerializeObject(new NetworkMessage(MessageType.GetToken))) > 0)
                {
                    // swipe ring to encrypt
                    int value = 0;
                    var task  = Task <string> .Factory.StartNew(() => { return(ServiceCommunication.ReadNetworkMessage(ref client)); });

                    t = new System.Threading.Timer((o) =>
                    {
                        Task <string> tsk = (Task <string>)o;
                        if (tsk.IsCompleted)
                        {
                            t.Change(Timeout.Infinite, Timeout.Infinite); // stop the timer
                            ClientCommon.SetControlPropertyThreadSafe(pgbAwaitingToken, "Visible", false);
                            ClientCommon.SetControlPropertyThreadSafe(lblSwipeEncrypt, "Visible", false);
                            if (tsk.Result != "")
                            {
                                string rawToken = JsonConvert.DeserializeObject <NetworkMessage>(tsk.Result).Token;
                                nm.Password     = NFCRing.Service.Common.Crypto.Encrypt(nm.Password, rawToken);
                                if (ServiceCommunication.SendNetworkMessage(ref client, JsonConvert.SerializeObject(nm)) > 0)
                                {
                                    Invoke(new Action(Close));
                                }
                            }
                            else
                            {
                                // failed to scan a ring.
                                // do we want to allow unencrypted passwords?
                            }
                        }
                        else
                        {
                            // still waiting for it to be scanned
                            value += 7;
                            ClientCommon.SetControlPropertyThreadSafe(pgbAwaitingToken, "Value", value);
                        }
                    }, task, 1000, 1000);
                    pgbAwaitingToken.Visible = true;
                }
            }
            else
            {
                // This event doesnt have a password field
                if (ServiceCommunication.SendNetworkMessage(ref client, JsonConvert.SerializeObject(nm)) > 0)
                {
                    Invoke(new Action(Close));
                }
            }
        }
コード例 #2
0
        private void btnRegister_Click(object sender, EventArgs e)
        {
            // this should take the token ID, friendly name, and the current username (with domain) and send it to the service
            int res = ServiceCommunication.SendNetworkMessage(ref client, JsonConvert.SerializeObject(new NetworkMessage(MessageType.RegisterToken)
            {
                Token = txtToken.Text, TokenFriendlyName = txtFriendlyName.Text, Username = ClientCommon.GetCurrentUsername()
            }));

            if (res > 0)
            {
                this.Close(); // we might have registered a token now?
            }
        }
コード例 #3
0
ファイル: Form1.cs プロジェクト: zero-system/Sesame
        private void LoadConfig()
        {
startAgain:
            ServiceCommunication.SendNetworkMessage(ref client, JsonConvert.SerializeObject(new NetworkMessage(MessageType.GetState)
            {
                Username = ClientCommon.GetCurrentUsername()
            }));
            var task = Task <string> .Factory.StartNew(() =>
            {
                return(ServiceCommunication.ReadNetworkMessage(ref client));
            });

            if (task.Result == "")
            {
                if (MessageBox.Show("Unable to connect to service. Please make sure its running", "NFC Ring Service Registration App", MessageBoxButtons.RetryCancel) == DialogResult.Cancel)
                {
                    Application.Exit();
                }
                // RETRY ISNT GOING TO DO ANYTHING YET
                goto startAgain;
            }
            else
            {
                tvwConfig.Nodes.Clear();
                uss = JsonConvert.DeserializeObject <UserServerState>(task.Result);
                TreeNode user   = tvwConfig.Nodes.Add(uss.UserConfiguration.Username);
                TreeNode tokens = user.Nodes.Add("Tokens");
                if (uss.UserConfiguration.Tokens != null)
                {
                    foreach (KeyValuePair <string, string> tok in uss.UserConfiguration.Tokens)
                    {
                        TreeNode tokenNode = tokens.Nodes.Add(tok.Value + " - " + tok.Key);
                        tokenNode.Tag = "Token";
                    }
                }
                TreeNode plugins = user.Nodes.Add("Plugins");
                if (uss.Plugins != null)
                {
                    foreach (PluginInfo p in uss.Plugins)
                    {
                        TreeNode aPlugin = plugins.Nodes.Add(p.Name);
                        aPlugin.Tag = "Plugin";
                    }
                }
                TreeNode events = user.Nodes.Add("Events");
                if (uss.UserConfiguration.Events != null)
                {
                    foreach (Event ev in uss.UserConfiguration.Events)
                    {
                        TreeNode eventNode = events.Nodes.Add(ev.PluginName + " - " + ev.Token);
                        eventNode.Tag = "Event";
                        foreach (KeyValuePair <string, object> param in ev.Parameters)
                        {
                            if (param.Value != null)
                            {
                                TreeNode e = eventNode.Nodes.Add(param.Key + " = " + param.Value.ToString());
                                //e.Tag = "Event";
                            }
                        }
                    }
                }
                if ((uss.UserConfiguration.Tokens != null && uss.UserConfiguration.Tokens.Count > 0) && (uss.Plugins != null && uss.Plugins.Count > 0))
                {
                    btnAddEvent.Enabled = true;
                }
                tvwConfig.ExpandAll();
            }
        }