revtel / react-native-nfc-manager

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

Unlock the password protected tag #653

Closed shenoyv closed 8 months ago

shenoyv commented 1 year ago

I am trying to unlock the password protected Ntag213 nfc tag in ios. I am getting error [TypeError: Cannot read property 'transceive' of undefined] I am using this command NfcManager.MifareUltralight.transceive Here is the short description of the code

const authCommand = ["1B", ...pwdArrayBytes]; let response2 = await NfcManager.MifareUltralight.transceive(authCommand);

amitsingheplanetsoft commented 12 months ago

const pack = [0x00, 0x00];

async function removePasswordProtection(value) { const password = strToHex(value); let respBytes = null; let writeRespBytes = null; let authPageIdx;

try { if (Platform.OS === "android") { getOutlet("androidPrompt").update({ visible: true, message: "Ready to scan NFC", }); } // check tag type await NfcManager.requestTechnology(NfcTech.NfcA); respBytes = await NfcManager.nfcAHandler.transceive([0x30, 0]); const cc2 = respBytes[14]; //todo more conditions to be implemented if (cc2 === 109) { authPageIdx = 227; // NTAG 216 } else if (cc2 === 62) { authPageIdx = 131; // NTAG 215 } else if (cc2 === 18) { authPageIdx = 41; // NTAG 213 } else if (cc2 === 16) { authPageIdx = 37; // NTAG 212 } else if (cc2 === 6) { authPageIdx = 37; // ultralight ev1 } else { authPageIdx = 16; // NTAG 210 }

// check if AUTH is enabled
// console.log("respBytes:::::::::", respBytes);
respBytes = await NfcManager.nfcAHandler.transceive([0x30, authPageIdx]);
// console.log("respBytes::::2:::::", respBytes);

const auth = respBytes[3];
if (auth === 255) {
  // configure the tag to support password protection
  handleException(
    "Tag not supported or tag does not have password protection",
  );
} else {
  // send password to NFC tags, so we can perform write operations
  writeRespBytes = await NfcManager.nfcAHandler.transceive([
    0x1b,
    ...password,
  ]);

  if (writeRespBytes[0] !== pack[0] || writeRespBytes[1] !== pack[1]) {
    handleException("incorrect password");
    throw new Error("incorrect password");
  } else {
    let response = await NfcManager.nfcAHandler.transceive([
      0x30,
      authPageIdx,
    ]);

    let resp = await NfcManager.nfcAHandler.transceive([
      0xa2,
      authPageIdx,
      response[0],
      response[1],
      response[2],
      0xff,
    ]);
    if (Platform.OS === "ios") {
      await NfcManager?.setAlertMessageIOS("Success");
    }
    if (Platform.OS === "android") {
      getOutlet("androidPrompt").update({
        visible: true,
        message: "Completed",
        isDone: true,
      });
    }
  }
}

} catch (error) { handleException( "Tag not supported or tag does not have password protection or incorrect password", ); } finally { NfcManager.cancelTechnologyRequest(); } }

export default removePasswordProtection;

github-actions[bot] commented 8 months 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 8 months ago

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