mirror of
https://github.com/jambonz/sbc-sip-sidecar.git
synced 2026-07-04 19:32:03 +00:00
update db-helper
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user