mirror of
https://github.com/jambonz/sbc-sip-sidecar.git
synced 2026-10-04 02:04:20 +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 bent = require('bent');
|
||||||
const qs = require('qs');
|
const qs = require('qs');
|
||||||
const crypto = require('crypto');
|
const crypto = require('crypto');
|
||||||
const { decrypt } = require('./utils');
|
|
||||||
const toBase64 = (str) => Buffer.from(str || '', 'utf8').toString('base64');
|
const toBase64 = (str) => Buffer.from(str || '', 'utf8').toString('base64');
|
||||||
|
|
||||||
function basicAuth(username, password) {
|
function basicAuth(username, password) {
|
||||||
@@ -172,8 +171,7 @@ async function clientAuthentication(logger, data, req) {
|
|||||||
if (clients.length) {
|
if (clients.length) {
|
||||||
// Only take the first result.
|
// Only take the first result.
|
||||||
const client = clients[0];
|
const client = clients[0];
|
||||||
const password = decrypt(client.password);
|
if (calculateResponse(data, client.password) === response) {
|
||||||
if (calculateResponse(data, password) === response) {
|
|
||||||
return {
|
return {
|
||||||
status: 'ok',
|
status: 'ok',
|
||||||
statusCode: 200
|
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) {
|
function isUacBehindNat(req) {
|
||||||
|
|
||||||
// no need for nat handling if wss or tcp being used
|
// 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';
|
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 = {
|
module.exports = {
|
||||||
isUacBehindNat,
|
isUacBehindNat,
|
||||||
getSipProtocol,
|
getSipProtocol,
|
||||||
decrypt,
|
|
||||||
NAT_EXPIRES: 30
|
NAT_EXPIRES: 30
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user