Fixed GCM cookie decoding authtag.

This commit is contained in:
Ylian Saint-Hilaire 2020-05-03 14:12:26 -07:00
parent 32e99e67e3
commit 76c34dfa70
2 changed files with 2 additions and 2 deletions

2
db.js
View File

@ -296,7 +296,7 @@ module.exports.CreateDB = function (parent, func) {
const iv = ciphertextBytes.slice(0, 12); const iv = ciphertextBytes.slice(0, 12);
const data = ciphertextBytes.slice(28); const data = ciphertextBytes.slice(28);
const aes = parent.crypto.createDecipheriv('aes-256-gcm', obj.dbRecordsDecryptKey, iv); const aes = parent.crypto.createDecipheriv('aes-256-gcm', obj.dbRecordsDecryptKey, iv);
aes.setAuthTag(ciphertextBytes.slice(12, 16)); aes.setAuthTag(ciphertextBytes.slice(12, 28));
var plaintextBytes, r; var plaintextBytes, r;
try { try {
plaintextBytes = Buffer.from(aes.update(data)); plaintextBytes = Buffer.from(aes.update(data));

View File

@ -2236,7 +2236,7 @@ function CreateMeshCentralServer(config, args) {
if (key == null) { key = obj.serverKey; } if (key == null) { key = obj.serverKey; }
cookie = Buffer.from(cookie.replace(/\@/g, '+').replace(/\$/g, '/'), obj.args.cookieencoding ? obj.args.cookieencoding : 'base64'); cookie = Buffer.from(cookie.replace(/\@/g, '+').replace(/\$/g, '/'), obj.args.cookieencoding ? obj.args.cookieencoding : 'base64');
const decipher = obj.crypto.createDecipheriv('aes-256-gcm', key.slice(0, 32), cookie.slice(0, 12)); const decipher = obj.crypto.createDecipheriv('aes-256-gcm', key.slice(0, 32), cookie.slice(0, 12));
decipher.setAuthTag(cookie.slice(12, 16)); decipher.setAuthTag(cookie.slice(12, 28));
const o = JSON.parse(decipher.update(cookie.slice(28), 'binary', 'utf8') + decipher.final('utf8')); const o = JSON.parse(decipher.update(cookie.slice(28), 'binary', 'utf8') + decipher.final('utf8'));
if ((o.time == null) || (o.time == null) || (typeof o.time != 'number')) { obj.debug('cookie', 'ERR: Bad cookie due to invalid time'); return null; } if ((o.time == null) || (o.time == null) || (typeof o.time != 'number')) { obj.debug('cookie', 'ERR: Bad cookie due to invalid time'); return null; }
o.time = o.time * 1000; // Decode the cookie creation time o.time = o.time * 1000; // Decode the cookie creation time