center: support node18 crypto

pull/464/head
undefined 2 years ago
parent e32f285876
commit 067eb2c348

@ -1,15 +1,15 @@
import assert from 'assert';
import crypto from 'crypto';
import crypto from 'crypto-js';
import {
db, definePlugin, ForbiddenError, Handler, post, Types, yaml,
} from 'hydrooj';
function decrypt(encrypted: string) {
if (!encrypted) throw new Error();
const decipher = crypto.createDecipheriv('des-ecb', 'hydro-oj', '');
let decrypted = decipher.update(encrypted, 'hex', 'utf8');
decrypted += decipher.final('utf8');
return decrypted;
return crypto.DES.decrypt(
{ ciphertext: crypto.enc.Hex.parse(encrypted) },
crypto.enc.Utf8.parse('hydro-oj'),
{ mode: crypto.mode.ECB },
).toString(crypto.enc.Utf8);
}
declare module 'hydrooj' {
@ -38,6 +38,7 @@ class DataReportHandler extends Handler {
try {
assert(typeof payload.url === 'string');
} catch (e) {
console.log(payload);
throw new ForbiddenError();
}
const old = await coll.findOne({ _id: installId });

@ -1,6 +1,6 @@
{
"name": "@hydrooj/center",
"version": "0.2.0",
"version": "0.2.1",
"main": "index.ts",
"repository": "https://github.com/hydro-dev/Hydro.git",
"author": "undefined <i@undefined.moe>",
@ -8,5 +8,8 @@
"preferUnplugged": true,
"peerDependencies": {
"hydrooj": "*"
},
"dependencies": {
"crypto-js": "^4.1.1"
}
}

Loading…
Cancel
Save