@scrypted/server 0.146.2 → 0.148.0
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/dist/cluster/cluster-setup.js +16 -17
- package/dist/cluster/cluster-setup.js.map +1 -1
- package/dist/http-interfaces.js +16 -2
- package/dist/http-interfaces.js.map +1 -1
- package/dist/plugin/media.d.ts +5 -39
- package/dist/plugin/media.js +73 -109
- package/dist/plugin/media.js.map +1 -1
- package/dist/plugin/plugin-console.d.ts +2 -0
- package/dist/plugin/plugin-console.js +10 -0
- package/dist/plugin/plugin-console.js.map +1 -1
- package/dist/plugin/plugin-host.js +7 -3
- package/dist/plugin/plugin-host.js.map +1 -1
- package/dist/plugin/plugin-remote-worker.js.map +1 -1
- package/dist/plugin/plugin-remote.d.ts +15 -0
- package/dist/plugin/plugin-remote.js +36 -39
- package/dist/plugin/plugin-remote.js.map +1 -1
- package/dist/rpc-serializer.js +4 -0
- package/dist/rpc-serializer.js.map +1 -1
- package/dist/scrypted-cluster-main.js +20 -0
- package/dist/scrypted-cluster-main.js.map +1 -1
- package/dist/scrypted-server-main.js +31 -15
- package/dist/scrypted-server-main.js.map +1 -1
- package/dist/services/cluster-fork.js +3 -3
- package/dist/services/cluster-fork.js.map +1 -1
- package/dist/services/plugin.d.ts +1 -0
- package/dist/services/plugin.js +5 -0
- package/dist/services/plugin.js.map +1 -1
- package/package.json +1 -1
- package/python/cluster_setup.py +20 -20
- package/python/plugin_remote.py +0 -1
- package/src/cluster/cluster-setup.ts +16 -17
- package/src/http-interfaces.ts +16 -2
- package/src/plugin/media.ts +95 -120
- package/src/plugin/plugin-console.ts +11 -0
- package/src/plugin/plugin-host.ts +14 -4
- package/src/plugin/plugin-remote-worker.ts +1 -1
- package/src/plugin/plugin-remote.ts +43 -41
- package/src/rpc-serializer.ts +4 -0
- package/src/scrypted-cluster-main.ts +24 -0
- package/src/scrypted-server-main.ts +34 -16
- package/src/services/cluster-fork.ts +3 -3
- package/src/services/plugin.ts +6 -0
|
@@ -46,6 +46,18 @@ if (SCRYPTED_SERVER_LISTEN_HOSTNAMES) {
|
|
|
46
46
|
}
|
|
47
47
|
}
|
|
48
48
|
|
|
49
|
+
// constant time comparison for password hashes and tokens so the string comparison
|
|
50
|
+
// does not leak how many leading characters matched.
|
|
51
|
+
function timingSafeStringEqual(a: string | undefined, b: string | undefined) {
|
|
52
|
+
if (typeof a !== 'string' || typeof b !== 'string')
|
|
53
|
+
return false;
|
|
54
|
+
const ab = Buffer.from(a);
|
|
55
|
+
const bb = Buffer.from(b);
|
|
56
|
+
if (ab.length !== bb.length)
|
|
57
|
+
return false;
|
|
58
|
+
return crypto.timingSafeEqual(ab, bb);
|
|
59
|
+
}
|
|
60
|
+
|
|
49
61
|
async function listenServerPort(env: string, port: number, server: http.Server | https.Server | net.Server) {
|
|
50
62
|
server.listen(port);
|
|
51
63
|
try {
|
|
@@ -187,7 +199,7 @@ async function start(mainFilename: string, options?: {
|
|
|
187
199
|
hash.update(salted);
|
|
188
200
|
const sha = hash.digest().toString('hex');
|
|
189
201
|
|
|
190
|
-
callback(sha
|
|
202
|
+
callback(timingSafeStringEqual(sha, user.passwordHash) || timingSafeStringEqual(password, user.token));
|
|
191
203
|
});
|
|
192
204
|
|
|
193
205
|
// the default http-auth will returns a WWW-Authenticate header if login fails.
|
|
@@ -273,7 +285,7 @@ async function start(mainFilename: string, options?: {
|
|
|
273
285
|
// lack of login from cookie auth.
|
|
274
286
|
|
|
275
287
|
const checkToken = (token: string) => {
|
|
276
|
-
if (process.env.SCRYPTED_ADMIN_TOKEN
|
|
288
|
+
if (process.env.SCRYPTED_ADMIN_TOKEN && timingSafeStringEqual(process.env.SCRYPTED_ADMIN_TOKEN, token)) {
|
|
277
289
|
let username = process.env.SCRYPTED_ADMIN_USERNAME;
|
|
278
290
|
if (!username) {
|
|
279
291
|
const firstAdmin = [...scrypted.usersService.users.values()].find(u => !u.aclId);
|
|
@@ -287,7 +299,7 @@ async function start(mainFilename: string, options?: {
|
|
|
287
299
|
}
|
|
288
300
|
|
|
289
301
|
for (const user of scrypted.usersService.users.values()) {
|
|
290
|
-
if (user.token
|
|
302
|
+
if (timingSafeStringEqual(user.token, token)) {
|
|
291
303
|
res.locals.username = user._id;
|
|
292
304
|
res.locals.aclId = user.aclId;
|
|
293
305
|
break;
|
|
@@ -302,7 +314,7 @@ async function start(mainFilename: string, options?: {
|
|
|
302
314
|
hash.update(salted);
|
|
303
315
|
const sha = hash.digest().toString('hex');
|
|
304
316
|
|
|
305
|
-
if (checkHash
|
|
317
|
+
if (timingSafeStringEqual(checkHash, sha)) {
|
|
306
318
|
const userToken = checkValidUserToken(tokenPart);
|
|
307
319
|
if (userToken) {
|
|
308
320
|
res.locals.username = userToken.username;
|
|
@@ -551,8 +563,10 @@ async function start(mainFilename: string, options?: {
|
|
|
551
563
|
return undefined;
|
|
552
564
|
try {
|
|
553
565
|
const userToken = UserToken.validateToken(token);
|
|
554
|
-
|
|
555
|
-
|
|
566
|
+
const user = scrypted.usersService.users.get(userToken.username);
|
|
567
|
+
if (!user || userToken.timestamp < user.passwordDate || userToken.aclId !== user.aclId)
|
|
568
|
+
return undefined;
|
|
569
|
+
return userToken;
|
|
556
570
|
}
|
|
557
571
|
catch (e) {
|
|
558
572
|
// console.warn('invalid token', e.message);
|
|
@@ -594,9 +608,13 @@ async function start(mainFilename: string, options?: {
|
|
|
594
608
|
};
|
|
595
609
|
}
|
|
596
610
|
|
|
611
|
+
async function updateUser(user: ScryptedUser) {
|
|
612
|
+
await db.upsert(user);
|
|
613
|
+
scrypted.usersService.users.set(user._id, user);
|
|
614
|
+
}
|
|
615
|
+
|
|
597
616
|
app.post('/login', async (req, res) => {
|
|
598
617
|
const { username, password, change_password, maxAge: maxAgeRequested } = req.body;
|
|
599
|
-
const timestamp = Date.now();
|
|
600
618
|
const maxAge = parseInt(maxAgeRequested) || ONE_DAY_MILLISECONDS;
|
|
601
619
|
const alternateAddresses = await getAlternateAddresses();
|
|
602
620
|
|
|
@@ -614,7 +632,7 @@ async function start(mainFilename: string, options?: {
|
|
|
614
632
|
const hash = crypto.createHash('sha256');
|
|
615
633
|
hash.update(salted);
|
|
616
634
|
const sha = hash.digest().toString('hex');
|
|
617
|
-
if (user.passwordHash
|
|
635
|
+
if (!timingSafeStringEqual(user.passwordHash, sha) && !timingSafeStringEqual(user.token, password)) {
|
|
618
636
|
res.send({
|
|
619
637
|
error: 'Incorrect password.',
|
|
620
638
|
hasLogin,
|
|
@@ -622,7 +640,12 @@ async function start(mainFilename: string, options?: {
|
|
|
622
640
|
return;
|
|
623
641
|
}
|
|
624
642
|
|
|
625
|
-
|
|
643
|
+
if (change_password) {
|
|
644
|
+
setScryptedUserPassword(user, change_password, Date.now());
|
|
645
|
+
await updateUser(user);
|
|
646
|
+
}
|
|
647
|
+
|
|
648
|
+
const userToken = new UserToken(username, user.aclId, Date.now(), maxAge);
|
|
626
649
|
const login_user_token = userToken.toString();
|
|
627
650
|
res.cookie(getLoginUserToken(req), login_user_token, {
|
|
628
651
|
maxAge,
|
|
@@ -631,11 +654,6 @@ async function start(mainFilename: string, options?: {
|
|
|
631
654
|
httpOnly: true,
|
|
632
655
|
});
|
|
633
656
|
|
|
634
|
-
if (change_password) {
|
|
635
|
-
setScryptedUserPassword(user, change_password, timestamp);
|
|
636
|
-
await db.upsert(user);
|
|
637
|
-
}
|
|
638
|
-
|
|
639
657
|
res.send({
|
|
640
658
|
...createTokens(userToken),
|
|
641
659
|
username,
|
|
@@ -657,7 +675,7 @@ async function start(mainFilename: string, options?: {
|
|
|
657
675
|
const user = await scrypted.usersService.addUserInternal(username, password, undefined);
|
|
658
676
|
hasLogin = true;
|
|
659
677
|
|
|
660
|
-
const userToken = new UserToken(username, user.aclId,
|
|
678
|
+
const userToken = new UserToken(username, user.aclId, Date.now());
|
|
661
679
|
const login_user_token = userToken.toString();
|
|
662
680
|
res.cookie(getLoginUserToken(req), login_user_token, {
|
|
663
681
|
maxAge,
|
|
@@ -725,7 +743,7 @@ async function start(mainFilename: string, options?: {
|
|
|
725
743
|
const user = await db.tryGet(ScryptedUser, username) as ScryptedUser;
|
|
726
744
|
if (!user.token) {
|
|
727
745
|
user.token = crypto.randomBytes(16).toString('hex');
|
|
728
|
-
await
|
|
746
|
+
await updateUser(user);
|
|
729
747
|
}
|
|
730
748
|
|
|
731
749
|
const userToken = new UserToken(user._id, user.aclId, Date.now());
|
|
@@ -92,9 +92,9 @@ export class ClusterForkService {
|
|
|
92
92
|
});
|
|
93
93
|
forkResultPromise.then(forkResult => {
|
|
94
94
|
forkResult.clusterWorkerId = worker.id;
|
|
95
|
-
forkResult.waitKilled().catch(() => { })
|
|
96
|
-
|
|
97
|
-
|
|
95
|
+
return forkResult.waitKilled().catch(() => { });
|
|
96
|
+
}).catch(() => { }).finally(() => {
|
|
97
|
+
worker.forks.delete(options);
|
|
98
98
|
});
|
|
99
99
|
|
|
100
100
|
const ret: ClusterForkResultInterface = new WrappedForkResult(worker.id, forkResultPromise);
|
package/src/services/plugin.ts
CHANGED
|
@@ -172,6 +172,12 @@ export class PluginComponent {
|
|
|
172
172
|
consoleServer.clear(pluginDevice.nativeId);
|
|
173
173
|
}
|
|
174
174
|
|
|
175
|
+
async readConsole(id: string) {
|
|
176
|
+
const pluginDevice = this.scrypted.findPluginDeviceById(id)!;
|
|
177
|
+
const consoleServer = await this.scrypted.plugins[pluginDevice.pluginId]!.consoleServer;
|
|
178
|
+
return consoleServer.read(pluginDevice.nativeId).toString();
|
|
179
|
+
}
|
|
180
|
+
|
|
175
181
|
async getRemoteServicePort(pluginId: string, name: string, ...args: any[]): Promise<[number, string]> {
|
|
176
182
|
if (name === 'console') {
|
|
177
183
|
const consoleServer = await this.scrypted.plugins[pluginId]!.consoleServer;
|