Skip to content

Commit

Permalink
Merge pull request #866 from pano9000/refactor_session_secret
Browse files Browse the repository at this point in the history
refactor(session_secret): use existing randomSecureToken function
  • Loading branch information
eliandoran authored Jan 1, 2025
2 parents c482cef + 79887d1 commit a8f0520
Showing 1 changed file with 2 additions and 8 deletions.
10 changes: 2 additions & 8 deletions src/services/session_secret.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,18 @@
"use strict";

import fs from "fs";
import crypto from "crypto";
import dataDir from "./data_dir.js";
import log from "./log.js";
import utils from "./utils.js"

const sessionSecretPath = `${dataDir.TRILIUM_DATA_DIR}/session_secret.txt`;

let sessionSecret: string;

const ENCODING = "ascii";

function randomValueHex(len: number) {
return crypto.randomBytes(Math.ceil(len / 2))
.toString('hex') // convert to hexadecimal format
.slice(0, len).toUpperCase(); // return required number of characters
}

if (!fs.existsSync(sessionSecretPath)) {
sessionSecret = randomValueHex(64);
sessionSecret = utils.randomSecureToken(64).slice(0, 64);

log.info("Generated session secret");

Expand Down

0 comments on commit a8f0520

Please sign in to comment.