feat: log the plaintext RAM APDUs of the install steps (v3.6.19)

`_ram_send_gp_apdu` (the shared step sender of /api/ram-install and
/api/ram-install-app) now logs every step's plaintext APDU and packed
packet, like /api/send-ota's unconditional lines:

  RAM C-APDU (INSTALL [for load]): 80E602000C07F0414C4641610100000000
  RAM SECURED-PACKET (INSTALL [for load]): 00281516212525000000...

No flag - the step name keeps the sequence readable, and --apdu-trace stays
the card-level (ENVELOPE) trace.  Tests: the logging pinned with stubbed
packet builders.

498 Python / 650 frontend green; version 3.6.19; sw simple-v292.
This commit is contained in:
2026-09-28 08:23:28 +03:00
parent face2268ca
commit 31162efc8c
5 changed files with 43 additions and 4 deletions
+35
View File
@@ -1475,3 +1475,38 @@ class ResponseScriptingTest(unittest.TestCase):
self.assertIsNone(_parse_response_scripting(bytes.fromhex('027100000263100BD2')))
self.assertIsNone(_parse_response_scripting(b''))
class RamSendGpApduLoggingTest(unittest.TestCase):
"""_ram_send_gp_apdu (the shared step sender of /api/ram-install and
/api/ram-install-app) logs the plaintext RAM APDU and the packed SCP80
packet for every step, like /api/send-ota does."""
def test_logs_plaintext_apdu_and_packed_packet(self):
import contextlib
import io
from pysim_simple_server import server as srv
class FakeServer:
sms_oa = '12345'
sms_sc = '12345678912'
sp = {'spi1': '16', 'spi2': '01', 'kic': '25', 'kid': '25', 'tar': '000000',
'kic_key': 'AA', 'kid_key': 'BB', 'include_cpi': True}
state = {'steps': [], 'encode_error': None, 'failure': {}, 'cntr': '0000000001'}
orig_build = srv._build_secured_packet
orig_send = srv._send_secured_packet
try:
srv._build_secured_packet = lambda *a, **k: ('AABB', {})
srv._send_secured_packet = lambda *a, **k: {'success': False, 'error': 'stub'}
buf = io.StringIO()
with contextlib.redirect_stderr(buf):
ok = srv._ram_send_gp_apdu(FakeServer(), object(), sp, state,
'LOAD (1/2)', '80E8800001AA')
finally:
srv._build_secured_packet = orig_build
srv._send_secured_packet = orig_send
self.assertFalse(ok)
out = buf.getvalue()
self.assertIn('RAM C-APDU (LOAD (1/2)): 80E8800001AA', out)
self.assertIn('RAM SECURED-PACKET (LOAD (1/2)): AABB', out)