Regenerating fresh cookie

Regenerating fresh cookie
This commit is contained in:
ShahanaFarooqui 2019-04-03 22:36:08 -04:00
parent 65209239e8
commit 0ca3ed99b3
3 changed files with 17 additions and 4 deletions

View File

@ -204,7 +204,7 @@ const setSSOParams = (config) => {
} else {
common.rtl_cookie_path = common.rtl_conf_file_path + '/cookies/auth.cookie';
}
readCookie(common.rtl_cookie_path);
connect.readCookie(common.rtl_cookie_path);
}
};
@ -221,7 +221,7 @@ const createDirectory = (dirname) => {
}
}
const readCookie = (cookieFile) => {
connect.readCookie = (cookieFile) => {
let exists = fs.existsSync(cookieFile);
if (exists) {
common.cookie = fs.readFileSync(cookieFile, 'utf-8');
@ -239,6 +239,17 @@ const readCookie = (cookieFile) => {
}
}
connect.refreshCookie = (cookieFile) => {
try {
fs.writeFileSync(cookieFile, crypto.randomBytes(64).toString('hex'));
common.cookie = fs.readFileSync(cookieFile, 'utf-8');
}
catch(err) {
console.error('Something went wrong while refreshing cookie: \n' + err);
throw new Error(err);
}
}
String.random = function (length) {
let radom13chars = function () {
return Math.random().toString(16).substring(2, 15).toUpperCase();
@ -290,4 +301,4 @@ connect.configFileExists = () => {
}
}
module.exports = connect.configFileExists();
module.exports = connect;

View File

@ -1,6 +1,7 @@
var ini = require('ini');
var fs = require('fs');
var common = require('../common');
var connect = require('../connect');
const jwt = require("jsonwebtoken");
var upperCase = require('upper-case');
var atob = require('atob');
@ -32,6 +33,7 @@ exports.authenticateUser = (req, res, next) => {
// Replace access_key value from req.cookies['access-key'] to req.body.password to test SSO on http
// const access_key = atob(req.body.password);
if (common.cookie === access_key) {
connect.refreshCookie(common.rtl_cookie_path);
const token = jwt.sign(
{ user: 'Custom_User', lndConfigPath: common.lnd_config_path, macaroonPath: common.macaroon_path },
common.secret_key

2
rtl.js
View File

@ -2,7 +2,7 @@ const app = require("./app");
const common = require("./common");
const debug = require("debug")("node-angular");
const http = require("http");
var connect = require('./connect'); //Do NOT Remove
var connect = require('./connect').configFileExists(); //Do NOT Remove
const onError = error => {
if (error.syscall !== "listen") {