Skip to content

Commit 4930dc2

Browse files
committed
Externalize key for flag HMACs
(refactoring for juice-shop#260)
1 parent db067aa commit 4930dc2

File tree

3 files changed

+13
-3
lines changed

3 files changed

+13
-3
lines changed

ctf.key

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
TRwzkRJnHOTckssAeyJbysWgP!Qc2T

lib/utils.js

+11-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/* jslint node: true */
22
'use strict'
33

4+
var fs = require('fs')
45
var colors = require('colors/safe')
56
var notifications = require('../data/datacache').notifications
67
var packageJson = require('../package.json')
@@ -11,6 +12,14 @@ var entities = new Entities()
1112

1213
var months = ['JAN', 'FEB', 'MAR', 'APR', 'MAY', 'JUN', 'JUL', 'AUG', 'SEP', 'OCT', 'NOV', 'DEC']
1314

15+
var ctfKey
16+
fs.readFile('ctf.key', 'utf8', function (err, data) {
17+
if (err) {
18+
throw err
19+
}
20+
ctfKey = data
21+
})
22+
1423
exports.queryResultToJson = function (data, status) {
1524
var wrappedData = {}
1625
if (data) {
@@ -69,7 +78,7 @@ exports.version = function (module) {
6978

7079
exports.toHmac = function (text) {
7180
var shaObj = new jsSHA('SHA-1', 'TEXT') // eslint-disable-line new-cap
72-
shaObj.setHMACKey('TRwzkRJnHOTckssAeyJbysWgP!Qc2T', 'TEXT')
81+
shaObj.setHMACKey(ctfKey, 'TEXT')
7382
shaObj.update(text)
7483
return shaObj.getHMAC('HEX')
7584
}
@@ -85,7 +94,7 @@ exports.solve = function (challenge) {
8594
console.log(colors.green('Solved') + ' challenge ' + colors.cyan(challenge.name) + ' (' + challenge.description + ')')
8695
notifications.push({challenge: challenge.description, flag: flag})
8796
if (global.io) {
88-
global.io.emit('challenge solved', {id: challenge.name, challenge: challenge.description, flag: flag})
97+
global.io.emit('challenge solved', {challenge: challenge.description, flag: flag})
8998
}
9099
})
91100
}

server.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ app.use(errorhandler())
161161
io.on('connection', function (socket) {
162162
// send all outstanding notifications on (re)connect
163163
notifications.forEach(function (notification) {
164-
socket.emit('challenge solved', { id: notification.id, challenge: notification.challenge, flag: notification.flag })
164+
socket.emit('challenge solved', {challenge: notification.challenge, flag: notification.flag })
165165
})
166166
socket.on('notification received', function (data) {
167167
var i = notifications.indexOf(data)

0 commit comments

Comments
 (0)