scp81: always reuse the connection, collapsible options, label polish (v2.2.15)

- Keep-alive is no longer a setting: the TLS connection stays open between
  POSTs for the whole dialog (the card, as HTTP client, may still dial a new
  one at any time - GP Am. B 4.3.1) and only the 204 ends it, with a clean
  close_notify while the response is still buffered, then FIN. Dropped
  keep_alive/on_before_close/_scp81_wait_drained and the Connection-header
  'close' value (the API, status and UI no longer carry a keep-alive knob).
- The Listener Options block is a collapsed <details> with a 'custom' badge
  when anything differs from the reference defaults; the Reset button moved
  into the body so it cannot toggle the panel.
- X-Admin-Targeted-Application is opt-in (checkbox + //aid/... field, field
  disabled while off); X-Admin-Next-URI has a checkbox + hint explaining the
  one-shot rule of GP Am. B 4.4.2; both dependent fields grey out when
  unchecked.
- Labels/i18n: 'Chunked body (Transfer-Encoding: chunked)' stays English,
  'Show link events (...)', 'Теги comprehension-required'; the compact-header
  wording now spells out that it omits the optional space after ':' (legal
  per RFC 7230 3.2 OWS; saves one byte per header).
- Tests: a 200 keeps the socket for the next POST; the 204 closes with a
  mutual close_notify exchange; options helper/badge unit tests; removed the
  close-per-response and drain-wait tests. SW cache otaman-v181.
