From b5f871641f2b4bb2295c5cb65eb5f2b2de7dd8a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D0=BD=D1=82=D0=BE=D0=BD=20=D0=A2=D1=80=D0=BE=D1=88?= =?UTF-8?q?=D0=B8=D0=BD?= Date: Mon, 31 Aug 2026 09:09:20 +0300 Subject: [PATCH] docs: update RAM section, add explorer delete buttons, add /api/ram-install - README/README_RUS: RAM tab now describes Explore Card + Install Package operations, explorer view with inline Delete/Delete All buttons for Applications and ELFs - docs/api.md: add full /api/ram-install endpoint documentation - index.html: remove Delete from dropdown, add ramDeleteFromExplorer() with confirm dialog, add Delete buttons in explorer for Apps and ELFs (ELFs get cascade option) --- README.md | 23 +++- README_RUS.md | 23 +++- docs/api.md | 55 +++++++++ frontend/index.html | 51 ++++---- pysim_otaman_server/server.py | 213 ++++++++++++++++++++++++++++++++++ 5 files changed, 339 insertions(+), 26 deletions(-) diff --git a/README.md b/README.md index 4179f48..45748bc 100644 --- a/README.md +++ b/README.md @@ -132,9 +132,28 @@ Error Action supports the same builder (DISPLAY TEXT, PLAY TONE). ## RAM Tab -CLA = `80` (GlobalPlatform Card Specification v2.3.1). Remote Application Management commands for card content management. +CLA = `80` (GlobalPlatform Card Specification v2.3.1). Remote Application Management operations for card content management over SCP80. -### Commands +### Operations + +The RAM subtab offers two operations selected from the **Operation** dropdown: + +| Operation | Description | +|---|---| +| **Explore Card (all GP data)** | Queries GET STATUS for ISD, Applications, ELFs, and ELF Modules, plus GET DATA FF21 for memory info. Results appear in an explorer view with per-item **Delete** buttons. | +| **Install Package (.cap file)** | Sends a `.cap` file to the card via the server: INSTALL\[for load\] → LOAD ×N → INSTALL\[for install (+make selectable)\]. | + +### Explorer View + +After "Explore Card" runs, the explorer view displays: + +- **ISD** — AID, lifecycle, privileges (no delete; the ISD cannot be removed) +- **Applications** — AID, lifecycle, privileges, associated ELF/SD. Each has a **Delete** button (GP `DELETE` by AID). +- **Executable Load Files** — AID, lifecycle, version, module AIDs. Each has **Delete** (ELF only) and **Delete All** (cascade: ELF + modules + installed Applications, P2=0x80) buttons. + +Delete confirms via a browser prompt before sending the GP `DELETE` command via SCP80. The explorer auto-refreshes after a successful deletion. + +### GP Commands Reference | Command | INS | P1 | Description | |---|---|---|---| diff --git a/README_RUS.md b/README_RUS.md index 5bb2e32..5ceb5a9 100644 --- a/README_RUS.md +++ b/README_RUS.md @@ -127,9 +127,28 @@ CLA = `00` (ETSI TS 102 221). Те же команды, что и SIM, но SELE ## Вкладка RAM -CLA = `80` (GlobalPlatform v2.3.1). Команды удалённого управления приложениями. +CLA = `80` (GlobalPlatform v2.3.1). Удалённое управление содержимым карты через SCP80. -### Команды +### Операции + +В RAM-подвкладке доступны две операции через выпадающий список **Operation**: + +| Операция | Описание | +|---|---| +| **Explore Card (all GP data)** | Запрос GET STATUS для ISD, приложений, ELF и модулей ELF, а также GET DATA FF21 для информации о памяти. Результаты отображаются в обзоре с кнопками **Delete** для каждого элемента. | +| **Install Package (.cap file)** | Отправка `.cap` файла на карту через сервер: INSTALL\[for load\] → LOAD ×N → INSTALL\[for install (+make selectable)\]. | + +### Обзор карты (Explorer View) + +После выполнения "Explore Card" отображается: + +- **ISD** — AID, жизненный цикл, привилегии (без удаления; ISD нельзя удалить) +- **Приложения** — AID, жизненный цикл, привилегии, связанный ELF/SD. Каждое имеет кнопку **Delete** (GP `DELETE` по AID). +- **Executable Load Files** — AID, жизненный цикл, версии, AID модулей. Каждый имеет **Delete** (только ELF) и **Delete All** (каскадное: ELF + модули + установленные приложения, P2=0x80). + +Удаление подтверждается через диалог браузера перед отправкой команды GP `DELETE` через SCP80. Обзор автоматически обновляется после успешного удаления. + +### Справочник GP-команд | Команда | INS | P1 | Описание | |---|---|---|---| diff --git a/docs/api.md b/docs/api.md index 4928dfd..e45e41b 100644 --- a/docs/api.md +++ b/docs/api.md @@ -32,6 +32,7 @@ connect and warns if versions are incompatible. | `/api/send-ota` | POST | SCP80 OTA secured packet delivery | | `/api/ram-install` | POST | Install a Java Card `.cap` file via SCP80 (INSTALL[for load] → LOAD ×N → INSTALL[for install]) | | `/api/sp-verify` | POST | Verify secured packet against pySim reference | +| `/api/ram-install` | POST | Install a Java Card `.cap` file via SCP80 (INSTALL[for load] → LOAD ×N → INSTALL[for install]) | | `/api/menu` | GET | Current STK menu (title + items + active) | | `/api/menu-select` | POST | ENVELOPE(Menu Selection) with item_id | | `/api/menu-respond` | POST | TERMINAL RESPONSE for paused STK command | @@ -213,6 +214,60 @@ and the decoded SPI fields. "diffs": [], "spi": {"counter": "counter_must_be_higher", ...}} ``` +### `POST /api/ram-install` + +Install a Java Card `.cap` file on the card via GlobalPlatform commands (INSTALL[for load] → LOAD ×N → INSTALL[for install (+ make selectable)]) wrapped in SCP80 secured packets. Each step is sent via ENVELOPE and its PoR is checked; the sequence aborts on the first PoR error. Requires pySim with `pySim.javacard.CapFile` and `pySim.global_platform` available on the server. + +**Request body:** +```json +{ + "cap_hex": "DECAFFED...", + "sd_aid": "A000000003000000", + "install_params": "C90000", + "stk_params": "", + "nv_quota": 0, + "volatile_quota": 0, + "make_selectable": true, + "spi1": "0E", "spi2": "01", + "kic": "15", "kid": "15", + "tar": "000000", + "cntr": "0000000001", + "kicKey": "D6FCC023...", + "kidKey": "1B07E7E0..." +} +``` + +| Field | Req | Description | +|---|---|---| +| `cap_hex` | yes | Even-length hex of the `.cap` file (zipped Java Card CAP), max 48 kB (98304 hex chars) | +| `sd_aid` | no | Security Domain AID for INSTALL[for load]; empty → default ISD `A000000003000000` | +| `install_params` | no | Hex C9 TLV install parameters; if empty, `gen_install_parameters()` is used with the quota/stk params | +| `stk_params` | no | Hex CA TLV (TS 102 226 §8.2.1.3.2.1) for SIM toolkit app-specific params | +| `nv_quota` / `volatile_quota` | no | Integer memory quotas (bytes) for `gen_install_parameters()` | +| `make_selectable` | no | If true (default), final INSTALL uses P1=`0C` (install + make selectable) | + +**Response (success):** +```json +{"success": true, "failed_step": null, + "steps": [{"name": "install_for_load", "apdu": "80E60200...", "por_status": "por_ok", "sw": "9000"}, + {"name": "load_0", "apdu": "80E80000...", "por_status": "por_ok", "sw": "9000"}, + {"name": "install_for_install", "apdu": "80E60C00...", "por_status": "por_ok", "sw": "9000"}], + "final_cntr": "0000000004", + "load_file_aid": "A000000003000000", + "module_aid": "A000000003000000", + "application_aid": "A000000003000000"} +``` + +**Response (failure):** +```json +{"success": false, "failed_step": "load_1", + "steps": [{"name": "install_for_load", "por_status": "por_ok", "sw": "9000"}, + {"name": "load_1", "por_status": "rc_error", "sw": null}], + "error": "..."} +``` + +The `steps` array contains one entry per GP command. `final_cntr` is the counter value after all successful steps (use it to update the card preset). The response is not streamed — all steps run server-side before the JSON is returned. + ### `GET /api/menu` Returns the SIM Toolkit SETUP MENU captured from the card's TERMINAL PROFILE diff --git a/frontend/index.html b/frontend/index.html index d5b5200..666f8b4 100644 --- a/frontend/index.html +++ b/frontend/index.html @@ -891,20 +891,11 @@
- -