NFCPassportReader: SM data objects incorrect / Wrong length

Starting Basic Access Control (BAC)
BAC Successful
Reading tag - COM
got resp - ResponseAPDU(data: [95, 1, 4, 48, 49, 48, 55, 95, 54, 6, 48, 52, 48, 48, 48, 48, 92, 6, 97, 117, 103, 107, 108, 109], sw1: 144, sw2: 0)
DG Found - ["DG1", "DG2", "DG7", "DG11", "DG12", "DG13"]
Reading tag - SOD
Error reading tag: sw1 - 6C, sw2 - 0E - reason: Wrong length Le: SW2 indicates the exact length - (exact length :14)
ERROR - Wrong length Le: SW2 indicates the exact length - (exact length :14)
Reading tag - SOD
Error reading tag: sw1 - 69, sw2 - 88 - reason: SM data objects incorrect
ERROR - SM data objects incorrect

then

Starting Basic Access Control (BAC)
BAC Successful
Reading tag - SOD
Error reading tag: sw1 - 6C, sw2 - 0E - reason: Wrong length Le: SW2 indicates the exact length - (exact length :14)
ERROR - Wrong length Le: SW2 indicates the exact length - (exact length :14)
Reading tag - SOD
Error reading tag: sw1 - 69, sw2 - 88 - reason: SM data objects incorrect
ERROR - SM data objects incorrect

repeats endlessly till the session expired

Affected version: 1.0.4 Document: ID card from Kazakhstan

Fix the issue

adding self.tagReader?.reduceDataReadingAmount() inside the condition

} else if errMsg == "SM data objects incorrect" {
  // Can't read this element security objects now invalid - and return out so we re-do BAC
  completed(nil)
}

fixes the issue:

} else if errMsg == "SM data objects incorrect" {
   // Can't read this element security objects now invalid - and return out so we re-do BAC
   self.tagReader?.reduceDataReadingAmount()
   completed(nil)
}

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 17 (7 by maintainers)

Most upvoted comments

@maxxx777 You are right. I have slightly modified version of this library so the above suggestion works. Ok, so what you can try for test is setting the constant cmd in TagReader.swift:L280 to

       NFCISO7816APDU(
            instructionClass: 00,
            instructionCode: 0xB0,
            p1Parameter: offset[0],
            p2Parameter: offset[1],
            data: Data(),
            expectedResponseLength: 256
        )

What argument expectedResponseLength: 256 does is telling passport that arbitrary long chunk of data is expected in response.

@smlu this change works as well 👍

I’m currently testing the above fix (successfully so far but have some more passports I want to run through it), and if its consistent good I’ll update the main repo.