This commit is contained in:
2026-09-17 09:25:23 +03:00
parent f4462c14e7
commit a59e374ff9
12 changed files with 287 additions and 268 deletions
+134 -75
View File
@@ -18,7 +18,7 @@
<div class="max-w-7xl mx-auto px-6 py-2">
<div class="flex items-center justify-between mb-3">
<h1 class="text-2xl font-bold text-heading">OTAMan <span id="slogan" class="text-sm font-normal text-gray-500 dark:text-slate-400 ml-2" data-l10n="SIM OTA with a Human Face">SIM OTA with a Human Face</span> <span class="text-xs text-gray-400 dark:text-slate-500 ml-1">v2.2.14</span></h1>
<h1 class="text-2xl font-bold text-heading">OTAMan <span id="slogan" class="text-sm font-normal text-gray-500 dark:text-slate-400 ml-2" data-l10n="SIM OTA with a Human Face">SIM OTA with a Human Face</span> <span class="text-xs text-gray-400 dark:text-slate-500 ml-1">v2.2.15</span></h1>
<div class="flex items-center gap-4">
<span id="state-indicator" class="flex items-center select-none" style="cursor:default" title="Connecting...">
<span id="state-indicator-dot" class="text-xs text-gray-400" title="Connecting..."></span>
@@ -995,44 +995,49 @@
<div id="scp81-redirect-note" class="hidden mt-2 text-xs text-gray-500 dark:text-slate-400" data-l10n="Redirect: every BIP channel the card opens is connected to this Host:Port (the external HTTP OTA platform); TLS is terminated there, and the address the card requests is only logged.">Redirect: every BIP channel the card opens is connected to this Host:Port (the external HTTP OTA platform); TLS is terminated there, and the address the card requests is only logged.</div>
<div id="scp81-passthru-note" class="hidden mt-2 text-xs text-gray-500 dark:text-slate-400" data-l10n="Pass-through: the terminal connects each BIP channel to the destination the card requests in OPEN CHANNEL (Other address + transport port, TCP client only); Host and Port above are not used, TLS is terminated by that platform, and the server's network is used (lab only).">Pass-through: the terminal connects each BIP channel to the destination the card requests in OPEN CHANNEL (Other address + transport port, TCP client only); Host and Port above are not used, TLS is terminated by that platform, and the server's network is used (lab only).</div>
</div>
<div class="border border-gray-200 dark:border-slate-700 rounded p-3 mb-3">
<div class="flex flex-wrap items-center gap-2 mb-2">
<span class="text-sm text-gray-500 dark:text-slate-400" data-l10n="Options (applied at Start)">Options (applied at Start)</span>
<button onclick="scp81OptionsReset()" class="ml-auto px-2 py-0.5 text-xs rounded border border-gray-300 dark:border-slate-600 hover:bg-gray-200 dark:hover:bg-slate-700 text-gray-700 dark:text-slate-300" data-l10n="Reset to defaults">Reset to defaults</button>
</div>
<div id="scp81-opts-http" class="space-y-2">
<div class="text-xs font-medium text-gray-500 dark:text-slate-400" data-l10n="HTTP framing">HTTP framing</div>
<label class="flex items-center gap-2 text-xs text-gray-600 dark:text-slate-300 cursor-pointer"><input type="checkbox" id="opt-chunked" onchange="scp81OptionsPersist()" class="rounded"> <span data-l10n="Chunked body (Transfer-Encoding: chunked)">Chunked body (Transfer-Encoding: chunked)</span></label>
<div class="flex flex-wrap items-center gap-2">
<label class="text-xs text-gray-600 dark:text-slate-400" data-l10n="Chunk size (bytes, 0 = one TLS record)">Chunk size (bytes, 0 = one TLS record)</label>
<input id="opt-chunk-size" type="number" min="0" max="4096" onchange="scp81OptionsPersist()" class="w-24 font-mono border border-gray-300 dark:border-slate-600 text-sm rounded px-2 py-1 dark:bg-slate-800">
<details id="scp81-opts" class="border border-gray-200 dark:border-slate-700 rounded mb-3">
<summary class="p-3 cursor-pointer select-none text-sm text-gray-500 dark:text-slate-400">
<span data-l10n="Options (applied at Start)">Options (applied at Start)</span>
<span id="scp81-opts-badge" class="ml-1 text-xs text-amber-500 dark:text-amber-400"></span>
</summary>
<div class="px-3 pb-3">
<div class="flex items-center gap-2 mb-2">
<button onclick="scp81OptionsReset()" class="ml-auto px-2 py-0.5 text-xs rounded border border-gray-300 dark:border-slate-600 hover:bg-gray-200 dark:hover:bg-slate-700 text-gray-700 dark:text-slate-300" data-l10n="Reset to defaults">Reset to defaults</button>
</div>
<label class="flex items-center gap-2 text-xs text-gray-600 dark:text-slate-300 cursor-pointer"><input type="checkbox" id="opt-keep-alive" onchange="scp81OptionsPersist()" class="rounded"> <span data-l10n="Keep-alive (one connection until the session ends)">Keep-alive (one connection until the session ends)</span></label>
<div class="flex flex-wrap items-center gap-2">
<label class="text-xs text-gray-600 dark:text-slate-400" data-l10n="Connection header">Connection header</label>
<select id="opt-conn-header" onchange="scp81OptionsPersist()" class="border border-gray-300 dark:border-slate-600 text-sm rounded px-2 py-1 dark:bg-slate-800">
<option value="none" data-l10n="omit (implicit keep-alive)">omit (implicit keep-alive)</option>
<option value="close">close</option>
<option value="keep-alive">keep-alive</option>
</select>
<div id="scp81-opts-http" class="space-y-2">
<div class="text-xs font-medium text-gray-500 dark:text-slate-400" data-l10n="HTTP framing">HTTP framing</div>
<label class="flex items-center gap-2 text-xs text-gray-600 dark:text-slate-300 cursor-pointer"><input type="checkbox" id="opt-chunked" onchange="scp81OptionsPersist()" class="rounded"> <span data-l10n="Chunked body (Transfer-Encoding: chunked)">Chunked body (Transfer-Encoding: chunked)</span></label>
<div class="flex flex-wrap items-center gap-2">
<label class="text-xs text-gray-600 dark:text-slate-400" data-l10n="Chunk size (bytes, 0 = one TLS record)">Chunk size (bytes, 0 = one TLS record)</label>
<input id="opt-chunk-size" type="number" min="0" max="4096" onchange="scp81OptionsPersist()" class="w-24 font-mono border border-gray-300 dark:border-slate-600 text-sm rounded px-2 py-1 dark:bg-slate-800">
</div>
<div class="flex flex-wrap items-center gap-2">
<label class="text-xs text-gray-600 dark:text-slate-400" data-l10n="Connection header">Connection header</label>
<select id="opt-conn-header" onchange="scp81OptionsPersist()" class="border border-gray-300 dark:border-slate-600 text-sm rounded px-2 py-1 dark:bg-slate-800">
<option value="none" data-l10n="omit (implicit keep-alive)">omit (implicit keep-alive)</option>
<option value="keep-alive">keep-alive</option>
</select>
</div>
<label class="flex items-center gap-2 text-xs text-gray-600 dark:text-slate-300 cursor-pointer"><input type="checkbox" id="opt-compact" onchange="scp81OptionsPersist()" class="rounded"> <span data-l10n="Compact headers (omit the optional space after ':')">Compact headers (omit the optional space after ':')</span></label>
<label class="flex items-center gap-2 text-xs text-gray-600 dark:text-slate-300 cursor-pointer"><input type="checkbox" id="opt-next-uri" onchange="scp81NextUriToggle()" class="rounded"> <span data-l10n="Send X-Admin-Next-URI (required to continue the session)">Send X-Admin-Next-URI (required to continue the session)</span></label>
<input id="opt-next-uri-value" onchange="scp81OptionsPersist()" class="w-full font-mono border border-gray-300 dark:border-slate-600 text-sm rounded px-2 py-1 dark:bg-slate-800" placeholder="/api/scp81?req=%d">
<div class="text-xs text-gray-400 dark:text-slate-500" data-l10n="Unchecked = one-shot: per GP Am. B §4.4.2 the card executes the command, returns no response string and closes the session.">Unchecked = one-shot: per GP Am. B §4.4.2 the card executes the command, returns no response string and closes the session.</div>
</div>
<label class="flex items-center gap-2 text-xs text-gray-600 dark:text-slate-300 cursor-pointer"><input type="checkbox" id="opt-compact" onchange="scp81OptionsPersist()" class="rounded"> <span data-l10n="Compact headers (no space after ':')">Compact headers (no space after ':')</span></label>
<label class="flex items-center gap-2 text-xs text-gray-600 dark:text-slate-300 cursor-pointer"><input type="checkbox" id="opt-next-uri" onchange="scp81OptionsPersist()" class="rounded"> <span data-l10n="Next-URI (unchecked = omit the header)">Next-URI (unchecked = omit the header)</span></label>
<input id="opt-next-uri-value" onchange="scp81OptionsPersist()" class="w-full font-mono border border-gray-300 dark:border-slate-600 text-sm rounded px-2 py-1 dark:bg-slate-800" placeholder="/api/scp81?req=%d">
</div>
<div id="scp81-opts-script" class="space-y-2 mt-3">
<div class="text-xs font-medium text-gray-500 dark:text-slate-400" data-l10n="Script framing">Script framing</div>
<div class="flex flex-wrap items-center gap-2">
<select id="opt-script-template" onchange="scp81OptionsPersist()" class="border border-gray-300 dark:border-slate-600 text-sm rounded px-2 py-1 dark:bg-slate-800">
<option value="indefinite" data-l10n="Indefinite (AE 80 … 00 00)">Indefinite (AE 80 … 00 00)</option>
<option value="definite" data-l10n="Definite (AA)">Definite (AA)</option>
</select>
<label class="flex items-center gap-2 text-xs text-gray-600 dark:text-slate-300 cursor-pointer"><input type="checkbox" id="opt-cr-tag" onchange="scp81OptionsPersist()" class="rounded"> <span data-l10n="Comprehension-required tags">Comprehension-required tags</span></label>
<div id="scp81-opts-script" class="space-y-2 mt-3">
<div class="text-xs font-medium text-gray-500 dark:text-slate-400" data-l10n="Script framing">Script framing</div>
<div class="flex flex-wrap items-center gap-2">
<select id="opt-script-template" onchange="scp81OptionsPersist()" class="border border-gray-300 dark:border-slate-600 text-sm rounded px-2 py-1 dark:bg-slate-800">
<option value="indefinite" data-l10n="Indefinite (AE 80 … 00 00)">Indefinite (AE 80 … 00 00)</option>
<option value="definite" data-l10n="Definite (AA)">Definite (AA)</option>
</select>
<label class="flex items-center gap-2 text-xs text-gray-600 dark:text-slate-300 cursor-pointer"><input type="checkbox" id="opt-cr-tag" onchange="scp81OptionsPersist()" class="rounded"> <span data-l10n="Comprehension-required tags">Comprehension-required tags</span></label>
</div>
<label class="flex items-center gap-2 text-xs text-gray-600 dark:text-slate-300 cursor-pointer"><input type="checkbox" id="opt-targeted-app-on" onchange="scp81TargetedAppToggle()" class="rounded"> <span data-l10n="Send X-Admin-Targeted-Application">Send X-Admin-Targeted-Application</span></label>
<input id="opt-targeted-app" onchange="scp81OptionsPersist()" class="w-full font-mono border border-gray-300 dark:border-slate-600 text-sm rounded px-2 py-1 dark:bg-slate-800" placeholder="//aid/A000000151000000">
</div>
<input id="opt-targeted-app" onchange="scp81OptionsPersist()" class="w-full font-mono border border-gray-300 dark:border-slate-600 text-sm rounded px-2 py-1 dark:bg-slate-800" placeholder="X-Admin-Targeted-Application, e.g. //aid/A000000151000000">
<label class="flex items-center gap-2 text-xs text-gray-600 dark:text-slate-300 cursor-pointer mt-3"><input type="checkbox" id="opt-link-events" onchange="scp81OptionsPersist()" class="rounded"> <span data-l10n="Show link events (Channel status ENVELOPEs, TS 102 223 7.5.11)">Show link events (Channel status ENVELOPEs, TS 102 223 7.5.11)</span></label>
</div>
<label class="flex items-center gap-2 text-xs text-gray-600 dark:text-slate-300 cursor-pointer mt-3"><input type="checkbox" id="opt-link-events" onchange="scp81OptionsPersist()" class="rounded"> <span data-l10n="Link events (Channel status ENVELOPEs, TS 102 223 7.5.11)">Link events (Channel status ENVELOPEs, TS 102 223 7.5.11)</span></label>
</div>
</details>
<div class="border border-gray-200 dark:border-slate-700 rounded p-3 mb-3">
<div class="flex justify-between items-center mb-2">
<span class="text-sm text-gray-500 dark:text-slate-400" data-l10n="Script results (R-APDUs)">Script results (R-APDUs)</span>
@@ -7810,58 +7815,102 @@ let _scp81LastStatus = null;
// ===== SCP81 listener options (HTTP framing / script framing / link events) =====
// The API takes these at listener start; they are kept in localStorage so a
// test setup survives reloads. TLS itself has no settings: the listener
// accepts everything it can and reports the negotiated version/cipher.
// test setup survives reloads. The block is collapsed by default and shows a
// 'custom' marker when anything differs from the reference defaults. TLS
// itself has no settings: the listener accepts everything it can and reports
// the negotiated version/cipher.
const SCP81_OPT_DEFAULTS = {
chunked: true, chunkSize: 0, keepAlive: true, connHeader: 'none',
compact: false, nextUri: '/api/scp81?req=%d', linkEvents: true,
scriptTemplate: 'indefinite', crTag: false, targetedApp: ''
chunked: true, chunkSize: 0, connHeader: 'none', compact: false,
nextUriOn: true, nextUri: '/api/scp81?req=%d', linkEvents: true,
scriptTemplate: 'indefinite', crTag: false,
targetedAppOn: false, targetedApp: ''
};
function scp81OptionsState() {
const val = id => { const el = document.getElementById(id); return el ? el.value : ''; };
const on = id => { const el = document.getElementById(id); return !!(el && el.checked); };
return {
chunked: on('opt-chunked'),
chunkSize: Math.max(0, parseInt(val('opt-chunk-size'), 10) || 0),
connHeader: val('opt-conn-header') || 'none',
compact: on('opt-compact'),
nextUriOn: on('opt-next-uri'),
nextUri: val('opt-next-uri-value').trim(),
linkEvents: on('opt-link-events'),
scriptTemplate: val('opt-script-template') === 'definite' ? 'definite' : 'indefinite',
crTag: on('opt-cr-tag'),
targetedAppOn: on('opt-targeted-app-on'),
targetedApp: val('opt-targeted-app').trim()
};
}
function scp81OptionsFromForm() {
const s = scp81OptionsState();
return {
chunked: s.chunked,
chunk_size: s.chunkSize,
conn_header: s.connHeader,
compact_headers: s.compact,
next_uri: s.nextUriOn ? (s.nextUri || SCP81_OPT_DEFAULTS.nextUri) : '',
link_events: s.linkEvents,
script_template: s.scriptTemplate,
cr_tag: s.crTag,
targeted_app: s.targetedAppOn ? s.targetedApp : ''
};
}
function scp81OptionsSyncDisabled() {
const on = id => { const el = document.getElementById(id); return !!(el && el.checked); };
const sync = (id, enabled) => {
const el = document.getElementById(id);
if (!el) return;
el.disabled = !enabled;
el.classList.toggle('opacity-40', !enabled);
};
sync('opt-next-uri-value', on('opt-next-uri'));
sync('opt-targeted-app', on('opt-targeted-app-on'));
}
function scp81OptionsBadge() {
const el = document.getElementById('scp81-opts-badge');
if (!el) return;
const s = scp81OptionsState();
const d = SCP81_OPT_DEFAULTS;
const same = s.chunked === d.chunked && s.chunkSize === d.chunkSize &&
s.connHeader === d.connHeader && s.compact === d.compact &&
s.nextUriOn === d.nextUriOn && (s.nextUri || d.nextUri) === d.nextUri &&
s.linkEvents === d.linkEvents && s.scriptTemplate === d.scriptTemplate &&
s.crTag === d.crTag && s.targetedAppOn === d.targetedAppOn &&
s.targetedApp === d.targetedApp;
el.textContent = same ? '' : t('custom');
}
function scp81OptionsLoad() {
let saved = {};
try { saved = JSON.parse(localStorage.getItem('otaman_scp81_opts') || '{}') || {}; } catch (e) { saved = {}; }
const opt = Object.assign({}, SCP81_OPT_DEFAULTS, saved);
if (saved.nextUriOn === undefined) opt.nextUriOn = (opt.nextUri || '') !== '';
const set = (id, v) => { const el = document.getElementById(id); if (el) el.value = v; };
const chk = (id, v) => { const el = document.getElementById(id); if (el) el.checked = !!v; };
chk('opt-chunked', opt.chunked);
set('opt-chunk-size', opt.chunkSize);
chk('opt-keep-alive', opt.keepAlive);
set('opt-conn-header', opt.connHeader);
set('opt-conn-header', opt.connHeader === 'keep-alive' ? 'keep-alive' : 'none');
chk('opt-compact', opt.compact);
chk('opt-next-uri', opt.nextUri !== '');
chk('opt-next-uri', opt.nextUriOn);
set('opt-next-uri-value', opt.nextUri || SCP81_OPT_DEFAULTS.nextUri);
chk('opt-link-events', opt.linkEvents);
set('opt-script-template', opt.scriptTemplate === 'definite' ? 'definite' : 'indefinite');
chk('opt-cr-tag', opt.crTag);
chk('opt-targeted-app-on', opt.targetedAppOn);
set('opt-targeted-app', opt.targetedApp);
}
function scp81OptionsFromForm() {
const val = id => { const el = document.getElementById(id); return el ? el.value : ''; };
const on = id => { const el = document.getElementById(id); return !!(el && el.checked); };
return {
chunked: on('opt-chunked'),
chunk_size: Math.max(0, parseInt(val('opt-chunk-size'), 10) || 0),
keep_alive: on('opt-keep-alive'),
conn_header: val('opt-conn-header') || 'none',
compact_headers: on('opt-compact'),
next_uri: on('opt-next-uri') ? (val('opt-next-uri-value').trim() || SCP81_OPT_DEFAULTS.nextUri) : '',
link_events: on('opt-link-events'),
script_template: val('opt-script-template') === 'definite' ? 'definite' : 'indefinite',
cr_tag: on('opt-cr-tag'),
targeted_app: val('opt-targeted-app').trim()
};
scp81OptionsSyncDisabled();
scp81OptionsBadge();
}
function scp81OptionsPersist() {
const o = scp81OptionsFromForm();
localStorage.setItem('otaman_scp81_opts', JSON.stringify({
chunked: o.chunked, chunkSize: o.chunk_size, keepAlive: o.keep_alive,
connHeader: o.conn_header, compact: o.compact_headers, nextUri: o.next_uri,
linkEvents: o.link_events, scriptTemplate: o.script_template,
crTag: o.cr_tag, targetedApp: o.targeted_app
}));
localStorage.setItem('otaman_scp81_opts', JSON.stringify(scp81OptionsState()));
scp81OptionsSyncDisabled();
scp81OptionsBadge();
}
function scp81OptionsReset() {
@@ -7869,6 +7918,16 @@ function scp81OptionsReset() {
scp81OptionsLoad();
}
function scp81NextUriToggle() {
scp81OptionsSyncDisabled();
scp81OptionsPersist();
}
function scp81TargetedAppToggle() {
scp81OptionsSyncDisabled();
scp81OptionsPersist();
}
function scp81ModeChanged() {
const mode = document.getElementById('scp81-mode').value;
const row = document.getElementById('scp81-script-row');
@@ -8242,7 +8301,6 @@ async function scp81StatusRefresh() {
s += ' | ' + (l.chunked
? ('chunked' + (l.chunk_size ? ' ' + l.chunk_size : ''))
: 'content-length');
if (l.keep_alive) s += ' | keep-alive';
}
const ch = (bip.channels || []).map(c => 'ch' + c.id + (c.target ? ' → ' + c.target : '') + ' in:' + c.bytes_in + ' out:' + c.bytes_out).join(', ');
if (ch) s += ' | ' + ch;
@@ -8289,7 +8347,6 @@ async function scp81Start() {
if (mode === 'tls') {
body.chunked = opts.chunked;
body.chunk_size = opts.chunk_size;
body.keep_alive = opts.keep_alive;
body.conn_header = opts.conn_header;
body.compact_headers = opts.compact_headers;
body.next_uri = opts.next_uri;
@@ -11579,18 +11636,20 @@ const LANG_RU = {
'Options (applied at Start)': 'Настройки (применяются при запуске)',
'Reset to defaults': 'Сбросить к умолчаниям',
'HTTP framing': 'HTTP-фрейминг',
'Chunked body (Transfer-Encoding: chunked)': 'Chunked-тело (Transfer-Encoding: chunked)',
'Chunked body (Transfer-Encoding: chunked)': 'Chunked body (Transfer-Encoding: chunked)',
'Chunk size (bytes, 0 = one TLS record)': 'Размер чанка (байт, 0 = одна TLS-запись)',
'Keep-alive (one connection until the session ends)': 'Keep-alive (одно соединение до конца сессии)',
'Connection header': 'Заголовок Connection',
'omit (implicit keep-alive)': 'не отправлять (неявный keep-alive)',
"Compact headers (no space after ':')": 'Компактные заголовки (без пробела после «:»)',
'Next-URI (unchecked = omit the header)': 'Next-URI (снято — заголовок не отправляется)',
"Compact headers (omit the optional space after ':')": 'Компактные заголовки (без необязательного пробела после «:»)',
'Send X-Admin-Next-URI (required to continue the session)': 'Отправлять X-Admin-Next-URI (нужен для продолжения сессии)',
'Unchecked = one-shot: per GP Am. B §4.4.2 the card executes the command, returns no response string and closes the session.': 'Снято — одноразовый режим: по GP Am. B §4.4.2 карта выполнит команду, не вернёт строку ответа и закроет сессию.',
'Send X-Admin-Targeted-Application': 'Отправлять X-Admin-Targeted-Application',
'custom': 'изменены',
'Script framing': 'Фрейминг скрипта',
'Indefinite (AE 80 … 00 00)': 'Неопределённая длина (AE 80 … 00 00)',
'Definite (AA)': 'Определённая длина (AA)',
'Comprehension-required tags': 'Теги с обязательным пониманием (CR)',
'Link events (Channel status ENVELOPEs, TS 102 223 7.5.11)': 'События канала (ENVELOPE Channel status, TS 102 223 7.5.11)',
'Comprehension-required tags': 'Теги comprehension-required',
'Show link events (Channel status ENVELOPEs, TS 102 223 7.5.11)': 'Показывать события канала (ENVELOPE Channel status, TS 102 223 7.5.11)',
'ADM verified': 'ADM подтверждён',
'ADM not verified': 'ADM не подтверждён',
'TERMINAL PROFILE': 'TERMINAL PROFILE',