Exemplo n.º 1
0
        /// <summary>
        /// Insert keys into tag
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnInsertKeys_Click(object sender, RoutedEventArgs e)
        {
            TagOp op;

            try
            {
                if (txtbxKeyOne.Text.Replace(" ", "").Length == 32 && txtbxKeyZero.Text.Replace(" ", "").Length == 32)
                {
                    byte[]   KeytoWrite = ByteFormat.FromHex(txtbxKeyZero.Text.Replace(" ", ""));
                    ushort[] Key0       = new ushort[KeytoWrite.Length / 2];
                    Key0 = ByteConv.ToU16s(KeytoWrite);
                    op   = new Gen2.WriteData(Gen2.Bank.USER, 0xC0, Key0);
                    objReader.ExecuteTagOp(op, searchSelect);

                    KeytoWrite = ByteFormat.FromHex(txtbxKeyOne.Text.Replace(" ", ""));
                    ushort[] Key1 = new ushort[KeytoWrite.Length / 2];
                    Key1 = ByteConv.ToU16s(KeytoWrite);
                    op   = new Gen2.WriteData(Gen2.Bank.USER, 0xD0, Key1);
                    objReader.ExecuteTagOp(op, searchSelect);
                    MessageBox.Show("Insert keys operation success", "Universal Reader Assistant", MessageBoxButton.OK, MessageBoxImage.Information);
                }
                else
                {
                    MessageBox.Show("Please input valid Keys to insert ", "Universal Reader Assistant", MessageBoxButton.OK, MessageBoxImage.Error);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Universal Reader Assistant", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
 /// <summary>
 /// Write the kill password in the reserved memory
 /// </summary>
 public void WriteKillPassword(string killPassword)
 {
     try
     {
         _reader.ParamSet("/reader/tagop/protocol", TagProtocol.GEN2);
         ushort[] dataToBeWritten = null;
         dataToBeWritten = ByteConv.ToU16s(ByteFormat.FromHex(killPassword.Replace(" ", "")));
         _reader.ExecuteTagOp(new Gen2.WriteData(Gen2.Bank.RESERVED, 0, dataToBeWritten), null);
         //MessageBox.Show("Access Password has successfully been set to 0x" + txtbxAccesspaasword.Text.Replace(" ", ""), "Info", MessageBoxButton.OK, MessageBoxImage.Information);
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
     }
 }
Exemplo n.º 3
0
 public void WritePassword(uint byteIndex, string password)
 {
     try
     {
         DateTime timeBeforeRead = DateTime.Now;
         ushort[] data           = ByteConv.ToU16s(ByteFormat.FromHex(password));
         using (Reader reader = Reader.Create("tmr:///" + Vars.comport.ToLower()))
         {
             reader.Connect();
             TagOp          tagOp = new Gen2.WriteData(Gen2.Bank.RESERVED, byteIndex, data);
             SimpleReadPlan plan  = new SimpleReadPlan(null, TagProtocol.GEN2, null, tagOp, 1000);
             reader.ParamSet("/reader/read/plan", plan);
             reader.ExecuteTagOp(tagOp, tagData);
         }
         DateTime timeAfterRead = DateTime.Now;
         TimeSpan timeElapsed   = timeAfterRead - timeBeforeRead;
         commandTotalTimeTextBox.Text = timeElapsed.TotalSeconds.ToString();
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
Exemplo n.º 4
0
        /// <summary>
        /// Authenticate with key1
        /// </summary>
        private void btnAuthKeyOne_Click(object sender, RoutedEventArgs e)
        {
            Gen2.NXP.AES.Tam2Authentication tam2Auth;
            Gen2.NXP.AES.Tam1Authentication tam1Auth;
            ushort[] Key1, Ichallenge, returnedIchallenge;
            byte[]   Response, Challenge;
            lblDataValue.Content       = "";
            lblTam2DataValue.Content   = "";
            lblChallenge1Value.Content = "";
            switch (cbxReadDataBank.Text)
            {
            case "TID":
                MemoryProfile = Gen2.NXP.AES.Profile.TID;
                break;

            case "User":
                MemoryProfile = Gen2.NXP.AES.Profile.USER;
                break;

            case "EPC":
                MemoryProfile = Gen2.NXP.AES.Profile.EPC;
                break;
            }

            if (txtbxVerifyKeyOne.Text.Length == 32)
            {
                byte[] KeytoWrite = ByteFormat.FromHex(txtbxVerifyKeyOne.Text);
                Key1 = new ushort[KeytoWrite.Length / 2];
                Key1 = ByteConv.ToU16s(KeytoWrite);
            }
            else
            {
                MessageBox.Show("Please input valid Key1", "Universal Reader Assistant", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            byte[] randmNumber = ByteFormat.FromHex(lblRandomChallengeValue.Content.ToString().Replace(" ", ""));
            Ichallenge = new ushort[randmNumber.Length / 2];
            Ichallenge = ByteConv.ToU16s(randmNumber);

            try
            {
                if ((bool)chkReadData.IsChecked && (bool)chkReadBuffer.IsChecked)
                {
                    //ReadBuffer with Tam2
                    tam2Auth = new Gen2.NXP.AES.Tam2Authentication(Gen2.NXP.AES.KeyId.KEY1, Key1, Ichallenge, MemoryProfile,
                                                                   (ushort)Convert.ToUInt32(txtReadStartAddr.Text), (ushort)Convert.ToUInt32(txtReadLength.Text), false);
                    Gen2.ReadBuffer buffer = new Gen2.NXP.AES.ReadBuffer(0, 256, tam2Auth);

                    Response = (byte[])objReader.ExecuteTagOp(buffer, searchSelect);
                    //swap the bytes
                    for (int i = 0; i < Response.Length; i += 2)
                    {
                        SwapBytes(ref Response, i, i + 1);
                    }
                    Challenge                  = DecryptIchallenge(Response.Skip(0).Take(16).ToArray(), ByteConv.ConvertFromUshortArray(Key1)).Skip(6).Take(10).ToArray();
                    lblDataValue.Content       = DecryptCustomData(Response.Skip(16).Take(16).ToArray(), ByteConv.ConvertFromUshortArray(Key1), Response.Skip(0).Take(16).ToArray());
                    lblChallenge1Value.Content = ByteFormat.ToHex(Challenge, "", " ");
                }
                else if (chkReadData.IsChecked == false && chkReadBuffer.IsChecked == false)
                {
                    //Auth with tam1
                    tam1Auth = new Gen2.NXP.AES.Tam1Authentication(Gen2.NXP.AES.KeyId.KEY1, Key1, Ichallenge, true);
                    Gen2.NXP.AES.Authenticate auth = new Gen2.NXP.AES.Authenticate(tam1Auth);
                    Response  = (byte[])objReader.ExecuteTagOp(auth, searchSelect);
                    Challenge = DecryptIchallenge(Response.Skip(0).Take(16).ToArray(), ByteConv.ConvertFromUshortArray(Key1)).Skip(6).Take(10).ToArray();
                    lblChallenge1Value.Content = ByteFormat.ToHex(Challenge, "", " ");
                }
                else if (chkReadData.IsChecked == false && chkReadBuffer.IsChecked == true)
                {
                    //Readbuffer with Tam1
                    tam1Auth = new Gen2.NXP.AES.Tam1Authentication(Gen2.NXP.AES.KeyId.KEY1, Key1, Ichallenge, false);
                    Gen2.ReadBuffer buffer = new Gen2.NXP.AES.ReadBuffer(0, 128, tam1Auth);
                    Response = (byte[])objReader.ExecuteTagOp(buffer, searchSelect);
                    //swap the bytes
                    for (int i = 0; i < Response.Length; i += 2)
                    {
                        SwapBytes(ref Response, i, i + 1);
                    }
                    Challenge = DecryptIchallenge(Response.Skip(0).Take(16).ToArray(), ByteConv.ConvertFromUshortArray(Key1)).Skip(6).Take(10).ToArray();
                    lblChallenge1Value.Content = ByteFormat.ToHex(Challenge, "", " ");
                    lblDataValue.Content       = "";
                }
                else
                {
                    //Authenticate with tam2
                    tam2Auth = new Gen2.NXP.AES.Tam2Authentication(Gen2.NXP.AES.KeyId.KEY1, Key1, Ichallenge, MemoryProfile,
                                                                   (ushort)Convert.ToUInt32(txtReadStartAddr.Text), (ushort)Convert.ToUInt32(txtReadLength.Text), true);
                    Gen2.NXP.AES.Authenticate auth = new Gen2.NXP.AES.Authenticate(tam2Auth);
                    Response = (byte[])objReader.ExecuteTagOp(auth, searchSelect);
                    if (Response != null)
                    {
                        lblTam2DataValue.Content = ByteFormat.ToHex(Response, "", " ");
                    }
                    lblTam2DataValue.Content = DecryptCustomData(Response.Skip(16).Take(16).ToArray(), ByteConv.ConvertFromUshortArray(Key1), Response.Skip(0).Take(16).ToArray());
                    Challenge = DecryptIchallenge(Response.Skip(0).Take(16).ToArray(), ByteConv.ConvertFromUshortArray(Key1)).Skip(6).Take(10).ToArray();
                    lblChallenge1Value.Content = ByteFormat.ToHex(Challenge, "", " ");
                }
                returnedIchallenge = new ushort[Challenge.Length / 2];
                returnedIchallenge = ByteConv.ToU16s(Challenge);
                if (returnedIchallenge.SequenceEqual(Ichallenge))
                {
                    MessageBox.Show("Tag Successfully Authenticated", "Universal Reader Assistant", MessageBoxButton.OK, MessageBoxImage.Information);
                }
                else
                {
                    MessageBox.Show("Tag Failed Authentication; Confirm Verification Key is Correct.", "Universal Reader Assistant", MessageBoxButton.OK, MessageBoxImage.Warning);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Universal Reader Assistant", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Authenticate with key0
        /// </summary>
        private void btnAuthKeyZero_Click(object sender, RoutedEventArgs e)
        {
            //Gen2.NXP.AES.Tam2Authentication tam2Auth;
            Gen2.NXP.AES.Tam1Authentication tam1Auth;
            ushort[] Key0, Ichallenge, returnedIchallenge;
            byte[]   Response, Challenge;
            lblDataValue.Content       = "";
            lblTam2DataValue.Content   = "";
            lblChallenge1Value.Content = "";

            switch (cbxReadDataBank.Text)
            {
            case "TID":
                MemoryProfile = Gen2.NXP.AES.Profile.TID;
                break;

            case "User":
                MemoryProfile = Gen2.NXP.AES.Profile.USER;
                break;

            case "EPC":
                MemoryProfile = Gen2.NXP.AES.Profile.EPC;
                break;
            }

            if (txtbxVerifyKeyZero.Text.Length == 32)
            {
                byte[] KeytoWrite = ByteFormat.FromHex(txtbxVerifyKeyZero.Text);
                Key0 = new ushort[KeytoWrite.Length / 2];
                Key0 = ByteConv.ToU16s(KeytoWrite);
            }
            else
            {
                MessageBox.Show("Please input valid Key0", "Universal Reader Assistant", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            byte[] randmNumber = ByteFormat.FromHex(lblRandomChallengeValue.Content.ToString().Replace(" ", ""));
            Ichallenge = new ushort[randmNumber.Length / 2];
            Ichallenge = ByteConv.ToU16s(randmNumber);
            try
            {
                if ((bool)chkReadData.IsChecked && (bool)chkReadBuffer.IsChecked)
                {
                    //ReadBuffer with Tam2
                    MessageBox.Show("Operation is not supported", "Universal Reader Assistant", MessageBoxButton.OK, MessageBoxImage.Error);
                    return;
                }
                else if (chkReadData.IsChecked == false && chkReadBuffer.IsChecked == false)
                {
                    //Authentication with tam1
                    tam1Auth = new Gen2.NXP.AES.Tam1Authentication(Gen2.NXP.AES.KeyId.KEY0, Key0, true);
                    Gen2.NXP.AES.Authenticate auth = new Gen2.NXP.AES.Authenticate(tam1Auth);
                    Response  = (byte[])objReader.ExecuteTagOp(auth, searchSelect);
                    Challenge = DecryptIchallenge(Response.Skip(0).Take(16).ToArray(), ByteConv.ConvertFromUshortArray(Key0)).Skip(6).Take(10).ToArray();
                    lblChallenge1Value.Content = ByteFormat.ToHex(Challenge, "", " ");
                    returnedIchallenge         = new ushort[Challenge.Length / 2];
                    returnedIchallenge         = ByteConv.ToU16s(Challenge);
                    byte[] generatedIChallenge = new byte[10];
                    byte[] tempBuffer          = new byte[16];
                    Array.Copy(Response, 0, generatedIChallenge, 0, 10);
                    Array.Copy(Response, 10, tempBuffer, 0, 16);
                    byte[] receivedIChallenge = DecryptIchallenge(tempBuffer, ByteConv.ConvertFromUshortArray(Key0).ToArray());
                    Array.Copy(receivedIChallenge, 6, receivedIChallenge, 0, 10);
                    Array.Resize(ref receivedIChallenge, 10);
                    if (generatedIChallenge.SequenceEqual(receivedIChallenge))
                    {
                        MessageBox.Show("Tag Successfully Authenticated", "Universal Reader Assistant", MessageBoxButton.OK, MessageBoxImage.Information);
                    }
                    else
                    {
                        MessageBox.Show("Tag Failed Authentication; Confirm Verification Key is Correct.", "Universal Reader Assistant", MessageBoxButton.OK, MessageBoxImage.Warning);
                    }
                }
                else if (chkReadData.IsChecked == false && chkReadBuffer.IsChecked == true)
                {
                    //Read Buffer with Tam1
                    tam1Auth = new Gen2.NXP.AES.Tam1Authentication(Gen2.NXP.AES.KeyId.KEY0, Key0, true);
                    Gen2.ReadBuffer buffer = new Gen2.NXP.AES.ReadBuffer(0, 128, tam1Auth);
                    Response  = (byte[])objReader.ExecuteTagOp(buffer, searchSelect);
                    Challenge = DecryptIchallenge(Response.Skip(0).Take(16).ToArray(), ByteConv.ConvertFromUshortArray(Key0)).Skip(6).Take(10).ToArray();
                    lblChallenge1Value.Content = ByteFormat.ToHex(Challenge, "", " ");
                    lblDataValue.Content       = "";
                    byte[] generatedIChallenge = new byte[10];
                    byte[] tempBuffer          = new byte[16];
                    Array.Copy(Response, 0, generatedIChallenge, 0, 10);
                    Array.Copy(Response, 10, tempBuffer, 0, 16);
                    byte[] receivedIChallenge = DecryptIchallenge(tempBuffer, ByteConv.ConvertFromUshortArray(Key0));
                    Array.Copy(receivedIChallenge, 6, receivedIChallenge, 0, 10);
                    Array.Resize(ref receivedIChallenge, 10);
                    if (generatedIChallenge.SequenceEqual(receivedIChallenge))
                    {
                        MessageBox.Show("Tag Successfully Authenticated", "Universal Reader Assistant", MessageBoxButton.OK, MessageBoxImage.Information);
                    }
                    else
                    {
                        MessageBox.Show("Tag Failed Authentication; Confirm Verification Key is Correct.", "Universal Reader Assistant", MessageBoxButton.OK, MessageBoxImage.Warning);
                    }
                }
                else
                {
                    //Authenticate with tam2
                    MessageBox.Show("Operation is not supported", "Universal Reader Assistant", MessageBoxButton.OK, MessageBoxImage.Error);
                    return;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Universal Reader Assistant", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }
        }