feature(config) add algo

This commit is contained in:
coderaiser 2015-03-24 07:07:03 -04:00
parent 56a7c49cbc
commit 4c06854897
5 changed files with 36 additions and 29 deletions

View file

@ -183,6 +183,7 @@ Here is description of options:
"auth" : false, /* enable http authentication */
"username" : "root", /* username for authentication */
"password" : "toor", /* password hash in sha-1 for authentication*/
"algo" : "sha512WithRSAEncryption", /* cryptographic algorithm */
"editor" : "edward", /* default, could be "dword" or "edward" */
"diff" : true, /* when save - send patch, not whole file */
"zip" : true, /* zip text before send / unzip before save */

View file

@ -2,6 +2,7 @@
"auth": false,
"username": "root",
"password": "2b64f2e3f9fee1942af9ff60d40aa5a719db33b8ba8dd4864bb4f11e25ca2bee00907de32a59429602336cac832c8f2eeff5177cc14c864dd116c8bf6ca5d9a9",
"algo": "sha512WithRSAEncryption",
"editor": "edward",
"diff": true,
"zip" : true,

View file

@ -3,10 +3,9 @@
var DIR = './',
crypto = require('crypto'),
tryRequire = require('tryrequire'),
config = require(DIR + 'config'),
cryptPassword = require(DIR + 'password'),
oldPass,
oldName;
@ -32,11 +31,11 @@
var auth = httpAuth.basic({
realm: 'Cloud Commander'
}, function (username, password, callback) {
var hash, sha,
var hash,
name = config('username'),
pass = config('password'),
equal = username === name,
algo = 'sha512WithRSAEncryption';
algo = config('algo');
if (!oldPass)
oldPass = pass;
@ -47,17 +46,12 @@
if (!equal)
username === oldName;
sha = crypto.createHash(algo);
sha.update(password);
hash = sha.digest('hex');
hash = cryptPassword(algo, password);
equal = pass === hash && equal;
if (!equal) {
sha = crypto.createHash(algo);
sha.update(oldPass);
hash = sha.digest('hex');
equal = pass === hash && equal;
hash = cryptPassword(algo, oldPass);
equal = pass === hash && equal;
}
callback(equal);

View file

@ -11,14 +11,13 @@
HOME = (HOME_UNIX || HOME_WIN) + '/',
fs = require('fs'),
crypto = require('crypto'),
password = require(DIR_SERVER + 'password'),
Util = require(DIR_LIB + 'util'),
CloudFunc = require(DIR_LIB + 'cloudfunc'),
check = require('checkup'),
tryRequire = require('tryrequire'),
pipe = require('pipe-io'),
ponse = require('ponse'),
json = require('jonny'),
@ -32,11 +31,11 @@
tryRequire(ConfigHome) ||
tryRequire(ConfigPath, {log: true}) || {};
module.exports = set;
module.exports = manage;
module.exports.save = save;
module.exports.socket = socket;
function set(key, value) {
function manage(key, value) {
var result;
if (key)
@ -154,25 +153,17 @@
Object.keys(json).forEach(function(name) {
data = CloudFunc.formatMsg('config', name);
set(name, json[name]);
manage(name, json[name]);
});
return data;
}
function cryptoPass(json) {
var algo = manage('algo');
if (json && json.password)
json.password = crypt(json.password);
}
function crypt(password) {
var result,
sha = crypto.createHash('sha512WithRSAEncryption');
sha.update(password);
result = sha.digest('hex');
return result;
json.password = password(algo, json.password);
}
})();

20
lib/server/password.js Normal file
View file

@ -0,0 +1,20 @@
(function() {
'use strict';
var crypto = require('crypto');
module.exports = function(algo, password) {
var result, sha;
if (!algo)
algo = 'sha512WithRSAEncryption';
sha = crypto.createHash(algo);
sha.update(password);
result = sha.digest('hex');
return result;
};
})();