Improved MPS error messages.

Ylian Saint-Hilaire committed Apr 1, 2021 at 13:53 UTC 8ec41c70464fddf223e344dcaddb53a9dd57e130
1 file changed +35 -5
mpsserver.js
+35 -5
@@ -561,8 +561,20 @@ module.exports.CreateMpsServer = function (parent, db, args, certificates) {
561 // If the login uses a cookie, check this now
562 if ((username == '**MeshAgentApfTunnel**') && (password != null)) {
563 const cookie = parent.decodeCookie(password, parent.loginCookieEncryptionKey);
564 - if ((cookie == null) || (cookie.a !== 'apf')) { incorrectPasswordCount++; parent.debug('mps', 'Incorrect password', username, password); SendUserAuthFail(socket); return -1; }
565 - if (obj.parent.webserver.meshes[cookie.m] == null) { meshNotFoundCount++; parent.debug('mps', 'Device group not found', username, password); SendUserAuthFail(socket); return -1; }
564 + if ((cookie == null) || (cookie.a !== 'apf')) {
565 + incorrectPasswordCount++;
566 + socket.ControlMsg({ action: 'console', msg: 'Invalid login username/password' });
567 + parent.debug('mps', 'Incorrect password', username, password);
568 + SendUserAuthFail(socket);
569 + return -1;
570 + }
571 + if (obj.parent.webserver.meshes[cookie.m] == null) {
572 + meshNotFoundCount++;
573 + socket.ControlMsg({ action: 'console', msg: 'Device group not found' });
574 + parent.debug('mps', 'Device group not found', username, password);
575 + SendUserAuthFail(socket);
576 + return -1;
577 + }
578
579 // Setup the connection
580 socket.tag.nodeid = cookie.n;
@@ -575,13 +587,31 @@ module.exports.CreateMpsServer = function (parent, db, args, certificates) {
587 return 18 + usernameLen + serviceNameLen + methodNameLen + passwordLen;
588 } else {
589 // Check the CIRA password
578 - if ((args.mpspass != null) && (password != args.mpspass)) { incorrectPasswordCount++; parent.debug('mps', 'Incorrect password', username, password); SendUserAuthFail(socket); return -1; }
590 + if ((args.mpspass != null) && (password != args.mpspass)) {
591 + incorrectPasswordCount++;
592 + socket.ControlMsg({ action: 'console', msg: 'Invalid login username/password' });
593 + parent.debug('mps', 'Incorrect password', username, password);
594 + SendUserAuthFail(socket);
595 + return -1;
596 + }
597
598 // Check the CIRA username, which should be the start of the MeshID.
581 - if (usernameLen != 16) { badUserNameLengthCount++; parent.debug('mps', 'Username length not 16', username, password); SendUserAuthFail(socket); return -1; }
599 + if (usernameLen != 16) {
600 + badUserNameLengthCount++;
601 + socket.ControlMsg({ action: 'console', msg: 'Username length not 16' });
602 + parent.debug('mps', 'Username length not 16', username, password);
603 + SendUserAuthFail(socket);
604 + return -1;
605 + }
606 var meshIdStart = '/' + username, mesh = null;
607 if (obj.parent.webserver.meshes) { for (var i in obj.parent.webserver.meshes) { if (obj.parent.webserver.meshes[i]._id.replace(/\@/g, 'X').replace(/\$/g, 'X').indexOf(meshIdStart) > 0) { mesh = obj.parent.webserver.meshes[i]; break; } } }
584 - if (mesh == null) { meshNotFoundCount++; parent.debug('mps', 'Device group not found', username, password); SendUserAuthFail(socket); return -1; }
608 + if (mesh == null) {
609 + meshNotFoundCount++;
610 + socket.ControlMsg({ action: 'console', msg: 'Device group not found' });
611 + parent.debug('mps', 'Device group not found', username, password);
612 + SendUserAuthFail(socket);
613 + return -1;
614 + }
615 }
616
617 // If this is a agent-less mesh, use the device guid 3 times as ID.