Exemplo n.º 1
0
 public void NCFRingDown(string id, Dictionary <string, object> parameters, SystemState state)
 {
     //if(state.SessionStatus != SessionState.Locked && state.SessionStatus != SessionState.LoggedOff)
     //{
     //    // we dont need to do anything if it's already active
     //    return;
     //}
     if (!state.CredentialData.ProviderActive || state.CredentialData.Client == null)
     {
         return;
     }
     // intially we'll send the ID to replace existing reader functionality.
     // then we'll swap to sending a username and password (ideally it'll be encrypted)
     NFCRing.Service.Core.ServiceCore.Log("Unlock Workstation: Send data to client");
     try
     {
         TcpClient tc = state.CredentialData.Client;
         ServiceCommunication.SendNetworkMessage(ref tc, (string)parameters["Username"]);
         ServiceCommunication.SendNetworkMessage(ref tc, NFCRing.Service.Common.Crypto.Decrypt((string)parameters["Password"], id));
         // send domain if they set one else send a blank
         ServiceCommunication.SendNetworkMessage(ref tc, (parameters.ContainsKey("Domain") ? (string)parameters["Domain"] : ""));
         state.CredentialData.Client = tc;
     }
     catch (Exception ex)
     {
         // it blew up
         state.CredentialData.Client.Close(); // maybe i shouldnt do this here?
         state.CredentialData.ProviderActive = false;
         state.CredentialData.Client         = null;
     }
 }
Exemplo n.º 2
0
        private void frmNewToken_Load(object sender, EventArgs e)
        {
            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);
                    if (tsk.Result != "")
                    {
                        ClientCommon.SetControlPropertyThreadSafe(txtToken, "Text", JsonConvert.DeserializeObject <NetworkMessage>(tsk.Result).Token);
                        ClientCommon.SetControlPropertyThreadSafe(lblSwipe, "Visible", false);
                    }
                    else
                    {
                        // failed to scan a ring.
                        Invoke(new Action(Close));
                    }
                }
                else
                {
                    // still waiting for it to be scanned
                    value += 7;
                    ClientCommon.SetControlPropertyThreadSafe(pgbAwaitingToken, "Value", value);
                }
            }, task, 1000, 1000);
            pgbAwaitingToken.Visible = true;
        }
Exemplo n.º 3
0
        public async Task <Dictionary <string, string> > GetTokensAsync(string userName)
        {
            TcpClient client = null;

            ServiceCommunication.SendNetworkMessage(ref client, JsonConvert.SerializeObject(new NetworkMessage(MessageType.GetState)
            {
                Username = userName
            }));

            var response = await Task <string> .Factory.StartNew(() =>
            {
                return(ServiceCommunication.ReadNetworkMessage(ref client));
            });

            if (string.IsNullOrEmpty(response))
            {
                return(new Dictionary <string, string>());
            }

            UserServerState userServerState = JsonConvert.DeserializeObject <UserServerState>(response);

            _logger.Trace($"GetTokensAsync: {JsonConvert.SerializeObject(userServerState.UserConfiguration.Tokens)}");

            return(userServerState.UserConfiguration.Tokens ?? new Dictionary <string, string>());
        }
Exemplo n.º 4
0
        public LoginVm()
        {
            LoginBtnClickedCmd = new RelayCommand <object>(Login);

            //Crate Instance of Communication
            client = new ServiceCommunication();
            client.InitClient();
        }
Exemplo n.º 5
0
        private void SendCancel(ref TcpClient client)
        {
            _logger.Trace("Send CancelRegistration");

            var cancelMessage = ServiceCommunication.SendNetworkMessage(ref client, JsonConvert.SerializeObject(new NetworkMessage(MessageType.CancelRegistration)));

            _logger.Trace($"CancelRegistration: {cancelMessage}");
        }
