Skip to content

Commit

Permalink
Merge pull request #30 from jptmoore/string-secret
Browse files Browse the repository at this point in the history
using string-based secrets for easier debugging and help with issue v…
  • Loading branch information
yousefamar committed Jul 26, 2017
2 parents de02a20 + 516aaba commit af244c6
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 13 deletions.
13 changes: 4 additions & 9 deletions main.js
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion 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"
Expand Down Expand Up @@ -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": {
Expand Down
4 changes: 2 additions & 2 deletions test/stores.js
Expand Up @@ -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);
});
Expand All @@ -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);
});
Expand Down
2 changes: 1 addition & 1 deletion test/tokens.js
Expand Up @@ -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);
});
Expand Down

0 comments on commit af244c6

Please sign in to comment.