Exemple #1
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;
            }
        }
Exemple #2
0
        static void Main(string[] args)
        {
            // Program setup
            if (1 > args.Length)
            {
                Usage();
            }

            for (int nextarg = 1; nextarg < args.Length; nextarg++)
            {
                string arg = args[nextarg];
                if (arg.Equals("--ant"))
                {
                    if (null != antennaList)
                    {
                        Console.WriteLine("Duplicate argument: --ant specified more than once");
                        Usage();
                    }
                    antennaList = ParseAntennaList(args, nextarg);
                    nextarg++;
                }
                else
                {
                    Console.WriteLine("Argument {0}:\"{1}\" is not recognized", nextarg, arg);
                    Usage();
                }
            }

            try
            {
                // Create Reader object, connecting to physical device.
                // Wrap reader in a "using" block to get automatic
                // reader shutdown (using IDisposable interface).
                using (r = Reader.Create(args[0]))
                {
                    //Uncomment this line to add default transport listener.
                    //r.Transport += r.SimpleTransportListener;

                    r.Connect();
                    if (Reader.Region.UNSPEC == (Reader.Region)r.ParamGet("/reader/region/id"))
                    {
                        Reader.Region[] supportedRegions = (Reader.Region[])r.ParamGet("/reader/region/supportedRegions");
                        if (supportedRegions.Length < 1)
                        {
                            throw new FAULT_INVALID_REGION_Exception();
                        }
                        r.ParamSet("/reader/region/id", supportedRegions[0]);
                    }
                    string model = r.ParamGet("/reader/version/model").ToString();
                    if ((model.Equals("M6e Micro") || model.Equals("M6e Nano") || model.Equals("Sargas")) && antennaList == null)
                    {
                        Console.WriteLine("Module doesn't has antenna detection support please provide antenna list");
                        Usage();
                    }

                    // Create a simplereadplan which uses the antenna list created above
                    SimpleReadPlan plan = new SimpleReadPlan(antennaList, TagProtocol.GEN2, null, null, 1000);
                    // Set the created readplan
                    r.ParamSet("/reader/read/plan", plan);

                    //Use first antenna for operation
                    if (antennaList != null)
                    {
                        r.ParamSet("/reader/tagop/antenna", antennaList[0]);
                    }


                    ushort[] Key0       = new ushort[] { 0x0123, 0x4567, 0x89AB, 0xCDEF, 0x0123, 0x4567, 0x89AB, 0xCDEF };
                    ushort[] Key1       = new ushort[] { 0x1122, 0x3344, 0x5566, 0x7788, 0x1122, 0x3344, 0x5566, 0x7788 };
                    ushort[] Ichallenge = new ushort[] { 0x0123, 0x4567, 0x89AB, 0xCDEF, 0xABCD };

                    Gen2.Select filter = new Gen2.Select(false, Gen2.Bank.EPC, 32, 96,
                                                         new byte[] { 0xDE, 0xAD, 0xBE, 0xEF, 0xDE, 0xAD, 0xBE, 0xEF, 0xDE, 0xAD, 0xBE, 0xEF });

                    bool   SendRawData = true;
                    bool   _isNMV2DTag = false;
                    byte[] Response;
                    Gen2.NXP.AES.Tam1Authentication tam1Auth;
                    Gen2.NXP.AES.Tam2Authentication tam2Auth;

                    //Uncomment this to enable Authenticate with TAM1 with key0 for NXPUCODE AES tag

                    tam1Auth = new Gen2.NXP.AES.Tam1Authentication(Gen2.NXP.AES.KeyId.KEY0, Key0, Ichallenge, SendRawData);
                    Gen2.NXP.AES.Authenticate auth = new Gen2.NXP.AES.Authenticate(tam1Auth);
                    Response = (byte[])r.ExecuteTagOp(auth, null);
                    if (SendRawData)
                    {
                        byte[] Challenge = DecryptIchallenge(Response, ByteConv.ConvertFromUshortArray(Key0));
                        Array.Copy(Challenge, 6, Challenge, 0, 10);
                        Array.Resize(ref Challenge, 10);
                        Console.WriteLine("Returned Ichallenge:" + ByteFormat.ToHex(Challenge, "", " "));
                    }

                    //Uncomment this to enable Authenticate with TAM1 with Key1

                    //tam1Auth = new Gen2.NXP.AES.Tam1Authentication(Gen2.NXP.AES.KeyId.KEY1, Key1, Ichallenge, SendRawData);
                    //Gen2.NXP.AES.Authenticate tam1AuthKey1 = new Gen2.NXP.AES.Authenticate(tam1Auth);
                    //Response = (byte[])r.ExecuteTagOp(tam1AuthKey1, null);
                    //if (SendRawData)
                    //{
                    //    byte[] Challenge = DecryptIchallenge(Response, ByteConv.ConvertFromUshortArray(Key1));
                    //    Array.Copy(Challenge, 6, Challenge, 0, 10);
                    //    Array.Resize(ref Challenge, 10);
                    //    Console.WriteLine("Returned Ichallenge:" + ByteFormat.ToHex(Challenge, "", " "));
                    //}

                    //Uncomment this to enable Authenticate with TAM2 with key1

                    //ushort Offset = 0;
                    //ushort BlockCount = 1;
                    ////supported protMode value is 1 for NXPUCODE AES
                    //ushort ProtMode = 1;
                    //tam2Auth = new Gen2.NXP.AES.Tam2Authentication(Gen2.NXP.AES.KeyId.KEY1, Key1, Ichallenge, Gen2.NXP.AES.Profile.EPC,
                    //   Offset, BlockCount, ProtMode, SendRawData);
                    //Gen2.NXP.AES.Authenticate tam2AuthKey1 = new Gen2.NXP.AES.Authenticate(tam2Auth);
                    //Response = (byte[])r.ExecuteTagOp(tam2AuthKey1, null);
                    //if (SendRawData)
                    //{
                    //    byte[] IV = new byte[16];
                    //    byte[] CipherData = new byte[16];
                    //    Array.Copy(Response, 0, IV, 0, 16);
                    //    Array.Copy(Response, 16, CipherData, 0, 16);
                    //    Console.WriteLine("Custom Data: " + DecryptCustomData(CipherData, ByteConv.ConvertFromUshortArray(Key1), (byte[])IV.Clone()));
                    //    byte[] Challenge = DecryptIchallenge(IV, ByteConv.ConvertFromUshortArray(Key1));
                    //    Array.Copy(Challenge, 6, Challenge, 0, 10);
                    //    Array.Resize(ref Challenge, 10);
                    //    Console.WriteLine("Returned Ichallenge:" + ByteFormat.ToHex(Challenge, "", " "));
                    //}
                    //else
                    //{
                    //    Console.WriteLine("Data: " + ByteFormat.ToHex(Response, "", " "));
                    //}

                    // Embedded tag operations

                    #region EmbeddedTagOperations
                    {
                        //Uncomment this to execute embedded tagop for TAM1 Authentication using Key0
                        //tam1Auth = new Gen2.NXP.AES.Tam1Authentication(Gen2.NXP.AES.KeyId.KEY0, Key0, Ichallenge, SendRawData);
                        //Gen2.NXP.AES.Authenticate embeddedauth = new Gen2.NXP.AES.Authenticate(tam1Auth);
                        //Response = performEmbeddedOperation(null, embeddedauth);
                        //if (SendRawData)
                        //{
                        //    byte[] Challenge = DecryptIchallenge(Response, ByteConv.ConvertFromUshortArray(Key0));
                        //    Array.Copy(Challenge, 6, Challenge, 0, 10);
                        //    Array.Resize(ref Challenge, 10);
                        //    Console.WriteLine("Returned Ichallenge:" + ByteFormat.ToHex(Challenge, "", " "));
                        //}

                        //Uncomment this to execute embedded tagop for Authenticate with TAM1 using Key1
                        //tam1Auth = new Gen2.NXP.AES.Tam1Authentication(Gen2.NXP.AES.KeyId.KEY1, Key1, Ichallenge, SendRawData);
                        //Gen2.NXP.AES.Authenticate embeddedtam1AuthKey1 = new Gen2.NXP.AES.Authenticate(tam1Auth);
                        //Response = performEmbeddedOperation(null, embeddedtam1AuthKey1);
                        //if (SendRawData)
                        //{
                        //    byte[] Challenge = DecryptIchallenge(Response, ByteConv.ConvertFromUshortArray(Key1));
                        //    Array.Copy(Challenge, 6, Challenge, 0, 10);
                        //    Array.Resize(ref Challenge, 10);
                        //    Console.WriteLine("Returned Ichallenge:" + ByteFormat.ToHex(Challenge, "", " "));
                        //}

                        //Uncomment this to execute embedded tagop for Authenticate with TAM2 with key1
                        //ushort EmbeddedOffset = 0;
                        //ushort EmbeddedBlockCount = 1;
                        ////supported protMode value is 1 for NXPUCODE AES
                        //ushort EmbeddedProtMode = 1;
                        //tam2Auth = new Gen2.NXP.AES.Tam2Authentication(Gen2.NXP.AES.KeyId.KEY1, Key1, Ichallenge, Gen2.NXP.AES.Profile.EPC,
                        //   EmbeddedOffset, EmbeddedBlockCount, EmbeddedProtMode, SendRawData);
                        //Gen2.NXP.AES.Authenticate embeddedtam2AuthKey1 = new Gen2.NXP.AES.Authenticate(tam2Auth);
                        //Response = performEmbeddedOperation(null, embeddedtam2AuthKey1);
                        //if (SendRawData)
                        //{
                        //    byte[] IV = new byte[16];
                        //    byte[] CipherData = new byte[16];
                        //    Array.Copy(Response, 0, IV, 0, 16);
                        //    Array.Copy(Response, 16, CipherData, 0, 16);
                        //    Console.WriteLine("Custom Data: " + DecryptCustomData(CipherData, ByteConv.ConvertFromUshortArray(Key1), (byte[])IV.Clone()));
                        //    byte[] Challenge = DecryptIchallenge(IV, ByteConv.ConvertFromUshortArray(Key1));
                        //    Array.Copy(Challenge, 6, Challenge, 0, 10);
                        //    Array.Resize(ref Challenge, 10);
                        //    Console.WriteLine("Returned Ichallenge:" + ByteFormat.ToHex(Challenge, "", " "));
                        //}
                        //else
                        //{
                        //    Console.WriteLine("Data: " + ByteFormat.ToHex(Response, "", " "));
                        //}
                    }
                    #endregion EmbeddedTagOperations

                    //Enable flag _isNMV2DTag for TAM1/TAM2 Authentication with KEY0 for NMV2D Tag
                    if (_isNMV2DTag)
                    {
                        // NMV2D tag only supports KEY0
                        // Uncomment this to enable TAM1 Authentication with KEY0
                        ushort[] Key0_NMV2D = new ushort[] { 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000 };
                        //tam1Auth = new Gen2.NXP.AES.Tam1Authentication(Gen2.NXP.AES.KeyId.KEY0, Key0_NMV2D, Ichallenge, SendRawData);
                        //Gen2.NXP.AES.Authenticate tam1AuthKey0 = new Gen2.NXP.AES.Authenticate(tam1Auth);
                        //Response = (byte[])r.ExecuteTagOp(tam1AuthKey0, null);
                        //if (SendRawData)
                        //{
                        //    byte[] Challenge = DecryptIchallenge(Response, ByteConv.ConvertFromUshortArray(Key0_NMV2D));
                        //    Array.Copy(Challenge, 6, Challenge, 0, 10);
                        //    Array.Resize(ref Challenge, 10);
                        //    Console.WriteLine("Returned Ichallenge:" + ByteFormat.ToHex(Challenge, "", " "));
                        //}
                        //else
                        //{
                        //    Console.WriteLine("Data: " + ByteFormat.ToHex(Response, "", " "));
                        //}

                        //TAM2 Authentication with KEY0
                        ushort offset     = 0;
                        ushort blockCount = 1;
                        //supported protMode values are 0x00, 0x01, 0x02, 0x03
                        ushort protMode = 0;
                        tam2Auth = new Gen2.NXP.AES.Tam2Authentication(Gen2.NXP.AES.KeyId.KEY0, Key0_NMV2D, Ichallenge, Gen2.NXP.AES.Profile.EPC,
                                                                       offset, blockCount, protMode, SendRawData);
                        Gen2.NXP.AES.Authenticate tam2AuthKey0 = new Gen2.NXP.AES.Authenticate(tam2Auth);
                        Response = (byte[])r.ExecuteTagOp(tam2AuthKey0, null);
                        if (SendRawData)
                        {
                            byte[] IV         = new byte[16];
                            byte[] CipherData = new byte[16];
                            Array.Copy(Response, 0, IV, 0, 16);
                            Array.Copy(Response, 16, CipherData, 0, 16);
                            if (protMode == 1 || protMode == 3)
                            {
                                Console.WriteLine("Custom Data: " + DecryptCustomData(CipherData, ByteConv.ConvertFromUshortArray(Key0_NMV2D), (byte[])IV.Clone()));
                            }
                            else
                            {
                                Console.WriteLine("Custom Data: " + ByteFormat.ToHex(CipherData, "", " "));
                            }
                            byte[] Challenge = DecryptIchallenge(IV, ByteConv.ConvertFromUshortArray(Key0_NMV2D));
                            Array.Copy(Challenge, 6, Challenge, 0, 10);
                            Array.Resize(ref Challenge, 10);
                            Console.WriteLine("Returned Ichallenge:" + ByteFormat.ToHex(Challenge, "", " "));
                        }
                        else
                        {
                            Console.WriteLine("Data: " + ByteFormat.ToHex(Response, "", " "));
                        }
                    }
                }
            }
            catch (ReaderException re)
            {
                Console.WriteLine("Error: " + re.Message);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error: " + ex.Message);
            }
        }
