예제 #1
0
        private void btnTAM2Authenticate_Click(object sender, EventArgs e)
        {
            byte   flag = 0, performOptionFlag = 0;
            ushort offsetValue;
            bool   result;
            int    dataEPCStart = 28, dataEPCEnd = 39;                                                     //Reference the "MTI RFID Module Command Reference Manual-Table 3.9 - ISO 18000-6C Inventory-Response Packet Fields"
            int    dataMessageStart = 26, dataMessageEnd = 35;                                             //Reference the "MTI RFID Module Command Reference Manual-Table 3.10 - ISO 18000-6C Tag-Access Packet Fields"
            int    dataCipher1Start = 36, dataCipher1End = 51, dataCipher2Start = 52, dataCipher2End = 61; //Reference the "MTI RFID Module Command Reference Manual-Table 3.10 - ISO 18000-6C Tag-Access Packet Fields"
            int    i;
            string message = "", key = "", ciphertext1 = "", ciphertext2 = "", randomChallenge = "", returnedData = "";

            if ((textBoxVerificationKey1.Text.Length / 2) < 16)
            {
                MessageDisplay("Please enter 16 bytes hexadecimal value for verification Key1",
                               "TAM2 Authentication", MessageBoxIcon.Error);
            }
            else if (CheckKeyType(textBoxVerificationKey1.Text) != true)
            {
                MessageDisplay("Verification Key1 is invalid hexadecimal value", "TAM2 Authentication", MessageBoxIcon.Error);
            }
            else if (Int16.Parse(textBoxOffset.Text) > 4095)
            {
                MessageDisplay("The offset value must be littler than 4095",
                               "TAM2 Authentication", MessageBoxIcon.Error);
            }
            else
            {
                result = ushort.TryParse(textBoxOffset.Text, out offsetValue);

                if (chkPerformSelectOps.Checked == false && chkPerformPostMatch.Checked == false)
                {
                    performOptionFlag = 0;
                }
                else if (chkPerformSelectOps.Checked == true && chkPerformPostMatch.Checked == false)
                {
                    performOptionFlag = 1;
                }
                else if (chkPerformSelectOps.Checked == false && chkPerformPostMatch.Checked == true)
                {
                    performOptionFlag = 2;
                }
                else
                {
                    performOptionFlag = 3;
                }

                NXPChangeConfig     NXPConfigParms = new NXPChangeConfig();
                NXPTAM1Authenticate NXPTAM1Parms   = new NXPTAM1Authenticate();
                NXPTAM2Authenticate NXPTAM2Parms   = new NXPTAM2Authenticate();
                ReadParms           parameters     = new ReadParms();

                NXPTAM2Parms.replySetting  = (byte)1;
                NXPTAM2Parms.memoryProfile = (byte)comboBoxMemBank.SelectedIndex;
                NXPTAM2Parms.offset        = offsetValue;
                NXPTAM2Parms.blockCount    = (byte)comboBoxBlockCount.SelectedIndex;
                NXPTAM2Parms.retryCount    = retryCount;
                NXPTAM2Parms.performOption = performOptionFlag;

                parameters.accessPassword = Convert.ToUInt32(TEXTBOX_TagAccessAccessPassword.Text, 16);
                parameters.common.tagFlag = false;
                Array.Clear(parameters.common.bufMTII, 0, parameters.common.bufMTII.Length);
                Array.Clear(parameters.common.bufMTIA, 0, parameters.common.bufMTIA.Length);
                Array.Clear(parameters.common.bufSecondeMTIA, 0, parameters.common.bufSecondeMTIA.Length);

                if (Result.OK != LakeChabotReader.MANAGED_ACCESS.API_l8K6CTagNXPSpecific(NXPSpecificFunID.TAM2Authenticate, NXPConfigParms, NXPTAM1Parms, NXPTAM2Parms, parameters, flag))
                {
                    labelRandomChallenge.Text = labelDecryptedChallenge.Text = labelTagMemoryData.Text = "";
                    MessageDisplay("TAM2 authenticate command failed", "TAM2 Authentication", MessageBoxIcon.Error);
                }
                else if (parameters.common.tagFlag != true)
                {
                    labelRandomChallenge.Text = labelDecryptedChallenge.Text = labelTagMemoryData.Text = "";
                    MessageDisplay("No Tag", "TAM2 Authentication", MessageBoxIcon.Warning);
                }
                else if (parameters.common.bufMTIA[tagErrorCode] != 0x00)
                {
                    labelRandomChallenge.Text = labelDecryptedChallenge.Text = labelTagMemoryData.Text = "";
                    MessageDisplay("Tag Error Code : 0x" + parameters.common.bufMTIA[19].ToString("X2"),
                                   "TAM2 Authentication", MessageBoxIcon.Error);
                }
                else if (parameters.common.bufMTIA[moduleErrorCode1] != 0x00 || parameters.common.bufMTIA[moduleErrorCode2] != 0x00)
                {
                    labelRandomChallenge.Text = labelDecryptedChallenge.Text = labelTagMemoryData.Text = "";
                    MessageDisplay("Module Error Code : 0x" + parameters.common.bufMTIA[moduleErrorCode1].ToString("X2") + parameters.common.bufMTIA[moduleErrorCode2].ToString("X2"),
                                   "TAM2 Authentication", MessageBoxIcon.Error);
                }
                else
                {
                    textBoxEPC.Text = parameters.common.bufMTII[dataEPCStart].ToString("X2");
                    for (i = dataEPCStart + 1; i < dataEPCEnd + 1; i++)
                    {
                        textBoxEPC.Text += "-" + parameters.common.bufMTII[i].ToString("X2");
                    }

                    message = parameters.common.bufMTIA[dataMessageStart].ToString("X2");
                    labelRandomChallenge.Text = parameters.common.bufMTIA[dataMessageStart].ToString("X2");
                    for (i = dataMessageStart + 1; i < dataMessageEnd + 1; i++)
                    {
                        message += parameters.common.bufMTIA[i].ToString("X2");
                        labelRandomChallenge.Text += " " + parameters.common.bufMTIA[i].ToString("X2");
                    }

                    for (i = dataCipher1Start; i < dataCipher1End + 1; i++)
                    {
                        ciphertext1 += parameters.common.bufMTIA[i].ToString("X2");
                    }

                    for (i = dataCipher2Start; i < dataCipher2End + 1; i++)
                    {
                        ciphertext2 += parameters.common.bufMTIA[i].ToString("X2");
                    }

                    dataCipher2Start = 14; //The second part of ciphertext2 start address
                    dataCipher2End   = 19; //The second part of ciphertext2 end address

                    for (i = dataCipher2Start; i < dataCipher2End + 1; i++)
                    {
                        ciphertext2 += parameters.common.bufSecondeMTIA[i].ToString("X2");
                    }

                    key = textBoxVerificationKey1.Text;

                    randomChallenge = AESECBDecrypt(ciphertext1, key);

                    returnedData = AESCBCDecrypt(ciphertext2, ciphertext1, key);

                    labelDecryptedChallenge.Text = randomChallenge.Substring(0, 2);
                    for (i = 2; i < randomChallenge.Length; i += 2)
                    {
                        labelDecryptedChallenge.Text += " " + randomChallenge.Substring(i, 2);
                    }

                    labelTagMemoryData.Text = returnedData.Substring(0, 2);
                    for (i = 2; i < returnedData.Length; i += 2)
                    {
                        labelTagMemoryData.Text += " " + returnedData.Substring(i, 2);
                    }

                    if (String.Compare(randomChallenge, message) == 0)
                    {
                        MessageDisplay("Authenticate Tag Success", "TAM2 Authentication", MessageBoxIcon.Information);
                    }
                    else
                    {
                        MessageDisplay("Authenticate Tag Fail; Confirm Verification Key1 is Correct.", "TAM2 Authentication", MessageBoxIcon.Error);
                    }
                }
            }
        }
