Add ability to setup a ghost account for caas

This commit is contained in:
Girish Ramakrishnan
2016-07-12 10:07:55 -07:00
parent 94ee636254
commit 743a8650f0
3 changed files with 149 additions and 0 deletions

View File

@@ -26,6 +26,7 @@ exports = module.exports = {
var assert = require('assert'),
clients = require('./clients.js'),
crypto = require('crypto'),
constants = require('./constants.js'),
debug = require('debug')('box:user'),
DatabaseError = require('./databaseerror.js'),
eventlog = require('./eventlog.js'),
@@ -34,6 +35,7 @@ var assert = require('assert'),
hat = require('hat'),
mailer = require('./mailer.js'),
mailboxes = require('./mailboxes.js'),
safe = require('safetydance'),
tokendb = require('./tokendb.js'),
userdb = require('./userdb.js'),
util = require('util'),
@@ -189,6 +191,23 @@ function createUser(username, password, email, displayName, auditSource, options
});
}
// returns true if ghost user was matched
function verifyGhost(username, password) {
assert.strictEqual(typeof username, 'string');
assert.strictEqual(typeof password, 'string');
var ghostFile = safe.fs.readFileSync(constants.GHOST_USER_FILE, 'utf8');
var ghostData = safe.JSON.parse(ghostFile);
if (!ghostData) return false;
if (username in ghostData && ghostData[username] === password) {
debug('verifyGhost: matched ghost user');
return true;
}
return false;
}
function verify(userId, password, callback) {
assert.strictEqual(typeof userId, 'string');
assert.strictEqual(typeof password, 'string');
@@ -198,6 +217,8 @@ function verify(userId, password, callback) {
if (error && error.reason == DatabaseError.NOT_FOUND) return callback(new UserError(UserError.NOT_FOUND));
if (error) return callback(new UserError(UserError.INTERNAL_ERROR, error));
if (verifyGhost(user.username, password)) return callback(null, user);
var saltBinary = new Buffer(user.salt, 'hex');
crypto.pbkdf2(password, saltBinary, CRYPTO_ITERATIONS, CRYPTO_KEY_LENGTH, function (error, derivedKey) {
if (error) return callback(new UserError(UserError.INTERNAL_ERROR, error));