Exemplo n.º 6
0
 private void btnNetworkRegistrationStart_Click(object sender, EventArgs e)
 {
     if (ServiceCommunication.SendNetworkMessage(ref client, JsonConvert.SerializeObject(new NetworkMessage(MessageType.GetToken))) > 0)
     {
         frmNewToken nt = new frmNewToken(ref client);
         nt.ShowDialog();
         LoadConfig();
     }
 }
Exemplo n.º 7
0
        public void SendMessage()
        {
            ServiceCommunication com = new ServiceCommunication();

            com.Start();
            com.Submit(new CoreMessage()
            {
                Source = "WebService", Date = DateTime.Now, Data = "Test"
            });
        }
Exemplo n.º 8
0
        public AdminAccountsVm()
        {
            //Get Parameter - optional - Set identifier parameter to: "ViewModel + Identifier", eg.: "DemoReceiverIdentifier"
            messenger.Register <PropertyChangedMessage <MessageContent> >(this, "AdminAccountsIdentifier", GetParameter);

            NewAdmin = new AdminVm();
            SaveBtnClickedCommand = new RelayCommand(SaveAdmin, CanExecuteSaveBtn);

            client = new ServiceCommunication();
        }
Exemplo n.º 9
0
 private void btnCancel_Click(object sender, EventArgs e)
 {
     if (t != null)
     {
         t.Change(Timeout.Infinite, Timeout.Infinite); // stop the timer
     }
     // tell the service we dont care anymore
     ServiceCommunication.SendNetworkMessage(ref client, JsonConvert.SerializeObject(new NetworkMessage(MessageType.CancelRegistration)));
     pgbAwaitingToken.Visible = false;
     pgbAwaitingToken.Value   = 0;
     this.Close();
 }
Exemplo n.º 10
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?
            }
        }
Exemplo n.º 11
0
 private void btnDeleteToken_Click(object sender, EventArgs e)
 {
     if (tvwConfig.SelectedNode.Tag.ToString() == "Token")
     {
         string         tokenId = uss.UserConfiguration.Tokens.Keys.ToList()[tvwConfig.SelectedNode.Index];
         NetworkMessage nm      = new NetworkMessage(MessageType.Delete)
         {
             Username = uss.UserConfiguration.Username, Token = tokenId
         };
         ServiceCommunication.SendNetworkMessage(ref client, JsonConvert.SerializeObject(nm));
         LoadConfig();
     }
     btnDeleteToken.Enabled = false;
 }
Exemplo n.º 12
0
 private void btnDeleteEvent_Click(object sender, EventArgs e)
 {
     if (tvwConfig.SelectedNode.Tag.ToString() == "Event")
     {
         Event          ev = uss.UserConfiguration.Events[tvwConfig.SelectedNode.Index];
         NetworkMessage nm = new NetworkMessage(MessageType.Delete)
         {
             Username = uss.UserConfiguration.Username, Token = ev.Token, PluginName = ev.PluginName
         };
         ServiceCommunication.SendNetworkMessage(ref client, JsonConvert.SerializeObject(nm));
         LoadConfig();
     }
     btnDeleteEvent.Enabled = false;
 }
Exemplo n.º 13
0
        public ReportedPicturesVm()
        {
            //Get Params - optional - Set identifier parameter to: "ViewModel + Identifier", eg.: "DemoReceiverIdentifier"
            messenger.Register <PropertyChangedMessage <MessageContent> >(this, "ReportedPicturesIdentifier", SetParameter);

            AllowPictureBtnClickedCmd  = new RelayCommand(PictureIsAllowed, CanExecuteAllowPictureBtn);
            DeletePictureBtnClickedCmd = new RelayCommand(PictureIsForbidden, CanExecuteDeletePictureBtn);

            client  = new ServiceCommunication();
            Reports = new ObservableCollection <ReportVm>();

            //Get Data
            GetReports();
        }
Exemplo n.º 14
0
        public bool Ping()
        {
            TcpClient client = null;

            var result = ServiceCommunication.SendNetworkMessage(ref client, JsonConvert.SerializeObject(new NetworkMessage(MessageType.State)));

            if (result == 0)
            {
                _logger.Error($"Service not available");

                return(false);
            }

            return(true);
        }
