From 3df8b3d18f2230f3df6814967bb59f8954c2f218 Mon Sep 17 00:00:00 2001 From: Findeton Date: Thu, 27 Jun 2024 16:38:38 -0500 Subject: [PATCH 1/6] wip --- avBooth/booth-directive/booth-directive.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/avBooth/booth-directive/booth-directive.js b/avBooth/booth-directive/booth-directive.js index 526814ab..9fa79592 100644 --- a/avBooth/booth-directive/booth-directive.js +++ b/avBooth/booth-directive/booth-directive.js @@ -773,9 +773,9 @@ angular.module('avBooth') } // verify message, which should be of the format - // "userid:vote:AuthEvent:1110:134234111" + // "userid:AuthEvent:34570195:vote:1719523403:timeout-token:1719523283" var splitMessage = hmac.message.split(':'); - if (splitMessage.length !== 5) { + if (splitMessage.length !== 7) { showError( "avBooth.errorLoadingElection", { @@ -789,6 +789,7 @@ angular.module('avBooth') var objectType = splitMessage[1]; var objectId = splitMessage[2]; var action = splitMessage[3]; + var startTimeSecsStr = splitMessage[4]; // timestamp has already been validated so we don't validate it again if ( isNaN(parseInt(objectId, 10)) || @@ -810,13 +811,12 @@ angular.module('avBooth') scope.authorizationHeader = currentElectionCredentials.token; scope.currentElectionCredentials = currentElectionCredentials; scope.isDemo = false; + scope.startTimeMs = Number(startTimeSecsStr) * 1000; } - var startTimeMs = Date.now(); - function getSessionStartTime() { readVoteCredentials(); - return scope.currentElectionCredentials && scope.currentElectionCredentials.sessionStartedAtMs || startTimeMs; + return scope.currentElectionCredentials && scope.currentElectionCredentials.sessionStartedAtMs || scope.startTimeMs; } // After cookies expires, redirect to login. But only if cookies do From 43c1e445c8dfc773e72316fe4adbaeeafd835435 Mon Sep 17 00:00:00 2001 From: Findeton Date: Fri, 28 Jun 2024 14:07:04 -0500 Subject: [PATCH 2/6] wip --- avBooth/booth-directive/booth-directive.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/avBooth/booth-directive/booth-directive.js b/avBooth/booth-directive/booth-directive.js index 9fa79592..4c5b0ba4 100644 --- a/avBooth/booth-directive/booth-directive.js +++ b/avBooth/booth-directive/booth-directive.js @@ -814,9 +814,9 @@ angular.module('avBooth') scope.startTimeMs = Number(startTimeSecsStr) * 1000; } - function getSessionStartTime() { + function getSessionEndTime() { readVoteCredentials(); - return scope.currentElectionCredentials && scope.currentElectionCredentials.sessionStartedAtMs || scope.startTimeMs; + return scope.currentElectionCredentials && scope.currentElectionCredentials.sessionStartedAtMs || (scope.sessionEndsAtMs + ConfigService.authTokenExpirationSeconds * 1000); } // After cookies expires, redirect to login. But only if cookies do @@ -843,11 +843,11 @@ angular.module('avBooth') ) ) { - var logoutTimeMs = getSessionStartTime() + ConfigService.authTokenExpirationSeconds * 1000; + var logoutTimeMs = getSessionEndTime(); setTimeout( function tryTimeout() { - var newLogoutTimeMs = getSessionStartTime() + ConfigService.authTokenExpirationSeconds * 1000; + var newLogoutTimeMs = getSessionEndTime(); if (newLogoutTimeMs > Date.now()) { logoutTimeMs = newLogoutTimeMs; setTimeout( @@ -1345,7 +1345,7 @@ angular.module('avBooth') next: next, redirectToLogin: redirectToLogin, checkFixToBottom: checkFixToBottom, - getSessionStartTime: getSessionStartTime, + getSessionEndTime: getSessionEndTime, isStateCompatibleWithCountdown: isStateCompatibleWithCountdown, // stateData stores information used by the directive being shown. From 908fad47b7011d17e3ac07e4141eec01795c5283 Mon Sep 17 00:00:00 2001 From: Findeton Date: Sun, 30 Jun 2024 12:34:16 -0500 Subject: [PATCH 3/6] wip --- avBooth/booth-directive/booth-directive.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/avBooth/booth-directive/booth-directive.js b/avBooth/booth-directive/booth-directive.js index 4c5b0ba4..487cbeee 100644 --- a/avBooth/booth-directive/booth-directive.js +++ b/avBooth/booth-directive/booth-directive.js @@ -806,17 +806,21 @@ angular.module('avBooth') return; } + var refreshToken = $http.defaults.headers.common.Authorization; + var decodedRefreshToken = Authmethod.decodeToken(refreshToken); + // set scope.voterId and scope.authorizationHeader scope.voterId = voterId; scope.authorizationHeader = currentElectionCredentials.token; scope.currentElectionCredentials = currentElectionCredentials; scope.isDemo = false; scope.startTimeMs = Number(startTimeSecsStr) * 1000; + scope.sessionEndsAtMs = decodedRefreshToken.expiry_timestamp * 1000; } function getSessionEndTime() { readVoteCredentials(); - return scope.currentElectionCredentials && scope.currentElectionCredentials.sessionStartedAtMs || (scope.sessionEndsAtMs + ConfigService.authTokenExpirationSeconds * 1000); + return scope.sessionEndsAtMs || scope.currentElectionCredentials && scope.currentElectionCredentials.sessionEndsAtMs || (scope.startTimeMs + ConfigService.authTokenExpirationSeconds * 1000); } // After cookies expires, redirect to login. But only if cookies do From 3fac8edc68862aa45d7f291aa50a5109a478db8b Mon Sep 17 00:00:00 2001 From: Findeton Date: Sun, 30 Jun 2024 13:43:30 -0500 Subject: [PATCH 4/6] wip --- avBooth/booth-directive/booth-directive.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/avBooth/booth-directive/booth-directive.js b/avBooth/booth-directive/booth-directive.js index 487cbeee..511d8ab8 100644 --- a/avBooth/booth-directive/booth-directive.js +++ b/avBooth/booth-directive/booth-directive.js @@ -761,6 +761,7 @@ angular.module('avBooth') // token should be valid var hmac = HmacService.checkKhmac(currentElectionCredentials.token); + var decodedToken = Authmethod.decodeToken(currentElectionCredentials.token); if (!hmac) { showError( "avBooth.errorLoadingElection", @@ -806,16 +807,13 @@ angular.module('avBooth') return; } - var refreshToken = $http.defaults.headers.common.Authorization; - var decodedRefreshToken = Authmethod.decodeToken(refreshToken); - // set scope.voterId and scope.authorizationHeader scope.voterId = voterId; scope.authorizationHeader = currentElectionCredentials.token; scope.currentElectionCredentials = currentElectionCredentials; scope.isDemo = false; scope.startTimeMs = Number(startTimeSecsStr) * 1000; - scope.sessionEndsAtMs = decodedRefreshToken.expiry_timestamp * 1000; + scope.sessionEndsAtMs = decodedToken.expiry_timestamp * 1000; } function getSessionEndTime() { From 9f8361b51b848b1081f272e8b001a7153ed4b327 Mon Sep 17 00:00:00 2001 From: Findeton Date: Tue, 2 Jul 2024 18:15:22 -0500 Subject: [PATCH 5/6] wip --- avBooth/booth-directive/booth-directive.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/avBooth/booth-directive/booth-directive.js b/avBooth/booth-directive/booth-directive.js index 511d8ab8..3f7bfd50 100644 --- a/avBooth/booth-directive/booth-directive.js +++ b/avBooth/booth-directive/booth-directive.js @@ -821,6 +821,11 @@ angular.module('avBooth') return scope.sessionEndsAtMs || scope.currentElectionCredentials && scope.currentElectionCredentials.sessionEndsAtMs || (scope.startTimeMs + ConfigService.authTokenExpirationSeconds * 1000); } + function getSessionStartTime() { + readVoteCredentials(); + return scope.startTimeMs || (scope.currentElectionCredentials && scope.currentElectionCredentials.sessionStartedAtMs); + } + // After cookies expires, redirect to login. But only if cookies do // expire. function autoredirectToLoginAfterTimeout() { @@ -1348,6 +1353,7 @@ angular.module('avBooth') redirectToLogin: redirectToLogin, checkFixToBottom: checkFixToBottom, getSessionEndTime: getSessionEndTime, + getSessionStartTime: getSessionStartTime, isStateCompatibleWithCountdown: isStateCompatibleWithCountdown, // stateData stores information used by the directive being shown. From 5165b7cce10a591bad40f95c4e782c5f4b9d3f5c Mon Sep 17 00:00:00 2001 From: Findeton Date: Tue, 2 Jul 2024 19:23:02 -0500 Subject: [PATCH 6/6] wip --- avBooth/booth-directive/booth-directive.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/avBooth/booth-directive/booth-directive.js b/avBooth/booth-directive/booth-directive.js index 3f7bfd50..aca29f8b 100644 --- a/avBooth/booth-directive/booth-directive.js +++ b/avBooth/booth-directive/booth-directive.js @@ -822,7 +822,9 @@ angular.module('avBooth') } function getSessionStartTime() { - readVoteCredentials(); + if (!scope.startTimeMs) { + readVoteCredentials(); + } return scope.startTimeMs || (scope.currentElectionCredentials && scope.currentElectionCredentials.sessionStartedAtMs); }