deadbyte-mcp 0.15.72 → 0.15.75

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (144) hide show
  1. package/MANIFEST.SHA256 +143 -35
  2. package/PROVENANCE.json +47 -21
  3. package/README.txt +29 -18
  4. package/RELEASE.json +85 -18
  5. package/SBOM.cdx.json +14 -2
  6. package/TEST-MATRIX.json +50 -2
  7. package/bin/deadbyte-desktop-uia-r199-fixed.exe +0 -0
  8. package/bin/deadbyte-desktop-uia-r199-fixed.obj +0 -0
  9. package/bin/deadbyte-desktop-uia-r199.exe +0 -0
  10. package/bin/deadbyte-desktop-uia-r199.obj +0 -0
  11. package/bin/deadbyte-fs-read-r197-fixed.exe +0 -0
  12. package/bin/deadbyte-fs-read-r198.exe +0 -0
  13. package/bin/deadbyte-fs-read-r198.obj +0 -0
  14. package/bin/deadbyte-owner-token-r193.exe +0 -0
  15. package/bin/deadbyte-root-relative-probe-r197.exe +0 -0
  16. package/bridge/package.json +1 -1
  17. package/controller/deadbyte-process-policy.json +4 -4
  18. package/docs/R184-package-lock.json +2 -8
  19. package/native/deadbyte-desktop-uia-r199.cpp +345 -0
  20. package/native/deadbyte-fs-read-r197.cpp +174 -0
  21. package/native/deadbyte-fs-read-r198.cpp +181 -0
  22. package/native/deadbyte-owner-token-r193.cpp +156 -0
  23. package/native/deadbyte-root-relative-probe-r197.cpp +97 -0
  24. package/package.json +4 -2
  25. package/scripts/build-native-desktop-uia-r199-fixed.ps1 +28 -0
  26. package/scripts/build-native-desktop-uia-r199.ps1 +28 -0
  27. package/scripts/build-native-fs-read-r197-fixed.ps1 +28 -0
  28. package/scripts/build-native-fs-read-r197.ps1 +28 -0
  29. package/scripts/build-native-fs-read-r198.ps1 +28 -0
  30. package/scripts/build-native-root-probe-r197.ps1 +28 -0
  31. package/scripts/gate-windows-r193.ps1 +108 -0
  32. package/scripts/gate-windows-r194.ps1 +112 -0
  33. package/scripts/gate-windows-r195.ps1 +114 -0
  34. package/scripts/gate-windows-r206.ps1 +116 -0
  35. package/scripts/init-desktop-policy-r199.ps1 +85 -0
  36. package/scripts/npm-interactive-r194.mjs +13 -0
  37. package/scripts/npm-publication-r65.mjs +64 -4
  38. package/scripts/npm-release-r48.mjs +75 -11
  39. package/scripts/npm-release-readiness-r193.mjs +80 -0
  40. package/scripts/npm-release-readiness-r194.mjs +80 -0
  41. package/scripts/npm-release-readiness-r195.mjs +72 -0
  42. package/scripts/npm-release-readiness-r206.mjs +76 -0
  43. package/scripts/r188-owner-uac-review.ps1 +91 -0
  44. package/scripts/r188-uac-review-preview.mjs +65 -0
  45. package/scripts/r193-compile-token.ps1 +22 -0
  46. package/scripts/r193-evidence-relocate.ps1 +12 -0
  47. package/scripts/r193-focused-gate.mjs +20 -0
  48. package/scripts/r193-import-r188-scripts.ps1 +14 -0
  49. package/scripts/r193-limited-subject-probe.ps1 +25 -0
  50. package/scripts/r193-migrate-runtime-limited.ps1 +103 -0
  51. package/scripts/r193-owner-keygen.mjs +43 -0
  52. package/scripts/r193-owner-request-live.mjs +49 -0
  53. package/scripts/r193-owner-uac-approve.ps1 +42 -0
  54. package/scripts/r193-owner-uac-broker.mjs +139 -0
  55. package/scripts/r193-owner-uac-enroll-and-approve.ps1 +62 -0
  56. package/scripts/r193-test-limited-token.ps1 +49 -0
  57. package/scripts/r193-toolchain-inventory.ps1 +7 -0
  58. package/scripts/r193-uac-bridge-focused.mjs +21 -0
  59. package/scripts/r205-candidate-selection.mjs +22 -0
  60. package/src/candidate-selection-evidence-r206.mjs +71 -0
  61. package/src/candidate-selection-r205.mjs +96 -0
  62. package/src/desktop-postcondition-r196.mjs +30 -0
  63. package/src/desktop-runtime-r40.mjs +44 -7
  64. package/src/desktop-uia-identity-r199.mjs +51 -0
  65. package/src/desktop-uia-r40.mjs +9 -1
  66. package/src/machine-fs-handle-read-r196.mjs +43 -0
  67. package/src/machine-fs-native-read-r197.mjs +73 -0
  68. package/src/machine-fs-native-read-r198.mjs +76 -0
  69. package/src/machine-fs-read-worker.mjs +5 -25
  70. package/src/machine-fs.mjs +31 -16
  71. package/src/r188-owner-uac.mjs +105 -0
  72. package/src/r188-uac-boundary.mjs +21 -0
  73. package/src/r193-live-owner-subject.mjs +110 -0
  74. package/src/r193-owner-secret-acl.mjs +67 -0
  75. package/src/r193-owner-uac-broker.mjs +85 -0
  76. package/src/r193-uac-r70-bridge.mjs +54 -0
  77. package/src/r195-canonical-owner-observation.mjs +15 -0
  78. package/src/remote-destination-journal-r202.mjs +120 -0
  79. package/src/remote-device-r44.mjs +89 -14
  80. package/src/remote-payload-boundary-r201.mjs +71 -0
  81. package/src/remote-terminal-evidence-r200.mjs +60 -0
  82. package/src/version.mjs +1 -1
  83. package/test/desktop-runtime-r40.test.mjs +111 -0
  84. package/test/desktop-uia-r40.test.mjs +15 -0
  85. package/test/fixtures/r197-junction-swap-worker.mjs +21 -0
  86. package/test/fixtures/r203-journal-writer.mjs +6 -0
  87. package/test/process-policy-refresh.test.mjs +4 -4
  88. package/test/r130-release-security-contract.test.mjs +8 -8
  89. package/test/r132-release-identity.test.mjs +7 -7
  90. package/test/r153-prepublish-identity.test.mjs +1 -1
  91. package/test/r160-release-contract.test.mjs +3 -3
  92. package/test/r165-live-cli-skew.test.mjs +1 -1
  93. package/test/r167-release-contract.test.mjs +11 -11
  94. package/test/r168-release-contract.test.mjs +4 -4
  95. package/test/r172-release-contract.test.mjs +6 -6
  96. package/test/r173-release-contract.test.mjs +16 -16
  97. package/test/r179-release-contract.test.mjs +12 -12
  98. package/test/r188-owner-uac.test.mjs +48 -0
  99. package/test/r188-uac-boundary.test.mjs +42 -0
  100. package/test/r190-release-contract.test.mjs +10 -10
  101. package/test/r191-release-contract.test.mjs +12 -12
  102. package/test/r192-release-identity.test.mjs +10 -10
  103. package/test/r193-limited-migration-contract.test.mjs +26 -0
  104. package/test/r193-live-owner-subject.test.mjs +61 -0
  105. package/test/r193-native-process-observer.test.mjs +36 -0
  106. package/test/r193-native-token.test.mjs +43 -0
  107. package/test/r193-owner-enrollment-entrypoint.test.mjs +38 -0
  108. package/test/r193-owner-secret-acl.test.mjs +23 -0
  109. package/test/r193-owner-uac-broker.test.mjs +82 -0
  110. package/test/r193-owner-uac-entrypoint.test.mjs +36 -0
  111. package/test/r193-release-identity.test.mjs +58 -0
  112. package/test/r193-release-readiness.test.mjs +87 -0
  113. package/test/r193-uac-r70-bridge.test.mjs +88 -0
  114. package/test/r193-windows-gate.test.mjs +30 -0
  115. package/test/r194-npm-auth-recovery.test.mjs +77 -0
  116. package/test/r194-npm-preauth.test.mjs +57 -0
  117. package/test/r194-release-identity.test.mjs +47 -0
  118. package/test/r194-release-readiness.test.mjs +87 -0
  119. package/test/r194-windows-gate.test.mjs +22 -0
  120. package/test/r195-canonical-owner-observation.test.mjs +32 -0
  121. package/test/r195-release-readiness.test.mjs +22 -0
  122. package/test/r196-desktop-postcondition.test.mjs +53 -0
  123. package/test/r196-handle-bound-read.test.mjs +99 -0
  124. package/test/r196-remote-outcome.test.mjs +94 -0
  125. package/test/r197-namespace-race.test.mjs +41 -0
  126. package/test/r197-native-dispatch-race.test.mjs +49 -0
  127. package/test/r197-native-file-read.test.mjs +60 -0
  128. package/test/r197-native-root-open.test.mjs +61 -0
  129. package/test/r198-root-identity.test.mjs +88 -0
  130. package/test/r199-native-uia-worker.test.mjs +28 -0
  131. package/test/r199-uia-identity.test.mjs +43 -0
  132. package/test/r200-remote-reconcile.test.mjs +106 -0
  133. package/test/r201-payload-boundary.test.mjs +78 -0
  134. package/test/r201-payload-fuzz.test.mjs +37 -0
  135. package/test/r201-tool-boundary-fuzz.test.mjs +120 -0
  136. package/test/r202-destination-journal.test.mjs +92 -0
  137. package/test/r203-atomic-journal.test.mjs +86 -0
  138. package/test/r205-candidate-selection-cli.test.mjs +31 -0
  139. package/test/r205-candidate-selection.test.mjs +83 -0
  140. package/test/r206-candidate-evidence.test.mjs +64 -0
  141. package/test/r206-release-contract.test.mjs +42 -0
  142. package/test/r206-release-readiness.test.mjs +23 -0
  143. package/test/r59-tool-surface-compat.test.mjs +1 -1
  144. package/test/r64-machine-fs-large-read.test.mjs +26 -12
