From 2f1fa93ffcfcc586d5d9d62b9c3f202a3ef7762a Mon Sep 17 00:00:00 2001 From: Jian Gao Date: Thu, 15 Nov 2018 11:01:03 +0800 Subject: [PATCH 1/2] Make the reletive file path against zlux-example-server/bin/ explicitly Signed-off-by: Jian Gao --- js/plugin-loader.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/js/plugin-loader.js b/js/plugin-loader.js index c661cc76..3e30dc0d 100644 --- a/js/plugin-loader.js +++ b/js/plugin-loader.js @@ -326,6 +326,10 @@ Plugin.prototype = { else { throw new Error (`No file name for data service`) } + // Make the relative path clear. process.cwd() is zlux-example-server/bin/ + if (!path.isAbsolute(fileLocation)) { + fileLocation = path.join(process.cwd(),fileLocation); + } const nodeModule = require(fileLocation); dataservice.nodeModule = nodeModule; } @@ -427,7 +431,11 @@ NodeAuthenticationPlugIn.prototype = { }, init(context) { - const filepath = path.join(this.location, 'lib', this.filename); + let filepath = path.join(this.location, 'lib', this.filename); + // Make the relative path clear. process.cwd() is zlux-example-server/bin/ + if (!path.isAbsolute(filepath)) { + filepath = path.join(process.cwd(),filepath); + } bootstrapLogger.log(bootstrapLogger.INFO, `Auth plugin ${this.identifier}: loading auth handler module ${filepath}`) this.authenticationModule = require(filepath); From 3388cb1129293055834805f662f8736208549c10 Mon Sep 17 00:00:00 2001 From: Jian Gao Date: Thu, 15 Nov 2018 11:20:21 +0800 Subject: [PATCH 2/2] Add a function to get key from password in sync way Signed-off-by: Jian Gao --- js/encryption.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/js/encryption.js b/js/encryption.js index 7df1bb37..029abe9a 100644 --- a/js/encryption.js +++ b/js/encryption.js @@ -19,6 +19,11 @@ function encryptWithKey(text,key) { return encrypted; } +function getKeyFromPasswordSync(password,salt,length) { + var rounds = 500; + return crypto.pbkdf2Sync(password,salt,rounds,length,'sha256'); +} + function getKeyFromPassword(password,salt,length,callback) { var rounds = 500; crypto.pbkdf2(password,salt,rounds,length,'sha256',(error, derivedKey) => { @@ -54,6 +59,7 @@ function decryptWithKeyAndIV(text,key,iv) { exports.encryptWithKeyAndIV = encryptWithKeyAndIV; exports.decryptWithKeyAndIV = decryptWithKeyAndIV; exports.getKeyFromPassword = getKeyFromPassword; +exports.getKeyFromPasswordSync = getKeyFromPasswordSync; exports.encryptWithKey = encryptWithKey; exports.decryptWithKey = decryptWithKey;