mirror of
https://github.com/balena-os/balena-supervisor.git
synced 2025-01-18 18:56:24 +00:00
Use crypto.randomBytes for API secret
This commit is contained in:
parent
0373607c56
commit
8de173f6c3
@ -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",
|
||||
|
@ -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.
|
||||
|
9
src/lib/random-hex-string.coffee
Normal file
9
src/lib/random-hex-string.coffee
Normal 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)
|
Loading…
Reference in New Issue
Block a user