feature(cloudcmd) middleware: password: plain -> encrypted (#136)

This commit is contained in:
coderaiser 2017-10-02 13:41:02 +03:00
parent 6255bed777
commit 598817a02e
3 changed files with 34 additions and 13 deletions

27
HELP.md
View file

@ -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

View file

@ -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);

View file

@ -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');