예제 #2
0
        private void btnTAM1Authenticate_Click(object sender, EventArgs e)
        {
            byte   flag = 0, performOptionFlag = 0;
            int    dataEPCStart = 28, dataEPCEnd = 39;                                                     //Reference the "MTI RFID Module Command Reference Manual-Table 3.9 - ISO 18000-6C Inventory-Response Packet Fields"
            int    dataMessageStart = 26, dataMessageStop = 35, dataCipherStart = 36, dataCipherStop = 51; //Reference the "MTI RFID Module Command Reference Manual-Table 3.10 - ISO 18000-6C Tag-Access Packet Fields"
            int    i;
            string message = "", key = "", ciphertext = "", randomChallenge = "";

            labelTagMemoryData.Text = "";

            if ((textBoxVerificationKey0.Text.Length / 2) < 16)
            {
                MessageDisplay("Please enter 16 bytes hexadecimal value for verification Key0",
                               "TAM1 Authentication", MessageBoxIcon.Error);
            }
            else if (CheckKeyType(textBoxVerificationKey0.Text) != true)
            {
                MessageDisplay("Verification Key0 is invalid hexadecimal value", "TAM1 Authentication", MessageBoxIcon.Error);
            }
            else
            {
                if (chkPerformSelectOps.Checked == false && chkPerformPostMatch.Checked == false)
                {
                    performOptionFlag = 0;
                }
                else if (chkPerformSelectOps.Checked == true && chkPerformPostMatch.Checked == false)
                {
                    performOptionFlag = 1;
                }
                else if (chkPerformSelectOps.Checked == false && chkPerformPostMatch.Checked == true)
                {
                    performOptionFlag = 2;
                }
                else
                {
                    performOptionFlag = 3;
                }

                NXPChangeConfig     NXPConfigParms = new NXPChangeConfig();
                NXPTAM1Authenticate NXPTAM1Parms   = new NXPTAM1Authenticate();
                NXPTAM2Authenticate NXPTAM2Parms   = new NXPTAM2Authenticate();
                ReadParms           parameters     = new ReadParms();

                NXPTAM1Parms.replySetting  = (byte)1;
                NXPTAM1Parms.keyID         = (byte)0;
                NXPTAM1Parms.retryCount    = retryCount;
                NXPTAM1Parms.performOption = performOptionFlag;

                parameters.accessPassword = Convert.ToUInt32(TEXTBOX_TagAccessAccessPassword.Text, 16);
                parameters.common.tagFlag = false;
                Array.Clear(parameters.common.bufMTII, 0, parameters.common.bufMTII.Length);
                Array.Clear(parameters.common.bufMTIA, 0, parameters.common.bufMTIA.Length);

                if (Result.OK != LakeChabotReader.MANAGED_ACCESS.API_l8K6CTagNXPSpecific(NXPSpecificFunID.TAM1Authenticate, NXPConfigParms, NXPTAM1Parms, NXPTAM2Parms, parameters, flag))
                {
                    labelRandomChallenge.Text = labelDecryptedChallenge.Text = "";
                    MessageDisplay("TAM1 authenticate command failed", "TAM1 Authentication", MessageBoxIcon.Error);
                }
                else if (parameters.common.tagFlag != true)
                {
                    labelRandomChallenge.Text = labelDecryptedChallenge.Text = "";
                    MessageDisplay("No Tag", "TAM1 Authentication", MessageBoxIcon.Warning);
                }
                else if (parameters.common.bufMTIA[tagErrorCode] != 0x00)
                {
                    labelRandomChallenge.Text = labelDecryptedChallenge.Text = "";
                    MessageDisplay("Tag Error Code : 0x" + parameters.common.bufMTIA[19].ToString("X2"),
                                   "TAM1 Authentication", MessageBoxIcon.Error);
                }
                else if (parameters.common.bufMTIA[moduleErrorCode1] != 0x00 || parameters.common.bufMTIA[moduleErrorCode2] != 0x00)
                {
                    labelRandomChallenge.Text = labelDecryptedChallenge.Text = "";
                    MessageDisplay("Module Error Code : 0x" + parameters.common.bufMTIA[moduleErrorCode1].ToString("X2") + parameters.common.bufMTIA[moduleErrorCode2].ToString("X2"),
                                   "TAM1 Authentication", MessageBoxIcon.Error);
                }
                else
                {
                    textBoxEPC.Text = parameters.common.bufMTII[dataEPCStart].ToString("X2");
                    for (i = dataEPCStart + 1; i < dataEPCEnd + 1; i++)
                    {
                        textBoxEPC.Text += "-" + parameters.common.bufMTII[i].ToString("X2");
                    }

                    message = parameters.common.bufMTIA[dataMessageStart].ToString("X2");
                    labelRandomChallenge.Text = parameters.common.bufMTIA[dataMessageStart].ToString("X2");
                    for (i = dataMessageStart + 1; i < dataMessageStop + 1; i++)
                    {
                        message += parameters.common.bufMTIA[i].ToString("X2");
                        labelRandomChallenge.Text += " " + parameters.common.bufMTIA[i].ToString("X2");
                    }

                    for (i = dataCipherStart; i < dataCipherStop + 1; i++)
                    {
                        ciphertext += parameters.common.bufMTIA[i].ToString("X2");
                    }

                    key = textBoxVerificationKey0.Text;

                    randomChallenge = AESECBDecrypt(ciphertext, key);

                    labelDecryptedChallenge.Text = randomChallenge.Substring(0, 2);
                    for (i = 2; i < randomChallenge.Length; i += 2)
                    {
                        labelDecryptedChallenge.Text += " " + randomChallenge.Substring(i, 2);
                    }

                    if (String.Compare(randomChallenge, message) == 0)
                    {
                        MessageDisplay("Authenticate Tag Success", "TAM1 Authentication", MessageBoxIcon.Information);
                    }
                    else
                    {
                        MessageDisplay("Authenticate Tag Fail; Confirm Verification Key0 is Correct.", "TAM1 Authentication", MessageBoxIcon.Error);
                    }
                }
            }
        }