Use crypto.timingSafeEqual() vs hand rolled method for constant time password comparison
This commit is contained in:
parent
70f160daa3
commit
65ef1feb6c
14
core/user.js
14
core/user.js
|
@ -60,18 +60,6 @@ module.exports = class User {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
static isSamePasswordSlowCompare(passBuf1, passBuf2) {
|
|
||||||
if(passBuf1.length !== passBuf2.length) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
let c = 0;
|
|
||||||
for(let i = 0; i < passBuf1.length; i++) {
|
|
||||||
c |= passBuf1[i] ^ passBuf2[i];
|
|
||||||
}
|
|
||||||
return 0 === c;
|
|
||||||
}
|
|
||||||
|
|
||||||
isAuthenticated() {
|
isAuthenticated() {
|
||||||
return true === this.authenticated;
|
return true === this.authenticated;
|
||||||
}
|
}
|
||||||
|
@ -220,7 +208,7 @@ module.exports = class User {
|
||||||
const passDkBuf = Buffer.from(passDk, 'hex');
|
const passDkBuf = Buffer.from(passDk, 'hex');
|
||||||
const propsDkBuf = Buffer.from(propsDk, 'hex');
|
const propsDkBuf = Buffer.from(propsDk, 'hex');
|
||||||
|
|
||||||
return callback(User.isSamePasswordSlowCompare(passDkBuf, propsDkBuf) ?
|
return callback(crypto.timingSafeEqual(passDkBuf, propsDkBuf) ?
|
||||||
null :
|
null :
|
||||||
Errors.AccessDenied('Invalid password')
|
Errors.AccessDenied('Invalid password')
|
||||||
);
|
);
|
||||||
|
|
Loading…
Reference in New Issue