@remoteshell/device 0.1.0-beta.12 → 0.1.0-beta.17
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.
- package/NOTICE +17 -1
- package/bin/ci-backed-update-approval.mjs +58 -0
- package/bin/dev-agent-client.mjs +1 -1
- package/bin/dev-agent-runner.mjs +28 -4
- package/bin/dev-api-client.mjs +0 -0
- package/bin/dev-auto-worker.mjs +2 -2
- package/bin/dev-browser-open.mjs +0 -0
- package/bin/dev-dogfood-read.mjs +0 -0
- package/bin/dev-heartbeat-service.mjs +0 -0
- package/bin/dev-pairing-client.mjs +0 -0
- package/bin/dev-secrets.mjs +0 -0
- package/bin/dev-setup-recovery.mjs +0 -0
- package/bin/dev-signer-pin.mjs +0 -0
- package/bin/device.mjs +2 -2
- package/bin/direct-npx-runtime.mjs +61 -10
- package/bin/enrollment-client.mjs +0 -0
- package/bin/install-acquire.mjs +0 -0
- package/bin/install-integrity.mjs +0 -0
- package/bin/install-plan.mjs +0 -0
- package/bin/lifecycle.mjs +0 -0
- package/bin/native-path-contract.mjs +0 -0
- package/bin/remoteshell-device-install.sh +0 -0
- package/bin/remoteshell-easy-install.sh +0 -0
- package/bin/remoteshell-npx-entry.ps1 +54 -0
- package/bin/remoteshell-npx-entry.sh +34 -0
- package/bin/safe-update-artifact.mjs +0 -0
- package/bin/safe-update-contract.mjs +3 -1
- package/bin/safe-update-stage.mjs +0 -0
- package/bin/safe-update-transition.mjs +3 -1
- package/bin/windows-acl-wmi-client.mjs +35 -9
- package/bin/windows-credential-boundary.mjs +6 -5
- package/bin/windows-direct-autostart-runner.mjs +26 -8
- package/bin/windows-direct-autostart.mjs +0 -0
- package/bin/windows-install-layout.mjs +0 -0
- package/bin/windows-native-installer.mjs +1 -1
- package/bin/windows-private-store.mjs +10 -10
- package/bin/windows-safe-update-coordinator.mjs +2 -1
- package/bin/windows-safe-update-journal.mjs +0 -0
- package/bin/windows-safe-update-pin.mjs +3 -1
- package/bin/windows-safe-update-stage.mjs +59 -0
- package/bin/windows-user-lifecycle.mjs +0 -0
- package/npm-shrinkwrap.json +407 -27
- package/package.json +5 -2
- package/shared/lib/contracts.mjs +24 -1
- package/shared/lib/dc-tool-catalog.mjs +7 -0
- package/src/config/l2-dev-oci-credential.mjs +1 -1
- package/src/connection/cp-heartbeat-bootstrap.mjs +24 -0
- package/src/connection/dev-cp-heartbeat-worker.mjs +39 -0
- package/src/connection/startup-native-proof.mjs +18 -0
- package/src/core/c1-worker.mjs +3 -3
- package/src/gateway-keepalive.mjs +6 -3
- package/src/main.mjs +60 -12
|
@@ -8,6 +8,19 @@ const root=dirname(fileURLToPath(import.meta.url));
|
|
|
8
8
|
const FAIL=()=>{process.exitCode=1;};
|
|
9
9
|
function validPath(x){return typeof x==='string'&&/^[A-Za-z]:\\/.test(x)&&
|
|
10
10
|
!/[\r\n"'&|<>%]/.test(x)&&!x.split('\\').includes('..');}
|
|
11
|
+
// Only an explicit native Windows ACL scheduling timeout may be retried.
|
|
12
|
+
// A genuine authorization denial, update failure, or unknown exit is terminal.
|
|
13
|
+
export function isTransientStartupFailure({code,stderr}={}){
|
|
14
|
+
return Number.isInteger(code)&&code!==0&&typeof stderr==='string'&&
|
|
15
|
+
/(?:^|\r?\n)DEVICE_WINDOWS_ACL_TIMEOUT(?:\r?\n|$)/.test(stderr);
|
|
16
|
+
}
|
|
17
|
+
export function startupRetryDelay(attempt,random=Math.random){
|
|
18
|
+
if(!Number.isSafeInteger(attempt)||attempt<1||typeof random!=='function')
|
|
19
|
+
throw Error('DEVICE_STARTUP_RETRY_INVALID');
|
|
20
|
+
const jitter=Number(random());
|
|
21
|
+
if(!Number.isFinite(jitter)||jitter<0||jitter>=1)throw Error('DEVICE_STARTUP_RETRY_INVALID');
|
|
22
|
+
return Math.min(60000,10000*2**Math.min(attempt-1,3))+Math.floor(jitter*1000);
|
|
23
|
+
}
|
|
11
24
|
// S3: a crash during activation must never boot an unverified candidate.
|
|
12
25
|
// This self-contained guard is copied with the persistent runner on new installs.
|
|
13
26
|
export function resolveStartupVersion(config,journal){
|
|
@@ -61,20 +74,25 @@ if(config){
|
|
|
61
74
|
const child=spawn(config.node,args,{shell:false,windowsHide:true,
|
|
62
75
|
stdio:['ignore','ignore','pipe'],env});
|
|
63
76
|
let errors='',settled=false;
|
|
64
|
-
child.stderr?.on('data',chunk=>{
|
|
65
|
-
const finish=code=>{if(!settled){settled=true;resolve({code,cacheMiss:/ENOTCACHED/i.test(errors)})}};
|
|
77
|
+
child.stderr?.on('data',chunk=>{errors=(errors+String(chunk)).slice(-2048);});
|
|
78
|
+
const finish=code=>{if(!settled){settled=true;resolve({code,cacheMiss:/ENOTCACHED/i.test(errors),transientAcl:isTransientStartupFailure({code,stderr:errors})})}};
|
|
66
79
|
child.once('error',()=>finish(1));
|
|
67
80
|
child.once('exit',code=>finish(code??1));
|
|
68
81
|
});
|
|
69
82
|
try{
|
|
70
83
|
// No network for normal logons. Only an explicit cache miss may fetch
|
|
71
84
|
// the exact same immutable version; never substitute @beta or @latest.
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
85
|
+
// The same pinned immutable version is retried after temporary native ACL
|
|
86
|
+
// timeouts. No re-enrollment, credential change or immediate restart loop.
|
|
87
|
+
for(let retries=0;;){
|
|
88
|
+
const first=await execute(true);
|
|
89
|
+
const result=first.code!==0&&first.cacheMiss?await execute(false):first;
|
|
90
|
+
if(result.code===0)break;
|
|
91
|
+
if(!result.transientAcl){FAIL();break;}
|
|
92
|
+
retries=Math.min(retries+1,8);
|
|
93
|
+
const delay=startupRetryDelay(retries);
|
|
94
|
+
console.warn('RS_STARTUP_RETRY',JSON.stringify({reason:'native_acl_timeout',delay_ms:delay}));
|
|
95
|
+
await new Promise(resolve=>setTimeout(resolve,delay));
|
|
78
96
|
}
|
|
79
97
|
}catch{FAIL();}
|
|
80
98
|
}
|
|
File without changes
|
|
File without changes
|
|
@@ -23,7 +23,7 @@ function receipt(install,expected){
|
|
|
23
23
|
const data=JSON.parse(readFileSync(file,'utf8'));
|
|
24
24
|
if(data?.schema!==1||data.version!==expected||data.distribution!=='synthetic-private'||
|
|
25
25
|
data.registered!==false||data.serviceEnabled!==false)fail();
|
|
26
|
-
for(const [name,version] of [['@remoteshell/device',expected],['@wonderwhy-er/desktop-commander','0.3.
|
|
26
|
+
for(const [name,version] of [['@remoteshell/device',expected],['@wonderwhy-er/desktop-commander','0.3.4']]){
|
|
27
27
|
const p=win32.join(install,'node_modules',...name.split('/'),'package.json');
|
|
28
28
|
const s=lstatSync(p);
|
|
29
29
|
if(!s.isFile()||s.isSymbolicLink()||JSON.parse(readFileSync(p,'utf8')).version!==version)fail();
|
|
@@ -93,33 +93,33 @@ export function ensureWindowsPrivateStore(store,{home=homedir(),run=spawnSync}={
|
|
|
93
93
|
checkStore(store,{home});
|
|
94
94
|
inspectWindowsPrivateDirectoryAcl({directory:store,home});
|
|
95
95
|
return Object.freeze({ready:true,created:!existed,aclVerified:true});
|
|
96
|
-
}catch{deny();}
|
|
96
|
+
}catch(error){if(error?.message==='DEVICE_WINDOWS_ACL_TIMEOUT')throw error;deny();}
|
|
97
97
|
}
|
|
98
|
-
function verifyFile(file,{home=homedir()}={}){
|
|
98
|
+
function verifyFile(file,{home=homedir(),maxFileSize=8192}={}){
|
|
99
99
|
const store=win32.dirname(file);
|
|
100
100
|
checkStore(store,{home});
|
|
101
101
|
// The native file snapshot also checks its protected parent directory.
|
|
102
102
|
// Avoid a duplicate PowerShell invocation in every credential operation.
|
|
103
|
-
inspectWindowsCredentialAcl({file,home});
|
|
103
|
+
inspectWindowsCredentialAcl({file,home,maxFileSize});
|
|
104
104
|
}
|
|
105
105
|
// Seal a newly created exclusive lock using the same owner/SYSTEM ACL proof
|
|
106
106
|
// as credentials. Used by #327 S2 for Windows logoff/reboot recovery.
|
|
107
|
-
export function sealWindowsPrivateFile(file,{home=homedir()}={}){
|
|
107
|
+
export function sealWindowsPrivateFile(file,{home=homedir(),maxFileSize=8192}={}){
|
|
108
108
|
try{
|
|
109
109
|
const store=win32.dirname(file);
|
|
110
110
|
checkStore(store,{home});
|
|
111
111
|
const stat=lstatSync(file);
|
|
112
112
|
if(!stat.isFile()||stat.isSymbolicLink()||stat.nlink!==1)deny();
|
|
113
113
|
sealAcl(file);
|
|
114
|
-
verifyFile(file,{home});
|
|
114
|
+
verifyFile(file,{home,maxFileSize});
|
|
115
115
|
return true;
|
|
116
|
-
}catch{deny();}
|
|
116
|
+
}catch(error){if(error?.message==='DEVICE_WINDOWS_ACL_TIMEOUT')throw error;deny();}
|
|
117
117
|
}
|
|
118
118
|
export function readWindowsPrivate(file,{home=homedir()}={}){
|
|
119
119
|
try{
|
|
120
120
|
verifyFile(file,{home});
|
|
121
121
|
return readFileSync(file,'utf8');
|
|
122
|
-
}catch{deny();}
|
|
122
|
+
}catch(error){if(error?.message==='DEVICE_WINDOWS_ACL_TIMEOUT')throw error;deny();}
|
|
123
123
|
}
|
|
124
124
|
// A one-use update capability keeps the old credential ACL verification and
|
|
125
125
|
// the new credential ACL verification, without re-launching PowerShell twice
|
|
@@ -141,9 +141,9 @@ export function readWindowsPrivateForUpdate(file,{home=homedir()}={}){
|
|
|
141
141
|
current.ctimeMs!==stat.ctimeMs||readFileSync(file,'utf8')!==initial)deny();
|
|
142
142
|
return atomicWindowsPrivate(file,value,{replace:true,home,
|
|
143
143
|
[verifiedUpdate]:true});
|
|
144
|
-
}catch{deny();}
|
|
144
|
+
}catch(error){if(error?.message==='DEVICE_WINDOWS_ACL_TIMEOUT')throw error;deny();}
|
|
145
145
|
}});
|
|
146
|
-
}catch{deny();}
|
|
146
|
+
}catch(error){if(error?.message==='DEVICE_WINDOWS_ACL_TIMEOUT')throw error;deny();}
|
|
147
147
|
}
|
|
148
148
|
export function atomicWindowsPrivate(file,value,{replace=false,home=homedir(),run=spawnSync,...proof}={}){
|
|
149
149
|
let temp;
|
|
@@ -171,6 +171,6 @@ export function atomicWindowsPrivate(file,value,{replace=false,home=homedir(),ru
|
|
|
171
171
|
sealAcl(file,{run});
|
|
172
172
|
verifyFile(file,{home});
|
|
173
173
|
return Object.freeze({written:true,aclVerified:true});
|
|
174
|
-
}catch{deny();
|
|
174
|
+
}catch(error){if(error?.message==='DEVICE_WINDOWS_ACL_TIMEOUT')throw error;deny();
|
|
175
175
|
}finally{if(temp&&existsSync(temp))rmSync(temp,{force:true});}
|
|
176
176
|
}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
// The caller supplies verified health/identity checks and guarantees quiescence.
|
|
3
3
|
// Production activation remains disabled until the trusted runner is integrated.
|
|
4
4
|
import {advanceTransition,recoverTransition} from './safe-update-transition.mjs';
|
|
5
|
+
import {isAuthenticatedCiApproval} from './ci-backed-update-approval.mjs';
|
|
5
6
|
const DENY=()=>{throw Error('DEVICE_SAFE_UPDATE_COORDINATOR_DENIED');};
|
|
6
7
|
function matches(j,identity){
|
|
7
8
|
if(!j||!identity||j.deviceId!==identity.deviceId||
|
|
@@ -12,7 +13,7 @@ export async function activateWindowsCandidate({readJournal,persistJournal,chang
|
|
|
12
13
|
verifyHealth,identity,approved,candidateVerified,quiescent}={}){
|
|
13
14
|
requireFunctions([readJournal,persistJournal,changePin,verifyHealth]);
|
|
14
15
|
if(quiescent!==true||candidateVerified!==true||
|
|
15
|
-
approved?.proof!=='ed25519-approved-release-intent')DENY();
|
|
16
|
+
(approved?.proof!=='ed25519-approved-release-intent'&& !isAuthenticatedCiApproval(approved)))DENY();
|
|
16
17
|
let j=await readJournal();
|
|
17
18
|
matches(j,identity);
|
|
18
19
|
if(j.phase!=='staged'||j.candidate!==approved.version||
|
|
File without changes
|
|
@@ -5,6 +5,7 @@ import {directPaths} from './direct-npx-runtime.mjs';
|
|
|
5
5
|
import {canonicalWindowsLocalFile,isWindowsChildPath} from './native-path-contract.mjs';
|
|
6
6
|
import {readWindowsPrivateForUpdate} from './windows-private-store.mjs';
|
|
7
7
|
import {readUpdateJournal} from './windows-safe-update-journal.mjs';
|
|
8
|
+
import {isAuthenticatedCiApproval} from './ci-backed-update-approval.mjs';
|
|
8
9
|
const DENY=()=>{throw Error('DEVICE_SAFE_UPDATE_PIN_DENIED');};
|
|
9
10
|
const VERSION=/^0\.1\.0-beta\.[1-9]\d{0,5}$/;
|
|
10
11
|
const DEVICE=/^[a-f0-9-]{36}$/;
|
|
@@ -35,7 +36,8 @@ export function planWindowsPinChange(j,config,{
|
|
|
35
36
|
let next;
|
|
36
37
|
if(action==='activate'){
|
|
37
38
|
if(j.phase!=='activation-pending'||candidateVerified!==true||
|
|
38
|
-
approved?.proof!=='ed25519-approved-release-intent'
|
|
39
|
+
(approved?.proof!=='ed25519-approved-release-intent'&& !isAuthenticatedCiApproval(approved))||
|
|
40
|
+
approved.version!==j.candidate||
|
|
39
41
|
approved.previousVersion!==j.previous||current.version!==j.previous)DENY();
|
|
40
42
|
next=j.candidate;
|
|
41
43
|
}else if(action==='restore'){
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
// #327 S3: Windows per-user private staging of a CI- or signature-verified npm tarball.
|
|
2
|
+
// Never extracts, executes, installs, changes HKCU, or modifies credentials.
|
|
3
|
+
import {randomBytes,createHash,timingSafeEqual} from 'node:crypto';
|
|
4
|
+
import {homedir,platform} from 'node:os';
|
|
5
|
+
import {win32} from 'node:path';
|
|
6
|
+
import {openSync,writeSync,fsyncSync,closeSync,linkSync,unlinkSync,lstatSync,readFileSync,existsSync} from 'node:fs';
|
|
7
|
+
import {directPaths} from './direct-npx-runtime.mjs';
|
|
8
|
+
import {canonicalWindowsLocalFile,isWindowsChildPath} from './native-path-contract.mjs';
|
|
9
|
+
import {verifyTarballBytes} from './safe-update-artifact.mjs';
|
|
10
|
+
import {ensureWindowsPrivateStore,sealWindowsPrivateFile} from './windows-private-store.mjs';
|
|
11
|
+
import {inspectWindowsCredentialAcl} from './windows-credential-boundary.mjs';
|
|
12
|
+
const DENY=()=>{throw Error('DEVICE_WINDOWS_UPDATE_STAGE_DENIED');};
|
|
13
|
+
const VERSION=/^0\.1\.0-beta\.[1-9]\d{0,5}$/;
|
|
14
|
+
function same(bytes,wanted){
|
|
15
|
+
const actual=createHash('sha512').update(bytes).digest();
|
|
16
|
+
const expected=Buffer.from(wanted.slice(7),'base64');
|
|
17
|
+
return expected.length===64&&timingSafeEqual(actual,expected);
|
|
18
|
+
}
|
|
19
|
+
export function stageWindowsVerifiedTarball(approved,metadata,bytes,{
|
|
20
|
+
home=homedir(),localAppData=process.env.LOCALAPPDATA,os=platform(),
|
|
21
|
+
ensure=ensureWindowsPrivateStore,seal=sealWindowsPrivateFile,
|
|
22
|
+
inspect=inspectWindowsCredentialAcl
|
|
23
|
+
}={}){
|
|
24
|
+
let temp=null,fd;
|
|
25
|
+
try{
|
|
26
|
+
if(os!=='win32'||!VERSION.test(approved?.version||''))DENY();
|
|
27
|
+
verifyTarballBytes(approved,metadata,bytes);
|
|
28
|
+
const dir=directPaths({home,localAppData,os}).storageDir;
|
|
29
|
+
const dest=win32.join(dir,'direct-update-'+approved.version+'.tgz');
|
|
30
|
+
for(const p of [dest]){canonicalWindowsLocalFile(p);isWindowsChildPath(p,dir);}
|
|
31
|
+
ensure(dir,{home});
|
|
32
|
+
temp=win32.join(dir,'direct-update-'+randomBytes(16).toString('hex')+'.tmp');
|
|
33
|
+
canonicalWindowsLocalFile(temp);isWindowsChildPath(temp,dir);
|
|
34
|
+
fd=openSync(temp,'wx',0o600);
|
|
35
|
+
let offset=0;
|
|
36
|
+
while(offset<bytes.length){
|
|
37
|
+
const n=writeSync(fd,bytes,offset,bytes.length-offset);
|
|
38
|
+
if(n<=0)DENY();
|
|
39
|
+
offset+=n;
|
|
40
|
+
}
|
|
41
|
+
fsyncSync(fd);closeSync(fd);fd=undefined;
|
|
42
|
+
seal(temp,{home,maxFileSize:32*1024*1024});
|
|
43
|
+
try{linkSync(temp,dest)}catch(e){
|
|
44
|
+
if(e.code!=='EEXIST')DENY();
|
|
45
|
+
}
|
|
46
|
+
// Removing the temporary link must leave exactly one private immutable candidate.
|
|
47
|
+
unlinkSync(temp);temp=null;
|
|
48
|
+
inspect({file:dest,home,maxFileSize:32*1024*1024});
|
|
49
|
+
const st=lstatSync(dest);
|
|
50
|
+
if(!st.isFile()||st.isSymbolicLink()||st.nlink!==1||
|
|
51
|
+
st.size!==bytes.length||!same(readFileSync(dest),approved.sha512))DENY();
|
|
52
|
+
return Object.freeze({path:dest,version:approved.version,verified:true,
|
|
53
|
+
activated:false,sha512:approved.sha512,bytes:st.size});
|
|
54
|
+
}catch{DENY()}
|
|
55
|
+
finally{
|
|
56
|
+
if(fd!==undefined)try{closeSync(fd)}catch{}
|
|
57
|
+
if(temp&&existsSync(temp))try{unlinkSync(temp)}catch{}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
File without changes
|