Exemplo n.º 15
0
        public async Task RemoveTokenAsync(string token)
        {
            TcpClient client = null;

            ServiceCommunication.SendNetworkMessage(ref client,
                                                    JsonConvert.SerializeObject(new NetworkMessage(MessageType.Delete)
            {
                Token = token, Username = _userCredentials.GetName()
            }));

            _logger.Trace($"RemoveTokenAsync: {token}");

            RemoveTokenImage(token);

            await Task.Yield();
        }
Exemplo n.º 16
0
        public async Task UpdateNameAsync(string token, string name)
        {
            TcpClient client = null;

            await Task.Factory.StartNew(() =>
            {
                ServiceCommunication.SendNetworkMessage(ref client,
                                                        JsonConvert.SerializeObject(new NetworkMessage(MessageType.UpdateFriendlyName)
                {
                    TokenFriendlyName = name,
                    Token             = token
                }));
            });

            _logger.Trace($"UpdateNameAsync: name: {name} token: {token}");
        }
Exemplo n.º 17
0
        public async Task AddTokenAsync(string userName, string password, string token)
        {
            TcpClient client = null;

            var ringName = await GetRingNameAsync(userName);

            await Task.Factory.StartNew(() =>
            {
                ServiceCommunication.SendNetworkMessage(ref client,
                                                        JsonConvert.SerializeObject(new NetworkMessage(MessageType.RegisterAll)
                {
                    TokenFriendlyName = ringName,
                    Username          = userName,
                    Password          = Crypto.Encrypt(password, token),
                    Token             = token
                }));
            });

            _logger.Trace($"AddTokenAsync: username: {userName} token: {token}");
        }
Exemplo n.º 18
0
        private string GetNewToken(CancellationToken cancellationToken)
        {
            TcpClient client = null;

            _logger.Trace($"Send GetToken");

            var getTokenMessage = ServiceCommunication.SendNetworkMessage(ref client, JsonConvert.SerializeObject(new NetworkMessage(MessageType.GetToken)));

            _logger.Trace($"GetToken: {getTokenMessage}");

            if (getTokenMessage <= 0)
            {
                return(null);
            }

            _logger.Trace($"Send ReadNetworkMessage");

            if (cancellationToken.IsCancellationRequested)
            {
                return(null);
            }

            try
            {
                var message = ServiceCommunication.ReadNetworkMessage(ref client);
                if (!string.IsNullOrEmpty(message))
                {
                    _logger.Trace($"GetNewToken: {message}");
                    var networkMessage = JsonConvert.DeserializeObject <NetworkMessage>(message);
                    return(networkMessage?.Token);
                }

                return(null);
            }
            finally
            {
                SendCancel(ref client);
            }
        }
