revtel / react-native-nfc-manager

React Native NFC module for Android & iOS
MIT License
1.39k stars 317 forks source link

makeReadOnly Not support for Tag type ISO 14443-3A #625

Closed LeoLaiFookSiang closed 1 year ago

LeoLaiFookSiang commented 1 year ago

Hi, I have a NFC Tag with below spec: Tag Type: ISO 14443-3A Tag Model and Chip Type: NTAG213 Technologies: Mifare

When I use makeReadOnly on iOS it shows error and not able to write. And then I did try to change the trailer section at the end of tag to make it read only. But I receive error the tag is not an iso7816 tag

  makeMifareReadOnly = withAndroidPrompt(async () => {
    let result = false;

    try {
      // Connect to the NTAG213 tag
      await NfcManager.requestTechnology(NfcTech.NfcA);

      // Send commands to each sector trailer to set it to read-only mode
    for (let i = 0; i < 16; i++) {
      // Access bits for NTAG213
      const access_bits = [0x00, 0x00, 0xFF, 0x07];

      // Set the last byte of the access bits to 0x0F to prevent further writes
      access_bits[2] |= 0x0F;

      // NTAG213 uses 7-byte keys
      const key = [0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00];

      // Create the data block for the sector trailer
      const data = [
        (i * 4) + 3,  // Block number of the sector trailer
        ...key,  // Key A
        ...access_bits,  // Access bits
        ...key,  // Key B
        0x00  // Access bits for the trailer block
      ];

      // Construct the APDU command to write the sector trailer
      const apduData = {
        cla: 0xFF,
        ins: 0xD6,
        p1: 0x00,
        p2: data[0],
        data: data.slice(1)
      };

      // Send the APDU command to write the sector trailer
      const response = await NfcManager.sendCommandAPDUIOS(apduData);
      if (response.statusCode !== '9000') {
        throw new Error(`Failed to lock sector ${i}: ${response}`);
      }
    }
  } catch (error) {
    console.error(error);
  } finally {
    await NfcManager.cancelTechnologyRequest();
  }

    return result;
  });

Any way to make my tag to read-only ?

github-actions[bot] commented 1 year ago

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

github-actions[bot] commented 1 year ago

This issue was closed because it has been stalled for 5 days with no activity.