5.4.7: added support for ancient vk videos & salt improvements

- now you can download 240p hardbass videos from 2008!
- implemented updated stream salt and ip salt properly
This commit is contained in:
wukko
2023-04-29 21:30:59 +06:00
parent 1f40cb9fab
commit 6e097de2db
7 changed files with 38 additions and 16 deletions

View File

@@ -1,10 +1,12 @@
import NodeCache from "node-cache";
import { randomBytes } from "crypto";
import { nanoid } from 'nanoid';
import { sha256 } from "../sub/crypto.js";
import { streamLifespan } from "../config.js";
const streamCache = new NodeCache({ stdTTL: streamLifespan/1000, checkperiod: 10, deleteOnExpire: true });
const streamSalt = randomBytes(64).toString('hex');
streamCache.on("expired", (key) => {
streamCache.del(key);
@@ -13,7 +15,7 @@ streamCache.on("expired", (key) => {
export function createStream(obj) {
let streamID = nanoid(),
exp = Math.floor(new Date().getTime()) + streamLifespan,
ghmac = sha256(`${streamID},${obj.ip},${obj.service},${exp}`, process.env.streamSalt);
ghmac = sha256(`${streamID},${obj.ip},${obj.service},${exp}`, streamSalt);
if (!streamCache.has(streamID)) {
streamCache.set(streamID, {
@@ -46,7 +48,7 @@ export function verifyStream(ip, id, hmac, exp) {
let streamInfo = streamCache.get(id);
if (!streamInfo) return { error: 'this stream token does not exist', status: 400 };
let ghmac = sha256(`${id},${ip},${streamInfo.service},${exp}`, process.env.streamSalt);
let ghmac = sha256(`${id},${ip},${streamInfo.service},${exp}`, streamSalt);
if (String(hmac) === ghmac && String(exp) === String(streamInfo.exp) && ghmac === String(streamInfo.hmac)
&& String(ip) === streamInfo.ip && Number(exp) > Math.floor(new Date().getTime())) {
return streamInfo;