Fixed GCM cookie decoding authtag.

Ylian Saint-Hilaire committed May 3, 2020 at 14:12 UTC 43c8567b0d20e61827d78d3230dab6d53664f640
2 files changed +2 -2
db.js
+1 -1
@@ -296,7 +296,7 @@ module.exports.CreateDB = function (parent, func) {
296 const iv = ciphertextBytes.slice(0, 12);
297 const data = ciphertextBytes.slice(28);
298 const aes = parent.crypto.createDecipheriv('aes-256-gcm', obj.dbRecordsDecryptKey, iv);
299 - aes.setAuthTag(ciphertextBytes.slice(12, 16));
299 + aes.setAuthTag(ciphertextBytes.slice(12, 28));
300 var plaintextBytes, r;
301 try {
302 plaintextBytes = Buffer.from(aes.update(data));
meshcentral.js
+1 -1
@@ -2236,7 +2236,7 @@ function CreateMeshCentralServer(config, args) {
2236 if (key == null) { key = obj.serverKey; }
2237 cookie = Buffer.from(cookie.replace(/\@/g, '+').replace(/\$/g, '/'), obj.args.cookieencoding ? obj.args.cookieencoding : 'base64');
2238 const decipher = obj.crypto.createDecipheriv('aes-256-gcm', key.slice(0, 32), cookie.slice(0, 12));
2239 - decipher.setAuthTag(cookie.slice(12, 16));
2239 + decipher.setAuthTag(cookie.slice(12, 28));
2240 const o = JSON.parse(decipher.update(cookie.slice(28), 'binary', 'utf8') + decipher.final('utf8'));
2241 if ((o.time == null) || (o.time == null) || (typeof o.time != 'number')) { obj.debug('cookie', 'ERR: Bad cookie due to invalid time'); return null; }
2242 o.time = o.time * 1000; // Decode the cookie creation time