Exemplo n.º 1
0
        private void linkWriteNFC_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            PasswordForm pwdForm = new PasswordForm();

            if (pwdForm.ShowDialog(this) == DialogResult.OK)
            {
                try
                {
                    RFIDKeyProvider.ChipAction(new Action <Chip>(delegate(Chip chip)
                    {
                        NFCTagCardService nfcsvc = chip.getService(CardServiceType.CST_NFC_TAG) as NFCTagCardService;
                        if (nfcsvc == null)
                        {
                            throw new KeePassRFIDException(Properties.Resources.UnsupportedNFCTag);
                        }

                        NdefMessage msg = new NdefMessage();
                        msg.addTextRecord(pwdForm.Password, "en");

                        // Special case until new LLA SWIG version get released
                        if (nfcsvc is DESFireEV1NFCTag4CardService)
                        {
                            var storagesvc = chip.getService(CardServiceType.CST_STORAGE) as DESFireStorageCardService;
                            if (storagesvc == null)
                            {
                                throw new KeePassRFIDException(Properties.Resources.UnsupportedNFCTag);
                            }
                            storagesvc.erase();
                        }
                        else
                        {
                            nfcsvc.eraseNDEF();
                        }

                        nfcsvc.writeNDEF(msg);
                    }), GetConfiguration());

                    MessageBox.Show(Properties.Resources.NFCTagWritten, Properties.Resources.Information, MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                catch (KeePassRFIDException ex)
                {
                    MessageBox.Show(ex.Message, Properties.Resources.PluginError, MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
Exemplo n.º 2
0
        private void linkWriteNFC_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            PasswordForm pwdForm = new PasswordForm();

            if (pwdForm.ShowDialog(this) == DialogResult.OK)
            {
                try
                {
                    RFIDKeyProvider.ChipAction(new Action <Chip>(delegate(Chip chip)
                    {
                        // Only tag type 4 supported for now.
                        NFCTagCardService nfcsvc = chip.getService(CardServiceType.CST_NFC_TAG) as NFCTagCardService;
                        if (nfcsvc == null)
                        {
                            throw new KeePassRFIDException(Properties.Resources.UnsupportedNFCTag);
                        }

                        NdefMessage msg = new NdefMessage();
                        msg.addTextRecord(pwdForm.Password);

                        StorageCardService storage = chip.getService(CardServiceType.CST_STORAGE) as StorageCardService;
                        if (storage != null)
                        {
                            storage.erase();
                        }
                        nfcsvc.writeNDEF(msg);
                    }), GetConfiguration());

                    MessageBox.Show(Properties.Resources.NFCTagWritten, Properties.Resources.Information, MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                catch (KeePassRFIDException ex)
                {
                    MessageBox.Show(ex.Message, Properties.Resources.PluginError, MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }