diff --git a/HELP.md b/HELP.md index 84491848..e646434c 100644 --- a/HELP.md +++ b/HELP.md @@ -503,6 +503,33 @@ server.listen(port); And you are ready to go. +### Authorization + +If you want to enable `authorization` you can pass credentials in a `config`. +To generate password you can install `criton` with `npm i criton --save` and use it +or any other way to generate a `hash` of a `password`. + +```js +const criton = require('criton'); +const algo = 'sha512WithRSAEncryption'; // default + +// you can generate hash dynamically +const password = criton('root', algo); + +// or use pregenerated hash as well +'2b64f2e..ca5d9a9'; + +const auth = true; +const username = 'root'; + +const config = { + algo, // optional + auth, + username, + pasword, +} +``` + Server --------------- Standard practices say no non-root process gets to talk to diff --git a/server/cloudcmd.js b/server/cloudcmd.js index 18a8d1d4..f8e536b1 100644 --- a/server/cloudcmd.js +++ b/server/cloudcmd.js @@ -30,7 +30,6 @@ const remedy = require('remedy'); const ishtar = require('ishtar'); const salam = require('salam'); const omnes = require('omnes'); -const criton = require('criton'); const setUrl = currify(_setUrl); @@ -56,30 +55,23 @@ module.exports = (params) => { const keys = Object.keys(options); - let prefix; - checkPlugins(plugins); keys.forEach((name) => { - let value = options[name]; + const value = options[name]; switch(name) { case 'root': validate.root(value); break; + case 'editor': validate.editor(value); break; + case 'packer': validate.packer(value); break; - case 'password': - /* could be useful when used as middleware */ - value = criton(value, config('algo')); - break; - case 'prefix': - prefix = prefixer(value); - break; } config(name, value); @@ -88,6 +80,8 @@ module.exports = (params) => { config('console', defaultValue('console', options)); config('configDialog', defaultValue('configDialog', options)); + const prefix = prefixer(options.prefix); + if (p.socket) listen(prefix, p.socket); diff --git a/test/server/cloudcmd.js b/test/server/cloudcmd.js index f650f4f4..397ccc3d 100644 --- a/test/server/cloudcmd.js +++ b/test/server/cloudcmd.js @@ -1,6 +1,7 @@ 'use strict'; const test = require('tape'); + const DIR = '../../server/'; const cloudcmd = require(DIR + 'cloudcmd'); const config = require(DIR + 'config'); @@ -34,8 +35,7 @@ test('cloudcmd: defaults: config', (t) => { }); test('cloudcmd: defaults: console', (t) => { - const console = config('console'); - + const console = config('console'); config('console', false); cloudcmd(); t.notOk(config('console'), 'should not override config with defaults');