Skip to content

Commit c4aa0ef

Browse files
committed
dev-bl/config-ip: Add dataset to token hash.
1 parent 0f26ee5 commit c4aa0ef

File tree

3 files changed

+25
-14
lines changed

3 files changed

+25
-14
lines changed

build/app/unisys/common-session.js

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,12 @@ var m_current_groupid = null;
2929
containing as many decoded values as possible. Check isValid for
3030
complete decode succes. groupId is also set if successful
3131
/*/
32-
SESUTIL.DecodeToken = function(token) {
32+
SESUTIL.DecodeToken = function(token, dataset) {
3333
if (token === undefined) return {};
34+
if (dataset === undefined) {
35+
console.error('SESUTIL.DecodeToken called without "dataset" parameter.');
36+
return {};
37+
}
3438
let tokenBits = token.split("-");
3539
let classId, projId, hashedId, groupId, subId, isValid;
3640
// optimistically set valid flag to be negated on failure
@@ -46,7 +50,7 @@ SESUTIL.DecodeToken = function(token) {
4650
if (tokenBits[2]) hashedId = tokenBits[2].toUpperCase();
4751
if (tokenBits[3]) subId = tokenBits[3].toUpperCase();
4852
// initialize hashid structure
49-
let salt = `${classId}${projId}`;
53+
let salt = `${classId}${projId}${dataset}`;
5054
let hashids = new HashIds(salt, HASH_MINLEN, HASH_ABET);
5155
// try to decode the groupId
5256
groupId = hashids.decode(hashedId)[0];
@@ -88,16 +92,16 @@ SESUTIL.DecodeToken = function(token) {
8892
/// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
8993
/*/ Return TRUE if the token decodes into an expected range of values
9094
/*/
91-
SESUTIL.IsValidToken = function(token) {
92-
let decoded = SESUTIL.DecodeToken(token);
95+
SESUTIL.IsValidToken = function(token, dataset) {
96+
let decoded = SESUTIL.DecodeToken(token, dataset);
9397
return decoded && Number.isInteger(decoded.groupId);
9498
};
9599
/// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
96100
/*/ Returns a token string of form CLASS-PROJECT-HASHEDID
97101
classId and projId should be short and are case-insensitive.
98102
groupId must be a non-negative integer
99103
/*/
100-
SESUTIL.MakeToken = function(classId, projId, groupId) {
104+
SESUTIL.MakeToken = function(classId, projId, groupId, dataset) {
101105
// type checking
102106
if (typeof classId !== "string")
103107
throw Error(`classId arg1 '${classId}' must be string`);
@@ -114,7 +118,7 @@ SESUTIL.MakeToken = function(classId, projId, groupId) {
114118
// initialize hashid structure
115119
classId = classId.toUpperCase();
116120
projId = projId.toUpperCase();
117-
let salt = `${classId}${projId}`;
121+
let salt = `${classId}${projId}${dataset}`;
118122
let hashids = new HashIds(salt, HASH_MINLEN, HASH_ABET);
119123
let hashedId = hashids.encode(groupId);
120124
return `${classId}-${projId}-${hashedId}`;
@@ -124,7 +128,12 @@ SESUTIL.MakeToken = function(classId, projId, groupId) {
124128
/*/ Set the global GROUPID, which is included in all NetMessage
125129
packets that are sent to server.
126130
/*/
127-
SESUTIL.SetGroupID = function(token) {
131+
// REVIEW/FIXME
132+
// `SetGroupID` isn't being called by anyone?
133+
// If it is, the DecodeToken call needs to add a 'dataset' parameter or it will
134+
// fail.
135+
SESUTIL.SetGroupID = function (token) {
136+
console.error('SetGroupID calling decodeToken NC_CONFIG IS', window.NC_CONFIG);
128137
let good = SESUTIL.DecodeToken(token).isValid;
129138
if (good) m_current_groupid = token;
130139
return good;

build/app/unisys/component/SessionShell.jsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ class SessionShell extends UNISYS.Component {
174174
// login after a ForceReload. This is a bit hacky and the app would benefit
175175
// from not relying on forced reloads. See handleChange().
176176
let token = this.props.match.params.token;
177-
let decoded = SESSION.DecodeToken(token) || {};
177+
let decoded = SESSION.DecodeToken(token, window.NC_CONFIG.dataset) || {};
178178
this.SetAppState("SESSION", decoded);
179179
}
180180
/// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@@ -203,7 +203,7 @@ class SessionShell extends UNISYS.Component {
203203
let token = this.props.match.params.token;
204204
if (!token) return this.renderLogin();
205205
// try to decode token
206-
let decoded = SESSION.DecodeToken(token);
206+
let decoded = SESSION.DecodeToken(token, window.NC_CONFIG.dataset);
207207
if (decoded.isValid) {
208208
return this.renderLoggedIn(decoded);
209209
} else {
@@ -215,7 +215,7 @@ class SessionShell extends UNISYS.Component {
215215
/// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
216216
handleChange(event) {
217217
let token = event.target.value;
218-
let decoded = SESSION.DecodeToken(token);
218+
let decoded = SESSION.DecodeToken(token, window.NC_CONFIG.dataset);
219219
let { classId, projId, hashedId, subId, groupId } = decoded;
220220
this.setState(decoded);
221221
}

build/app/view/netcreate/nc-logic.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1105,12 +1105,14 @@ JSCLI.AddFunction(
11051105
/// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
11061106
/*/ Command: Token Generator
11071107
/*/
1108-
JSCLI.AddFunction(function ncMakeTokens(clsId, projId, numGroups) {
1108+
JSCLI.AddFunction(function ncMakeTokens(clsId, projId, dataset, numGroups) {
11091109
// type checking
11101110
if (typeof clsId !== "string")
1111-
return "args: str classId, str projId, int numGroups";
1111+
return "args: str classId, str projId, str dataset, int numGroups";
11121112
if (typeof projId !== "string")
1113-
return "args: str classId, str projId, int numGroups";
1113+
return "args: str classId, str projId, str dataset, int numGroups";
1114+
if (typeof dataset !== "string")
1115+
return "args: str classId, str projId, str dataset, int numGroups";
11141116
if (clsId.length > 12) return "classId arg1 should be 12 chars or less";
11151117
if (projId.length > 12) return "classId arg1 should be 12 chars or less";
11161118
if (!Number.isInteger(numGroups)) return "numGroups arg3 must be integer";
@@ -1121,7 +1123,7 @@ JSCLI.AddFunction(function ncMakeTokens(clsId, projId, numGroups) {
11211123
for (let i = 1; i <= numGroups; i++) {
11221124
let id = String(i);
11231125
id = id.padStart(pad, "0");
1124-
out += `group ${id}\t${SESSION.MakeToken(clsId, projId, i)}\n`;
1126+
out += `group ${id}\t${SESSION.MakeToken(clsId, projId, i, dataset)}\n`;
11251127
}
11261128
if (window && window.location) {
11271129
let ubits = new URL(window.location);

0 commit comments

Comments
 (0)