Generate tokens and ids with cryptoUtils module.

Move object ID, token, and random string generation into their own
module, cryptoUtils.

Remove hat dependency, which was used to generate session and some other
tokens, because it  used non-cryptographic random number generator.
Replace it with the cryptographically secure one. The result has the
same format (32-character hex string, 128 bits of entropy).

Remove randomstring dependency, as we already have this functionality.

Add tests.
This commit is contained in:
Dmitry Chestnykh
2016-02-12 02:02:55 +01:00
parent 0c75f6022d
commit 62cbc451aa
8 changed files with 142 additions and 41 deletions

View File

@@ -1,6 +1,5 @@
// These methods handle the User-related routes.
import hat from 'hat';
import deepcopy from 'deepcopy';
import ClassesRouter from './ClassesRouter';
@@ -9,8 +8,7 @@ import rest from '../rest';
import Auth from '../Auth';
import passwordCrypto from '../password';
import RestWrite from '../RestWrite';
const rack = hat.rack();
import { newToken } from '../cryptoUtils';
export class UsersRouter extends ClassesRouter {
handleFind(req) {
@@ -89,7 +87,7 @@ export class UsersRouter extends ClassesRouter {
throw new Parse.Error(Parse.Error.OBJECT_NOT_FOUND, 'Invalid username/password.');
}
let token = 'r:' + rack();
let token = 'r:' + newToken();
user.sessionToken = token;
delete user.password;