fix: use the card's own SimCardCommands for ADM and AUTHENTICATE (v2.7.20)

/api/verify-adm sent VERIFY with CLA A0 on a UICC (SW 6E00) while
pySim-shell's verify_adm worked: fast init builds the card on its own
SimCardCommands instance, but __main__ kept server.scc at the startup
placeholder left at the SIM defaults; only an equip repointed it.

- __main__ adopts card._scc after init (cat_cla still set on it), so
  server.scc carries the card's cla_byte/sel_ctrl from startup on.
- _verify_adm prefers app.rs.lchan[0].scc / app.card._scc, exactly like
  pySim-shell's verify_adm, independent of server.scc.
- netsim AUTHENTICATE follows the card class: a UICC gets 00 88 00 81 22
  (RAND+AUTN, DB/DC response), a SIM gets A0 88 00 00 10 (RAND only,
  SRES+Kc); the 61xx GET RESPONSE uses the same CLA.
- tests: ADM with a stale placeholder scc; 2G builder/parser; SIM-CLA
  runner case; help EN/RU and AGENTS updated.
This commit is contained in:
2026-09-21 22:13:52 +03:00
parent 0446d2a93c
commit f8ba5dea2c
10 changed files with 92 additions and 12 deletions
+17
View File
@@ -77,6 +77,23 @@ class AdmVerifyTests(unittest.TestCase):
self.assertEqual(out, {'adm': '<redacted>', 'psk_hex': '<redacted>', 'other': 'x'})
self.assertEqual(server._redact_psk_fields({'adm': ''}), {'adm': ''})
def test_verify_adm_uses_the_cards_own_channel(self):
# server.scc can be the startup placeholder left at the SIM CLA ('a0')
# while the card is a UICC: the VERIFY must go out through the card's
# own channel (CLA 00), exactly like pySim-shell's verify_adm.
stale = FakeScc('6E00')
stale.cla_byte = 'a0'
card_scc = FakeScc('9000')
card_scc.cla_byte = '00'
app = SimpleNamespace(
card=SimpleNamespace(_adm_chv_num=0x0A, _scc=card_scc),
rs=SimpleNamespace(adm_verified=False,
lchan=[SimpleNamespace(scc=card_scc)]))
res = server._verify_adm(stale, app, '0011')
self.assertEqual(res, {'ok': True, 'sw': '9000'})
self.assertEqual(card_scc.apdus, ['0020000A08' + '0011' + 'f' * 12])
self.assertEqual(stale.apdus, [])
if __name__ == '__main__':
unittest.main()