Use constants for security types

Makes everything much more readable.
This commit is contained in:
Pierre Ossman 2022-08-18 14:53:10 +02:00
parent 6719b932cf
commit e1174e813b
1 changed files with 43 additions and 29 deletions

View File

@ -54,6 +54,21 @@ const GESTURE_SCRLSENS = 50;
const DOUBLE_TAP_TIMEOUT = 1000; const DOUBLE_TAP_TIMEOUT = 1000;
const DOUBLE_TAP_THRESHOLD = 50; const DOUBLE_TAP_THRESHOLD = 50;
// Security types
const securityTypeNone = 1;
const securityTypeVNCAuth = 2;
const securityTypeRA2ne = 6;
const securityTypeTight = 16;
const securityTypeVeNCrypt = 19;
const securityTypeXVP = 22;
const securityTypeARD = 30;
// Special Tight security types
const securityTypeUnixLogon = 129;
// VeNCrypt security types
const securityTypePlain = 256;
// Extended clipboard pseudo-encoding formats // Extended clipboard pseudo-encoding formats
const extendedClipboardFormatText = 1; const extendedClipboardFormatText = 1;
/*eslint-disable no-unused-vars */ /*eslint-disable no-unused-vars */
@ -1356,20 +1371,20 @@ export default class RFB extends EventTargetMixin {
Log.Debug("Server security types: " + types); Log.Debug("Server security types: " + types);
// Look for each auth in preferred order // Look for each auth in preferred order
if (types.includes(1)) { if (types.includes(securityTypeNone)) {
this._rfbAuthScheme = 1; // None this._rfbAuthScheme = securityTypeNone;
} else if (types.includes(22)) { } else if (types.includes(securityTypeXVP)) {
this._rfbAuthScheme = 22; // XVP this._rfbAuthScheme = securityTypeXVP;
} else if (types.includes(16)) { } else if (types.includes(securityTypeTight)) {
this._rfbAuthScheme = 16; // Tight this._rfbAuthScheme = securityTypeTight;
} else if (types.includes(6)) { } else if (types.includes(securityTypeRA2ne)) {
this._rfbAuthScheme = 6; // RA2ne Auth this._rfbAuthScheme = securityTypeRA2ne;
} else if (types.includes(2)) { } else if (types.includes(securityTypeVNCAuth)) {
this._rfbAuthScheme = 2; // VNC Auth this._rfbAuthScheme = securityTypeVNCAuth;
} else if (types.includes(30)) { } else if (types.includes(securityTypeARD)) {
this._rfbAuthScheme = 30; // ARD Auth this._rfbAuthScheme = securityTypeARD;
} else if (types.includes(19)) { } else if (types.includes(securityTypeVeNCrypt)) {
this._rfbAuthScheme = 19; // VeNCrypt Auth this._rfbAuthScheme = securityTypeVeNCrypt;
} else { } else {
return this._fail("Unsupported security types (types: " + types + ")"); return this._fail("Unsupported security types (types: " + types + ")");
} }
@ -1441,7 +1456,7 @@ export default class RFB extends EventTargetMixin {
this._rfbCredentials.username + this._rfbCredentials.username +
this._rfbCredentials.target; this._rfbCredentials.target;
this._sock.sendString(xvpAuthStr); this._sock.sendString(xvpAuthStr);
this._rfbAuthScheme = 2; this._rfbAuthScheme = securityTypeVNCAuth;
return this._negotiateAuthentication(); return this._negotiateAuthentication();
} }
@ -1499,8 +1514,7 @@ export default class RFB extends EventTargetMixin {
subtypes.push(this._sock.rQshift32()); subtypes.push(this._sock.rQshift32());
} }
// 256 = Plain subtype if (subtypes.indexOf(securityTypePlain) != -1) {
if (subtypes.indexOf(256) != -1) {
// 0x100 = 256 // 0x100 = 256
this._sock.send([0, 0, 1, 0]); this._sock.send([0, 0, 1, 0]);
this._rfbVeNCryptState = 4; this._rfbVeNCryptState = 4;
@ -1778,11 +1792,11 @@ export default class RFB extends EventTargetMixin {
case 'STDVNOAUTH__': // no auth case 'STDVNOAUTH__': // no auth
this._rfbInitState = 'SecurityResult'; this._rfbInitState = 'SecurityResult';
return true; return true;
case 'STDVVNCAUTH_': // VNC auth case 'STDVVNCAUTH_':
this._rfbAuthScheme = 2; this._rfbAuthScheme = securityTypeVNCAuth;
return true; return true;
case 'TGHTULGNAUTH': // UNIX auth case 'TGHTULGNAUTH':
this._rfbAuthScheme = 129; this._rfbAuthScheme = securityTypeUnixLogon;
return true; return true;
default: default:
return this._fail("Unsupported tiny auth scheme " + return this._fail("Unsupported tiny auth scheme " +
@ -1834,29 +1848,29 @@ export default class RFB extends EventTargetMixin {
_negotiateAuthentication() { _negotiateAuthentication() {
switch (this._rfbAuthScheme) { switch (this._rfbAuthScheme) {
case 1: // no auth case securityTypeNone:
this._rfbInitState = 'SecurityResult'; this._rfbInitState = 'SecurityResult';
return true; return true;
case 22: // XVP auth case securityTypeXVP:
return this._negotiateXvpAuth(); return this._negotiateXvpAuth();
case 30: // ARD auth case securityTypeARD:
return this._negotiateARDAuth(); return this._negotiateARDAuth();
case 2: // VNC authentication case securityTypeVNCAuth:
return this._negotiateStdVNCAuth(); return this._negotiateStdVNCAuth();
case 16: // TightVNC Security Type case securityTypeTight:
return this._negotiateTightAuth(); return this._negotiateTightAuth();
case 19: // VeNCrypt Security Type case securityTypeVeNCrypt:
return this._negotiateVeNCryptAuth(); return this._negotiateVeNCryptAuth();
case 129: // TightVNC UNIX Security Type case securityTypeUnixLogon:
return this._negotiateTightUnixAuth(); return this._negotiateTightUnixAuth();
case 6: // RA2ne Security Type case securityTypeRA2ne:
return this._negotiateRA2neAuth(); return this._negotiateRA2neAuth();
default: default: