update db-helper

This commit is contained in:
Quan HL
2023-06-14 19:40:11 +07:00
parent 3bf0255023
commit 78ea63b8ea
2 changed files with 1 additions and 18 deletions
+1 -3
View File
@@ -3,7 +3,6 @@ const debug = require('debug')('jambonz:sbc-registrar');
const bent = require('bent');
const qs = require('qs');
const crypto = require('crypto');
const { decrypt } = require('./utils');
const toBase64 = (str) => Buffer.from(str || '', 'utf8').toString('base64');
function basicAuth(username, password) {
@@ -172,8 +171,7 @@ async function clientAuthentication(logger, data, req) {
if (clients.length) {
// Only take the first result.
const client = clients[0];
const password = decrypt(client.password);
if (calculateResponse(data, password) === response) {
if (calculateResponse(data, client.password) === response) {
return {
status: 'ok',
statusCode: 200
-15
View File
@@ -1,10 +1,3 @@
const crypto = require('crypto');
const algorithm = process.env.LEGACY_CRYPTO ? 'aes-256-ctr' : 'aes-256-cbc';
const secretKey = crypto.createHash('sha256')
.update(process.env.ENCRYPTION_SECRET || process.env.JWT_SECRET)
.digest('base64')
.substring(0, 32);
function isUacBehindNat(req) {
// no need for nat handling if wss or tcp being used
@@ -21,16 +14,8 @@ function getSipProtocol(req) {
if (req.getParsedHeader('Via')[0].protocol.toLowerCase().startsWith('udp')) return 'udp';
}
const decrypt = (data) => {
const hash = JSON.parse(data);
const decipher = crypto.createDecipheriv(algorithm, secretKey, Buffer.from(hash.iv, 'hex'));
const decrpyted = Buffer.concat([decipher.update(Buffer.from(hash.content, 'hex')), decipher.final()]);
return decrpyted.toString();
};
module.exports = {
isUacBehindNat,
getSipProtocol,
decrypt,
NAT_EXPIRES: 30
};