@remoteshell/device 0.0.0-stage → 0.1.0-beta.10
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/LICENSE +26 -0
- package/NOTICE +20 -0
- package/bin/dev-agent-client.mjs +228 -0
- package/bin/dev-agent-runner.mjs +60 -0
- package/bin/dev-api-client.mjs +31 -0
- package/bin/dev-auto-worker.mjs +25 -0
- package/bin/dev-browser-open.mjs +12 -0
- package/bin/dev-dogfood-read.mjs +3 -0
- package/bin/dev-heartbeat-service.mjs +77 -0
- package/bin/dev-pairing-client.mjs +63 -0
- package/bin/dev-secrets.mjs +33 -0
- package/bin/dev-setup-recovery.mjs +34 -0
- package/bin/dev-signer-pin.mjs +22 -0
- package/bin/device.mjs +384 -0
- package/bin/direct-npx-runtime.mjs +150 -0
- package/bin/enrollment-client.mjs +105 -0
- package/bin/install-acquire.mjs +89 -0
- package/bin/install-integrity.mjs +74 -0
- package/bin/install-plan.mjs +43 -0
- package/bin/lifecycle.mjs +172 -0
- package/bin/native-path-contract.mjs +23 -0
- package/bin/remoteshell-device-install.cmd +17 -0
- package/bin/remoteshell-device-install.ps1 +17 -0
- package/bin/remoteshell-device-install.sh +15 -0
- package/bin/remoteshell-device-preflight.cmd +10 -0
- package/bin/remoteshell-device-preflight.ps1 +10 -0
- package/bin/remoteshell-easy-diagnose.ps1 +32 -0
- package/bin/remoteshell-easy-install.ps1 +292 -0
- package/bin/remoteshell-easy-install.sh +71 -0
- package/bin/remoteshell-easy-uninstall.ps1 +128 -0
- package/bin/windows-acl-wmi-client.mjs +50 -0
- package/bin/windows-acl-wmi.js +43 -0
- package/bin/windows-credential-boundary.mjs +113 -0
- package/bin/windows-direct-autostart-runner.mjs +50 -0
- package/bin/windows-direct-autostart.mjs +110 -0
- package/bin/windows-install-layout.mjs +28 -0
- package/bin/windows-native-installer.mjs +91 -0
- package/bin/windows-private-store.mjs +176 -0
- package/bin/windows-user-lifecycle.mjs +34 -0
- package/npm-shrinkwrap.json +8591 -0
- package/package.json +27 -4
- package/shared/lib/bounded-search-contract.mjs +5 -0
- package/shared/lib/bounded-search-policy.mjs +24 -0
- package/shared/lib/config.mjs +14 -0
- package/shared/lib/contracts.mjs +26 -0
- package/shared/lib/dc-generic-policy.mjs +102 -0
- package/shared/lib/dc-relay-contract.mjs +42 -0
- package/shared/lib/dc-tool-catalog.mjs +67 -0
- package/shared/lib/dev-dc-relay-contract.mjs +20 -0
- package/shared/lib/dev-paged-output.mjs +32 -0
- package/shared/lib/dev-root-exclusions.mjs +56 -0
- package/shared/lib/errors.mjs +9 -0
- package/shared/lib/events.mjs +5 -0
- package/shared/lib/execution-policy.mjs +41 -0
- package/shared/lib/isolated-read-boundary.mjs +50 -0
- package/shared/lib/isolated-read-policy.mjs +29 -0
- package/shared/lib/lifecycle-events.mjs +13 -0
- package/shared/lib/runtime-timing.mjs +9 -0
- package/shared/lib/synthetic-auxiliary-policy.mjs +21 -0
- package/shared/lib/synthetic-write-policy.mjs +52 -0
- package/shared/lib/tool-registry.mjs +58 -0
- package/src/config/l2-dev-oci-credential.mjs +39 -0
- package/src/config/p2-private-credential.mjs +15 -0
- package/src/connection/dev-dogfood-processes.mjs +25 -0
- package/src/connection/dev-dogfood-read.mjs +64 -0
- package/src/connection/dev-dogfood-task.mjs +113 -0
- package/src/connection/dev-dogfood-write.mjs +62 -0
- package/src/connection/dev-file-task.mjs +119 -0
- package/src/connection/dev-r4-file-task.mjs +56 -0
- package/src/connection/dev-read-tools.mjs +134 -0
- package/src/connection/dev-root-scopes.mjs +82 -0
- package/src/core/c1-dc-transport.mjs +26 -0
- package/src/core/c1-startup.mjs +22 -0
- package/src/core/c1-supervisor.mjs +111 -0
- package/src/core/c1-worker.mjs +88 -0
- package/src/core/fixture.txt +2 -0
- package/src/dc/dc-access-readiness.mjs +31 -0
- package/src/dc/dev-dc-relay.mjs +47 -0
- package/src/device-agent/main.mjs +1 -0
- package/src/gateway-keepalive.mjs +73 -0
- package/src/main.mjs +436 -0
- package/src/policy/bounded-search-adapter.mjs +115 -0
- package/src/policy/isolated-read-adapter.mjs +50 -0
- package/src/policy/isolated-read-mount.mjs +27 -0
- package/src/policy/synthetic-auxiliary-adapter.mjs +75 -0
- package/src/policy/synthetic-file-adapter.mjs +26 -0
- package/src/policy/synthetic-file-transaction.mjs +87 -0
- package/src/policy/synthetic-write-adapter.mjs +151 -0
- package/src/policy/synthetic-write-mount.mjs +23 -0
- package/src/policy/verified-bounded-search.mjs +12 -0
- package/src/policy/verified-isolated-read.mjs +15 -0
- package/src/policy/verified-synthetic-write.mjs +14 -0
- package/README.md +0 -3
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
// Device-side enrollment CONSUMER. Local synthetic fixture only until #123
|
|
2
|
+
// specifies/ships an authenticated Agent-credential envelope API.
|
|
3
|
+
// Does not implement a Control Plane, owner approval, a database, or a token issuer.
|
|
4
|
+
import {generateKeyPairSync,sign,verify,createHash,randomBytes,createPublicKey,createPrivateKey} from 'node:crypto';
|
|
5
|
+
import {existsSync,lstatSync,mkdirSync,writeFileSync,readFileSync,renameSync,rmSync} from 'node:fs';
|
|
6
|
+
import {join} from 'node:path';
|
|
7
|
+
const FAIL='DEVICE_ENROLLMENT_DENIED';
|
|
8
|
+
const deny=()=>{throw Error(FAIL);};
|
|
9
|
+
const b64=b=>Buffer.from(b).toString('base64url');
|
|
10
|
+
const sha=b=>createHash('sha256').update(b).digest('hex');
|
|
11
|
+
const validId=id=>typeof id==='string'&&/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(id);
|
|
12
|
+
const canonical=data=>JSON.stringify(data);
|
|
13
|
+
const own=(path,mode)=>{
|
|
14
|
+
const s=lstatSync(path);
|
|
15
|
+
if(!s.isFile()||s.isSymbolicLink()||s.uid!==process.getuid?.()||(s.mode&0o777)!==mode)deny();
|
|
16
|
+
};
|
|
17
|
+
function privateDir(path){
|
|
18
|
+
if(!existsSync(path))mkdirSync(path,{mode:0o700});
|
|
19
|
+
const s=lstatSync(path);
|
|
20
|
+
if(!s.isDirectory()||s.isSymbolicLink()||s.uid!==process.getuid?.()||(s.mode&0o777)!==0o700)deny();
|
|
21
|
+
}
|
|
22
|
+
function atomicFile(path,data){
|
|
23
|
+
if(existsSync(path))deny();
|
|
24
|
+
const temp=path+'.tmp-'+b64(randomBytes(12));
|
|
25
|
+
try{writeFileSync(temp,data,{mode:0o600,flag:'wx'});renameSync(temp,path);}finally{rmSync(temp,{force:true});}
|
|
26
|
+
}
|
|
27
|
+
export function prepareDeviceProof({enrollmentId,challenge,consumer='remoteshell-device.v0.1',keypair}={}){
|
|
28
|
+
// PROPOSED v0.1 proof: canonical JSON + Ed25519. Real wire contract is unapproved.
|
|
29
|
+
if(!validId(enrollmentId)||typeof challenge!=='string'||challenge.length<24||challenge.length>2048||
|
|
30
|
+
consumer!=='remoteshell-device.v0.1')deny();
|
|
31
|
+
const keys=keypair||generateKeyPairSync('ed25519');
|
|
32
|
+
const publicKey=keys.publicKey.export({type:'spki',format:'der'});
|
|
33
|
+
const nonce=b64(randomBytes(32));
|
|
34
|
+
const payload={v:'rs-device-proof-mock-v0.1',enrollment_id:enrollmentId,challenge_hash:sha(challenge),consumer,public_key:b64(publicKey),nonce};
|
|
35
|
+
const message=canonical(payload);
|
|
36
|
+
const signature=b64(sign(null,Buffer.from(message),keys.privateKey));
|
|
37
|
+
return {payload,signature,privateKey:keys.privateKey,publicKey:keys.publicKey};
|
|
38
|
+
}
|
|
39
|
+
export function verifyPreparedProof(proof){
|
|
40
|
+
if(proof?.payload?.v!=='rs-device-proof-mock-v0.1'||typeof proof.signature!=='string')deny();
|
|
41
|
+
const publicKey=createPublicKey({key:Buffer.from(proof.payload.public_key,'base64url'),type:'spki',format:'der'});
|
|
42
|
+
if(!verify(null,Buffer.from(canonical(proof.payload)),publicKey,Buffer.from(proof.signature,'base64url')))deny();
|
|
43
|
+
return true;
|
|
44
|
+
}
|
|
45
|
+
export function acceptMockCredential({proof,response,fixtureIssuerPublicKey,storageDir,now=Date.now()}={}){
|
|
46
|
+
// Fail closed: a raw/unverified credential or real CP v4 metadata response is
|
|
47
|
+
// never accepted. This fixture format is NOT the supplier API contract.
|
|
48
|
+
if(!proof?.privateKey||!fixtureIssuerPublicKey||!response||response.format!=='rs-device-credential-mock-v0.1')deny();
|
|
49
|
+
try{
|
|
50
|
+
const actualKey=b64(createPublicKey(proof.privateKey).export({type:'spki',format:'der'}));
|
|
51
|
+
if(actualKey!==proof.payload?.public_key||!verifyPreparedProof(proof))deny();
|
|
52
|
+
}catch{deny();}
|
|
53
|
+
if(!validId(response.device_id)||typeof response.credential!=='string'||response.credential.length<32||
|
|
54
|
+
response.credential.length>512||response.approved!==true||
|
|
55
|
+
response.public_key!==proof.payload.public_key||response.enrollment_id!==proof.payload.enrollment_id||
|
|
56
|
+
!Number.isSafeInteger(response.expires_at)||response.expires_at<=now||
|
|
57
|
+
typeof response.signature!=='string')deny();
|
|
58
|
+
const {signature,...body}=response;
|
|
59
|
+
if(!verify(null,Buffer.from(canonical(body)),fixtureIssuerPublicKey,Buffer.from(signature,'base64url')))deny();
|
|
60
|
+
// This path is a disposable synthetic credential store. Never place the
|
|
61
|
+
// credential in stdout, command arguments, web session, npm package, or logs.
|
|
62
|
+
privateDir(storageDir);
|
|
63
|
+
const file=join(storageDir,'device.json');
|
|
64
|
+
atomicFile(file,JSON.stringify({device_id:response.device_id,credential:response.credential})+'\n');
|
|
65
|
+
own(file,0o600);
|
|
66
|
+
return {saved:true,device_id:response.device_id,credentialReturned:false,provider:'mock'};
|
|
67
|
+
}
|
|
68
|
+
export function readDeviceCredential({storageDir}={}){
|
|
69
|
+
const stat=lstatSync(storageDir);
|
|
70
|
+
if(!stat.isDirectory()||stat.isSymbolicLink()||(stat.mode&0o777)!==0o700||stat.uid!==process.getuid?.())deny();
|
|
71
|
+
const file=join(storageDir,'device.json');
|
|
72
|
+
own(file,0o600);
|
|
73
|
+
const value=JSON.parse(readFileSync(file,'utf8'));
|
|
74
|
+
if(Object.keys(value).sort().join(',')!=='credential,device_id'||!validId(value.device_id)||
|
|
75
|
+
typeof value.credential!=='string'||value.credential.length<32)deny();
|
|
76
|
+
return value;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export function loadOrCreateMockDeviceKey({storageDir}={}){
|
|
80
|
+
if(!storageDir||typeof storageDir!=='string'||!storageDir.startsWith('/'))deny();
|
|
81
|
+
privateDir(storageDir);
|
|
82
|
+
const file=join(storageDir,'device-key.pem');
|
|
83
|
+
if(!existsSync(file)){
|
|
84
|
+
const pair=generateKeyPairSync('ed25519');
|
|
85
|
+
atomicFile(file,pair.privateKey.export({type:'pkcs8',format:'pem'}));
|
|
86
|
+
}
|
|
87
|
+
own(file,0o600);
|
|
88
|
+
const pem=readFileSync(file,'utf8');
|
|
89
|
+
if(pem.length>8192||!pem.includes('BEGIN PRIVATE KEY'))deny();
|
|
90
|
+
try{
|
|
91
|
+
const privateKey=createPrivateKey(pem);
|
|
92
|
+
if(privateKey.asymmetricKeyType!=='ed25519')deny();
|
|
93
|
+
return {privateKey,publicKey:createPublicKey(privateKey)};
|
|
94
|
+
}catch{deny();}
|
|
95
|
+
}
|
|
96
|
+
// Local mock-only credential revocation; real CP revoke must be confirmed
|
|
97
|
+
// by the authoritative provider before invoking this cleanup.
|
|
98
|
+
export function clearMockCredentialAfterRevoke({storageDir}={}){
|
|
99
|
+
privateDir(storageDir);
|
|
100
|
+
const file=join(storageDir,'device.json');
|
|
101
|
+
if(!existsSync(file))return {cleared:false,provider:'mock'};
|
|
102
|
+
own(file,0o600);
|
|
103
|
+
rmSync(file);
|
|
104
|
+
return {cleared:true,provider:'mock',deviceKeyPreserved:true};
|
|
105
|
+
}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
// #310 Private DEV: fetch only, verify before any installer executes. No new
|
|
2
|
+
// trust authority, shell execution, service mutation or token access.
|
|
3
|
+
import {request as httpsRequest} from 'node:https';
|
|
4
|
+
import {createWriteStream,readFileSync,lstatSync,rmSync,mkdtempSync} from 'node:fs';
|
|
5
|
+
import {tmpdir} from 'node:os';
|
|
6
|
+
import {join,basename,resolve} from 'node:path';
|
|
7
|
+
import {pipeline} from 'node:stream/promises';
|
|
8
|
+
import {Transform} from 'node:stream';
|
|
9
|
+
import {planVerifiedInstall} from './install-plan.mjs';
|
|
10
|
+
import {loadPinnedDevSigner} from './dev-signer-pin.mjs';
|
|
11
|
+
const MAX_MANIFEST=8192;
|
|
12
|
+
const MAX_ARTIFACT=128*1024*1024;
|
|
13
|
+
const deny=(code='DEVICE_INSTALL_DOWNLOAD_DENIED')=>{throw Error(code);};
|
|
14
|
+
function checkUrl(value,origin){
|
|
15
|
+
// Check raw URL before URL() normalizes traversal segments away.
|
|
16
|
+
if(typeof value!=='string'||/\/\.\.(?:\/|%2f|$)/i.test(value)||/%2e|%2f|%5c|\\/i.test(value))deny();
|
|
17
|
+
let url;
|
|
18
|
+
try{url=new URL(value);}catch{deny();}
|
|
19
|
+
if(url.protocol!=='https:'||url.username||url.password||url.hash||url.port&&url.port!=='443'||
|
|
20
|
+
url.hostname!==origin.hostname||url.origin!==origin.origin||url.search)deny();
|
|
21
|
+
if(!/^\/[A-Za-z0-9._/-]{1,200}$/.test(url.pathname)||url.pathname.includes('..')||url.pathname.includes('//'))deny();
|
|
22
|
+
return url;
|
|
23
|
+
}
|
|
24
|
+
async function getHttps(url,{requestImpl=httpsRequest,bytesMax}={}){
|
|
25
|
+
const response=await new Promise((ok,no)=>{
|
|
26
|
+
const req=requestImpl(url,{method:'GET',headers:{accept:'application/octet-stream'},timeout:15000},ok);
|
|
27
|
+
req.once('error',no);req.once('timeout',()=>req.destroy(Error('DEVICE_INSTALL_DOWNLOAD_TIMEOUT')));req.end();
|
|
28
|
+
});
|
|
29
|
+
if(response.statusCode!==200||response.headers?.location||
|
|
30
|
+
(response.headers?.['content-length']!==undefined&&
|
|
31
|
+
(!/^\d+$/.test(String(response.headers['content-length']))||Number(response.headers['content-length'])>bytesMax))){
|
|
32
|
+
response.destroy?.();deny();
|
|
33
|
+
}
|
|
34
|
+
return response;
|
|
35
|
+
}
|
|
36
|
+
async function consumeBounded(stream,limit){
|
|
37
|
+
let total=0;const chunks=[];
|
|
38
|
+
for await(const data of stream){
|
|
39
|
+
const b=Buffer.isBuffer(data)?data:Buffer.from(data);
|
|
40
|
+
total+=b.length;if(total>limit)deny('DEVICE_INSTALL_DOWNLOAD_TOO_LARGE');
|
|
41
|
+
chunks.push(b);
|
|
42
|
+
}
|
|
43
|
+
return Buffer.concat(chunks);
|
|
44
|
+
}
|
|
45
|
+
export async function acquireVerifiedDevArchive({manifestUrl,archiveUrl,publicKeyPath,
|
|
46
|
+
os,arch,nodeVersion,wsl=false,installedVersion=null,
|
|
47
|
+
consent=false,existingCredentials=false,existingService=false,
|
|
48
|
+
allowedOrigin,requestImpl=httpsRequest,stagingRoot=tmpdir(),loadSigner=loadPinnedDevSigner
|
|
49
|
+
}={}){
|
|
50
|
+
if(typeof allowedOrigin!=='string'||!/^https:\/\/[^/]+$/.test(allowedOrigin))deny();
|
|
51
|
+
const origin=new URL(allowedOrigin);
|
|
52
|
+
if(origin.username||origin.password||origin.hash||origin.search||origin.port&&origin.port!=='443')deny();
|
|
53
|
+
const manifestEndpoint=checkUrl(manifestUrl,origin);
|
|
54
|
+
const archiveEndpoint=checkUrl(archiveUrl,origin);
|
|
55
|
+
if(!manifestEndpoint.pathname.endsWith('.json')||!archiveEndpoint.pathname.endsWith('.tgz'))deny();
|
|
56
|
+
// Signer is pre-pinned in the installed program; server-controlled manifest
|
|
57
|
+
// cannot introduce a replacement trust key.
|
|
58
|
+
const trustedKeys=loadSigner({publicKeyPath});
|
|
59
|
+
const response=await getHttps(manifestEndpoint,{requestImpl,bytesMax:MAX_MANIFEST});
|
|
60
|
+
const raw=await consumeBounded(response,MAX_MANIFEST);
|
|
61
|
+
let manifest;try{manifest=JSON.parse(raw.toString('utf8'));}catch{deny('DEVICE_INSTALL_MANIFEST_DENIED');}
|
|
62
|
+
if(manifest?.signed_fields?.artifact!==basename(archiveEndpoint.pathname))deny('DEVICE_INSTALL_MANIFEST_DENIED');
|
|
63
|
+
const stat=lstatSync(stagingRoot);
|
|
64
|
+
if(!stat.isDirectory()||stat.isSymbolicLink())deny();
|
|
65
|
+
const stage=mkdtempSync(join(stagingRoot,'rs310-verified-'));
|
|
66
|
+
try{
|
|
67
|
+
const artifactPath=join(stage,basename(archiveEndpoint.pathname));
|
|
68
|
+
let count=0;
|
|
69
|
+
const bounded=new Transform({transform(chunk,_encoding,callback){
|
|
70
|
+
count+=chunk.length;
|
|
71
|
+
if(count>MAX_ARTIFACT){callback(Error('DEVICE_INSTALL_DOWNLOAD_TOO_LARGE'));return;}
|
|
72
|
+
callback(null,chunk);
|
|
73
|
+
}});
|
|
74
|
+
const archiveResponse=await getHttps(archiveEndpoint,{requestImpl,bytesMax:MAX_ARTIFACT});
|
|
75
|
+
await pipeline(archiveResponse,bounded,createWriteStream(artifactPath,{flags:'wx',mode:0o600}));
|
|
76
|
+
const decision=planVerifiedInstall({artifactPath,manifest,trustedKeys,os,arch,nodeVersion,wsl,
|
|
77
|
+
installedVersion,existingCredentials,existingService,consent});
|
|
78
|
+
return Object.freeze({...decision,archivePath:artifactPath,stagingDirectory:stage,
|
|
79
|
+
verifiedFromHttps:true,installerExecuted:false,cleanupRequired:true});
|
|
80
|
+
}catch(e){rmSync(stage,{recursive:true,force:true});throw e;}
|
|
81
|
+
}
|
|
82
|
+
export function cleanupVerifiedDevArchive({stagingDirectory,stagingRoot=tmpdir()}={}){
|
|
83
|
+
if(typeof stagingDirectory!=='string'||!stagingDirectory||
|
|
84
|
+
resolve(stagingDirectory)===resolve(stagingRoot)||
|
|
85
|
+
!resolve(stagingDirectory).startsWith(resolve(stagingRoot)+'/')||
|
|
86
|
+
!basename(stagingDirectory).startsWith('rs310-verified-'))deny();
|
|
87
|
+
rmSync(stagingDirectory,{recursive:true,force:true});
|
|
88
|
+
return {cleaned:true,installationPerformed:false};
|
|
89
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
// #310: non-executing installer preflight aligned with the existing DEV
|
|
2
|
+
// artifact-delivery schema v2 and the independently pinned Ed25519 key.
|
|
3
|
+
// Trust anchors come from the installer, never from a downloaded manifest.
|
|
4
|
+
import {createHash,createPublicKey,verify as verifySignature,timingSafeEqual} from 'node:crypto';
|
|
5
|
+
import {openSync,closeSync,readSync,lstatSync,fstatSync,constants} from 'node:fs';
|
|
6
|
+
import {basename} from 'node:path';
|
|
7
|
+
const MAX_BYTES=128*1024*1024;
|
|
8
|
+
const fail=code=>{throw Object.assign(new Error(code),{code});};
|
|
9
|
+
const versionOk=v=>typeof v==='string'&&/^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?$/.test(v);
|
|
10
|
+
const hashOk=x=>typeof x==='string'&&/^[0-9a-f]{64}$/.test(x);
|
|
11
|
+
const nameOk=x=>typeof x==='string'&&/^[a-zA-Z0-9][a-zA-Z0-9._-]{0,127}\.tgz$/.test(x)&&!x.includes('..');
|
|
12
|
+
export function installPreflight({os,arch,nodeVersion,wsl=false}={}){
|
|
13
|
+
const supported=(os==='win32'||os==='linux')&&['x64','arm64'].includes(arch);
|
|
14
|
+
const major=Number(/^v?(\d+)(?:\.|$)/.exec(nodeVersion||'')?.[1]);
|
|
15
|
+
if(!supported)fail('DEVICE_INSTALL_OS_UNSUPPORTED');
|
|
16
|
+
if(wsl)fail('DEVICE_INSTALL_WSL_BETA_EXCLUDED');
|
|
17
|
+
if(!Number.isInteger(major)||major<22)fail('DEVICE_INSTALL_NODE_UNSUPPORTED');
|
|
18
|
+
return Object.freeze({preflight:'PASS',os,arch,nodeMajor:major,automaticInstall:false,
|
|
19
|
+
installationReady:false,requiresOwnerConsent:true});
|
|
20
|
+
}
|
|
21
|
+
export function verifySignedInstallArchive({artifactPath,manifest,trustedKeys,os,arch,nodeVersion,wsl=false}={}){
|
|
22
|
+
installPreflight({os,arch,nodeVersion,wsl});
|
|
23
|
+
const fields=manifest?.signed_fields;
|
|
24
|
+
if(!manifest||typeof manifest!=='object'||Array.isArray(manifest)||
|
|
25
|
+
Object.keys(manifest).sort().join(',')!=='algorithm,public_key_sha256,signature,signed_fields'||
|
|
26
|
+
manifest.algorithm!=='ed25519'||!hashOk(manifest.public_key_sha256)||
|
|
27
|
+
typeof manifest.signature!=='string'||!/^[A-Za-z0-9_-]{86}$/.test(manifest.signature)||
|
|
28
|
+
!fields||typeof fields!=='object'||Array.isArray(fields)||
|
|
29
|
+
fields.schema_version!==2||fields.channel!=='private-dev'||fields.public_release!==false||
|
|
30
|
+
fields.package!=='@remoteshell/device'||!versionOk(fields.version)||
|
|
31
|
+
fields.os!==os||fields.arch!==arch||!nameOk(fields.artifact)||
|
|
32
|
+
fields.artifact!==basename(artifactPath||'')||!Number.isSafeInteger(fields.bytes)||
|
|
33
|
+
fields.bytes<1||fields.bytes>MAX_BYTES||!hashOk(fields.sha256)||
|
|
34
|
+
typeof fields.source_head!=='string'||!/^[a-f0-9]{40}$/.test(fields.source_head)||
|
|
35
|
+
typeof fields.feature!=='string'||fields.feature.length>150)
|
|
36
|
+
fail('DEVICE_INSTALL_MANIFEST_DENIED');
|
|
37
|
+
const trusted=trustedKeys&&Object.hasOwn(trustedKeys,manifest.public_key_sha256)?
|
|
38
|
+
trustedKeys[manifest.public_key_sha256]:null;
|
|
39
|
+
if(!trusted)fail('DEVICE_INSTALL_TRUST_ANCHOR_MISSING');
|
|
40
|
+
let key;
|
|
41
|
+
try{key=trusted?.type==='public'&&trusted?.asymmetricKeyType==='ed25519'?trusted:createPublicKey(trusted);}
|
|
42
|
+
catch{fail('DEVICE_INSTALL_TRUST_ANCHOR_INVALID');}
|
|
43
|
+
if(key.asymmetricKeyType!=='ed25519'||key.type!=='public')fail('DEVICE_INSTALL_TRUST_ANCHOR_INVALID');
|
|
44
|
+
const fingerprint=createHash('sha256').update(key.export({type:'spki',format:'der'})).digest('hex');
|
|
45
|
+
if(fingerprint!==manifest.public_key_sha256)fail('DEVICE_INSTALL_TRUST_ANCHOR_INVALID');
|
|
46
|
+
const signature=Buffer.from(manifest.signature,'base64url');
|
|
47
|
+
if(signature.length!==64||!verifySignature(null,Buffer.from(JSON.stringify(fields),'utf8'),key,signature))
|
|
48
|
+
fail('DEVICE_INSTALL_SIGNATURE_DENIED');
|
|
49
|
+
let fd;
|
|
50
|
+
try{
|
|
51
|
+
const st=lstatSync(artifactPath);
|
|
52
|
+
if(!st.isFile()||st.isSymbolicLink()||st.size!==fields.bytes)fail('DEVICE_INSTALL_ARTIFACT_DENIED');
|
|
53
|
+
fd=openSync(artifactPath,constants.O_RDONLY | (constants.O_NOFOLLOW||0));
|
|
54
|
+
const first=fstatSync(fd);
|
|
55
|
+
if(!first.isFile()||first.dev!==st.dev||first.ino!==st.ino||first.size!==st.size)
|
|
56
|
+
fail('DEVICE_INSTALL_ARTIFACT_DENIED');
|
|
57
|
+
const hash=createHash('sha256'),buffer=Buffer.alloc(65536);
|
|
58
|
+
let remaining=st.size;
|
|
59
|
+
while(remaining>0){
|
|
60
|
+
const count=readSync(fd,buffer,0,Math.min(buffer.length,remaining),null);
|
|
61
|
+
if(count<=0)fail('DEVICE_INSTALL_ARTIFACT_DENIED');
|
|
62
|
+
hash.update(buffer.subarray(0,count));remaining-=count;
|
|
63
|
+
}
|
|
64
|
+
const after=fstatSync(fd);
|
|
65
|
+
if(after.size!==first.size||after.mtimeMs!==first.mtimeMs||after.ino!==first.ino)
|
|
66
|
+
fail('DEVICE_INSTALL_ARTIFACT_DENIED');
|
|
67
|
+
const actual=Buffer.from(hash.digest('hex'),'hex');
|
|
68
|
+
if(!timingSafeEqual(actual,Buffer.from(fields.sha256,'hex')))
|
|
69
|
+
fail('DEVICE_INSTALL_CHECKSUM_DENIED');
|
|
70
|
+
}catch(e){if(e?.code?.startsWith('DEVICE_INSTALL_'))throw e;fail('DEVICE_INSTALL_ARTIFACT_DENIED');}
|
|
71
|
+
finally{if(fd!==undefined)closeSync(fd);}
|
|
72
|
+
return Object.freeze({verified:true,version:fields.version,os,arch,sha256:fields.sha256,
|
|
73
|
+
signingKeyFingerprint:fingerprint,channel:fields.channel,installed:false,registered:false});
|
|
74
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
// #310 Shared, non-executing installation decision. Both OS entrypoints must
|
|
2
|
+
// consume one verified artifact; this module never runs it or changes credentials.
|
|
3
|
+
import {verifySignedInstallArchive} from './install-integrity.mjs';
|
|
4
|
+
const fail=code=>{throw Error(code);};
|
|
5
|
+
function semver(value){
|
|
6
|
+
if(typeof value!=='string'||!/^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?$/.test(value))
|
|
7
|
+
fail('DEVICE_INSTALL_VERSION_DENIED');
|
|
8
|
+
return value.split('-')[0].split('.').map(Number);
|
|
9
|
+
}
|
|
10
|
+
function compare(a,b){
|
|
11
|
+
const av=semver(a),bv=semver(b);
|
|
12
|
+
for(let i=0;i<3;i++){if(av[i]>bv[i])return 1;if(av[i]<bv[i])return -1;}
|
|
13
|
+
// Never infer prerelease ordering or treat a prerelease as a final release.
|
|
14
|
+
if(a===b)return 0;
|
|
15
|
+
fail('DEVICE_INSTALL_VERSION_REVIEW_REQUIRED');
|
|
16
|
+
}
|
|
17
|
+
export function planVerifiedInstall({
|
|
18
|
+
artifactPath,manifest,trustedKeys,os,arch,nodeVersion,wsl=false,
|
|
19
|
+
installedVersion=null,existingCredentials=false,existingService=false,
|
|
20
|
+
consent=false
|
|
21
|
+
}={}){
|
|
22
|
+
// Validate before making a version or installation decision, even on no-op.
|
|
23
|
+
const verified=verifySignedInstallArchive({
|
|
24
|
+
artifactPath,manifest,trustedKeys,os,arch,nodeVersion,wsl
|
|
25
|
+
});
|
|
26
|
+
if(typeof existingCredentials!=='boolean'||typeof existingService!=='boolean'||
|
|
27
|
+
typeof consent!=='boolean')fail('DEVICE_INSTALL_STATE_DENIED');
|
|
28
|
+
const result=installedVersion===null?'fresh':
|
|
29
|
+
compare(verified.version,installedVersion)===0?'already-installed':
|
|
30
|
+
compare(verified.version,installedVersion)>0?'upgrade':'downgrade';
|
|
31
|
+
if(result==='downgrade')fail('DEVICE_INSTALL_DOWNGRADE_DENIED');
|
|
32
|
+
if(existingService&&installedVersion===null)fail('DEVICE_INSTALL_STATE_DENIED');
|
|
33
|
+
return Object.freeze({
|
|
34
|
+
verified:true,os,arch,version:verified.version,
|
|
35
|
+
signingKeyFingerprint:verified.signingKeyFingerprint,
|
|
36
|
+
artifactSha256:verified.sha256,action:result,
|
|
37
|
+
// Installing, replacing, service enabling and re-enrollment are separate
|
|
38
|
+
// later steps and require an explicit consent/restore plan.
|
|
39
|
+
next:consent?'OS_INSTALL_APPROVAL_REQUIRED':'USER_CONSENT_REQUIRED',
|
|
40
|
+
approvedToExecute:false,installed:false,deviceRegistered:false,
|
|
41
|
+
credentialsPreserved:true,existingCredentials,existingService
|
|
42
|
+
});
|
|
43
|
+
}
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
// #126 device-local lifecycle. Does not implement CP credential issuance.
|
|
2
|
+
// Commands are limited to the current user's dedicated private installation.
|
|
3
|
+
import {existsSync,lstatSync,mkdirSync,readFileSync,writeFileSync,rmSync} from 'node:fs';
|
|
4
|
+
import {homedir} from 'node:os';
|
|
5
|
+
import {dirname,join,resolve} from 'node:path';
|
|
6
|
+
import {spawnSync,spawn} from 'node:child_process';
|
|
7
|
+
import https from 'node:https';
|
|
8
|
+
import {readDeviceCredential} from './enrollment-client.mjs';
|
|
9
|
+
|
|
10
|
+
const ERROR='DEVICE_LIFECYCLE_DENIED';
|
|
11
|
+
const fail=()=>{throw Error(ERROR);};
|
|
12
|
+
const SERVICE='remoteshell-device.service';
|
|
13
|
+
function requireDir(path,mode=null){
|
|
14
|
+
const s=lstatSync(path);
|
|
15
|
+
if(!s.isDirectory()||s.isSymbolicLink()||s.uid!==process.getuid?.()||(mode!==null&&(s.mode&0o777)!==mode))fail();
|
|
16
|
+
}
|
|
17
|
+
function requireFile(path,mode=null){
|
|
18
|
+
const s=lstatSync(path);
|
|
19
|
+
if(!s.isFile()||s.isSymbolicLink()||s.uid!==process.getuid?.()||(mode!==null&&(s.mode&0o777)!==mode))fail();
|
|
20
|
+
}
|
|
21
|
+
function safeGateway({gatewayUrl,caFile}={}){
|
|
22
|
+
try{
|
|
23
|
+
const u=new URL(gatewayUrl);
|
|
24
|
+
if(u.pathname!=='/'||u.username||u.password||u.hash||u.search)fail();
|
|
25
|
+
if(!['http:','https:'].includes(u.protocol)||u.href!==u.protocol+'//'+u.host+'/'||u.host.length>255||[...u.host].some(c=>!'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.:-[]'.includes(c)))fail();
|
|
26
|
+
const local=['127.0.0.1','localhost','[::1]'].includes(u.hostname);
|
|
27
|
+
if(!local&&u.protocol!=='https:')fail();
|
|
28
|
+
if(u.protocol==='https:'){
|
|
29
|
+
if(typeof caFile!=='string'||!/^\/[A-Za-z0-9._/@+-]+$/.test(caFile))fail();
|
|
30
|
+
requireFile(caFile,0o600);requireDir(dirname(caFile),0o700);
|
|
31
|
+
}else if(caFile)fail();
|
|
32
|
+
return {origin:u.href,caFile:u.protocol==='https:'?caFile:null,remote:!local};
|
|
33
|
+
}catch{fail();}
|
|
34
|
+
}
|
|
35
|
+
function paths(home){
|
|
36
|
+
if(typeof home!=='string'||!home.startsWith('/')||resolve(home)==='/')fail();
|
|
37
|
+
requireDir(home);
|
|
38
|
+
const base=join(home,'.local/share/remoteshell-device'),install=join(base,'install');
|
|
39
|
+
requireDir(base,0o700);requireDir(install,0o700);
|
|
40
|
+
const runtime=join(install,'node_modules/@remoteshell/device/src/device-agent/main.mjs');
|
|
41
|
+
requireFile(runtime);
|
|
42
|
+
const credentials=join(base,'credentials');
|
|
43
|
+
const unitDir=join(home,'.config/systemd/user');
|
|
44
|
+
const unit=join(unitDir,SERVICE);
|
|
45
|
+
return {base,install,runtime,credentials,unitDir,unit};
|
|
46
|
+
}
|
|
47
|
+
function credentialPath(p){
|
|
48
|
+
const credential=readDeviceCredential({storageDir:p.credentials});
|
|
49
|
+
if(!credential?.device_id)fail();
|
|
50
|
+
return join(p.credentials,'device.json');
|
|
51
|
+
}
|
|
52
|
+
function checkUnitFile(file){
|
|
53
|
+
if(existsSync(file))requireFile(file,0o600);
|
|
54
|
+
}
|
|
55
|
+
function unitContent(p,gateway,nodeBin){
|
|
56
|
+
// No shell expansion, secrets, or environment from untrusted callers.
|
|
57
|
+
for(const path of [p.runtime,p.credentials,nodeBin,p.install]){
|
|
58
|
+
if(!/^\/[A-Za-z0-9._/@+-]+$/.test(path))fail();
|
|
59
|
+
}
|
|
60
|
+
return [
|
|
61
|
+
'[Unit]','Description=RemoteShell Device Agent (user)','After=network-online.target',
|
|
62
|
+
'Wants=network-online.target','','[Service]','Type=simple',
|
|
63
|
+
'ExecStart='+nodeBin+' '+p.runtime,'Environment=RS_P2_MODE=true',
|
|
64
|
+
'Environment=RS_P2_DEVICE_CREDENTIAL_FILE='+join(p.credentials,'device.json'),
|
|
65
|
+
'Environment=RS_GATEWAY_URL='+gateway.origin,
|
|
66
|
+
...(gateway.caFile?['Environment=RS_CA_FILE='+gateway.caFile]:[]),
|
|
67
|
+
...(gateway.remote?['Environment=RS_ENABLE_REMOTE=true']:[]),
|
|
68
|
+
'WorkingDirectory='+p.install,
|
|
69
|
+
'Restart=on-failure','RestartSec=5','UMask=0077','NoNewPrivileges=yes',
|
|
70
|
+
'PrivateTmp=yes','','[Install]','WantedBy=default.target',''
|
|
71
|
+
].join('\n');
|
|
72
|
+
}
|
|
73
|
+
function systemctl(args,run=spawnSync){
|
|
74
|
+
const result=run('systemctl',['--user',...args],{encoding:'utf8',timeout:5000,maxBuffer:16384,stdio:'pipe'});
|
|
75
|
+
if(result.error||result.signal||result.status!==0)fail();
|
|
76
|
+
return String(result.stdout||'');
|
|
77
|
+
}
|
|
78
|
+
export function installUserUnit({home=homedir(),gatewayUrl,caFile,nodeBin=process.execPath,run=spawnSync}={}){
|
|
79
|
+
const p=paths(home);credentialPath(p);const gateway=safeGateway({gatewayUrl,caFile});
|
|
80
|
+
if(existsSync(p.unit))fail();
|
|
81
|
+
const config=join(home,'.config'),systemd=join(config,'systemd');
|
|
82
|
+
for(const path of [config,systemd,p.unitDir]){
|
|
83
|
+
if(!existsSync(path))mkdirSync(path,{mode:0o700});
|
|
84
|
+
requireDir(path);
|
|
85
|
+
}
|
|
86
|
+
writeFileSync(p.unit,unitContent(p,gateway,nodeBin),{flag:'wx',mode:0o600});
|
|
87
|
+
try{systemctl(['daemon-reload'],run);}catch(e){rmSync(p.unit);throw e;}
|
|
88
|
+
return {unitInstalled:true,enabled:false,started:false,connected:false};
|
|
89
|
+
}
|
|
90
|
+
export function userService({action,home=homedir(),run=spawnSync}={}){
|
|
91
|
+
const p=paths(home);
|
|
92
|
+
if(action==='status'){
|
|
93
|
+
if(!existsSync(p.unit))return {unitInstalled:false,connected:false};
|
|
94
|
+
checkUnitFile(p.unit);
|
|
95
|
+
const r=run('systemctl',['--user','is-active',SERVICE],{encoding:'utf8',timeout:3000,stdio:'pipe'});
|
|
96
|
+
const enabled=run('systemctl',['--user','is-enabled',SERVICE],{encoding:'utf8',timeout:3000,stdio:'pipe'});
|
|
97
|
+
return {unitInstalled:true,active:r.status===0,enabled:enabled.status===0,connected:false};
|
|
98
|
+
}
|
|
99
|
+
checkUnitFile(p.unit);
|
|
100
|
+
if(!existsSync(p.unit))fail();
|
|
101
|
+
if(action==='start'){credentialPath(p);systemctl(['start',SERVICE],run);return {started:true,connected:false};}
|
|
102
|
+
if(action==='stop'){systemctl(['stop',SERVICE],run);return {stopped:true,connected:false};}
|
|
103
|
+
if(action==='restart'){credentialPath(p);systemctl(['restart',SERVICE],run);return {restarted:true,connected:false};}
|
|
104
|
+
if(action==='enable'){credentialPath(p);systemctl(['enable',SERVICE],run);return {enabled:true,connected:false};}
|
|
105
|
+
if(action==='disable'){systemctl(['disable',SERVICE],run);return {enabled:false,connected:false};}
|
|
106
|
+
if(action==='uninstall'){
|
|
107
|
+
// Stop/disable first, fail closed if either operation fails.
|
|
108
|
+
systemctl(['stop',SERVICE],run);systemctl(['disable',SERVICE],run);
|
|
109
|
+
const state=run('systemctl',['--user','is-active',SERVICE],{encoding:'utf8',timeout:3000,stdio:'pipe'});
|
|
110
|
+
if(state.status===0)fail();
|
|
111
|
+
rmSync(p.unit);systemctl(['daemon-reload'],run);
|
|
112
|
+
return {removed:true,credentialsPreserved:true,connected:false};
|
|
113
|
+
}
|
|
114
|
+
fail();
|
|
115
|
+
}
|
|
116
|
+
export async function foreground({home=homedir(),gatewayUrl,caFile,spawnImpl=spawn}={}){
|
|
117
|
+
const p=paths(home),file=credentialPath(p),gateway=safeGateway({gatewayUrl,caFile});
|
|
118
|
+
const child=spawnImpl(process.execPath,[p.runtime],{
|
|
119
|
+
cwd:p.install,stdio:['ignore','ignore','ignore'],
|
|
120
|
+
env:{PATH:process.env.PATH||'/usr/bin:/bin',HOME:home,
|
|
121
|
+
RS_P2_MODE:'true',RS_GATEWAY_URL:gateway.origin,RS_P2_DEVICE_CREDENTIAL_FILE:file,
|
|
122
|
+
...(gateway.caFile?{RS_CA_FILE:gateway.caFile}:{}),
|
|
123
|
+
...(gateway.remote?{RS_ENABLE_REMOTE:'true'}:{}),
|
|
124
|
+
RS_55C1_TEST_MODE:'false',RS_55D_TEST_MODE:'false'}
|
|
125
|
+
});
|
|
126
|
+
return await new Promise((done,reject)=>{
|
|
127
|
+
let exited=false;
|
|
128
|
+
child.once('error',reject);
|
|
129
|
+
child.once('exit',(code,signal)=>{exited=true;done({exited:true,code,signal,connected:false});});
|
|
130
|
+
const stop=()=>{if(!exited)child.kill('SIGTERM');};
|
|
131
|
+
process.once('SIGINT',stop);process.once('SIGTERM',stop);
|
|
132
|
+
child.once('exit',()=>{process.removeListener('SIGINT',stop);process.removeListener('SIGTERM',stop);});
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
export async function gatewayStatus({home=homedir(),gatewayUrl,caFile,timeoutMs=3000}={}){
|
|
137
|
+
const p=paths(home);
|
|
138
|
+
const credential=readDeviceCredential({storageDir:p.credentials});
|
|
139
|
+
const gateway=safeGateway({gatewayUrl,caFile});
|
|
140
|
+
const payload=JSON.stringify({device_id:credential.device_id});
|
|
141
|
+
const headers={authorization:'Bearer '+credential.credential,'content-type':'application/json'};
|
|
142
|
+
let response;
|
|
143
|
+
if(gateway.origin.startsWith('https:')){
|
|
144
|
+
response=await new Promise((done,reject)=>{
|
|
145
|
+
const request=https.request(new URL('/device/status',gateway.origin),{
|
|
146
|
+
method:'POST',ca:readFileSync(gateway.caFile),
|
|
147
|
+
headers:{...headers,'content-length':Buffer.byteLength(payload)},
|
|
148
|
+
timeout:timeoutMs
|
|
149
|
+
},res=>{
|
|
150
|
+
let text='';
|
|
151
|
+
res.on('data',chunk=>{text+=chunk;if(text.length>2048)request.destroy(new Error(ERROR));});
|
|
152
|
+
res.on('end',()=>done({status:res.statusCode,text}));
|
|
153
|
+
});
|
|
154
|
+
request.on('error',reject);
|
|
155
|
+
request.on('timeout',()=>request.destroy(new Error(ERROR)));
|
|
156
|
+
request.end(payload);
|
|
157
|
+
});
|
|
158
|
+
}else{
|
|
159
|
+
const r=await fetch(new URL('/device/status',gateway.origin),{
|
|
160
|
+
method:'POST',headers,body:payload,signal:AbortSignal.timeout(timeoutMs)
|
|
161
|
+
});
|
|
162
|
+
const text=await r.text();
|
|
163
|
+
if(text.length>2048)fail();
|
|
164
|
+
response={status:r.status,text};
|
|
165
|
+
}
|
|
166
|
+
if(response.status!==200)fail();
|
|
167
|
+
let data;
|
|
168
|
+
try{data=JSON.parse(response.text);}catch{fail();}
|
|
169
|
+
if(data?.device_id!==credential.device_id||typeof data.connected!=='boolean'||
|
|
170
|
+
Object.keys(data).sort().join(',')!=='connected,device_id')fail();
|
|
171
|
+
return {connected:data.connected,gatewayVerified:true};
|
|
172
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
// #310 Windows lexical path boundary for offline planning only. This is NOT
|
|
2
|
+
// proof of NTFS ownership/ACLs, reparse-point freedom, or an approved Root.
|
|
3
|
+
import {win32} from 'node:path';
|
|
4
|
+
const deny=()=>{throw Error('DEVICE_WINDOWS_PATH_DENIED');};
|
|
5
|
+
const reserved=/^(?:con|prn|aux|nul|com[1-9]|lpt[1-9])(?:\..*)?$/i;
|
|
6
|
+
export function canonicalWindowsLocalFile(path){
|
|
7
|
+
if(typeof path!=='string'||path.length<4||path.length>1024||!(/^[A-Za-z]:\\/.test(path)))
|
|
8
|
+
deny();
|
|
9
|
+
// Reject UNC, device namespaces, forward slashes, ADS, env interpolation and
|
|
10
|
+
// shell metacharacters before a name can be used in a task argument.
|
|
11
|
+
if(/[\x00-\x1f\x7f"<>|?*\/&^%]/.test(path)||path.slice(2).includes(':'))deny();
|
|
12
|
+
const segments=path.slice(3).split('\\');
|
|
13
|
+
if(segments.length===0||segments.some(x=>!x||x==='.'||x==='..'||/[. ]$/.test(x)||reserved.test(x)))deny();
|
|
14
|
+
const normalized=win32.normalize(path);
|
|
15
|
+
if(normalized!==path)deny(); // no invisible normalization changes
|
|
16
|
+
return path;
|
|
17
|
+
}
|
|
18
|
+
export function isWindowsChildPath(path,root){
|
|
19
|
+
const child=canonicalWindowsLocalFile(path),parent=canonicalWindowsLocalFile(root);
|
|
20
|
+
const rel=win32.relative(parent,child);
|
|
21
|
+
if(!rel||rel==='..'||rel.startsWith('..\\')||win32.isAbsolute(rel))deny();
|
|
22
|
+
return true;
|
|
23
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
@echo off
|
|
2
|
+
setlocal DisableDelayedExpansion
|
|
3
|
+
rem #310: package-local Windows bootstrap; no network download or privileged task.
|
|
4
|
+
rem Only run from an independently verified private package within this user profile.
|
|
5
|
+
if not "%~1"=="" (
|
|
6
|
+
echo DEVICE_INSTALL_ARGS_DENIED 1>&2
|
|
7
|
+
exit /b 2
|
|
8
|
+
)
|
|
9
|
+
where node >nul 2>nul
|
|
10
|
+
if errorlevel 1 (
|
|
11
|
+
echo DEVICE_INSTALL_NODE_UNSUPPORTED 1>&2
|
|
12
|
+
exit /b 1
|
|
13
|
+
)
|
|
14
|
+
node "%~dp0device.mjs" install-preflight
|
|
15
|
+
if errorlevel 1 exit /b %errorlevel%
|
|
16
|
+
node "%~dp0device.mjs" install
|
|
17
|
+
exit /b %errorlevel%
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# #310: package-local Windows bootstrap. Does not download or elevate.
|
|
2
|
+
# Run only from the verified private package in the current user's profile.
|
|
3
|
+
$ErrorActionPreference = 'Stop'
|
|
4
|
+
if ($args.Count -ne 0) {
|
|
5
|
+
[Console]::Error.WriteLine('DEVICE_INSTALL_ARGS_DENIED')
|
|
6
|
+
exit 2
|
|
7
|
+
}
|
|
8
|
+
$node = Get-Command node -CommandType Application -ErrorAction SilentlyContinue
|
|
9
|
+
if ($null -eq $node) {
|
|
10
|
+
[Console]::Error.WriteLine('DEVICE_INSTALL_NODE_UNSUPPORTED')
|
|
11
|
+
exit 1
|
|
12
|
+
}
|
|
13
|
+
$entry = Join-Path $PSScriptRoot 'device.mjs'
|
|
14
|
+
& $node.Source $entry install-preflight
|
|
15
|
+
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
|
|
16
|
+
& $node.Source $entry install
|
|
17
|
+
exit $LASTEXITCODE
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
#!/bin/sh
|
|
2
|
+
# #310: package-local Linux bootstrap; never executes downloaded shell text.
|
|
3
|
+
# Download/verify/signature trust must be handled before invoking this script.
|
|
4
|
+
set -eu
|
|
5
|
+
if [ "$#" -ne 0 ]; then
|
|
6
|
+
echo DEVICE_INSTALL_ARGS_DENIED >&2
|
|
7
|
+
exit 2
|
|
8
|
+
fi
|
|
9
|
+
if ! command -v node >/dev/null 2>&1; then
|
|
10
|
+
echo DEVICE_INSTALL_NODE_UNSUPPORTED >&2
|
|
11
|
+
exit 1
|
|
12
|
+
fi
|
|
13
|
+
entry_dir=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd -P)
|
|
14
|
+
node "$entry_dir/device.mjs" install-preflight
|
|
15
|
+
node "$entry_dir/device.mjs" install
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
@echo off
|
|
2
|
+
setlocal DisableDelayedExpansion
|
|
3
|
+
rem Windows native preflight only. No download, enrollment or service mutation.
|
|
4
|
+
where node >nul 2>nul
|
|
5
|
+
if errorlevel 1 (
|
|
6
|
+
echo DEVICE_INSTALL_NODE_UNSUPPORTED 1>&2
|
|
7
|
+
exit /b 1
|
|
8
|
+
)
|
|
9
|
+
node "%~dp0device.mjs" install-preflight
|
|
10
|
+
exit /b %errorlevel%
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
# Windows native preflight only. No download, enrollment or service mutation.
|
|
2
|
+
$ErrorActionPreference = 'Stop'
|
|
3
|
+
$node = Get-Command node -CommandType Application -ErrorAction SilentlyContinue
|
|
4
|
+
if ($null -eq $node) {
|
|
5
|
+
[Console]::Error.WriteLine('DEVICE_INSTALL_NODE_UNSUPPORTED')
|
|
6
|
+
exit 1
|
|
7
|
+
}
|
|
8
|
+
$entry = Join-Path $PSScriptRoot 'device.mjs'
|
|
9
|
+
& $node.Source $entry install-preflight
|
|
10
|
+
exit $LASTEXITCODE
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# Read-only DEV installer diagnostics. Never output device keys, poll tokens or raw pair.out.
|
|
2
|
+
$ErrorActionPreference='Stop'
|
|
3
|
+
$identity=[Security.Principal.WindowsIdentity]::GetCurrent().Name
|
|
4
|
+
$local=[Environment]::GetFolderPath('LocalApplicationData')
|
|
5
|
+
$root=Join-Path $local 'RemoteShell'
|
|
6
|
+
$logDir=Join-Path $root 'EasyInstall\logs'
|
|
7
|
+
$install=Join-Path $root 'DeviceAgent\install'
|
|
8
|
+
$credentials=Join-Path $root 'DeviceAgent\dev-credentials'
|
|
9
|
+
Write-Output ('DIAG_AT='+((Get-Date).ToString('o')))
|
|
10
|
+
Write-Output ('WINDOWS_USER='+$identity)
|
|
11
|
+
Write-Output ('AGENT_INSTALLED='+(Test-Path -LiteralPath $install))
|
|
12
|
+
Write-Output ('LOCAL_CREDENTIAL_FILE_PRESENT='+(Test-Path -LiteralPath (Join-Path $credentials 'device.json')))
|
|
13
|
+
foreach($n in @('result.txt','pair.err','install.err','stage-agent.err','status.err')) {
|
|
14
|
+
$p=Join-Path $logDir $n
|
|
15
|
+
if(Test-Path -LiteralPath $p -PathType Leaf) {
|
|
16
|
+
Write-Output ('LOG_FILE='+$n)
|
|
17
|
+
foreach($line in (Get-Content -LiteralPath $p -Tail 90)) {
|
|
18
|
+
if($line -match '^(\xFEFF)?(RemoteShell EasyInstall DEV|AGENT_INSTALLED=|PAIR_|RESULT=|USER_|NEXT=|DEVICE_[A-Z0-9_]+$)' -or ($n -ne 'result.txt' -and $line -match '^[A-Z][A-Z0-9_]{4,90}$')) {
|
|
19
|
+
# Only predefined status lines and status codes, never JSON response bodies or URLs.
|
|
20
|
+
$clean=$line -replace 'https?://\S+','[URL]' -replace '(?i)(poll_token|capability|nonce|private_key)=\S+','$1=[REDACTED]'
|
|
21
|
+
Write-Output $clean
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
} else { Write-Output ('LOG_MISSING='+$n) }
|
|
25
|
+
}
|
|
26
|
+
$uninstall=Join-Path $root 'UninstallLogs\easy-uninstall-result.txt'
|
|
27
|
+
if(Test-Path -LiteralPath $uninstall -PathType Leaf) {
|
|
28
|
+
Write-Output 'UNINSTALL_RESULT'
|
|
29
|
+
Get-Content -LiteralPath $uninstall -Tail 25 | Where-Object {$_ -match '^(RemoteShell easy uninstall |AGENT_|USER_|LOCAL_|PRIVATE_|RESULT=)'}
|
|
30
|
+
}
|
|
31
|
+
Write-Output 'NOTE: Browser HTTP status and Google identity are NOT available from Agent logs.'
|
|
32
|
+
Write-Output 'NOTE: Pairing IDs are non-secret request correlations; never share raw pair.out.'
|