Exemplo n.º 19
0
        public void ReadNetwork(object tc)
        {
            TcpClient client = tc as TcpClient;

            while ((state == ServiceState.Running || state == ServiceState.Starting) && client != null && client.Connected)
            {
                // do a read
                try
                {
                    string message = ServiceCommunication.ReadNetworkMessage(ref client);
                    // do something with data the provider sent us
                    if (message == "")
                    {
                        goto EndConnection;
                    }
                    else
                    {
                        NetworkMessage nm;
                        Log("Message received from network: " + message);
                        try
                        {
                            nm = JsonConvert.DeserializeObject <NetworkMessage>(message);
                        }
                        catch (Exception ex)
                        {
                            Log(message);
                            continue;
                        }
                        // the first message should probably be the type of message we're receiving
                        switch (nm.Type)
                        {
                        case MessageType.CancelRegistration:
                        {
                            SystemStatus.AwaitingToken = false;
                            break;
                        }

                        case MessageType.GetToken:
                        {
                            // we don't need to do anything here except store this connection and wait for a ring swipe
                            // SystemStatus.CredentialData.Client
                            SystemStatus.RegistrationClient = client;
                            SystemStatus.AwaitingToken      = true;
                            break;
                        }

                        case MessageType.RegisterToken:
                        {
                            // save this token against this username to be selected from the list later
                            RegisterToken(nm.Username, nm.Token, nm.TokenFriendlyName);
                            break;
                        }

                        case MessageType.GetState:
                        {
                            // return the current configuration for this user
                            bool            userfound = false;
                            UserServerState uss       = new UserServerState();
                            if (ApplicationConfiguration.Users != null)
                            {
                                foreach (User u in ApplicationConfiguration.Users)
                                {
                                    if (u.Username == nm.Username)
                                    {
                                        uss.UserConfiguration = u;
                                        // also need to send a list of plugins.
                                        userfound = true;
                                        break;
                                    }
                                }
                            }
                            if (!userfound)
                            {
                                uss.UserConfiguration = new User();
                            }
                            uss.Plugins = new List <PluginInfo>();
                            foreach (Lazy <INFCRingServicePlugin> p in plugins)
                            {
                                uss.Plugins.Add(new PluginInfo()
                                    {
                                        Name = p.Value.GetPluginName(), Parameters = p.Value.GetParameters()
                                    });
                            }
                            ServiceCommunication.SendNetworkMessage(ref client, JsonConvert.SerializeObject(uss));
                            break;
                        }

                        case MessageType.Message:
                        {
                            Log(nm.Message);
                            break;
                        }

                        case MessageType.AssociatePluginToToken:
                        {
                            // get a plugin name, token, and if this plugin requires a credential, do the provider swap and lock the pc
                            RegisterCredential(nm.Username, nm.Password, nm.Token, nm.PluginName);
                            break;
                        }

                        case MessageType.UserCredential:
                        {
                            //Log(message);
                            Log("Credential received");
                            if (SystemStatus.RegistrationClient != null && SystemStatus.RegistrationClient.Connected)
                            {
                                TcpClient otc = SystemStatus.RegistrationClient;
                                ServiceCommunication.SendNetworkMessage(ref otc, JsonConvert.SerializeObject(new NetworkMessage(MessageType.UserCredential)
                                    {
                                        Username = nm.Username, Password = Convert.ToBase64String(Encoding.UTF8.GetBytes(nm.Password))
                                    }));
                                SystemStatus.RegistrationClient = otc;
                            }
                            // so this is where the user registration credential provider sends an actual user credential
                            break;
                        }

                        case MessageType.Delete:
                        {
                            Log("Deleting item");
                            if (String.IsNullOrEmpty(nm.Username))
                            {
                                break;         // no username? lets not modify the config
                            }
                            if (!String.IsNullOrEmpty(nm.Token) && !String.IsNullOrEmpty(nm.PluginName))
                            {
                                // delete an event
                                RemoveEvent(nm.Username, nm.Token, nm.PluginName);
                            }
                            else if (!String.IsNullOrEmpty(nm.Token))
                            {
                                // delete a token entirely (this will also delete all its events)
                                RemoveToken(nm.Username, nm.Token);
                            }
                            break;
                        }

                        case MessageType.RegisterAll:
                        {
                            Log("Registering new token against all plugins");
                            string dht = RegisterToken(nm.Username, nm.Token, nm.TokenFriendlyName);
                            foreach (Lazy <INFCRingServicePlugin> p in plugins)
                            {
                                RegisterCredential(nm.Username, nm.Password, dht, p.Value.GetPluginName());
                            }
                            break;
                        }

                        case MessageType.UpdateFriendlyName:
                        {
                            Log("Update token friendly name");

                            UpdateFriendlyName(nm);

                            break;
                        }

                        default:
                            // failed
                            Log("Unknown network message received: " + message);
                            break;
                        }
                    }
                }
                catch (Exception ex)
                {
                    Log("TCP Client disconnected");
                    if (client.Connected)
                    {
                        client.Close();
                    }
                }
            }
EndConnection:
            Log("TCP Client network loop ended");
            if (client.Connected)
            {
                client.Close();
            }
            client = null;

            if (SystemStatus.RegistrationClient == null || !SystemStatus.RegistrationClient.Connected)
            {
                SystemStatus.AwaitingToken = false;
            }
            if (SystemStatus.CredentialData.Client == null || !SystemStatus.CredentialData.Client.Connected)
            {
                SystemStatus.CredentialData.ProviderActive = false;
            }
        }
