Use crypto.randomBytes for API secret

This commit is contained in:
Pablo Carranza Vélez 2015-09-01 14:11:46 -03:00
parent 0373607c56
commit 8de173f6c3
3 changed files with 14 additions and 4 deletions

View File

@ -22,7 +22,6 @@
"ngrok": "~0.1.97",
"pinejs-client": "^1.4.0",
"pubnub": "^3.7.13",
"randomstring": "~1.0.3",
"request": "^2.51.0",
"resin-register-device": "^2.0.0",
"rwlock": "^5.0.0",

View File

@ -21,10 +21,12 @@ knex.init.then ->
api = require './api'
application = require('./application')(uuid)
device = require './device'
randomstring = require 'randomstring'
secret = config.forceApiSecret ? randomstring.generate()
randomHexString = require './lib/random-hex-string'
bootstrap.done.then ->
bootstrap.done
.then ->
return config.forceApiSecret ? randomHexString.generate()
.then (secret) ->
console.log('Starting API server..')
api(secret, application).listen(config.listenPort)
# Let API know what version we are, and our api connection info.

View File

@ -0,0 +1,9 @@
Promise = require('bluebird')
crypto = require('crypto')
exports.generate = (length = 32, callback) ->
Promise.try ->
crypto.randomBytes(length).toString('hex')
.catch ->
Promise.delay(1).then(exports.generate)
.nodeify(callback)