Skip to content

Commit 042a58b

Browse files
authored
Merge pull request DeusData#2188 from DeusData/fix/1856-win10-tls-and-stock-au-ace
fix(install): unblock Windows 10 downloads, and make the activation refusal actionable (DeusData#1856)
2 parents dd454b2 + 7349063 commit 042a58b

6 files changed

Lines changed: 181 additions & 6 deletions

File tree

‎install.ps1‎

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,22 @@
77

88
$ErrorActionPreference = "Stop"
99

10-
# Enforce TLS 1.2+ (older PowerShell defaults to TLS 1.0 which GitHub rejects)
11-
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 -bor [Net.SecurityProtocolType]::Tls13
10+
# Enforce TLS 1.2+ (older PowerShell defaults to TLS 1.0 which GitHub rejects).
11+
#
12+
# TLS 1.3 is added ONLY where schannel can actually negotiate it: Windows 11 and
13+
# Server 2022 (build 20348+). On Windows 10 the enum value still exists from
14+
# .NET Framework 4.8 onward, so the assignment succeeds and nothing warns -- but
15+
# the handshake then fails outright with "The request was aborted: Could not
16+
# create SSL/TLS secure channel". An unsupported protocol flag in this bitmask
17+
# is a hard failure, not a graceful downgrade, so every Windows 10 user was
18+
# blocked at the first download (#1856). The enum-name probe additionally keeps
19+
# the script parsing on .NET Framework 4.7, where Tls13 is not defined at all.
20+
$CbmProtocols = [Net.SecurityProtocolType]::Tls12
21+
if ([Environment]::OSVersion.Version.Build -ge 20348 -and
22+
([enum]::GetNames([Net.SecurityProtocolType]) -contains 'Tls13')) {
23+
$CbmProtocols = $CbmProtocols -bor [Net.SecurityProtocolType]::Tls13
24+
}
25+
[Net.ServicePointManager]::SecurityProtocol = $CbmProtocols
1226
Add-Type -AssemblyName System.Net.Http
1327

1428
$Repo = "DeusData/codebase-memory-mcp"

‎scripts/test.sh‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,9 @@ bash "$ROOT/tests/test_soak_daemon_recovery_contract.sh"
215215
echo "=== Step 0e: Windows launcher bundle contract ==="
216216
bash "$ROOT/tests/test_windows_bundle_contract.sh"
217217

218+
echo "=== Step 0e2: activation refusal diagnostic contract ==="
219+
bash "$ROOT/tests/test_activation_diagnostic_contract.sh"
220+
218221
echo "=== Step 0f: tree-sitter runtime Makefile dependencies ==="
219222
bash "$ROOT/tests/test_makefile_ts_runtime_dependencies.sh"
220223

‎src/cli/activation_transaction.c‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -712,9 +712,17 @@ static bool activation_windows_acl_check(HANDLE handle, DWORD tolerated_untruste
712712
if (!trusted) {
713713
char label[128];
714714
LPSTR sid_text = NULL;
715-
(void)snprintf(label, sizeof(label), "acl-grants-cross-account-mutation to %s",
715+
/* #1856: say whether the grant is INHERITED. The remedy differs and
716+
* the wrong one silently does nothing: `icacls <dir> /remove:g <sid>`
717+
* cannot remove an inherited ACE -- that needs `/inheritance:r` --
718+
* and the stock `C:\` ACE for Authenticated Users reaches every new
719+
* child directory exactly this way. A reporter following the
720+
* generic advice sees the command succeed and the refusal persist. */
721+
bool inherited = (header->AceFlags & INHERITED_ACE) != 0;
722+
(void)snprintf(label, sizeof(label), "acl-grants-cross-account-mutation to %s%s",
716723
ConvertSidToStringSidA(sid, &sid_text) && sid_text ? sid_text
717-
: "unparsable-sid");
724+
: "unparsable-sid",
725+
inherited ? " (inherited from a parent directory)" : "");
718726
if (sid_text) {
719727
(void)LocalFree(sid_text);
720728
}

‎src/cli/cli.c‎

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,9 @@ static void cli_activation_diagnostic(const cbm_cli_activation_ops_t *ops, const
240240
"error: activation was refused by a filesystem safety check before any "
241241
"change was made: %s\n"
242242
"error: this is not a session problem. If the flagged directory is one you "
243-
"trust, remove the flagged permission grant (icacls <dir> /remove:g <sid>) "
243+
"trust, remove the flagged permission grant (icacls <dir> /remove:g <sid>; "
244+
"an INHERITED grant needs icacls <dir> /inheritance:r /grant:r "
245+
"\"%%USERNAME%%\":(OI)(CI)F instead, because /remove:g cannot delete one) "
244246
"or use an owner-private directory for --dir/CBM_CACHE_DIR, then retry.",
245247
note);
246248
diagnostic = attributed;
@@ -747,7 +749,15 @@ static int cli_activation_guard(cbm_daemon_runtime_activation_action_t action,
747749
cli_activation_production_context_t context;
748750
if (!cli_activation_production_context_init(&context, action, target_version, target_build)) {
749751
cli_activation_production_context_close(&context);
750-
cli_activation_production_diagnostic(NULL, CLI_ACTIVATION_REFUSED_MESSAGE);
752+
/* #1856: this refusal used to print the generic text BARE. Every other
753+
* emitter routes through cli_activation_diagnostic, which appends the
754+
* transaction refusal note or cbm_daemon_ipc_validation_detail() and so
755+
* names the check that actually refused. Here the reader got "Check the
756+
* errors above" with nothing above -- exactly the dead end #1537/#1416
757+
* fixed on the other paths and missed on this one. Context init is
758+
* where the cache, rendezvous and log directories are validated, so it
759+
* is the emitter MOST likely to hold a detail worth showing. */
760+
cli_activation_diagnostic(NULL, CLI_ACTIVATION_REFUSED_MESSAGE);
751761
return CLI_TRUE;
752762
}
753763
printf("Stopping active CBM sessions and operations for %s...\n",
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
#!/usr/bin/env bash
2+
# Activation-refusal diagnostics must never point at evidence they do not show.
3+
#
4+
# #1416 and #1537 both landed because a refusal printed generic text and told
5+
# the reader to "check the errors above" when nothing was above. The fix was
6+
# cli_activation_diagnostic(): it appends the transaction refusal note, or
7+
# cbm_daemon_ipc_validation_detail(), so the message names the check that
8+
# actually refused.
9+
#
10+
# #1856 showed the fix was incomplete in the way that matters: the property was
11+
# repaired on the paths that had tests and left broken on a sibling call site
12+
# that had none. cli_activation_production_context_init() -- the emitter that
13+
# validates the cache, rendezvous and log directories, i.e. the one MOST likely
14+
# to hold a useful detail -- printed the constant bare. A reporter with a full
15+
# ProcMon trace still could not tell which check refused, because the binary
16+
# discarded the answer before printing.
17+
#
18+
# So the guard here is the CLASS, not the one call site: every emitter of the
19+
# refusal constants goes through the attributing helper. A future emitter that
20+
# bypasses it fails this test instead of reaching a reporter.
21+
set -euo pipefail
22+
23+
ROOT="$(cd "$(dirname "$0")/.." && pwd)"
24+
25+
python3 - "$ROOT" <<'PY'
26+
from __future__ import annotations
27+
28+
import pathlib
29+
import re
30+
import sys
31+
32+
root = pathlib.Path(sys.argv[1])
33+
failures: list[str] = []
34+
35+
36+
def require(condition: bool, message: str) -> None:
37+
if not condition:
38+
failures.append(message)
39+
40+
41+
cli = (root / "src" / "cli" / "cli.c").read_text(encoding="utf-8")
42+
43+
# 1. Every call that passes a refusal constant to a diagnostic sink must use the
44+
# attributing helper. cli_activation_production_diagnostic is the raw sink --
45+
# legitimate as an ops->visible_diagnostic member (it receives the ALREADY
46+
# attributed string), never as a direct emitter of the constant.
47+
ATTRIBUTING = "cli_activation_diagnostic"
48+
CONSTANTS = ("CLI_ACTIVATION_REFUSED_MESSAGE", "CLI_ACTIVATION_BUSY_MESSAGE")
49+
50+
for call in re.finditer(r"(\w*diagnostic)\s*\(([^;]*?)\)\s*;", cli, re.S):
51+
callee, arguments = call.group(1), call.group(2)
52+
if not any(constant in arguments for constant in CONSTANTS):
53+
continue
54+
if callee == ATTRIBUTING:
55+
continue
56+
line = cli.count("\n", 0, call.start()) + 1
57+
require(
58+
False,
59+
f"src/cli/cli.c:{line}: {callee}() emits a refusal constant directly. "
60+
f"Route it through {ATTRIBUTING}() so the message names the check that "
61+
"refused instead of pointing at errors that were never printed (#1856)",
62+
)
63+
64+
# 2. The helper must still be the one that appends both attribution channels --
65+
# deleting either turns the message back into a dead end.
66+
helper = re.search(
67+
r"static void cli_activation_diagnostic\((?:.|\n)*?\n\}\n", cli
68+
)
69+
require(helper is not None, "cli_activation_diagnostic() not found in src/cli/cli.c")
70+
body = helper.group(0) if helper else ""
71+
require(
72+
"cbm_activation_transaction_refusal_note()" in body,
73+
"cli_activation_diagnostic() must append the transaction refusal note (#1416)",
74+
)
75+
require(
76+
"cbm_daemon_ipc_validation_detail()" in body,
77+
"cli_activation_diagnostic() must append the daemon validation detail (#1537)",
78+
)
79+
80+
# 3. The remedy must be one that works. `icacls /remove:g` silently does nothing
81+
# to an INHERITED ACE -- and the stock C:\ grant for Authenticated Users
82+
# reaches every new child directory exactly that way, which is the shape
83+
# #1856 was reported against. Advice that cannot fix the reported case is
84+
# worse than none: the command succeeds and the refusal persists.
85+
require(
86+
"/inheritance:r" in body,
87+
"the refusal remedy must name icacls /inheritance:r for an inherited grant "
88+
"-- /remove:g cannot remove one, so the advice fails on the stock C:\\ ACE "
89+
"that #1856 reported",
90+
)
91+
92+
# 4. And the refusal itself must say which of the two shapes it hit, or the
93+
# reader cannot choose between those commands.
94+
transaction = (root / "src" / "cli" / "activation_transaction.c").read_text(encoding="utf-8")
95+
require(
96+
re.search(r"AceFlags\s*&\s*INHERITED_ACE", transaction) is not None,
97+
"src/cli/activation_transaction.c must report whether the refusing ACE was "
98+
"inherited, so the printed remedy matches the grant (#1856)",
99+
)
100+
101+
if failures:
102+
print("Activation diagnostic contract FAILED:")
103+
for failure in failures:
104+
print(f" - {failure}")
105+
sys.exit(1)
106+
107+
print("Activation diagnostic contract passed")
108+
PY

‎tests/test_windows_bundle_contract.sh‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,38 @@ require(
242242
"install.ps1 version probes must relax EAP with restore and pre-seed LASTEXITCODE (#1255)",
243243
)
244244
245+
# ── 3c. The TLS bitmask must not name a protocol schannel cannot negotiate ───
246+
# Windows 10's schannel has no TLS 1.3 (it arrives with Windows 11 / Server
247+
# 2022, build 20348). .NET Framework 4.8 still DEFINES SecurityProtocolType
248+
# .Tls13, so setting the bit succeeds silently and nothing warns -- then the
249+
# first HTTPS request dies with "Could not create SSL/TLS secure channel",
250+
# because an unsupported flag in this bitmask is a hard failure rather than a
251+
# downgrade. That blocked the installer on every Windows 10 machine before it
252+
# downloaded a single byte (#1856). Pin both halves of the guard: the build
253+
# gate, and the enum-name probe that keeps the script parsing on 4.7, where
254+
# Tls13 does not exist.
255+
require(
256+
"[Net.SecurityProtocolType]::Tls12 -bor [Net.SecurityProtocolType]::Tls13" not in installer,
257+
"install.ps1 must not set the TLS 1.3 bit unconditionally -- it hard-fails "
258+
"the handshake on Windows 10, whose schannel cannot negotiate it (#1856)",
259+
)
260+
require(
261+
re.search(r"\[Environment\]::OSVersion\.Version\.Build\s+-ge\s+20348", installer) is not None,
262+
"install.ps1 must gate TLS 1.3 on build 20348+ (Windows 11 / Server 2022) (#1856)",
263+
)
264+
require(
265+
re.search(
266+
r"\[enum\]::GetNames\(\[Net\.SecurityProtocolType\]\)\s+-contains\s+'Tls13'", installer
267+
)
268+
is not None,
269+
"install.ps1 must probe the enum before naming Tls13, so it still parses on "
270+
".NET Framework 4.7 where the member is undefined (#1856)",
271+
)
272+
require(
273+
"[Net.ServicePointManager]::SecurityProtocol = $CbmProtocols" in installer,
274+
"install.ps1 must assign the computed protocol set, not a literal bitmask (#1856)",
275+
)
276+
245277
# ── 4. Package-manager shims resolve the single Windows binary ───────────────
246278
single_binary_contracts = {
247279
"pkg/npm/install.js": (

0 commit comments

Comments
 (0)