Exemplo n.º 20
0
        // thread to monitor nfc reader
        private void ScanForId()
        {
            Log("NFC Reading started");
            string currentId = "";

            // basically keep running until we're told to stop
            while (state == ServiceState.Starting || state == ServiceState.Running)
            {
                // start dll and just call it
                IntPtr idloc  = Marshal.AllocHGlobal(100);
                IntPtr errloc = Marshal.AllocHGlobal(100);
                int    len    = PCSC_GetID(idloc, errloc);
                string error  = Marshal.PtrToStringAnsi(errloc);
                string id     = "";
                if (len > 0)
                {
                    id = Marshal.PtrToStringAnsi(idloc, len);
                }
                //else
                //    Log("Read error: " + error);

                Marshal.FreeHGlobal(idloc);
                Marshal.FreeHGlobal(errloc);

                // check the id of the token
                if (currentId == "" && id != "")
                {
                    Log("NFCTagDownEvent");
                    currentId = id;
                    // we just got a new token (state change)

                    // load parameters from config
                    if (SystemStatus.AwaitingToken)
                    {
                        // this is where we capture it and show the next screen
                        if (SystemStatus.RegistrationClient != null)
                        {
                            TcpClient c = SystemStatus.RegistrationClient;
                            ServiceCommunication.SendNetworkMessage(ref c, JsonConvert.SerializeObject(new NetworkMessage()
                            {
                                Type = MessageType.Token, Token = id
                            }));
                            SystemStatus.RegistrationClient = c;
                        }
                    }
                    else
                    {
                        // check config
                        foreach (User u in ApplicationConfiguration.Users)
                        {
                            string hashedToken = Crypto.Hash(Crypto.Hash(id) + u.Salt);
                            foreach (Event e in u.Events)
                            {
                                if (hashedToken == e.Token)
                                {
                                    foreach (Lazy <INFCRingServicePlugin> plugin in plugins)
                                    {
                                        if (plugin.Value.GetPluginName() == e.PluginName)
                                        {
                                            plugin.Value.NCFRingDown(id, e.Parameters, SystemStatus);

                                            Log("Plugin " + plugin.Value.GetPluginName() + " passed TagDown event");
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                else if (currentId != "" && id == "")
                {
                    Log("NFCTagUpEvent");
                    string origId = currentId;
                    currentId = "";
                    // we just lost the token (state change)
                    if (SystemStatus.AwaitingToken)
                    {
                        // they just lifted it. reset this
                        SystemStatus.AwaitingToken = false;
                    }
                    else
                    {
                        // check config
                        foreach (User u in ApplicationConfiguration.Users)
                        {
                            string hashedToken = Crypto.Hash(Crypto.Hash(id) + u.Salt);
                            foreach (Event e in u.Events)
                            {
                                if (hashedToken == e.Token)
                                {
                                    foreach (Lazy <INFCRingServicePlugin> plugin in plugins)
                                    {
                                        if (plugin.Value.GetPluginName() == e.PluginName)
                                        {
                                            plugin.Value.NCFRingUp(id, e.Parameters, SystemStatus);
                                            Log("Plugin " + plugin.Value.GetPluginName() + " passed TagUp event");
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                // sleep for configured delay?
                Thread.Sleep(100);
            }
            Log("NFC Reading stopped");
        }
Exemplo n.º 21
0
        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();
            }
        }
Exemplo n.º 22
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));
                }
            }
        }