v3.29.0: the batch kinds (delete / reinstall) + the delete-package pre-step

The batch plan is a list of named steps ({name, apdu, delete}) now and
_ram_install_run generalized into _ram_plan_run; POST /api/ram-batch/start
dispatches on kind:
- install-cap (default; delete_package prepends a cascade DELETE on the
  package AID - a leftover package blocks INSTALL [for load]),
- reinstall-app (_ram_reinstall_plan: DELETE the applet instance + INSTALL
  [for install] from the loaded package - no .cap, no LOAD),
- delete (_ram_delete_plan: one GP DELETE, aid + target app/package ->
  P2=00/P2=80).

A delete step tolerates 'not found' (6A88/6A82 - the object is already
gone, the goal is met); any other delete failure stops the chain with the
delete's reason.  The policy serves all three kinds and the single
/api/ram-install-app, which now deletes the instance first (make
selectable stays one step); /api/ram-install takes delete_package too.

The status/summary carry the run's kind (the panel labels follow:
installed/deleted/reinstalled) and each attempt carries the last three
steps (steps + steps_total) for the panel's per-step detail.  The PWA's
three batch entries are grouped at the end of the operation selector (an
optgroup); ramIsBatchOp() is the one source for "per-card batch".

Docs: help EN/RU, api.md, the repo AGENTS.  Tests: the plan builders per
kind, the validations, the delete-package prepend, the not-found
tolerance, the kind dispatch/status/notice, the steps tail, the endpoint
steps, the PWA wiring.  925 frontend + 943 Python; sw cache simple-v447.
This commit is contained in:
2026-10-15 00:27:52 +03:00
parent 5ae8b1fdd1
commit cf7ee77a9e
11 changed files with 766 additions and 228 deletions
File diff suppressed because one or more lines are too long
+5 -3
View File
@@ -321,10 +321,12 @@
<thead><tr class="border-b border-gray-300 dark:border-slate-700"><th class="text-left py-1 px-2">Operation</th><th class="text-left py-1 px-2">Description</th></tr></thead>
<tbody>
<tr class="border-b border-gray-200 dark:border-slate-700"><td class="py-1 px-2">Explore Card (all GP data)</td><td class="py-1 px-2">Queries GET STATUS for ISD, Applications, ELFs, and ELF Modules, plus GET DATA FF21 (Extended Card Resources: the number of installed applications and the free non-volatile/volatile memory). The compact listing carries the AID, life cycle and privileges (the legacy format has no version); if a card rejects it (<code class="font-mono text-sm">P2.b2=0</code>, deprecated by GP) the queries are retried in the expanded <code class="font-mono text-sm">E3</code> form, and the <strong>Fetch expanded registry details (load-file / SD associations)</strong> checkbox also requests it as an extra pass and merges the expanded-only fields: the Executable Load File version, Load File AID, Security Domain AID, module lists, the applet STK menu entries (SCP Registry Data, TS 102 226 8.2.1.6) and any other registry data objects the card returns (shown raw, never dropped) &mdash; it costs a few extra secured packets per Explore and is <strong>on by default</strong> (remembered per browser; untick to skip). Cards differ in what they accept, so the expanded query is tried in three forms &mdash; the reference tag list (with the TS 102 226 <code class="font-mono text-sm">EA</code>), the same list without <code class="font-mono text-sm">EA</code>, and no tag list at all (the GlobalPlatformPro form) &mdash; and the explorer reports which form worked and where the run fell back to the compact listing (package versions are then unavailable). When the ELF rows still carry no version, the tag-list forms are retried for both P1=10 and P1=20, skipping the combinations already refused, and the walk stops as soon as a version appears. Results appear in an explorer view (the success line stays minimal; the counts are in the section headings) with per-item <strong>Delete</strong> buttons and the detected RAM command format (hover for what compact vs expanded means).</td></tr>
<tr><td class="py-1 px-2">Install Package (.cap file)</td><td class="py-1 px-2">Sends a <code class="font-mono text-sm">.cap</code> file to the card via the server: INSTALL[for load] &rarr; LOAD &times;N &rarr; INSTALL[for install (+make selectable)]. The load file is split into LOAD APDUs of the <strong>LOAD block size</strong> (1&ndash;240 bytes of payload, 240 by default); each secured packet is delivered as a single SMS or, when larger, as a concatenated SMS-PP download of up to 5 segments, so a large <code class="font-mono text-sm">.cap</code> simply takes several SMS. As soon as the file is selected it is validated and its <strong>memory requirements are estimated</strong> in the form: the <strong>NVRAM requirement</strong> (the code image + persistent data, the GlobalPlatform Card Spec C6+C8 style total) and the RAM estimate. The same box reports the <strong>libraries the CAP is linked against</strong> (its Import component: library name, AID and the minimum version <code class="font-mono text-sm">≥ x.y</code>, with standard names and families resolved and a Java Card SDK hint where known), the package/applet identity and the component breakdown (sizes and shares in load-file order) &mdash; grouped under the <strong>Package</strong>, <strong>Requires</strong>, <strong>Memory</strong> and <strong>Components</strong> headings. The <strong>Platform</strong> line names the minimum Java Card level the card must provide (derived from the <code class="font-mono text-sm">javacard.framework</code> import; the header <code class="font-mono text-sm">int</code> flag additionally requires int support, Java Card 2.2+) and the <strong>ETSI release</strong> the UICC API imports come from (<code class="font-mono text-sm">uicc.toolkit</code> version &rarr; REL-N, per the workspace <code class="font-mono text-sm">sim-tools</code> corpus; shown with its basis in brackets): the JCRE checks every import against its own packages when it verifies the load file (JC VM spec 4.5.2), so a card whose platform is older rejects the LOAD as soon as the <strong>Import</strong> component is complete (the step line carries the card's remote SW and names the component the block completed, e.g. <em>completes Import</em>): the failure hint and the popup then point at the <strong>CAP compatibility test</strong> (one click &mdash; the same <code class="font-mono text-sm">.cap</code> is still selected) to find the missing package and version; a smaller LOAD block only helps when the block exceeds the card's buffer. A corrupt or wrong-format file fails the analysis, and <strong>Execute</strong> stays disabled until a successful analysis. The estimate is informational only and is never used for installation: NVRAM is the code image plus the persistent data (the GlobalPlatform C6+C8 style total, Table 11-48 &mdash; card memory management, rounding and the registry entry are not included, and the static field image is counted in both parts); the suggested <strong>C6</strong> follows the load file, and the suggested quotas are decimal byte counts (the hex in parentheses is how the C7/C8 install parameters encode them: C6 = non-volatile code, C7 = volatile RAM, C8 = non-volatile data).</td></tr>
<tr class="border-b border-gray-200 dark:border-slate-700"><td class="py-1 px-2">Batch install (.cap file, per card)</td><td class="py-1 px-2">The bulk workflow: one <code class="font-mono text-sm">.cap</code> and one set of install parameters, applied to card after card. <strong>Start batch</strong> needs no card &mdash; the server owns the loop: it waits for a card, installs the moment the equip finishes, then waits for the next one. Every card's <strong>preset is matched by ICCID</strong> and supplies the keyset (the ISD role TAR's default, v3.26.0), the keys and the counter; a card with no matching preset or no usable ISD keyset is reported and skipped. Each attempt lands in the list with its time, ICCID, preset, verdict and duration; a failure shows the failing step and the remote status word &mdash; the batch never retries and never stops on a failure (failures are yours to manage afterwards). A card is attempted <strong>once per run</strong>: re-equipping it reports &ldquo;already processed&rdquo; &mdash; restart the batch to retry it. <strong>Stop</strong> finishes the current card first (an interrupted LOAD chain can leave a half-loaded package) and then ends the run; <strong>Clear</strong> drops the finished report. The loop runs in the server, so closing the tab, switching views or reloading the page does not interrupt it; a server restart ends it. A batch and a test run exclude each other.</td></tr>
<tr><td class="py-1 px-2">Install Package (.cap file)</td><td class="py-1 px-2">Sends a <code class="font-mono text-sm">.cap</code> file to the card via the server: INSTALL[for load] &rarr; LOAD &times;N &rarr; INSTALL[for install (+make selectable)]. The load file is split into LOAD APDUs of the <strong>LOAD block size</strong> (1&ndash;240 bytes of payload, 240 by default); each secured packet is delivered as a single SMS or, when larger, as a concatenated SMS-PP download of up to 5 segments, so a large <code class="font-mono text-sm">.cap</code> simply takes several SMS. As soon as the file is selected it is validated and its <strong>memory requirements are estimated</strong> in the form: the <strong>NVRAM requirement</strong> (the code image + persistent data, the GlobalPlatform Card Spec C6+C8 style total) and the RAM estimate. The same box reports the <strong>libraries the CAP is linked against</strong> (its Import component: library name, AID and the minimum version <code class="font-mono text-sm">≥ x.y</code>, with standard names and families resolved and a Java Card SDK hint where known), the package/applet identity and the component breakdown (sizes and shares in load-file order) &mdash; grouped under the <strong>Package</strong>, <strong>Requires</strong>, <strong>Memory</strong> and <strong>Components</strong> headings. The <strong>Platform</strong> line names the minimum Java Card level the card must provide (derived from the <code class="font-mono text-sm">javacard.framework</code> import; the header <code class="font-mono text-sm">int</code> flag additionally requires int support, Java Card 2.2+) and the <strong>ETSI release</strong> the UICC API imports come from (<code class="font-mono text-sm">uicc.toolkit</code> version &rarr; REL-N, per the workspace <code class="font-mono text-sm">sim-tools</code> corpus; shown with its basis in brackets): the JCRE checks every import against its own packages when it verifies the load file (JC VM spec 4.5.2), so a card whose platform is older rejects the LOAD as soon as the <strong>Import</strong> component is complete (the step line carries the card's remote SW and names the component the block completed, e.g. <em>completes Import</em>): the failure hint and the popup then point at the <strong>CAP compatibility test</strong> (one click &mdash; the same <code class="font-mono text-sm">.cap</code> is still selected) to find the missing package and version; a smaller LOAD block only helps when the block exceeds the card's buffer. A corrupt or wrong-format file fails the analysis, and <strong>Execute</strong> stays disabled until a successful analysis. The estimate is informational only and is never used for installation: NVRAM is the code image plus the persistent data (the GlobalPlatform C6+C8 style total, Table 11-48 &mdash; card memory management, rounding and the registry entry are not included, and the static field image is counted in both parts); the suggested <strong>C6</strong> follows the load file, and the suggested quotas are decimal byte counts (the hex in parentheses is how the C7/C8 install parameters encode them: C6 = non-volatile code, C7 = volatile RAM, C8 = non-volatile data). The <strong>Delete the package before installing (with its applications)</strong> checkbox prepends a cascade GP <code class="font-mono text-sm">DELETE</code> on the package AID (the load file with its modules and applications, P2=<code class="font-mono text-sm">0x80</code>) &mdash; a leftover package blocks INSTALL[for load]; 'not found' (a fresh card) proceeds, any other delete failure stops the chain with its reason.</td></tr>
<tr class="border-b border-gray-200 dark:border-slate-700"><td class="py-1 px-2">Batch install (.cap file, per card)</td><td class="py-1 px-2">The bulk workflow: one <code class="font-mono text-sm">.cap</code> and one set of install parameters, applied to card after card. <strong>Start batch</strong> needs no card &mdash; the server owns the loop: it waits for a card, installs the moment the equip finishes, then waits for the next one. Every card's <strong>preset is matched by ICCID</strong> and supplies the keyset (the ISD role TAR's default, v3.26.0), the keys and the counter; a card with no matching preset or no usable ISD keyset is reported and skipped. Each attempt lands in the list with its time, ICCID, preset, verdict and duration; a failure shows the failing step and the remote status word &mdash; the batch never retries and never stops on a failure (failures are yours to manage afterwards). A card is attempted <strong>once per run</strong>: re-equipping it reports &ldquo;already processed&rdquo; &mdash; restart the batch to retry it. <strong>Stop</strong> finishes the current card first (an interrupted LOAD chain can leave a half-loaded package) and then ends the run; <strong>Clear</strong> drops the finished report. The loop runs in the server, so closing the tab, switching views or reloading the page does not interrupt it; a server restart ends it. A batch and a test run exclude each other. The batch shares the install form, so the <strong>Delete the package before installing</strong> option applies to every card.</td></tr>
<tr class="border-b border-gray-200 dark:border-slate-700"><td class="py-1 px-2">Batch reinstall app (per card)</td><td class="py-1 px-2">The repair workflow: for every equipped card, delete the applet instance (tolerating 'not found') and run INSTALL [for install] again from the already loaded package &mdash; no <code class="font-mono text-sm">.cap</code> and no LOAD. The fields are the single INSTALL [for install] parameters (Load File / Module / Instance AIDs, privileges, the toolkit/STK parameters, <em>make selectable</em>); the preset, keyset and counter come from each card's own preset like the other batch operations, and the attempts list shows both verdicts (delete and install).</td></tr>
<tr class="border-b border-gray-200 dark:border-slate-700"><td class="py-1 px-2">Batch delete (per card)</td><td class="py-1 px-2">Deletes one object on every equipped card: an application (instance only, P2=<code class="font-mono text-sm">0x00</code>) or a package with its applications (cascade, P2=<code class="font-mono text-sm">0x80</code>). Fields: the AID and the target. A 'not found' result (the object is already gone) is reported as such and counted OK; any other failure is reported with the card's status word.</td></tr>
<tr class="border-b border-gray-200 dark:border-slate-700"><td class="py-1 px-2">CAP compatibility test</td><td class="py-1 px-2">Answers one question without installing anything: <strong>can this card satisfy the CAP's import list?</strong> The server runs the format check, INSTALL[for load] and the LOAD blocks only up to the block that completes the <strong>Import</strong> component &mdash; the point where the JCRE verifies the import list &mdash; then stops: no last-block flag and no INSTALL[for install], so nothing is committed and nothing has to be deleted afterwards. The <strong>Import versions to test</strong> list is pre-filled from the CAP analysis: <code class="font-mono text-sm">AID=version</code> rewrites an import's requested version, <code class="font-mono text-sm">+AID=version</code> appends a synthetic import (a card-capability query: the LOAD passes only if the card exports that package at &ge; that version), and <strong>Set all 0.0</strong> drops every requirement. Two-step use: press Set all 0.0 &mdash; if the test passes, the import list was the blocker; then restore one line at a time to find the package and version the card lacks. The verdict states it covers the <strong>LOAD/import gate only</strong>: the link gate (whether the applet's actual API calls exist) is what a real install checks at INSTALL[for install]. The run and its result appear in a popup (like the install): the step lines, the verdict and a per-AID detail block &mdash; on a rejection it names the CAP section the failing block covers (load-file byte range and components, and whether that block completes <strong>Import</strong>), the remote status word with its meaning, the import list exactly as tested (CAP versions, probe rewrites, appended synthetic entries, unmatched lines) and what the probe state implies; on success it lists the import list that passed.</td></tr>
<tr class="border-b border-gray-200 dark:border-slate-700"><td class="py-1 px-2">INSTALL [for install] (loaded package)</td><td class="py-1 px-2">One INSTALL [for install] APDU for a package that is already loaded on the card (its Load File AID and Module AID, privileges, install/STK parameters and an optional <em>make selectable</em>) &mdash; iterate the install parameters without deleting and re-loading the <code class="font-mono text-sm">.cap</code> every time.</td></tr>
<tr class="border-b border-gray-200 dark:border-slate-700"><td class="py-1 px-2">INSTALL [for install] (loaded package)</td><td class="py-1 px-2">For a package that is already loaded on the card (its Load File AID and Module AID, privileges, install/STK parameters and an optional <em>make selectable</em>). The applet instance is deleted first (tolerating 'not found' &mdash; a fresh card just installs; any other delete failure stops the chain with its reason), so the install parameters can be iterated without re-loading the <code class="font-mono text-sm">.cap</code>.</td></tr>
<tr><td class="py-1 px-2">INSTALL [for make selectable]</td><td class="py-1 px-2">One INSTALL [for make selectable] APDU (the instance AID) for an INSTALLED, non-selectable applet instance.</td></tr>
</tbody>
</table>
+123 -19
View File
@@ -700,10 +700,14 @@
<select id="ram-op" onchange="ramOpChanged()" class="w-full border border-gray-300 dark:border-slate-600 text-sm rounded px-3 py-1.5 dark:bg-slate-800">
<option value="explore" data-l10n="Explore Card (all GP data)">Explore Card (all GP data)</option>
<option value="install-cap" data-l10n="Install Package (.cap file)">Install Package (.cap file)</option>
<option value="batch" data-l10n="Batch install (.cap file, per card)">Batch install (.cap file, per card)</option>
<option value="compat" data-l10n="CAP compatibility test">CAP compatibility test</option>
<option value="install-app" data-l10n="INSTALL [for install] (loaded package)">INSTALL [for install] (loaded package)</option>
<option value="make-selectable" data-l10n="INSTALL [for make selectable]">INSTALL [for make selectable]</option>
<optgroup label="Batch (per card)" data-l10n="Batch (per card)">
<option value="batch" data-l10n="Batch install (.cap file, per card)">Batch install (.cap file, per card)</option>
<option value="batch-reinstall" data-l10n="Batch reinstall app (per card)">Batch reinstall app (per card)</option>
<option value="batch-delete" data-l10n="Batch delete (per card)">Batch delete (per card)</option>
</optgroup>
</select>
</div>
<div class="flex-1">
@@ -729,6 +733,10 @@
<div id="ram-cap-body"></div>
</fieldset>
</div>
<label id="ram-del-package-row" class="hidden flex items-center gap-2 mb-3 text-sm text-gray-700 dark:text-slate-300">
<input type="checkbox" id="ram-del-package" class="rounded border-gray-300 dark:border-slate-600">
<span data-l10n="Delete the package before installing (with its applications)">Delete the package before installing (with its applications)</span>
</label>
<div id="ram-compat-rows" class="hidden mb-3">
<fieldset class="border border-gray-200 dark:border-slate-700 rounded p-3" data-l10n-title="Runs the load only as far as the block that completes the CAP's Import component: the card checks the import list there, so its answer says whether the card can satisfy it. Nothing is installed and nothing is committed - the link gate is the real install's business. Lines are AID=version (rewrites an import) or +AID=version (appends a synthetic import, to query the card for a package the CAP does not use).">
<legend class="px-1 text-xs font-medium text-gray-500 dark:text-slate-400" data-l10n="Import versions to test">Import versions to test</legend>
@@ -742,6 +750,16 @@
<label class="block mb-1 mt-2 text-sm font-medium text-gray-700 dark:text-slate-300" data-l10n="LOAD block size (1..240, default 240)">LOAD block size (1..240, default 240)</label>
<input id="ram-compat-block" type="number" min="1" max="240" class="w-32 font-mono border border-gray-300 dark:border-slate-600 text-sm rounded px-3 py-1.5 dark:bg-slate-800" placeholder="240">
</div>
<div id="ram-delete-rows" class="hidden mb-3">
<label class="block mb-1 text-sm font-medium text-gray-700 dark:text-slate-300" data-l10n="AID (hex)">AID (hex)</label>
<input id="ram-del-aid" class="w-full font-mono border border-gray-300 dark:border-slate-600 text-sm rounded px-3 py-1.5 dark:bg-slate-800" placeholder="F0414C4641610101" maxlength="32">
<label class="block mb-1 mt-2 text-sm font-medium text-gray-700 dark:text-slate-300" data-l10n="Target">Target</label>
<select id="ram-del-target" class="w-full border border-gray-300 dark:border-slate-600 text-sm rounded px-3 py-1.5 dark:bg-slate-800">
<option value="app" data-l10n="Application (instance only)">Application (instance only)</option>
<option value="package" data-l10n="Package (with its applications)">Package (with its applications)</option>
</select>
<div class="text-xs text-gray-400 dark:text-slate-500 mt-1" data-l10n="A package delete cascades (the load file with its modules and installed applications, P2=80).">A package delete cascades (the load file with its modules and installed applications, P2=80).</div>
</div>
<div id="ram-install-params" class="hidden mb-3">
<label class="block mb-1 text-sm font-medium text-gray-700 dark:text-slate-300" data-l10n="SD AID (empty = ISD)">SD AID (empty = ISD)</label>
<input id="ram-sd-aid" class="w-full font-mono border border-gray-300 dark:border-slate-600 text-sm rounded px-3 py-1.5 dark:bg-slate-800" placeholder="A000000003000000" maxlength="32">
@@ -1910,7 +1928,7 @@
// ===== Version =====
// Single source of truth for the PWA version: shown in the header and used
// by the server version check in pysimConnect().
const SIMPLE_VERSION = '3.28.8';
const SIMPLE_VERSION = '3.29.0';
document.getElementById('app-version').textContent = 'v' + SIMPLE_VERSION;
// ===== view history (the browser Back/Forward buttons) =====
@@ -10110,14 +10128,22 @@ function ramApplyCard(idx) {
spPresetWarningRender();
}
// The three per-card batch operations (v3.29.0): the preset, keyset and
// counter resolve from each card's own preset, so the preset selector, the
// Execute button and the preset-mismatch banner do not apply.
function ramIsBatchOp(op) {
return op === 'batch' || op === 'batch-reinstall' || op === 'batch-delete';
}
function ramOpChanged() {
const op = document.getElementById('ram-op').value;
if (_ramOpLast !== null && op !== _ramOpLast) ramClearResults();
_ramOpLast = op;
const isBatch = op === 'batch';
const isCap = op === 'install-cap' || isBatch;
const isBatch = ramIsBatchOp(op);
const isCap = op === 'install-cap' || op === 'batch';
const isCompat = op === 'compat';
const isApp = op === 'install-app' || op === 'make-selectable';
const isApp = op === 'install-app' || op === 'make-selectable' || op === 'batch-reinstall';
const isDelete = op === 'batch-delete';
const setHidden = (id, hidden) => {
const el = document.getElementById(id);
if (el) el.classList.toggle('hidden', hidden);
@@ -10126,6 +10152,8 @@ function ramOpChanged() {
setHidden('ram-cap-rows', !(isCap || isCompat));
setHidden('ram-compat-rows', !isCompat);
setHidden('ram-app-rows', !isApp);
setHidden('ram-delete-rows', !isDelete);
setHidden('ram-del-package-row', !isCap);
// The batch resolves the preset per card (by ICCID): its selector and the
// single-card Execute button do not apply, and the batch panel takes over.
setHidden('ram-preset-cell', isBatch);
@@ -10164,7 +10192,7 @@ const RAM_BATCH_FETCH_STALE_MS = 10000;
function ramBatchPanelVisible() {
const op = document.getElementById('ram-op');
return isViewVisible('tab-scp80') && isViewVisible('scp80-sub-ram')
&& !!op && op.value === 'batch';
&& !!op && ramIsBatchOp(op.value);
}
async function ramBatchFetch() {
@@ -10218,6 +10246,13 @@ function ramBatchRender() {
_ramBatchLast || {}, _ramBatchSummary || {});
const active = !!st.active;
const phase = st.phase || (active ? 'waiting_card' : 'idle');
// The success labels follow the operation (v3.29.0): the counts bucket is
// 'installed' for every kind - "the operation succeeded".
const kind = st.kind || 'install-cap';
const okLabel = kind === 'delete' ? t('Deleted')
: (kind === 'reinstall-app' ? t('Reinstalled') : t('Installed'));
const actLabel = kind === 'delete' ? t('Deleting...')
: (kind === 'reinstall-app' ? t('Reinstalling...') : t('Installing...'));
const startBtn = document.getElementById('ram-batch-start');
if (startBtn) startBtn.classList.toggle('hidden', active);
const stopBtn = document.getElementById('ram-batch-stop');
@@ -10240,7 +10275,7 @@ function ramBatchRender() {
: (phase === 'finished' ? t('Batch finished') : '');
} else if (phase === 'installing') {
const cur = st.current || {};
stateEl.textContent = t('Installing...') + ' ' + (cur.iccid || '')
stateEl.textContent = actLabel + ' ' + (cur.iccid || '')
+ (cur.preset ? ' \u2014 ' + cur.preset : '');
} else if (phase === 'stopping') {
stateEl.textContent = t('Stopping after the current card...');
@@ -10256,7 +10291,7 @@ function ramBatchRender() {
const counts = document.getElementById('ram-batch-counts');
if (counts) {
const c = st.counts || {};
let text = t('Installed') + ': ' + (c.installed || 0)
let text = okLabel + ': ' + (c.installed || 0)
+ ' \u00b7 ' + t('Failed') + ': ' + (c.failed || 0)
+ ' \u00b7 ' + t('Skipped') + ': ' + (c.skipped || 0);
if (st.attempts_total) text += ' \u00b7 ' + st.attempts_total + ' ' + t('attempts');
@@ -10276,6 +10311,17 @@ function ramBatchRender() {
}
}
// The per-step verdict tail of an attempt (v3.29.0): e.g.
// "DELETE (application) 6101 · INSTALL [for install] 6101". Only short chains
// are rendered (the delete/reinstall kinds) - a full LOAD chain's tail would
// be noise; anything else keeps the skip reason.
function ramBatchStepsText(a) {
const steps = (a && a.steps) || [];
if (!steps.length || steps.length > 3) return (a && a.reason) || '';
return steps.map(s => s.name + (s.sw ? ' ' + s.sw : '') +
(s.not_found ? ' (' + t('not found') + ')' : '')).join(' \u00b7 ');
}
function ramBatchAttemptsHtml(attempts) {
if (!attempts.length) return '<div class="text-gray-400 dark:text-slate-500">' + esc(t('No cards processed yet.')) + '</div>';
let html = '<table class="w-full"><tbody>';
@@ -10288,7 +10334,7 @@ function ramBatchAttemptsHtml(attempts) {
: (a.result === 'failed' ? 'text-red-600 dark:text-red-400' : 'text-amber-600 dark:text-amber-400');
const detail = a.result === 'failed'
? [a.failed_step, a.por_sw || a.sw || a.error].filter(Boolean).join(' \u2014 ')
: (a.reason || '');
: ramBatchStepsText(a);
html += '<tr class="border-b border-gray-100 dark:border-slate-800">'
+ '<td class="py-0.5 pr-2 text-gray-400 dark:text-slate-500 whitespace-nowrap">' + esc(when) + '</td>'
+ '<td class="py-0.5 pr-2 font-mono whitespace-nowrap">' + esc(a.iccid || '') + '</td>'
@@ -10321,6 +10367,7 @@ function ramInstallCapFields() {
const composed = ramInstallParamsCompose();
const body = {
sd_aid: (document.getElementById('ram-sd-aid').value || '').replace(/[^0-9a-fA-F]/g, ''),
delete_package: !!(document.getElementById('ram-del-package') || {}).checked,
privileges: (document.getElementById('rc-priv').value || '00').replace(/[^0-9a-fA-F]/g, ''),
install_params: composed.install_params,
stk_params: composed.stk_params,
@@ -10337,17 +10384,50 @@ function ramInstallCapFields() {
}
async function ramBatchStart() {
if (!capGateOk('ram')) { alert(t('Analyze the CAP file first')); return; }
const fileInput = document.getElementById('ram-cap-file');
const file = fileInput.files[0];
if (!file) { alert(t('Select a .cap file')); return; }
if (file.size > 48 * 1024) { alert(t('CAP file exceeds 48 kB limit')); return; }
const fields = ramInstallCapFields();
if (!fields) return;
// The operation selects the batch kind (v3.29.0): the .cap install, the
// applet reinstall (no .cap - the package is loaded) or a GP delete. The
// server builds and validates the plan once at Start.
const op = document.getElementById('ram-op').value;
const clean = id => (document.getElementById(id).value || '').replace(/[^0-9a-fA-F]/g, '').toUpperCase();
let fields;
if (op === 'batch-delete') {
const aid = clean('ram-del-aid');
if (!/^(?:[0-9A-F]{2}){5,16}$/.test(aid)) { alert(t('AID must be 5-16 bytes of hex')); return; }
fields = {kind: 'delete', aid: aid,
target: document.getElementById('ram-del-target').value || 'app'};
} else if (op === 'batch-reinstall') {
const loadfile = clean('ram-app-loadfile');
const module = clean('ram-app-module');
const instance = clean('ram-app-instance');
if (!loadfile || !module) { alert(t('Load File AID and Module AID required')); return; }
// The privileges and the STK hex are derived from the form, never sent
// stale (the same rule the single install-app follows).
updateRcPriv();
const stkEl = document.getElementById('ram-stk-params');
if (document.getElementById('rc-toolkit-enable').checked && !(stkEl.dataset && stkEl.dataset.manual)) {
updateStkParamsHex();
}
const composed = ramInstallParamsCompose();
fields = {kind: 'reinstall-app', loadfile_aid: loadfile, module_aid: module,
instance_aid: instance,
privileges: (document.getElementById('rc-priv').value || '00').replace(/[^0-9a-fA-F]/g, ''),
install_params: composed.install_params, stk_params: composed.stk_params,
make_selectable: document.getElementById('ram-make-sel').checked};
} else {
if (!capGateOk('ram')) { alert(t('Analyze the CAP file first')); return; }
const fileInput = document.getElementById('ram-cap-file');
const file = fileInput.files[0];
if (!file) { alert(t('Select a .cap file')); return; }
if (file.size > 48 * 1024) { alert(t('CAP file exceeds 48 kB limit')); return; }
fields = ramInstallCapFields();
if (!fields) return;
fields.kind = 'install-cap';
fields.cap_hex = await ramReadFileHex(file);
}
fields.ram_format = (document.getElementById('ram-format') || {}).value || 'auto';
const startBtn = document.getElementById('ram-batch-start');
if (startBtn) startBtn.disabled = true;
try {
fields.cap_hex = await ramReadFileHex(file);
_ramBatchLast = await pysimFetchOk('/api/ram-batch/start', fields);
_ramBatchSummary = null;
} catch (e) {
@@ -12312,6 +12392,12 @@ function ramStepComponents(name, components, blockSize) {
// not a plain 9000. With the CAP analysis at hand the line also names the
// component the block completed (see ramStepComponents).
function ramStepLine(s, idx, comps, blockSize) {
// a delete step that answered 'not found' (6A88/6A82): the object was
// already gone - the delete's goal is met, the chain continued (v3.29.0)
if (s.delete_not_found) {
return '\u2796 ' + t('Step') + ' ' + (idx + 1) + ': ' + s.name + ' \u2014 ' +
(s.por_sw ? s.por_sw + ' (' + t('not found') + ')' : t('not found'));
}
const ok = !s.por_error && (s.por_status === 'por_ok' || s.por_status === 'no_por');
let line = (ok ? '\u2705' : '\u274c') + ' ' + t('Step') + ' ' + (idx + 1) + ': ' +
s.name + ' \u2014 ';
@@ -14052,7 +14138,7 @@ function spPresetWarningRender() {
// The batch resolves the preset per card, so the RAM view's warning does
// not apply there (v3.28.0).
const ramOp = document.getElementById('ram-op');
const batchMode = !!ramOp && ramOp.value === 'batch';
const batchMode = !!ramOp && ramIsBatchOp(ramOp.value);
show('ram-preset-warning', batchMode ? '' : spPresetWarning(iccid, cards, ramPresetIdx()));
show('tar-preset-warning', spPresetWarning(iccid, cards, tarPresetIdx()));
}
@@ -24442,14 +24528,29 @@ const LANG_RU = {
'Close': 'Закрыть',
'Installing package': 'Установка пакета',
'Batch install (.cap file, per card)': 'Пакетная установка (.cap на множество карт)',
'Batch (per card)': 'Пакетные операции (по картам)',
'Batch reinstall app (per card)': 'Пакетная переустановка приложения (по картам)',
'Batch delete (per card)': 'Пакетное удаление (по картам)',
'AID (hex)': 'AID (hex)',
'Target': 'Цель',
'Application (instance only)': 'Приложение (только экземпляр)',
'Package (with its applications)': 'Пакет (с его приложениями)',
'A package delete cascades (the load file with its modules and installed applications, P2=80).': 'Удаление пакета каскадное (load-файл с его модулями и установленными приложениями, P2=80).',
'Delete the package before installing (with its applications)': 'Удалить пакет перед установкой (с его приложениями)',
'AID must be 5-16 bytes of hex': 'AID должен быть 5-16 байт hex',
'not found': 'не найдено',
'Start batch': 'Запустить пакетную установку',
'Stopping...': 'Остановка…',
'Batch stopped': 'Пакетная установка остановлена',
'Batch finished': 'Пакетная установка завершена',
'Installing...': 'Установка…',
'Deleting...': 'Удаление…',
'Reinstalling...': 'Переустановка…',
'Stopping after the current card...': 'Остановка после текущей карты…',
'Insert next card. Waiting for a card...': 'Вставьте следующую карту. Ожидание карты…',
'Installed': 'Установлено',
'Deleted': 'Удалено',
'Reinstalled': 'Переустановлено',
'Skipped': 'Пропущено',
'attempts': 'попыток',
'No cards processed yet.': 'Карты ещё не обрабатывались.',
@@ -24794,7 +24895,10 @@ function setHelpAnchor(anchor) {
function translatePage() {
document.querySelectorAll('[data-l10n]').forEach(el => {
const key = el.getAttribute('data-l10n');
el.textContent = t(key);
// an optgroup's label is an attribute: setting its textContent would
// not change what the select renders
if (el.tagName === 'OPTGROUP') el.label = t(key);
else el.textContent = t(key);
});
// static tooltips (the data-l10n-title attribute; the html test checks
// those keys against LANG_RU together with the data-l10n ones)
+1 -1
View File
@@ -1,4 +1,4 @@
const CACHE = 'simple-v446';
const CACHE = 'simple-v447';
const URLS = [
'index.html',
'help.html',
+12 -1
View File
@@ -33,7 +33,7 @@ const FNS = ['berLenStr', 'buildApdu', 'escHtml', 'esc', 'chainInit', 'chainRamB
'spTarOptionsHtml', 'spTarRender', 'spSpi1Seed', 'spTarKeysetGuard', 'cardsTarKeysetCell', 'cardsTarKeysetFromForm', 'cardsTarKeysetRefresh', 'cardsTarRowsRender', 'cardsTarRowHtml', 'cardsTarsFromTable', 'cardsFreeTarsFromForm', 'spPresetIdx', 'tarPresetIdx',
'cardsKeysetsFromForm', 'spKeysetSync', 'spKeysetApply',
'ramPresetIdx', 'spKeysetGuard', 'ramKeysetGuard',
'ramCardIdxAfterRemove', 'ramClearResults', 'ramHideProgress', 'ramOpChanged', 'ramRender', 'ramApplyCard', 'ramExecute', 'decodePrivileges', 'ramActionBtn', 'ramCapToolkitMode', 'ramOpProgressText',
'ramCardIdxAfterRemove', 'ramClearResults', 'ramHideProgress', 'ramIsBatchOp', 'ramOpChanged', 'ramRender', 'ramApplyCard', 'ramExecute', 'decodePrivileges', 'ramActionBtn', 'ramCapToolkitMode', 'ramOpProgressText',
'jcAidNorm', 'jcAidName', 'jcAidSuffix', 'jcAidHtml'];
let code = '';
for (const f of FNS) {
@@ -419,6 +419,17 @@ test('ramStepLine shows the PoR verdict and the remote status word', () => {
assert.ok(noPor.startsWith('\u2705') && noPor.includes('no PoR'), noPor);
});
test('ramStepLine marks a tolerated not-found delete step (v3.29.0)', () => {
globalThis.t = s => s;
// a delete step's 'not found' (6A88/6A82) is not a failure: the object was
// already gone, the chain continued - the line says so instead of showing
// the failure style
const line = ramStepLine({ name: 'DELETE (application)', por_sw: '6A88',
por_error: 'remote SW 6A88', delete_not_found: true }, 0);
assert.strictEqual(line,
'\u2796 Step 1: DELETE (application) \u2014 6A88 (not found)');
});
test('ramStepComponents maps a LOAD step to the CAP components it covers', () => {
// RemMobileID-like layout: sizes include each component's 3-byte header
const comps = [
+116 -5
View File
@@ -23,9 +23,9 @@ function extractFunc(src, name, asyncFn) {
const ASYNC_FNS = ['ramBatchFetch', 'ramBatchStart', 'ramBatchStop', 'ramBatchClear'];
let code = '';
for (const fn of ['ramBatchPanelVisible', 'ramBatchAttemptsHtml', 'ramBatchRender',
'ramBatchApplyStatus', 'ramBatchFetch', 'ramBatchStart', 'ramBatchStop',
'ramBatchClear', 'esc']) {
for (const fn of ['ramIsBatchOp', 'ramBatchPanelVisible', 'ramBatchStepsText',
'ramBatchAttemptsHtml', 'ramBatchRender', 'ramBatchApplyStatus', 'ramBatchFetch',
'ramBatchStart', 'ramBatchStop', 'ramBatchClear', 'esc']) {
code += extractFunc(html, fn, ASYNC_FNS.indexOf(fn) >= 0) + '\n';
}
@@ -79,6 +79,9 @@ const app = new Function('els', `
var capGateOk = () => sandbox.capGate !== false;
var ramReadFileHex = async () => 'AABB';
var ramInstallCapFields = () => ({ sd_aid: '', install_params: '', ram_format: 'auto' });
var ramInstallParamsCompose = () => ({ install_params: 'C900', stk_params: '' });
var updateRcPriv = () => {};
var updateStkParamsHex = () => {};
var pysimApplyAvailability = () => {};
var _ramBatchLast = null;
var _ramBatchFetching = false;
@@ -96,6 +99,7 @@ const app = new Function('els', `
sandbox.getProgress = () => _ramBatchProgress;
sandbox.ramBatchPanelVisible = ramBatchPanelVisible;
sandbox.ramBatchAttemptsHtml = ramBatchAttemptsHtml;
sandbox.ramBatchStepsText = ramBatchStepsText;
sandbox.ramBatchRender = ramBatchRender;
sandbox.ramBatchApplyStatus = ramBatchApplyStatus;
sandbox.ramBatchFetch = ramBatchFetch;
@@ -119,11 +123,20 @@ test('the RAM view wires the batch operation and the panel', () => {
test('ramOpChanged hides the preset cell and Execute in batch mode', () => {
const src = extractFunc(html, 'ramOpChanged');
assert.match(src, /const isBatch = op === 'batch';/);
assert.match(src, /const isCap = op === 'install-cap' \|\| isBatch;/);
assert.match(src, /const isBatch = ramIsBatchOp\(op\);/);
// the per-card batch set lives in one place (the panel and the preset
// warning follow it too)
const helper = extractFunc(html, 'ramIsBatchOp');
assert.match(helper, /op === 'batch' \|\| op === 'batch-reinstall' \|\| op === 'batch-delete'/);
assert.match(extractFunc(html, 'ramBatchPanelVisible'), /ramIsBatchOp\(op\.value\)/);
assert.match(extractFunc(html, 'spPresetWarningRender'), /ramIsBatchOp\(ramOp\.value\)/);
assert.match(src, /const isCap = op === 'install-cap' \|\| op === 'batch';/);
assert.match(src, /const isDelete = op === 'batch-delete';/);
assert.match(src, /setHidden\('ram-preset-cell', isBatch\)/);
assert.match(src, /setHidden\('ram-exec-btn', isBatch\)/);
assert.match(src, /setHidden\('ram-batch-panel', !isBatch\)/);
assert.match(src, /setHidden\('ram-delete-rows', !isDelete\)/);
assert.match(src, /setHidden\('ram-del-package-row', !isCap\)/);
assert.match(src, /if \(isBatch\) ramBatchFetch\(\);/);
// the preset warning does not apply to the per-card resolution
const warn = extractFunc(html, 'spPresetWarningRender');
@@ -364,6 +377,104 @@ test('a stale fetch guard is released so the report recovers (v3.28.7)', async (
app.resetFetching();
});
test('the batch group carries the three operations (v3.29.0)', () => {
assert.match(html, /<optgroup label="Batch \(per card\)" data-l10n="Batch \(per card\)">/);
assert.match(html, /<option value="batch" data-l10n="Batch install \(\.cap file, per card\)">/);
assert.match(html, /<option value="batch-reinstall" data-l10n="Batch reinstall app \(per card\)">/);
assert.match(html, /<option value="batch-delete" data-l10n="Batch delete \(per card\)">/);
// the group sits at the end of the operation list
const sel = /<select id="ram-op"[\s\S]*?<\/select>/.exec(html)[0];
assert.ok(sel.indexOf('value="batch-delete"') > sel.indexOf('value="make-selectable"'));
// the batch delete fields and the delete-package option exist
assert.match(html, /id="ram-del-aid"/);
assert.match(html, /id="ram-del-target"/);
assert.match(html, /id="ram-del-package"/);
assert.match(html, /'Batch reinstall app \(per card\)': /);
assert.match(html, /'Batch delete \(per card\)': /);
assert.match(html, /'Deleted': /);
assert.match(html, /'Reinstalled': /);
});
test('ramBatchStart sends the kind-specific body (v3.29.0)', async () => {
// the delete kind: the AID and the target
clearEls();
setEl('ram-op', 'batch-delete');
setEl('ram-del-aid', 'f0414c4641610101');
setEl('ram-del-target', 'package');
app.fetched = [];
await app.ramBatchStart();
assert.deepStrictEqual(app.bodies['/api/ram-batch/start'],
{ kind: 'delete', aid: 'F0414C4641610101', target: 'package', ram_format: 'auto' });
// a short/odd AID is refused before anything is sent
clearEls();
setEl('ram-op', 'batch-delete');
setEl('ram-del-aid', 'F041');
setEl('ram-del-target', 'app');
app.fetched = [];
app.alerts = [];
await app.ramBatchStart();
assert.deepStrictEqual(app.fetched, []);
assert.match(app.alerts.join(' '), /5-16 bytes/);
// the reinstall kind: the install-app fields, no .cap
clearEls();
setEl('ram-op', 'batch-reinstall');
setEl('ram-app-loadfile', 'f0414c46416101');
setEl('ram-app-module', 'f0414c4641610101');
setEl('ram-app-instance', '');
setEl('rc-priv', '00');
setEl('rc-toolkit-enable', '');
setEl('ram-make-sel', '');
app.fetched = [];
await app.ramBatchStart();
const body = app.bodies['/api/ram-batch/start'];
assert.strictEqual(body.kind, 'reinstall-app');
assert.strictEqual(body.loadfile_aid, 'F0414C46416101');
assert.strictEqual(body.module_aid, 'F0414C4641610101');
assert.strictEqual(body.install_params, 'C900');
// the cap kind carries the delete-package flag (the shared field builder)
assert.match(extractFunc(html, 'ramInstallCapFields'),
/delete_package: !!\(document\.getElementById\('ram-del-package'\) \|\| \{\}\)\.checked/);
});
test('the batch panel labels follow the run kind (v3.29.0)', () => {
clearEls();
setEl('ram-op', 'batch-delete');
setEl('ram-batch-panel', '');
setEl('ram-batch-start', '');
setEl('ram-batch-stop', '');
setEl('ram-batch-state', '');
setEl('ram-batch-notice', '');
setEl('ram-batch-counts', '');
setEl('ram-batch-attempts', '');
setEl('ram-batch-clear', '');
setEl('ram-batch-spin', '');
app.setLast({ kind: 'delete', active: true, phase: 'installing', attempts: [],
counts: { installed: 2, failed: 0, skipped: 0 }, attempts_total: 2,
current: { iccid: '8970119000004600098' } });
app.ramBatchRender();
assert.match(els['ram-batch-state'].textContent, /Deleting\.\.\. 8970119000004600098/);
assert.match(els['ram-batch-counts'].textContent, /Deleted: 2/);
app.setLast({ kind: 'reinstall-app', active: true, phase: 'waiting_card',
attempts: [], counts: {}, attempts_total: 0 });
app.ramBatchRender();
assert.match(els['ram-batch-counts'].textContent, /Reinstalled: 0/);
});
test('the attempts render the per-step tail for short chains (v3.29.0)', () => {
const out = app.ramBatchAttemptsHtml([
{ iccid: '8970119000004600098', result: 'installed',
steps: [{ name: 'DELETE (application)', sw: '6101', ok: true },
{ name: 'INSTALL [for install]', sw: '6101', ok: true }] },
{ iccid: '8970119000004600106', result: 'installed',
steps: [{ name: 'DELETE (application)', sw: '6A88', ok: true, not_found: true },
{ name: 'INSTALL [for install]', sw: '6101', ok: true }] },
]);
assert.match(out, /DELETE \(application\) 6101 · INSTALL \[for install\] 6101/);
assert.match(out, /DELETE \(application\) 6A88 \(not found\)/);
// a long LOAD chain keeps no tail (the failing-step detail covers it)
assert.strictEqual(app.ramBatchStepsText({ steps: [{}, {}, {}, {}], reason: '' }), '');
});
test('the stop and clear calls hit their endpoints', async () => {
clearEls();
app.fetched = [];