diff --git a/main.js b/main.js index de5fd68..8aa58e3 100644 --- a/main.js +++ b/main.js @@ -8,6 +8,7 @@ var macaroons = require('macaroons.js'); var pathToRegexp = require('path-to-regexp'); var basicAuth = require('basic-auth'); var baseCat = require('./base-cat.json'); +var randomstring = require('randomstring'); var PORT = process.env.PORT || 8080; @@ -357,19 +358,13 @@ app.get('/store/secret', function (req, res) { } if (req.container.secret) { - res.send(req.container.secret.toString('base64')); + res.send(req.container.secret); return; } - crypto.randomBytes(macaroons.MacaroonsConstants.MACAROON_SUGGESTED_SECRET_LENGTH, function(err, buffer){ - if (err != null) { - res.status(500).send('Unable to register container (secret generation)'); - return; - } + req.container.secret = new Buffer(randomstring.generate({ length: 128 })).toString('base64'); + res.send(req.container.secret); - req.container.secret = buffer; - res.send(buffer.toString('base64')); - }); }); console.log("starting server",credentials); diff --git a/package.json b/package.json index ffda40b..870c565 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "databox-arbiter", - "version": "0.3.0", + "version": "0.3.1", "description": "The Databox Docker container that manages the flow of data", "config": { "registry": "registry.iotdatabox.com" @@ -47,6 +47,7 @@ "modclean": "", "path-to-regexp": "^1.7.0", "pug": "^2.0.0-beta11", + "randomstring": "^1.1.5", "request": "^2.72.0" }, "devDependencies": { diff --git a/test/stores.js b/test/stores.js index 0f6e13b..f64b965 100644 --- a/test/stores.js +++ b/test/stores.js @@ -107,7 +107,7 @@ describe('Test store endpoints', function() { .send(testStore) .expect(function (res) { // TODO: Error handling - res.text = Buffer.from(res.text, 'base64').length === 32; + res.text = Buffer.from(res.text, 'base64').length === 128; }) .expect(200, true, done); }); @@ -120,7 +120,7 @@ describe('Test store endpoints', function() { .send(testStore) .expect(function (res) { // TODO: Error handling - res.text = Buffer.from(res.text, 'base64').length === 32; + res.text = Buffer.from(res.text, 'base64').length === 128; }) .expect(200, true, done); }); diff --git a/test/tokens.js b/test/tokens.js index 400a438..06afd8e 100644 --- a/test/tokens.js +++ b/test/tokens.js @@ -111,7 +111,7 @@ describe('Test token endpoint', function() { .expect(function (res) { storeSecret = res.text; // TODO: Error handling - res.text = Buffer.from(res.text, 'base64').length === 32; + res.text = Buffer.from(res.text, 'base64').length === 128; }) .expect(200, true, done); });