Permalink
Browse files

Externalize key for flag HMACs

(refactoring for #260)
  • Loading branch information...
bkimminich committed Jan 25, 2017
1 parent db067aa commit 4930dc2415900333f39ac00011898d423aba7544
Showing with 13 additions and 3 deletions.
  1. +1 −0 ctf.key
  2. +11 −2 lib/utils.js
  3. +1 −1 server.js
View
@@ -0,0 +1 @@
TRwzkRJnHOTckssAeyJbysWgP!Qc2T
View
@@ -1,6 +1,7 @@
/* jslint node: true */
'use strict'
var fs = require('fs')
var colors = require('colors/safe')
var notifications = require('../data/datacache').notifications
var packageJson = require('../package.json')
@@ -11,6 +12,14 @@ var entities = new Entities()
var months = ['JAN', 'FEB', 'MAR', 'APR', 'MAY', 'JUN', 'JUL', 'AUG', 'SEP', 'OCT', 'NOV', 'DEC']
var ctfKey
fs.readFile('ctf.key', 'utf8', function (err, data) {
if (err) {
throw err
}
ctfKey = data
})
exports.queryResultToJson = function (data, status) {
var wrappedData = {}
if (data) {
@@ -69,7 +78,7 @@ exports.version = function (module) {
exports.toHmac = function (text) {
var shaObj = new jsSHA('SHA-1', 'TEXT') // eslint-disable-line new-cap
shaObj.setHMACKey('TRwzkRJnHOTckssAeyJbysWgP!Qc2T', 'TEXT')
shaObj.setHMACKey(ctfKey, 'TEXT')
shaObj.update(text)
return shaObj.getHMAC('HEX')
}
@@ -85,7 +94,7 @@ exports.solve = function (challenge) {
console.log(colors.green('Solved') + ' challenge ' + colors.cyan(challenge.name) + ' (' + challenge.description + ')')
notifications.push({challenge: challenge.description, flag: flag})
if (global.io) {
global.io.emit('challenge solved', {id: challenge.name, challenge: challenge.description, flag: flag})
global.io.emit('challenge solved', {challenge: challenge.description, flag: flag})
}
})
}
View
@@ -161,7 +161,7 @@ app.use(errorhandler())
io.on('connection', function (socket) {
// send all outstanding notifications on (re)connect
notifications.forEach(function (notification) {
socket.emit('challenge solved', { id: notification.id, challenge: notification.challenge, flag: notification.flag })
socket.emit('challenge solved', {challenge: notification.challenge, flag: notification.flag })
})
socket.on('notification received', function (data) {
var i = notifications.indexOf(data)

0 comments on commit 4930dc2

Please sign in to comment.