make users-test work
This commit is contained in:
11
src/users.js
11
src/users.js
@@ -91,6 +91,7 @@ const CRYPTO_KEY_LENGTH = 512; // bits
|
||||
const CRYPTO_DIGEST = 'sha1'; // used to be the default in node 4.1.1 cannot change since it will affect existing db records
|
||||
|
||||
const pbkdf2Async = util.promisify(crypto.pbkdf2);
|
||||
const randomBytesAsync = util.promisify(crypto.randomBytes);
|
||||
const getDirectoryConfigAsync = util.promisify(settings.getDirectoryConfig);
|
||||
|
||||
function postProcess(result) {
|
||||
@@ -203,10 +204,9 @@ async function add(email, data, auditSource) {
|
||||
error = validateRole(role);
|
||||
if (error) throw error;
|
||||
|
||||
const randomBytes = util.promisify(crypto.randomBytes);
|
||||
let salt, derivedKey;
|
||||
|
||||
[error, salt] = await safe(randomBytes(CRYPTO_SALT_SIZE));
|
||||
[error, salt] = await safe(randomBytesAsync(CRYPTO_SALT_SIZE));
|
||||
if (error) throw new BoxError(BoxError.CRYPTO_ERROR, error);
|
||||
|
||||
[error, derivedKey] = await safe(pbkdf2Async(password, salt, CRYPTO_ITERATIONS, CRYPTO_KEY_LENGTH, CRYPTO_DIGEST));
|
||||
@@ -611,13 +611,14 @@ async function setPassword(user, newPassword, auditSource) {
|
||||
if (settings.isDemo() && user.username === constants.DEMO_USERNAME) throw new BoxError(BoxError.BAD_FIELD, 'Not allowed in demo mode');
|
||||
if (user.source) throw new BoxError(BoxError.CONFLICT, 'User is from an external directory');
|
||||
|
||||
const saltBuffer = Buffer.from(user.salt, 'hex');
|
||||
let salt, derivedKey;
|
||||
[error, salt] = await safe(randomBytesAsync(CRYPTO_SALT_SIZE));
|
||||
|
||||
let derivedKey;
|
||||
[error, derivedKey] = await safe(pbkdf2Async(newPassword, saltBuffer, CRYPTO_ITERATIONS, CRYPTO_KEY_LENGTH, CRYPTO_DIGEST));
|
||||
[error, derivedKey] = await safe(pbkdf2Async(newPassword, salt, CRYPTO_ITERATIONS, CRYPTO_KEY_LENGTH, CRYPTO_DIGEST));
|
||||
if (error) throw new BoxError(BoxError.CRYPTO_ERROR, error);
|
||||
|
||||
const data = {
|
||||
salt: salt.toString('hex'),
|
||||
password: Buffer.from(derivedKey, 'binary').toString('hex'),
|
||||
resetToken: ''
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user