Exemple #3
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;
            }
        }
Exemple #4
0
        static void Main(string[] args)
        {
            // Program setup
            if (1 > args.Length)
            {
                Usage();
            }

            for (int nextarg = 1; nextarg < args.Length; nextarg++)
            {
                string arg = args[nextarg];
                if (arg.Equals("--ant"))
                {
                    if (null != antennaList)
                    {
                        Console.WriteLine("Duplicate argument: --ant specified more than once");
                        Usage();
                    }
                    antennaList = ParseAntennaList(args, nextarg);
                    nextarg++;
                }
                else
                {
                    Console.WriteLine("Argument {0}:\"{1}\" is not recognized", nextarg, arg);
                    Usage();
                }
            }

            try
            {
                // Create Reader object, connecting to physical device.
                // Wrap reader in a "using" block to get automatic
                // reader shutdown (using IDisposable interface).
                using (r = Reader.Create(args[0]))
                {
                    //Uncomment this line to add default transport listener.
                    //r.Transport += r.SimpleTransportListener;

                    r.Connect();
                    if (Reader.Region.UNSPEC == (Reader.Region)r.ParamGet("/reader/region/id"))
                    {
                        Reader.Region[] supportedRegions = (Reader.Region[])r.ParamGet("/reader/region/supportedRegions");
                        if (supportedRegions.Length < 1)
                        {
                            throw new FAULT_INVALID_REGION_Exception();
                        }
                        r.ParamSet("/reader/region/id", supportedRegions[0]);
                    }
                    if (r.isAntDetectEnabled(antennaList))
                    {
                        Console.WriteLine("Module doesn't has antenna detection support please provide antenna list");
                        Usage();
                    }

                    // Create a simplereadplan which uses the antenna list created above
                    SimpleReadPlan plan = new SimpleReadPlan(antennaList, TagProtocol.GEN2, null, null, 1000);
                    // Set the created readplan
                    r.ParamSet("/reader/read/plan", plan);

                    //Use first antenna for operation
                    if (antennaList != null)
                    {
                        r.ParamSet("/reader/tagop/antenna", antennaList[0]);
                    }

                    // Set the session to S0
                    r.ParamSet("/reader/gen2/session", Gen2.Session.S0);

                    ushort[] Key0 = new ushort[] { 0x0123, 0x4567, 0x89AB, 0xCDEF, 0x0123, 0x4567, 0x89AB, 0xCDEF };
                    ushort[] Key1 = new ushort[] { 0x1122, 0x3344, 0x5566, 0x7788, 0x1122, 0x3344, 0x5566, 0x7788 };

                    // Change enable filter to true inorder to enable filter.
                    bool        enableFilter = false;
                    Gen2.Select filter       = null;
                    if (enableFilter)
                    {
                        filter = new Gen2.Select(false, Gen2.Bank.EPC, 32, 96,
                                                 new byte[] { 0xDE, 0xAD, 0xBE, 0xEF, 0xDE, 0xAD, 0xBE, 0xEF, 0xDE, 0xAD, 0xBE, 0xEF });
                    }

                    int           EpcLength;
                    Gen2.Password accesspassword;
                    bool          SendRawData = false;
                    Gen2.NXP.AES.Tam1Authentication auth;
                    // Read tag epc before performing untraceable action
                    ReadTags(r);

                    // Untraceable with TAM1 using Key0
                    EpcLength = 4; //words
                    auth      = new Gen2.NXP.AES.Tam1Authentication(Gen2.NXP.AES.KeyId.KEY0, Key0, SendRawData);
                    Gen2.Untraceable UntraceWithTam1WithKey0 = new Gen2.NXP.AES.Untraceable(Gen2.Untraceable.EPC.HIDE, EpcLength,
                                                                                            Gen2.Untraceable.TID.HIDE_NONE, Gen2.Untraceable.UserMemory.SHOW, Gen2.Untraceable.Range.NORMAL, auth);
                    r.ExecuteTagOp(UntraceWithTam1WithKey0, filter);
                    ReadTags(r);

                    //Uncomment this to enable untraceable with TAM2 using Key1
                    //EpcLength = 6; //words
                    //auth = new Gen2.NXP.AES.Tam1Authentication(Gen2.NXP.AES.KeyId.KEY1, Key1, SendRawData);
                    //accesspassword = new Gen2.Password(0x00000000);
                    //r.ParamSet("/reader/gen2/accessPassword", accesspassword);
                    //Gen2.Untraceable UntraceWithTam1WithKey1 = new Gen2.NXP.AES.Untraceable(Gen2.Untraceable.EPC.HIDE, EpcLength,
                    //        Gen2.Untraceable.TID.HIDE_NONE, Gen2.Untraceable.UserMemory.SHOW, Gen2.Untraceable.Range.NORMAL, auth);
                    //r.ExecuteTagOp(UntraceWithTam1WithKey1, filter);
                    //ReadTags(r);

                    //Uncomment this to enable untraceable with Access
                    //EpcLength = 3;
                    //accesspassword = new Gen2.Password(0x00000001);
                    //r.ParamSet("/reader/gen2/accessPassword", accesspassword);
                    //Gen2.Untraceable UntraceWithAccess = new Gen2.NXP.AES.Untraceable(Gen2.Untraceable.EPC.HIDE, EpcLength,
                    //        Gen2.Untraceable.TID.HIDE_NONE, Gen2.Untraceable.UserMemory.SHOW, Gen2.Untraceable.Range.NORMAL, accesspassword.Value);
                    //r.ExecuteTagOp(UntraceWithAccess, filter);
                    //ReadTags(r);

                    #region EmbeddedTagOperations
                    {
                        // Uncomment this to execute Untraceable with TAM1 using Key0
                        //EpcLength = 4; //words
                        //auth = new Gen2.NXP.AES.Tam1Authentication(Gen2.NXP.AES.KeyId.KEY0, Key0, SendRawData);
                        //Gen2.Untraceable embeddedUntraceWithTam1WithKey0 = new Gen2.NXP.AES.Untraceable(Gen2.Untraceable.EPC.HIDE, EpcLength,
                        //        Gen2.Untraceable.TID.HIDE_NONE, Gen2.Untraceable.UserMemory.SHOW, Gen2.Untraceable.Range.NORMAL, auth);
                        //performEmbeddedOperation(filter, embeddedUntraceWithTam1WithKey0);
                        //ReadTags(r);

                        //Uncomment this to execute untraceable with TAM2 using Key1
                        //EpcLength = 6; //words
                        //auth = new Gen2.NXP.AES.Tam1Authentication(Gen2.NXP.AES.KeyId.KEY1, Key1, SendRawData);
                        //Gen2.Untraceable EmbeddedUntraceWithTam1WithKey1 = new Gen2.NXP.AES.Untraceable(Gen2.Untraceable.EPC.HIDE, EpcLength,
                        //        Gen2.Untraceable.TID.HIDE_NONE, Gen2.Untraceable.UserMemory.SHOW, Gen2.Untraceable.Range.NORMAL, auth);
                        //performEmbeddedOperation(filter, EmbeddedUntraceWithTam1WithKey1);
                        //ReadTags(r);

                        //Uncomment this to execute untraceable with Access
                        //EpcLength = 3;
                        //accesspassword = new Gen2.Password(0x00000000);

                        //Gen2.Untraceable EmbeddedUntraceWithAccess = new Gen2.NXP.AES.Untraceable(Gen2.Untraceable.EPC.HIDE, EpcLength,
                        //        Gen2.Untraceable.TID.HIDE_NONE, Gen2.Untraceable.UserMemory.SHOW, Gen2.Untraceable.Range.NORMAL, accesspassword.Value);
                        //performEmbeddedOperation(filter, EmbeddedUntraceWithAccess);
                        //ReadTags(r);
                    }
                    #endregion EmbeddedTagOperations
                }
            }
            catch (ReaderException re)
            {
                Console.WriteLine("Error: " + re.Message);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error: " + ex.Message);
            }
        }