Exemple #1
0
        public static void SetExtraSignDataFromTag(this NdefHandler handler, Tag tag)
        {
            if (tag == null)
            {
                handler.ClearExtraSignData();
                return;
            }

            byte[]   uid   = tag.GetId();
            string[] techs = tag.GetTechList();

            byte[] nuid = new byte[uid.Length + 1];
            Buffer.BlockCopy(uid, 0, nuid, 0, uid.Length);

            if (techs.Contains(Java.Lang.Class.FromType(typeof(MifareUltralight)).CanonicalName))
            {
                nuid[uid.Length] = 0xAA;
            }
            else if (techs.Contains(Java.Lang.Class.FromType(typeof(MifareClassic)).CanonicalName))
            {
                nuid[uid.Length] = 0xBB;
            }
            else
            {
                nuid = uid;
            }

            handler.SetExtraSignData(nuid);
        }
Exemple #2
0
        private byte[] ProcessUpdate(byte[] apdu)
        {
            int address = ((apdu[2] & 0xFF) << 8) | (apdu[3] & 0xFF);

            if (address < 0 || address >= 1024)
            {
                return(WRONG_PARAMETERS);
            }

            if (address != 0)
            {
                return(WRONG_PARAMETERS);
            }

            int length = apdu[4] & 0xFF;

            if (apdu.Length < length + 5)
            {
                return(STATUS_FAILED);
            }

            if (dataToPublish == null || confirmed)
            {
                return(FILE_NOT_FOUND);
            }

            byte[] challenge = new byte[length];
            Buffer.BlockCopy(apdu, 5, challenge, 0, length);

            try
            {
                ndefHandler.SetKeys(AppSettings.Global.PubKey, AppSettings.Global.PrivKey);
                ndefHandler.SetExtraSignData(challenge);
                ndefHandler.KeepEmptyFields = true;

                ndefData = ndefHandler.GenerateRawNdefMessage(dataToPublish);

                return(STATUS_SUCCESS);
            }
            catch (Exception e)
            {
                ShowToast("Failed preparing HCE data: " + e.Message);
                return(STATUS_FAILED);
            }
            finally
            {
                ndefHandler.ClearKeys();
                ndefHandler.ClearExtraSignData();
            }
        }