@@ -10,6 +10,8 @@ import { isInside, validatePortableRelativePath } from './path-policy.mjs';
10
10
  import { decodeUtf8Strict } from './text-policy.mjs';
11
11
  import { loadPrivateSigningKey, loadPublicVerifyKey } from './trust.mjs';
12
12
  import { atomicMutation } from './atomic-mutation.mjs';
13
+ import { readRangeFromHandle } from './machine-fs-handle-read-r196.mjs';
14
+ import { boundedNativeReadR198 } from './machine-fs-native-read-r198.mjs';
13
15
 
14
16
  export const MACHINE_FS_RECEIPT_SCHEMA = 'deadbyte.machine-fs-receipt.v1';
15
17
  const RECEIPT_DOMAIN = Buffer.from('DEADBYTE-MACHINE-FS-RECEIPT-V1\0', 'utf8');
@@ -48,14 +50,7 @@ async function boundedReadInProcess({ file, offset, length, hashFile, timeoutMs
48
50
  timer.unref?.();
49
51
  });
50
52
  try {
51
- const operation = (async () => {
52
- const buffer = Buffer.alloc(length);
53
- const result = length ? await handle.read(buffer, 0, length, offset) : { bytesRead: 0 };
54
- let fileSha256 = null;
55
- if (hashFile) fileSha256 = await sha256File(file, abortController.signal);
56
- return { schema: 'deadbyte.machine-fs-read-worker.v1', bytes_read: result.bytesRead,
57
- data_base64: buffer.subarray(0, result.bytesRead).toString('base64'), file_sha256: fileSha256 };
58
- })();
53
+ const operation = readRangeFromHandle(handle, { offset, length, hashFile, signal: abortController.signal });
59
54
  operation.catch(() => {});
60
55
  return await Promise.race([operation, abort]);
61
56
  } finally {
@@ -414,22 +409,42 @@ export function createMachineFsRuntime({ policy, signingKeyPath, verifyKeyPath,
414
409
  if (!Number.isInteger(maxBytes) || maxBytes < 1 || maxBytes > policy.max_read_bytes) throw new Error(`machine fs max_bytes must be in [1, ${policy.max_read_bytes}]`);
415
410
  if (!Number.isInteger(timeoutMs) || timeoutMs < 100 || timeoutMs > 180000) throw new Error('machine fs read timeout_ms must be in [100, 180000]');
416
411
  const grant = await assertCodingReadAllowed(policy, rootId);
412
+ // Capture the root object before path validation. The native worker must
413
+ // compare its opened root HANDLE identity before resolving any child.
414
+ const authorizedRoot = getRoot(policy, rootId, 'read');
415
+ const rootBefore = await lstat(authorizedRoot.real_path, { bigint: true });
416
+ if (rootBefore.isSymbolicLink() || !rootBefore.isDirectory() || rootBefore.ino === 0n)
417
+ throw new Error('R198 root directory identity unavailable');
417
418
  const found = await resolveExisting(policy, grant, rootId, relativePath, 'read', false);
418
- const info = await lstat(found.resolved);
419
+ // Node's numeric ino can round NTFS file IDs above 2^53.
420
+ // Keep the pre-open identity as BigInt and compare exact strings from the worker's fstat.
421
+ const info = await lstat(found.resolved, { bigint: true });
419
422
  if (!info.isFile()) throw new Error('machine fs read target must be a regular file');
420
- if (!Number.isSafeInteger(info.size)) throw new Error('machine fs read file size exceeds safe integer range');
421
- const effectiveOffset = offset < 0 ? Math.max(0, info.size + offset) : offset;
422
- if (effectiveOffset > info.size) throw new Error('machine fs read offset exceeds file size');
423
- const length = Math.min(maxBytes, info.size - effectiveOffset);
423
+ if (info.size > BigInt(Number.MAX_SAFE_INTEGER)) throw new Error('machine fs read file size exceeds safe integer range');
424
+ if (info.ino === 0n) throw new Error('R196 file object identity unavailable');
425
+ const fileSize = Number(info.size);
426
+ const effectiveOffset = offset < 0 ? Math.max(0, fileSize + offset) : offset;
427
+ if (effectiveOffset > fileSize) throw new Error('machine fs read offset exceeds file size');
428
+ const length = Math.min(maxBytes, fileSize - effectiveOffset);
424
429
  await recheckCodingReadAuthority(policy, grant, rootId);
425
- const worker = await boundedReadWorker({ file: found.resolved, offset: effectiveOffset, length, hashFile, timeoutMs, workerPath: readWorkerPath });
430
+ const worker = process.platform === 'win32' && readWorkerPath === machineFsReadWorkerPath
431
+ ? await boundedNativeReadR198({
432
+ rootPath: found.root.real_path, relativePath: found.relative,
433
+ offset: effectiveOffset, length, hashFile, timeoutMs,
434
+ expectedRootDev: String(rootBefore.dev), expectedRootIno: String(rootBefore.ino)
435
+ })
436
+ : await boundedReadWorker({ file: found.resolved, offset: effectiveOffset, length, hashFile, timeoutMs, workerPath: readWorkerPath });
426
437
  const buffer = Buffer.from(worker.data_base64, 'base64');
427
438
  if (buffer.length !== worker.bytes_read || buffer.length > length) throw new Error('machine fs read worker byte count mismatch');
439
+ if (!Number.isSafeInteger(worker.file_size) || worker.file_size !== fileSize)
440
+ throw new Error('R196 opened file size drifted after precheck');
441
+ if (worker.file_dev !== String(info.dev) || worker.file_ino !== String(info.ino))
442
+ throw new Error('R196 opened file object identity differs from precheck');
428
443
  await recheckCodingReadAuthority(policy, grant, rootId);
429
444
  return {
430
445
  status: 'ok', root_id: rootId, path: found.relative,
431
- offset: effectiveOffset, requested_offset: offset, next_offset: effectiveOffset + buffer.length, file_size: info.size,
432
- eof: effectiveOffset + buffer.length >= info.size, data_base64: buffer.toString('base64'),
446
+ offset: effectiveOffset, requested_offset: offset, next_offset: effectiveOffset + buffer.length, file_size: fileSize,
447
+ eof: effectiveOffset + buffer.length >= fileSize, data_base64: buffer.toString('base64'),
433
448
  data_sha256: sha256Bytes(buffer), file_sha256: worker.file_sha256,
434
449
  timeout_ms: timeoutMs
435
450
  };
@@ -0,0 +1,105 @@
1
+ // R188 - no Windows Hello, no PEM owner key, no grant issuance.
2
+ // Unprivileged challenge creation and read-only owner-review validation.
3
+ // Only an independently launched, R89-protected native elevated broker
4
+ // may record an actual approval. Do not turn this into a grant primitive.
5
+ import {createHash,randomBytes} from 'node:crypto';
6
+ import path from 'node:path';
7
+ import {canonicalJson} from './canonical-json.mjs';
8
+ const SHA=/^[a-f0-9]{64}$/;
9
+ const CHALLENGE=/^[A-Za-z0-9_-]{43}$/;
10
+ const ID=/^[A-Za-z0-9._-]{1,64}$/;
11
+ const digest=x=>createHash('sha256').update(Buffer.from(canonicalJson(x),'utf8')).digest('hex');
12
+ function invalid(msg){throw Error('R188 '+msg);}
13
+ function exact(value,fields,label){
14
+ if(!value||typeof value!=='object'||Array.isArray(value)||
15
+ Object.keys(value).length!==fields.length||
16
+ fields.some(f=>!Object.hasOwn(value,f)))invalid(label+' schema mismatch');
17
+ }
18
+ function project(p){
19
+ if(typeof p!=='string'||!path.win32.isAbsolute(p)||p.startsWith('\\\\')||
20
+ path.win32.normalize(p).toLowerCase()===path.win32.parse(p).root.toLowerCase())
21
+ invalid('project root must be a bounded local Windows path');
22
+ return path.win32.normalize(p);
23
+ }
24
+ function fields(o){
25
+ for(const k of ['machineEpoch','releaseManifestSha256','codingPolicySha256','autonomousPolicySha256']){
26
+ if(typeof o?.[k]!=='string'||!SHA.test(o[k]))invalid('invalid '+k);
27
+ }
28
+ if(o.rootId!=='core'||!ID.test(o.rootId))invalid('root scope must be core');
29
+ const root=project(o.projectRoot);
30
+ if(!Number.isSafeInteger(o.maxSeconds)||o.maxSeconds<1||o.maxSeconds>3600)
31
+ invalid('maxSeconds outside owner-reviewed window');
32
+ return root;
33
+ }
34
+ const scopeKeys=['schema','machine_epoch','release_manifest_sha256',
35
+ 'coding_policy_sha256','autonomous_policy_sha256','root_id','project_root',
36
+ 'operation','max_seconds','issued_at_utc','expires_at_utc'];
37
+ const requestKeys=['schema','challenge','subject','request_sha256','review_phrase',
38
+ 'owner_approved','authority_granted','require_interactive_uac'];
39
+ function iso(v){
40
+ if(typeof v!=='string'||!/^\d{4}-\d\d-\d\dT\d\d:\d\d:\d\d\.\d{3}Z$/.test(v)||
41
+ !Number.isFinite(Date.parse(v))||new Date(v).toISOString()!==v)
42
+ invalid('UTC time not canonical');
43
+ return Date.parse(v);
44
+ }
45
+ function hashFor(challenge,subject){return digest({schema:'deadbyte.r188-owner-uac-request.v1',challenge,subject});}
46
+ function phrase(hash){return 'APPROVE-'+hash.slice(0,12).toUpperCase();}
47
+ export function createR188OwnerUacRequest({
48
+ machineEpoch,releaseManifestSha256,codingPolicySha256,autonomousPolicySha256,
49
+ rootId,projectRoot,maxSeconds,now=new Date(),expiresInMs=120000
50
+ }={}){
51
+ const input={machineEpoch,releaseManifestSha256,codingPolicySha256,
52
+ autonomousPolicySha256,rootId,projectRoot,maxSeconds};
53
+ const normalized=fields(input);
54
+ if(!(now instanceof Date)||!Number.isFinite(now.getTime())||
55
+ !Number.isSafeInteger(expiresInMs)||expiresInMs<1000||expiresInMs>300000)
56
+ invalid('request lifetime invalid');
57
+ const subject=Object.freeze({
58
+ schema:'deadbyte.r188-owner-uac-subject.v1',machine_epoch:machineEpoch,
59
+ release_manifest_sha256:releaseManifestSha256,
60
+ coding_policy_sha256:codingPolicySha256,
61
+ autonomous_policy_sha256:autonomousPolicySha256,
62
+ root_id:rootId,project_root:normalized,
63
+ operation:'autonomous_goal_run',max_seconds:maxSeconds,
64
+ issued_at_utc:now.toISOString(),
65
+ expires_at_utc:new Date(now.getTime()+expiresInMs).toISOString()
66
+ });
67
+ const challenge=randomBytes(32).toString('base64url');
68
+ const request_sha256=hashFor(challenge,subject);
69
+ return Object.freeze({schema:'deadbyte.r188-owner-uac-request.v1',
70
+ challenge,subject,request_sha256,review_phrase:phrase(request_sha256),
71
+ owner_approved:false,authority_granted:false,require_interactive_uac:true});
72
+ }
73
+ export function verifyR188OwnerUacRequest({request,expected,now=new Date()}={}){
74
+ exact(request,requestKeys,'request');exact(request.subject,scopeKeys,'subject');
75
+ const subject=request.subject;
76
+ const root=fields(expected);
77
+ if(request.schema!=='deadbyte.r188-owner-uac-request.v1'||
78
+ subject.schema!=='deadbyte.r188-owner-uac-subject.v1'||
79
+ request.owner_approved!==false||request.authority_granted!==false||
80
+ request.require_interactive_uac!==true||
81
+ typeof request.challenge!=='string'||!CHALLENGE.test(request.challenge)||
82
+ Buffer.from(request.challenge,'base64url').length!==32||
83
+ Buffer.from(request.challenge,'base64url').toString('base64url')!==request.challenge)
84
+ invalid('request shape or challenge invalid');
85
+ const expectedBindings={
86
+ machine_epoch:expected.machineEpoch,release_manifest_sha256:expected.releaseManifestSha256,
87
+ coding_policy_sha256:expected.codingPolicySha256,
88
+ autonomous_policy_sha256:expected.autonomousPolicySha256,root_id:expected.rootId,
89
+ project_root:root,operation:'autonomous_goal_run',max_seconds:expected.maxSeconds
90
+ };
91
+ for(const [k,v] of Object.entries(expectedBindings)){
92
+ if(subject[k]!==v)invalid('request scope mismatch: '+k);
93
+ }
94
+ if(!(now instanceof Date)||!Number.isFinite(now.getTime()))invalid('current time invalid');
95
+ const issued=iso(subject.issued_at_utc),expires=iso(subject.expires_at_utc);
96
+ if(expires<=issued||expires-issued>300000||
97
+ now.getTime()<issued||now.getTime()>=expires)invalid('request expired or not yet valid');
98
+ if(typeof request.request_sha256!=='string'||!SHA.test(request.request_sha256)||
99
+ request.request_sha256!==hashFor(request.challenge,subject)||
100
+ request.review_phrase!==phrase(request.request_sha256))
101
+ invalid('request digest or owner phrase altered');
102
+ return Object.freeze({status:'VERIFIED_FOR_REVIEW_ONLY',request_sha256:request.request_sha256,
103
+ review_phrase:request.review_phrase,authority_granted:false,owner_approved:false,
104
+ next_gate:'PROTECTED_INTERACTIVE_UAC_WITH_EXACT_REQUEST_AND_EPOCH'});
105
+ }
@@ -0,0 +1,21 @@
1
+ // R188: pure fail-closed decision gate, NOT proof of a Windows UAC action.
2
+ // A privileged native broker MUST determine these facts independently using
3
+ // token and ACL inspection. Never accept a caller's self-reported booleans.
4
+ export function assessR188UacBoundary(e={}){
5
+ const finish=(reason)=>Object.freeze({schema:'deadbyte.r188-uac-boundary.v1',
6
+ status:'BLOCKED',reason,authority_granted:false,grant_issued:false});
7
+ if(e.codingElevation!=='standard')return finish('CODING_ALREADY_ELEVATED');
8
+ if(e.privilegedParentReachable!==false)return finish('ELEVATED_PARENT_STILL_REACHABLE');
9
+ if(e.ownerElevation!=='elevated')return finish('OWNER_NOT_ELEVATED');
10
+ if(e.protectedBroker!==true)return finish('BROKER_NOT_PROTECTED');
11
+ if(e.enableUac!==true||e.secureDesktop!==true||
12
+ e.promptMode!=='explicit_secure_desktop')
13
+ return finish('UAC_NOT_INTERACTIVE_AND_SECURE');
14
+ if(e.nativeEpochPinned!==true||e.releaseAndPoliciesPinned!==true)
15
+ return finish('AUTHORITY_EPOCH_OR_POLICY_NOT_PINNED');
16
+ if(e.ownerGesture!=='approved')return finish('OWNER_NOT_APPROVED');
17
+ return Object.freeze({schema:'deadbyte.r188-uac-boundary.v1',
18
+ status:'ELIGIBLE_FOR_PROTECTED_OWNER_REVIEW',reason:null,
19
+ authority_granted:false,grant_issued:false,
20
+ next_gate:'SIGNED_EPOCH_ONE_TIME_GRANT_TRANSACTION'});
21
+ }
@@ -0,0 +1,110 @@
1
+ // Build the R193 owner-signing subject from independently observed live state.
2
+ // No caller-supplied digest is trusted until it matches these exact bytes.
3
+ import {createHash} from 'node:crypto';
4
+ import {canonicalJson} from './canonical-json.mjs';
5
+ import {verifyR188OwnerUacRequest} from './r188-owner-uac.mjs';
6
+
7
+ const SHA=/^[a-f0-9]{64}$/;
8
+ const FILETIME=/^[a-f0-9]{16}$/;
9
+ const COMPONENTS=Object.freeze(['bridge','cloud','core','supervisor']);
10
+ const PLANES=Object.freeze(['process','coding','autonomous','desktop','host']);
11
+ const sha=bytes=>createHash('sha256').update(bytes).digest('hex');
12
+ function block(reason){throw new Error('R193 live owner subject blocked: '+reason);}
13
+ function record(value,label){if(!value||typeof value!=='object'||Array.isArray(value))block(label+' invalid');return value;}
14
+ function digest(value,label){if(typeof value!=='string'||!SHA.test(value))block(label+' invalid');return value;}
15
+ function samePath(a,b){return typeof a==='string'&&typeof b==='string'&&
16
+ a.replaceAll('/','\\').toLowerCase()===b.replaceAll('/','\\').toLowerCase();}
17
+ function isoFiletime(value){
18
+ const match=/^(\d{4}-\d\d-\d\dT\d\d:\d\d:\d\d)\.(\d{1,7})Z$/.exec(value??'');
19
+ if(!match)block('process creation UTC invalid');
20
+ const base=Date.parse(match[1]+'.000Z');
21
+ if(!Number.isFinite(base))block('process creation UTC invalid');
22
+ return (BigInt(base+11644473600000)*10000n+
23
+ BigInt(match[2].padEnd(7,'0'))).toString(16).padStart(16,'0');
24
+ }
25
+ function authorityVector(observation){
26
+ const authority=record(observation.authority,'authority observation');
27
+ const out={};
28
+ for(const plane of PLANES){
29
+ const item=record(authority[plane],plane+' authority');
30
+ if(typeof item.configured!=='boolean'||typeof item.armed!=='boolean'||
31
+ typeof item.reason!=='string'||item.reason.length<1||item.reason.length>64)
32
+ block(plane+' authority fields invalid');
33
+ const seq=item.epoch_seq??null,head=item.epoch_sha256??null;
34
+ if((seq!==null&&(!Number.isSafeInteger(seq)||seq<0))||
35
+ (head!==null&&!SHA.test(head)))block(plane+' epoch identity invalid');
36
+ if(item.armed===true&&(seq===null||head===null))block(plane+' armed epoch missing');
37
+ out[plane]={configured:item.configured,armed:item.armed,reason:item.reason,
38
+ epoch_seq:seq,epoch_sha256:head};
39
+ }
40
+ return out;
41
+ }
42
+
43
+ export function createR193LiveMachineEpoch({activePointer,controllerObservation}={}){
44
+ const pointer=record(activePointer,'active pointer');
45
+ const observation=record(controllerObservation,'controller observation');
46
+ for(const field of ['release_id','version','manifest_sha256','generation_manifest_sha256'])
47
+ if(typeof pointer[field]!=='string'||!pointer[field])block('active pointer '+field+' invalid');
48
+ digest(pointer.manifest_sha256,'release manifest SHA-256');
49
+ digest(pointer.generation_manifest_sha256,'generation manifest SHA-256');
50
+ if(observation.schema!=='deadbyte.controller-observation.v1'||
51
+ !samePath(observation.core_root,pointer.release_root))
52
+ block('controller does not match active release');
53
+ return sha(Buffer.from(canonicalJson({
54
+ schema:'deadbyte.r193-live-machine-epoch.v1',
55
+ release_id:pointer.release_id,version:pointer.version,
56
+ manifest_sha256:pointer.manifest_sha256,
57
+ generation_manifest_sha256:pointer.generation_manifest_sha256,
58
+ authority:authorityVector(observation)
59
+ }),'utf8'));
60
+ }
61
+
62
+ export function buildR193LiveOwnerBoundary({request,activePointer,installedManifestBytes,
63
+ codingPolicyBytes,autonomousPolicyBytes,controllerObservation,supervisorLedger,
64
+ processReports,brokerR89Trusted,keyAclTrusted,uac,ownerGesture,now=new Date()}={}){
65
+ if(!Buffer.isBuffer(installedManifestBytes)||installedManifestBytes.length<1)block('manifest bytes missing');
66
+ if(!Buffer.isBuffer(codingPolicyBytes)||codingPolicyBytes.length<1)block('Coding policy bytes missing');
67
+ if(!Buffer.isBuffer(autonomousPolicyBytes)||autonomousPolicyBytes.length<1)block('Autonomous policy bytes missing');
68
+ const pointer=record(activePointer,'active pointer');
69
+ const observation=record(controllerObservation,'controller observation');
70
+ const manifestSha=sha(installedManifestBytes),codingSha=sha(codingPolicyBytes),autonomousSha=sha(autonomousPolicyBytes);
71
+ if(pointer.manifest_sha256!==manifestSha)block('active release manifest drift');
72
+ if(request?.subject?.release_manifest_sha256!==manifestSha||
73
+ request?.subject?.coding_policy_sha256!==codingSha||
74
+ request?.subject?.autonomous_policy_sha256!==autonomousSha)
75
+ block('request release or policy drift');
76
+ const machineEpoch=createR193LiveMachineEpoch({activePointer:pointer,controllerObservation:observation});
77
+ const expected={machineEpoch,releaseManifestSha256:manifestSha,codingPolicySha256:codingSha,
78
+ autonomousPolicySha256:autonomousSha,rootId:request?.subject?.root_id,
79
+ projectRoot:request?.subject?.project_root,maxSeconds:request?.subject?.max_seconds};
80
+ verifyR188OwnerUacRequest({request,expected,now});
81
+ const supervisor=record(supervisorLedger,'supervisor ledger');
82
+ const sources={bridge:observation.bridge,core:observation.core,cloud:observation.cloud,supervisor};
83
+ const reports=record(processReports,'native process reports');
84
+ const agent_processes=[];
85
+ for(const component of COMPONENTS){
86
+ const source=record(sources[component],component+' identity');
87
+ const report=record(reports[component],component+' token report');
88
+ if(source.alive!==true&&component!=='supervisor')block(component+' is not alive');
89
+ if(component==='supervisor'&&observation.supervisor?.running!==true)block('supervisor is not running');
90
+ if(report.schema!=='deadbyte.r193-native-process-token.v1'||report.alive!==true||
91
+ report.identity_verified!==true||report.pid!==source.pid||
92
+ !FILETIME.test(report.creation_filetime_hex)||
93
+ report.creation_filetime_hex!==isoFiletime(source.creation_time_utc))
94
+ block(component+' native process identity mismatch');
95
+ agent_processes.push({component,pid:report.pid,
96
+ creation_time_utc:new Date(Date.parse(source.creation_time_utc)).toISOString(),
97
+ alive:true,identity_verified:true,elevated:report.elevated,
98
+ admin_enabled:report.admin_enabled,integrity_rid:report.integrity_rid,
99
+ token_type:report.token_type});
100
+ }
101
+ const u=record(uac,'UAC policy');
102
+ return Object.freeze({expected:Object.freeze(expected),boundary:Object.freeze({
103
+ schema:'deadbyte.r193-owner-runtime-boundary.v1',
104
+ broker_r89_trusted:brokerR89Trusted===true,key_acl_trusted:keyAclTrusted===true,
105
+ enable_uac:u.enable_uac===true,secure_desktop:u.secure_desktop===true,
106
+ prompt_mode:u.prompt_mode,owner_gesture:ownerGesture,
107
+ live_epoch_verified:true,live_policies_verified:true,live_release_verified:true,
108
+ agent_processes:Object.freeze(agent_processes)
109
+ })});
110
+ }
@@ -0,0 +1,67 @@
1
+ import {execFile} from 'node:child_process';
2
+ import {promisify} from 'node:util';
3
+ import path from 'node:path';
4
+
5
+ const execFileAsync=promisify(execFile);
6
+ const TRUSTED=new Set(['S-1-5-18','S-1-5-32-544',
7
+ 'S-1-5-80-956008885-3418522649-1831038044-1853292631-2271478464']);
8
+ function blocked(reason,pathValue=null){return Object.freeze({trusted:false,reason,path:pathValue});}
9
+ export function evaluateR193OwnerSecretAcl(records,files){
10
+ if(!Array.isArray(files)||files.length!==2||!Array.isArray(records)||records.length!==2)
11
+ return blocked('INCOMPLETE_OWNER_SECRET_ACL');
12
+ const expected=new Set(files.map(file=>path.win32.normalize(file).toLowerCase()));
13
+ const seen=new Set();
14
+ for(const record of records){
15
+ const key=typeof record?.path==='string'?path.win32.normalize(record.path).toLowerCase():'';
16
+ if(!expected.has(key)||seen.has(key))return blocked('OWNER_SECRET_ACL_PATH_MISMATCH',key);
17
+ seen.add(key);
18
+ if(record.reparse!==false||record.protected!==true||!TRUSTED.has(record.owner)||
19
+ typeof record.directory!=='boolean'||!Array.isArray(record.aces))
20
+ return blocked('OWNER_SECRET_ACL_UNTRUSTED',key);
21
+ for(const ace of record.aces){
22
+ if(!ace||!['Allow','Deny'].includes(ace.type)||typeof ace.sid!=='string'||
23
+ typeof ace.inherited!=='boolean'||!Number.isSafeInteger(ace.mask))
24
+ return blocked('OWNER_SECRET_ACL_UNKNOWN_RULE',key);
25
+ if(ace.inherited===true)return blocked('OWNER_SECRET_ACL_INHERITED_RULE',key);
26
+ if(ace.type==='Allow'&&!TRUSTED.has(ace.sid))
27
+ return blocked('OWNER_SECRET_READABLE_BY_AGENT_PRINCIPAL',key);
28
+ }
29
+ }
30
+ return Object.freeze({trusted:true,reason:'OWNER_SECRET_ADMIN_SYSTEM_ONLY'});
31
+ }
32
+
33
+ const probe=String.raw`
34
+ $ErrorActionPreference='Stop';Set-StrictMode -Version Latest
35
+ try{
36
+ $files=ConvertFrom-Json ([Text.Encoding]::UTF8.GetString([Convert]::FromBase64String('__FILES__')))
37
+ $out=@()
38
+ foreach($p in @($files)){
39
+ $item=Get-Item -LiteralPath $p -Force -ErrorAction Stop
40
+ $acl=Get-Acl -LiteralPath $p -ErrorAction Stop
41
+ $rules=@()
42
+ foreach($entry in $acl.GetAccessRules($true,$true,[Security.Principal.SecurityIdentifier])){
43
+ $rules+=@{sid=$entry.IdentityReference.Value;type=$entry.AccessControlType.ToString();
44
+ mask=([int64]$entry.FileSystemRights -band [int64]4294967295);inherited=[bool]$entry.IsInherited}
45
+ }
46
+ $out+=@{path=$item.FullName;owner=$acl.GetOwner([Security.Principal.SecurityIdentifier]).Value;
47
+ reparse=[bool]($item.Attributes -band [IO.FileAttributes]::ReparsePoint);
48
+ protected=[bool]$acl.AreAccessRulesProtected;directory=[bool]$item.PSIsContainer;aces=$rules}
49
+ }
50
+ ConvertTo-Json @($out) -Depth 7 -Compress
51
+ }catch{[Console]::Error.WriteLine('R193_OWNER_SECRET_ACL_PROBE_FAILED');exit 12}
52
+ `;
53
+ export async function inspectR193OwnerSecretAcl(files){
54
+ if(process.platform!=='win32'||process.arch!=='x64')
55
+ throw new Error('R193 owner secret ACL requires Windows x64');
56
+ const ps='C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe';
57
+ const encodedFiles=Buffer.from(JSON.stringify(files),'utf8').toString('base64');
58
+ const encoded=Buffer.from(probe.replace('__FILES__',encodedFiles),'utf16le').toString('base64');
59
+ let stdout;
60
+ try{({stdout}=await execFileAsync(ps,['-NoLogo','-NoProfile','-NonInteractive','-EncodedCommand',encoded],
61
+ {windowsHide:true,timeout:12000,maxBuffer:128*1024,encoding:'utf8'}));}
62
+ catch{throw new Error('R193 owner secret ACL inspection failed closed');}
63
+ let records;try{records=JSON.parse(stdout);}catch{throw new Error('R193 owner secret ACL response invalid');}
64
+ const decision=evaluateR193OwnerSecretAcl(records,files);
65
+ if(!decision.trusted)throw new Error('R193 owner secret ACL untrusted: '+decision.reason);
66
+ return decision;
67
+ }
@@ -0,0 +1,85 @@
1
+ // R193 protected owner decision boundary.
2
+ //
3
+ // This module is deliberately pure. It cannot launch UAC, enroll a key, write
4
+ // an approval, issue a grant, or mutate an epoch. A protected interactive host
5
+ // must independently observe the Windows token/process vector and R89/key ACLs
6
+ // before calling it. The returned R70 approval remains single-use input to the
7
+ // existing R186 transaction; it is not authority by itself.
8
+ import {createPublicKey} from 'node:crypto';
9
+ import {signR193R70ApprovalFromOwnerReview} from './r193-uac-r70-bridge.mjs';
10
+
11
+ const COMPONENTS=Object.freeze(['bridge','cloud','core','supervisor']);
12
+ const BOUNDARY_FIELDS=Object.freeze([
13
+ 'schema','broker_r89_trusted','key_acl_trusted','enable_uac','secure_desktop',
14
+ 'prompt_mode','owner_gesture','live_epoch_verified','live_policies_verified',
15
+ 'live_release_verified','agent_processes'
16
+ ]);
17
+ const PROCESS_FIELDS=Object.freeze([
18
+ 'component','pid','creation_time_utc','alive','identity_verified','elevated',
19
+ 'admin_enabled','integrity_rid','token_type'
20
+ ]);
21
+
22
+ function block(reason){throw new Error(`R193 owner UAC broker blocked: ${reason}`);}
23
+ function exact(value,fields,label){
24
+ if(!value||typeof value!=='object'||Array.isArray(value)||
25
+ Object.keys(value).length!==fields.length||
26
+ fields.some(field=>!Object.hasOwn(value,field)))block(`${label} schema mismatch`);
27
+ }
28
+ function canonicalUtc(value,label){
29
+ if(typeof value!=='string'||
30
+ !/^\d{4}-\d\d-\d\dT\d\d:\d\d:\d\d\.\d{3}Z$/.test(value)||
31
+ !Number.isFinite(Date.parse(value))||new Date(value).toISOString()!==value)
32
+ block(`${label} creation identity invalid`);
33
+ }
34
+ function verifyProcesses(processes){
35
+ if(!Array.isArray(processes)||processes.length!==COMPONENTS.length)
36
+ block('complete agent process vector required');
37
+ const observed=[];
38
+ for(const process of processes){
39
+ exact(process,PROCESS_FIELDS,'agent process');
40
+ if(!COMPONENTS.includes(process.component)||observed.includes(process.component))
41
+ block('agent process component missing or duplicated');
42
+ observed.push(process.component);
43
+ if(!Number.isSafeInteger(process.pid)||process.pid<1||process.pid>0x7fffffff)
44
+ block('agent process PID invalid');
45
+ canonicalUtc(process.creation_time_utc,process.component);
46
+ if(process.alive!==true||process.identity_verified!==true)
47
+ block(`${process.component} process identity unverified`);
48
+ if(process.elevated!==false||process.admin_enabled!==false||
49
+ process.integrity_rid<8192||process.integrity_rid>=12288||
50
+ process.token_type!=='primary')
51
+ block(`${process.component} process is not a verified Limited primary token`);
52
+ }
53
+ if(COMPONENTS.some(component=>!observed.includes(component)))
54
+ block('complete agent process vector required');
55
+ }
56
+
57
+ export function approveR193OwnerRequest({request,expected,privateKeyDer,boundary,now=new Date()}={}){
58
+ exact(boundary,BOUNDARY_FIELDS,'runtime boundary');
59
+ if(boundary.schema!=='deadbyte.r193-owner-runtime-boundary.v1')
60
+ block('runtime boundary schema invalid');
61
+ if(boundary.broker_r89_trusted!==true)block('R89 protected broker not verified');
62
+ if(boundary.key_acl_trusted!==true)block('owner signing key ACL not verified');
63
+ if(boundary.enable_uac!==true||boundary.secure_desktop!==true||
64
+ boundary.prompt_mode!=='explicit_secure_desktop')
65
+ block('secure interactive UAC policy not verified');
66
+ if(boundary.owner_gesture!=='approved')block('owner gesture absent or rejected');
67
+ if(boundary.live_epoch_verified!==true)block('live authority epoch not verified');
68
+ if(boundary.live_policies_verified!==true)block('live policy identities not verified');
69
+ if(boundary.live_release_verified!==true)block('live release identity not verified');
70
+ verifyProcesses(boundary.agent_processes);
71
+ const signed=signR193R70ApprovalFromOwnerReview({request,expected,privateKeyDer,now});
72
+ const publicPem=createPublicKey({key:signed.owner_public_key_spki_der,
73
+ format:'der',type:'spki'}).export({format:'pem',type:'spki'}).toString();
74
+ return Object.freeze({
75
+ status:'OWNER_APPROVED_FOR_SINGLE_USE_GRANT',
76
+ request_sha256:signed.request_sha256,
77
+ owner_key_id:signed.approval.owner_key_id,
78
+ owner_public_key_pem:publicPem,
79
+ approval:signed.approval,
80
+ owner_approved:true,
81
+ authority_granted:false,
82
+ private_key_material_returned:false,
83
+ next_gate:'R186_PROTECTED_SINGLE_USE_GRANT_TRANSACTION'
84
+ });
85
+ }
@@ -0,0 +1,54 @@
1
+ // R193 bridge: translate a short-lived, exact R188 scope review into the
2
+ // already-supported R70 signed approval format. This function is NOT consent,
3
+ // UAC evidence, protected-key enrollment, epoch issuance or a grant. Its caller
4
+ // must be an independently elevated, R89-protected owner broker and must never
5
+ // expose the owner's private DER or the signing operation to an agent process.
6
+ import {createHash,createPrivateKey,createPublicKey,sign} from 'node:crypto';
7
+ import {canonicalJson} from './canonical-json.mjs';
8
+ import {verifyR188OwnerUacRequest} from './r188-owner-uac.mjs';
9
+
10
+ const sha=b=>createHash('sha256').update(b).digest('hex');
11
+ const encode=x=>Buffer.from(canonicalJson(x),'utf8');
12
+ const DOMAIN=Buffer.from('DEADBYTE-R70-PROJECT-OWNER-APPROVAL\0','utf8');
13
+
14
+ export function signR193R70ApprovalFromOwnerReview({
15
+ request,expected,privateKeyDer,now=new Date()
16
+ }={}){
17
+ // The supplied private key is data for an already-trusted protected caller.
18
+ // Never read it from an agent-accessible path inside this module.
19
+ if(!Buffer.isBuffer(privateKeyDer)||privateKeyDer.length<32||privateKeyDer.length>8192)
20
+ throw Error('R193 protected owner signing material missing');
21
+ if(!(now instanceof Date)||!Number.isFinite(now.getTime()))
22
+ throw Error('R193 invalid review time');
23
+ const verified=verifyR188OwnerUacRequest({request,expected,now});
24
+ if(verified.status!=='VERIFIED_FOR_REVIEW_ONLY'||verified.authority_granted!==false)
25
+ throw Error('R193 unexpected owner-review contract');
26
+ let privateKey;
27
+ try{privateKey=createPrivateKey({key:privateKeyDer,format:'der',type:'pkcs8'});}
28
+ catch{throw Error('R193 protected Ed25519 key invalid');}
29
+ if(privateKey.asymmetricKeyType!=='ed25519')
30
+ throw Error('R193 protected signing key must be Ed25519');
31
+ const publicKey=createPublicKey(privateKey);
32
+ const ownerKeyId=sha(publicKey.export({format:'der',type:'spki'}));
33
+ const s=request.subject;
34
+ // Preserve the exact request expiry: signing does not extend authority.
35
+ const subject=Object.freeze({
36
+ schema:'deadbyte.project-authority-subject.r70.v1',
37
+ scope:'coding_autonomous_native_diff',
38
+ root_id:s.root_id,project_root:s.project_root,
39
+ coding_policy_sha256:s.coding_policy_sha256,
40
+ autonomous_policy_sha256:s.autonomous_policy_sha256,
41
+ reviewed_artifact_sha256:s.release_manifest_sha256,
42
+ issued_at_utc:s.issued_at_utc,expires_at_utc:s.expires_at_utc
43
+ });
44
+ const digest=sha(encode(subject));
45
+ const signed=Object.freeze({schema:'deadbyte.project-owner-approval.r70.v1',
46
+ subject_sha256:digest,owner_key_id:ownerKeyId});
47
+ const signature=sign(null,Buffer.concat([DOMAIN,encode(signed)]),privateKey);
48
+ return Object.freeze({
49
+ status:'PROTECTED_SIGNATURE_FORMAT_ONLY',authority_granted:false,owner_approved:false,
50
+ request_sha256:verified.request_sha256,
51
+ owner_public_key_spki_der:publicKey.export({format:'der',type:'spki'}),
52
+ approval:Object.freeze({...signed,subject,signature_base64:signature.toString('base64')})
53
+ });
54
+ }
@@ -0,0 +1,15 @@
1
+ import path from 'node:path';
2
+
3
+ export async function observeCanonicalController({stateRoot,powershell,env,execFileAsync}={}){
4
+ if(typeof stateRoot!=='string'||!path.win32.isAbsolute(stateRoot))
5
+ throw new Error('R195 canonical owner observation requires an absolute state root');
6
+ if(typeof powershell!=='string'||powershell.length<1||typeof execFileAsync!=='function')
7
+ throw new Error('R195 canonical owner observation dependency invalid');
8
+ const launcher=path.win32.join(path.win32.resolve(stateRoot),'bin','DEADBYTE-MCP.ps1');
9
+ const {stdout}=await execFileAsync(powershell,[
10
+ '-NoLogo','-NoProfile','-NonInteractive','-ExecutionPolicy','Bypass','-File',
11
+ launcher,'status','-Json'
12
+ ],{env,windowsHide:true,shell:false,timeout:20000,maxBuffer:1024*1024,encoding:'utf8'});
13
+ try{return JSON.parse(stdout);}
14
+ catch{throw new Error('R195 canonical owner observation returned invalid JSON');}
15
+ }