capawesome-team/capacitor-nfc

bug: Unable to write protected blocks after authentication (PWD_AUTH)

Closed this issue · 6 comments

Plugin version:

"@capawesome-team/capacitor-nfc": "^5.0.2",

Platform(s):

Android

Current behavior:

  1. Use transceive method to send PWD_AUTH command
  2. Receive the correct PACK
  3. Then directly send another command to write a protected block, assuming now the tag is in AUTHENTICATED state
  4. Receive an error
    Msg: Error: An unknown error has occurred.

Expected behavior:

  1. Use transceive method to send PWD_AUTH command
  2. Receive the correct PACK
  3. Then directly send another command to write a protected block, assuming now the tag is in AUTHENTICATED state
  4. Write command succeed

Steps to reproduce:

  1. Set PWD, PACK
  2. Set AUTH0 to 43 (decimal), PWD byte page
  3. Authenticate with PWD_AUTH command
  4. Try setting PWD byte value

Related code:

// AUTH0 is set to PWD byte page 43 (decimal)
// PWD is already set to [16, 16, 16, 16]

      Nfc.addListener('nfcTagScanned', async (event) => {

          // PWD AUTH
          const PWDAUTH_BYTES = [27, 16, 16, 16, 16];
          const responsePwdAuth = await Nfc.transceive({ techType: NfcTagTechType.NfcA, data: PWDAUTH_BYTES });
          console.log ("responsePwdAuth", responsePwdAuth.response)
          if ((responsePwdAuth.response != null) && (responsePwdAuth.response.length >= 2)) {
            // TODO: verify PACK to confirm that tag is authentic
            console.info ("Try set PWD authenticated")

            const NEWPWD_WRITE_BYTES = [162, 43, 17, 17, 17, 17];
            const writePwdResponseAfterAuthentication = await Nfc.transceive({ techType: NfcTagTechType.NfcA, data: NEWPWD_WRITE_BYTES });
            console.log ("writePwdResponseAfterAuthentication", writePwdResponseAfterAuthentication.response)
    
           }
          await Nfc.stopScanSession();
})

Other information:

Android 10 - Pixel 1

Capacitor doctor:

insert the output from `npx cap doctor` here

Thank you for your request. Please post the complete logcat output while the error occurs.

Also, what tag are you using?

Also, what tag are you using?

I'm using Ntag213

Logcat is very short

2023-07-10 13:11:23.368 30097-30097 Capacitor/Console com.sdl.one.dgsport.wallaby I File: https://localhost/7553.7e39d28a863f8aa9.js - Line 1 - Msg: TRy set PWD authenticated
2023-07-10 13:11:23.392 30097-30097 Capacitor/Console com.sdl.one.dgsport.wallaby E File: https://localhost/7553.7e39d28a863f8aa9.js - Line 1 - Msg: Error: An unknown error has occurred.

Thank you for your request. Please post the complete logcat output while the error occurs.

Here is a more complete logcat (you can notice Auth0 set to 43 (2Bh PWD page for Ntag213)

2023-07-10 13:29:22.891 9726-9726 Capacitor com.sdl.one.dgsport.wallaby V callback: 23975089, pluginId: Nfc, methodName: transceive, methodData: {"techType":"NFC_A","data":[48,41]}
2023-07-10 13:29:22.896 9726-9872 Capacitor/NetworkPlugin com.sdl.one.dgsport.wallaby V Notifying listeners for event networkStatusChange
2023-07-10 13:29:22.903 9726-9726 Capacitor/Console com.sdl.one.dgsport.wallaby W File: https://localhost/main.4dd7fa308afae5cc.js - Line 1 - Msg: !! Network status changed !! [object Object]
2023-07-10 13:29:22.932 9726-9726 Capacitor/Console com.sdl.one.dgsport.wallaby I File: https://localhost/7553.4f973890e639c1b0.js - Line 1 - Msg: auth0ReadResponse.response 4,0,0,43,0,5,0,0,0,0,0,0,0,0,0,0
2023-07-10 13:29:22.934 9726-9726 Capacitor/Plugin com.sdl.one.dgsport.wallaby V To native (Capacitor plugin): callbackId: 23975090, pluginId: Nfc, methodName: transceive
2023-07-10 13:29:22.934 9726-9726 Capacitor com.sdl.one.dgsport.wallaby V callback: 23975090, pluginId: Nfc, methodName: transceive, methodData: {"techType":"NFC_A","data":[27,49,55,49,55]}
2023-07-10 13:29:22.955 9726-9726 Capacitor/Console com.sdl.one.dgsport.wallaby I File: https://localhost/7553.4f973890e639c1b0.js - Line 1 - Msg: responsePwdAuth 54,54
2023-07-10 13:29:22.956 9726-9726 Capacitor/Console com.sdl.one.dgsport.wallaby I File: https://localhost/7553.4f973890e639c1b0.js - Line 1 - Msg: TRy set PWD authenticated
2023-07-10 13:29:22.957 9726-9726 Capacitor/Plugin com.sdl.one.dgsport.wallaby V To native (Capacitor plugin): callbackId: 23975091, pluginId: Nfc, methodName: transceive
2023-07-10 13:29:22.958 9726-9726 Capacitor com.sdl.one.dgsport.wallaby V callback: 23975091, pluginId: Nfc, methodName: transceive, methodData: {"techType":"NFC_A","data":[162,43,49,54,49,54]}
2023-07-10 13:29:22.974 9726-9845 NfcPlugin com.sdl.one.dgsport.wallaby E An unknown error has occurred.
2023-07-10 13:29:22.975 9726-9845 Capacitor com.sdl.one.dgsport.wallaby D Sending plugin error: {"save":false,"callbackId":"23975091","pluginId":"Nfc","methodName":"transceive","success":false,"error":{"message":"An unknown error has occurred."}}
2023-07-10 13:29:22.979 9726-9726 Capacitor/Console com.sdl.one.dgsport.wallaby E File: https://localhost/7553.4f973890e639c1b0.js - Line 1 - Msg: Error: An unknown error has occurred.
2023-07-10 13:29:22.981 9726-9726 Capacitor/Plugin com.sdl.one.dgsport.wallaby V To native (Capacitor plugin): callbackId: 23975092, pluginId: Nfc, methodName: stopScanSession

Thank you for the quick replies

Alright, thank you. Please provide a Minimal, Reproducible Example using this template in a public GitHub repository so I can debug the issue.

It looks like there hasn't been a reply in 30 days, so I'm closing this issue.