@novnc/novnc 1.6.0 → 1.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (103) hide show
  1. package/core/base64.js +104 -0
  2. package/core/crypto/aes.js +178 -0
  3. package/core/crypto/bigint.js +34 -0
  4. package/core/crypto/crypto.js +90 -0
  5. package/core/crypto/des.js +330 -0
  6. package/core/crypto/dh.js +55 -0
  7. package/core/crypto/md5.js +82 -0
  8. package/core/crypto/rsa.js +132 -0
  9. package/core/decoders/copyrect.js +27 -0
  10. package/core/decoders/h264.js +321 -0
  11. package/core/decoders/hextile.js +181 -0
  12. package/core/decoders/jpeg.js +161 -0
  13. package/core/decoders/raw.js +59 -0
  14. package/core/decoders/rre.js +44 -0
  15. package/core/decoders/tight.js +393 -0
  16. package/core/decoders/tightpng.js +27 -0
  17. package/core/decoders/zlib.js +51 -0
  18. package/core/decoders/zrle.js +185 -0
  19. package/core/deflator.js +84 -0
  20. package/core/display.js +578 -0
  21. package/core/encodings.js +54 -0
  22. package/core/inflator.js +65 -0
  23. package/core/input/domkeytable.js +311 -0
  24. package/core/input/fixedkeys.js +129 -0
  25. package/core/input/gesturehandler.js +567 -0
  26. package/core/input/keyboard.js +294 -0
  27. package/core/input/keysym.js +616 -0
  28. package/core/input/keysymdef.js +688 -0
  29. package/core/input/util.js +191 -0
  30. package/core/input/vkeys.js +116 -0
  31. package/core/input/xtscancodes.js +173 -0
  32. package/core/ra2.js +312 -0
  33. package/core/rfb.js +3411 -0
  34. package/core/util/browser.js +233 -0
  35. package/core/util/cursor.js +249 -0
  36. package/core/util/element.js +32 -0
  37. package/core/util/events.js +138 -0
  38. package/core/util/eventtarget.js +35 -0
  39. package/core/util/int.js +15 -0
  40. package/core/util/logging.js +56 -0
  41. package/core/util/strings.js +28 -0
  42. package/core/websock.js +369 -0
  43. package/docs/API.md +0 -5
  44. package/package.json +6 -10
  45. package/vendor/pako/LICENSE +21 -0
  46. package/vendor/pako/README.md +6 -0
  47. package/{lib/vendor → vendor}/pako/lib/utils/common.js +13 -23
  48. package/{lib/vendor → vendor}/pako/lib/zlib/adler32.js +12 -14
  49. package/vendor/pako/lib/zlib/constants.js +47 -0
  50. package/{lib/vendor → vendor}/pako/lib/zlib/crc32.js +15 -14
  51. package/{lib/vendor → vendor}/pako/lib/zlib/deflate.js +459 -334
  52. package/{lib/vendor → vendor}/pako/lib/zlib/gzheader.js +13 -19
  53. package/{lib/vendor → vendor}/pako/lib/zlib/inffast.js +116 -119
  54. package/vendor/pako/lib/zlib/inflate.js +1527 -0
  55. package/{lib/vendor → vendor}/pako/lib/zlib/inftrees.js +103 -91
  56. package/vendor/pako/lib/zlib/messages.js +11 -0
  57. package/{lib/vendor → vendor}/pako/lib/zlib/trees.js +313 -268
  58. package/{lib/vendor → vendor}/pako/lib/zlib/zstream.js +4 -10
  59. package/lib/base64.js +0 -100
  60. package/lib/crypto/aes.js +0 -481
  61. package/lib/crypto/bigint.js +0 -41
  62. package/lib/crypto/crypto.js +0 -109
  63. package/lib/crypto/des.js +0 -374
  64. package/lib/crypto/dh.js +0 -81
  65. package/lib/crypto/md5.js +0 -97
  66. package/lib/crypto/rsa.js +0 -312
  67. package/lib/decoders/copyrect.js +0 -40
  68. package/lib/decoders/h264.js +0 -349
  69. package/lib/decoders/hextile.js +0 -195
  70. package/lib/decoders/jpeg.js +0 -175
  71. package/lib/decoders/raw.js +0 -66
  72. package/lib/decoders/rre.js +0 -52
  73. package/lib/decoders/tight.js +0 -363
  74. package/lib/decoders/tightpng.js +0 -51
  75. package/lib/decoders/zlib.js +0 -57
  76. package/lib/decoders/zrle.js +0 -192
  77. package/lib/deflator.js +0 -88
  78. package/lib/display.js +0 -588
  79. package/lib/encodings.js +0 -70
  80. package/lib/inflator.js +0 -77
  81. package/lib/input/domkeytable.js +0 -313
  82. package/lib/input/fixedkeys.js +0 -127
  83. package/lib/input/gesturehandler.js +0 -573
  84. package/lib/input/keyboard.js +0 -293
  85. package/lib/input/keysym.js +0 -878
  86. package/lib/input/keysymdef.js +0 -1351
  87. package/lib/input/util.js +0 -217
  88. package/lib/input/vkeys.js +0 -121
  89. package/lib/input/xtscancodes.js +0 -343
  90. package/lib/ra2.js +0 -535
  91. package/lib/rfb.js +0 -3398
  92. package/lib/util/browser.js +0 -239
  93. package/lib/util/cursor.js +0 -269
  94. package/lib/util/element.js +0 -41
  95. package/lib/util/events.js +0 -133
  96. package/lib/util/eventtarget.js +0 -53
  97. package/lib/util/int.js +0 -21
  98. package/lib/util/logging.js +0 -56
  99. package/lib/util/strings.js +0 -36
  100. package/lib/vendor/pako/lib/zlib/constants.js +0 -47
  101. package/lib/vendor/pako/lib/zlib/inflate.js +0 -1602
  102. package/lib/vendor/pako/lib/zlib/messages.js +0 -25
  103. package/lib/websock.js +0 -395
package/lib/ra2.js DELETED
@@ -1,535 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports["default"] = void 0;
7
- var _strings = require("./util/strings.js");
8
- var _eventtarget = _interopRequireDefault(require("./util/eventtarget.js"));
9
- var _crypto = _interopRequireDefault(require("./crypto/crypto.js"));
10
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
11
- function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
12
- function _possibleConstructorReturn(t, e) { if (e && ("object" == _typeof(e) || "function" == typeof e)) return e; if (void 0 !== e) throw new TypeError("Derived constructors may only return object or undefined"); return _assertThisInitialized(t); }
13
- function _assertThisInitialized(e) { if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); return e; }
14
- function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
15
- function _getPrototypeOf(t) { return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) { return t.__proto__ || Object.getPrototypeOf(t); }, _getPrototypeOf(t); }
16
- function _inherits(t, e) { if ("function" != typeof e && null !== e) throw new TypeError("Super expression must either be null or a function"); t.prototype = Object.create(e && e.prototype, { constructor: { value: t, writable: !0, configurable: !0 } }), Object.defineProperty(t, "prototype", { writable: !1 }), e && _setPrototypeOf(t, e); }
17
- function _setPrototypeOf(t, e) { return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) { return t.__proto__ = e, t; }, _setPrototypeOf(t, e); }
18
- function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
19
- function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator["return"] && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, "catch": function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
20
- function asyncGeneratorStep(n, t, e, r, o, a, c) { try { var i = n[a](c), u = i.value; } catch (n) { return void e(n); } i.done ? t(u) : Promise.resolve(u).then(r, o); }
21
- function _asyncToGenerator(n) { return function () { var t = this, e = arguments; return new Promise(function (r, o) { var a = n.apply(t, e); function _next(n) { asyncGeneratorStep(a, r, o, _next, _throw, "next", n); } function _throw(n) { asyncGeneratorStep(a, r, o, _next, _throw, "throw", n); } _next(void 0); }); }; }
22
- function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
23
- function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } }
24
- function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
25
- function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
26
- function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
27
- var RA2Cipher = /*#__PURE__*/function () {
28
- function RA2Cipher() {
29
- _classCallCheck(this, RA2Cipher);
30
- this._cipher = null;
31
- this._counter = new Uint8Array(16);
32
- }
33
- return _createClass(RA2Cipher, [{
34
- key: "setKey",
35
- value: function () {
36
- var _setKey = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(key) {
37
- return _regeneratorRuntime().wrap(function _callee$(_context) {
38
- while (1) switch (_context.prev = _context.next) {
39
- case 0:
40
- _context.next = 2;
41
- return _crypto["default"].importKey("raw", key, {
42
- name: "AES-EAX"
43
- }, false, ["encrypt, decrypt"]);
44
- case 2:
45
- this._cipher = _context.sent;
46
- case 3:
47
- case "end":
48
- return _context.stop();
49
- }
50
- }, _callee, this);
51
- }));
52
- function setKey(_x) {
53
- return _setKey.apply(this, arguments);
54
- }
55
- return setKey;
56
- }()
57
- }, {
58
- key: "makeMessage",
59
- value: function () {
60
- var _makeMessage = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2(message) {
61
- var ad, encrypted, i, res;
62
- return _regeneratorRuntime().wrap(function _callee2$(_context2) {
63
- while (1) switch (_context2.prev = _context2.next) {
64
- case 0:
65
- ad = new Uint8Array([(message.length & 0xff00) >>> 8, message.length & 0xff]);
66
- _context2.next = 3;
67
- return _crypto["default"].encrypt({
68
- name: "AES-EAX",
69
- iv: this._counter,
70
- additionalData: ad
71
- }, this._cipher, message);
72
- case 3:
73
- encrypted = _context2.sent;
74
- for (i = 0; i < 16 && this._counter[i]++ === 255; i++);
75
- res = new Uint8Array(message.length + 2 + 16);
76
- res.set(ad);
77
- res.set(encrypted, 2);
78
- return _context2.abrupt("return", res);
79
- case 9:
80
- case "end":
81
- return _context2.stop();
82
- }
83
- }, _callee2, this);
84
- }));
85
- function makeMessage(_x2) {
86
- return _makeMessage.apply(this, arguments);
87
- }
88
- return makeMessage;
89
- }()
90
- }, {
91
- key: "receiveMessage",
92
- value: function () {
93
- var _receiveMessage = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee3(length, encrypted) {
94
- var ad, res, i;
95
- return _regeneratorRuntime().wrap(function _callee3$(_context3) {
96
- while (1) switch (_context3.prev = _context3.next) {
97
- case 0:
98
- ad = new Uint8Array([(length & 0xff00) >>> 8, length & 0xff]);
99
- _context3.next = 3;
100
- return _crypto["default"].decrypt({
101
- name: "AES-EAX",
102
- iv: this._counter,
103
- additionalData: ad
104
- }, this._cipher, encrypted);
105
- case 3:
106
- res = _context3.sent;
107
- for (i = 0; i < 16 && this._counter[i]++ === 255; i++);
108
- return _context3.abrupt("return", res);
109
- case 6:
110
- case "end":
111
- return _context3.stop();
112
- }
113
- }, _callee3, this);
114
- }));
115
- function receiveMessage(_x3, _x4) {
116
- return _receiveMessage.apply(this, arguments);
117
- }
118
- return receiveMessage;
119
- }()
120
- }]);
121
- }();
122
- var RSAAESAuthenticationState = exports["default"] = /*#__PURE__*/function (_EventTargetMixin) {
123
- function RSAAESAuthenticationState(sock, getCredentials) {
124
- var _this;
125
- _classCallCheck(this, RSAAESAuthenticationState);
126
- _this = _callSuper(this, RSAAESAuthenticationState);
127
- _this._hasStarted = false;
128
- _this._checkSock = null;
129
- _this._checkCredentials = null;
130
- _this._approveServerResolve = null;
131
- _this._sockReject = null;
132
- _this._credentialsReject = null;
133
- _this._approveServerReject = null;
134
- _this._sock = sock;
135
- _this._getCredentials = getCredentials;
136
- return _this;
137
- }
138
- _inherits(RSAAESAuthenticationState, _EventTargetMixin);
139
- return _createClass(RSAAESAuthenticationState, [{
140
- key: "_waitSockAsync",
141
- value: function _waitSockAsync(len) {
142
- var _this2 = this;
143
- return new Promise(function (resolve, reject) {
144
- var hasData = function hasData() {
145
- return !_this2._sock.rQwait('RA2', len);
146
- };
147
- if (hasData()) {
148
- resolve();
149
- } else {
150
- _this2._checkSock = function () {
151
- if (hasData()) {
152
- resolve();
153
- _this2._checkSock = null;
154
- _this2._sockReject = null;
155
- }
156
- };
157
- _this2._sockReject = reject;
158
- }
159
- });
160
- }
161
- }, {
162
- key: "_waitApproveKeyAsync",
163
- value: function _waitApproveKeyAsync() {
164
- var _this3 = this;
165
- return new Promise(function (resolve, reject) {
166
- _this3._approveServerResolve = resolve;
167
- _this3._approveServerReject = reject;
168
- });
169
- }
170
- }, {
171
- key: "_waitCredentialsAsync",
172
- value: function _waitCredentialsAsync(subtype) {
173
- var _this4 = this;
174
- var hasCredentials = function hasCredentials() {
175
- if (subtype === 1 && _this4._getCredentials().username !== undefined && _this4._getCredentials().password !== undefined) {
176
- return true;
177
- } else if (subtype === 2 && _this4._getCredentials().password !== undefined) {
178
- return true;
179
- }
180
- return false;
181
- };
182
- return new Promise(function (resolve, reject) {
183
- if (hasCredentials()) {
184
- resolve();
185
- } else {
186
- _this4._checkCredentials = function () {
187
- if (hasCredentials()) {
188
- resolve();
189
- _this4._checkCredentials = null;
190
- _this4._credentialsReject = null;
191
- }
192
- };
193
- _this4._credentialsReject = reject;
194
- }
195
- });
196
- }
197
- }, {
198
- key: "checkInternalEvents",
199
- value: function checkInternalEvents() {
200
- if (this._checkSock !== null) {
201
- this._checkSock();
202
- }
203
- if (this._checkCredentials !== null) {
204
- this._checkCredentials();
205
- }
206
- }
207
- }, {
208
- key: "approveServer",
209
- value: function approveServer() {
210
- if (this._approveServerResolve !== null) {
211
- this._approveServerResolve();
212
- this._approveServerResolve = null;
213
- }
214
- }
215
- }, {
216
- key: "disconnect",
217
- value: function disconnect() {
218
- if (this._sockReject !== null) {
219
- this._sockReject(new Error("disconnect normally"));
220
- this._sockReject = null;
221
- }
222
- if (this._credentialsReject !== null) {
223
- this._credentialsReject(new Error("disconnect normally"));
224
- this._credentialsReject = null;
225
- }
226
- if (this._approveServerReject !== null) {
227
- this._approveServerReject(new Error("disconnect normally"));
228
- this._approveServerReject = null;
229
- }
230
- }
231
- }, {
232
- key: "negotiateRA2neAuthAsync",
233
- value: function () {
234
- var _negotiateRA2neAuthAsync = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee4() {
235
- var serverKeyLengthBuffer, serverKeyLength, serverKeyBytes, serverN, serverE, serverRSACipher, serverPublickey, approveKey, clientKeyLength, clientKeyBytes, clientRSACipher, clientExportedRSAKey, clientN, clientE, clientPublicKey, clientRandom, clientEncryptedRandom, clientRandomMessage, serverEncryptedRandom, serverRandom, clientSessionKey, serverSessionKey, clientCipher, serverCipher, serverHash, clientHash, serverHashReceived, i, subtype, waitCredentials, username, password, credentials, _i, _i2;
236
- return _regeneratorRuntime().wrap(function _callee4$(_context4) {
237
- while (1) switch (_context4.prev = _context4.next) {
238
- case 0:
239
- this._hasStarted = true;
240
- // 1: Receive server public key
241
- _context4.next = 3;
242
- return this._waitSockAsync(4);
243
- case 3:
244
- serverKeyLengthBuffer = this._sock.rQpeekBytes(4);
245
- serverKeyLength = this._sock.rQshift32();
246
- if (!(serverKeyLength < 1024)) {
247
- _context4.next = 9;
248
- break;
249
- }
250
- throw new Error("RA2: server public key is too short: " + serverKeyLength);
251
- case 9:
252
- if (!(serverKeyLength > 8192)) {
253
- _context4.next = 11;
254
- break;
255
- }
256
- throw new Error("RA2: server public key is too long: " + serverKeyLength);
257
- case 11:
258
- serverKeyBytes = Math.ceil(serverKeyLength / 8);
259
- _context4.next = 14;
260
- return this._waitSockAsync(serverKeyBytes * 2);
261
- case 14:
262
- serverN = this._sock.rQshiftBytes(serverKeyBytes);
263
- serverE = this._sock.rQshiftBytes(serverKeyBytes);
264
- _context4.next = 18;
265
- return _crypto["default"].importKey("raw", {
266
- n: serverN,
267
- e: serverE
268
- }, {
269
- name: "RSA-PKCS1-v1_5"
270
- }, false, ["encrypt"]);
271
- case 18:
272
- serverRSACipher = _context4.sent;
273
- serverPublickey = new Uint8Array(4 + serverKeyBytes * 2);
274
- serverPublickey.set(serverKeyLengthBuffer);
275
- serverPublickey.set(serverN, 4);
276
- serverPublickey.set(serverE, 4 + serverKeyBytes);
277
-
278
- // verify server public key
279
- approveKey = this._waitApproveKeyAsync();
280
- this.dispatchEvent(new CustomEvent("serververification", {
281
- detail: {
282
- type: "RSA",
283
- publickey: serverPublickey
284
- }
285
- }));
286
- _context4.next = 27;
287
- return approveKey;
288
- case 27:
289
- // 2: Send client public key
290
- clientKeyLength = 2048;
291
- clientKeyBytes = Math.ceil(clientKeyLength / 8);
292
- _context4.next = 31;
293
- return _crypto["default"].generateKey({
294
- name: "RSA-PKCS1-v1_5",
295
- modulusLength: clientKeyLength,
296
- publicExponent: new Uint8Array([1, 0, 1])
297
- }, true, ["encrypt"]);
298
- case 31:
299
- clientRSACipher = _context4.sent.privateKey;
300
- _context4.next = 34;
301
- return _crypto["default"].exportKey("raw", clientRSACipher);
302
- case 34:
303
- clientExportedRSAKey = _context4.sent;
304
- clientN = clientExportedRSAKey.n;
305
- clientE = clientExportedRSAKey.e;
306
- clientPublicKey = new Uint8Array(4 + clientKeyBytes * 2);
307
- clientPublicKey[0] = (clientKeyLength & 0xff000000) >>> 24;
308
- clientPublicKey[1] = (clientKeyLength & 0xff0000) >>> 16;
309
- clientPublicKey[2] = (clientKeyLength & 0xff00) >>> 8;
310
- clientPublicKey[3] = clientKeyLength & 0xff;
311
- clientPublicKey.set(clientN, 4);
312
- clientPublicKey.set(clientE, 4 + clientKeyBytes);
313
- this._sock.sQpushBytes(clientPublicKey);
314
- this._sock.flush();
315
-
316
- // 3: Send client random
317
- clientRandom = new Uint8Array(16);
318
- window.crypto.getRandomValues(clientRandom);
319
- _context4.next = 50;
320
- return _crypto["default"].encrypt({
321
- name: "RSA-PKCS1-v1_5"
322
- }, serverRSACipher, clientRandom);
323
- case 50:
324
- clientEncryptedRandom = _context4.sent;
325
- clientRandomMessage = new Uint8Array(2 + serverKeyBytes);
326
- clientRandomMessage[0] = (serverKeyBytes & 0xff00) >>> 8;
327
- clientRandomMessage[1] = serverKeyBytes & 0xff;
328
- clientRandomMessage.set(clientEncryptedRandom, 2);
329
- this._sock.sQpushBytes(clientRandomMessage);
330
- this._sock.flush();
331
-
332
- // 4: Receive server random
333
- _context4.next = 59;
334
- return this._waitSockAsync(2);
335
- case 59:
336
- if (!(this._sock.rQshift16() !== clientKeyBytes)) {
337
- _context4.next = 61;
338
- break;
339
- }
340
- throw new Error("RA2: wrong encrypted message length");
341
- case 61:
342
- serverEncryptedRandom = this._sock.rQshiftBytes(clientKeyBytes);
343
- _context4.next = 64;
344
- return _crypto["default"].decrypt({
345
- name: "RSA-PKCS1-v1_5"
346
- }, clientRSACipher, serverEncryptedRandom);
347
- case 64:
348
- serverRandom = _context4.sent;
349
- if (!(serverRandom === null || serverRandom.length !== 16)) {
350
- _context4.next = 67;
351
- break;
352
- }
353
- throw new Error("RA2: corrupted server encrypted random");
354
- case 67:
355
- // 5: Compute session keys and set ciphers
356
- clientSessionKey = new Uint8Array(32);
357
- serverSessionKey = new Uint8Array(32);
358
- clientSessionKey.set(serverRandom);
359
- clientSessionKey.set(clientRandom, 16);
360
- serverSessionKey.set(clientRandom);
361
- serverSessionKey.set(serverRandom, 16);
362
- _context4.next = 75;
363
- return window.crypto.subtle.digest("SHA-1", clientSessionKey);
364
- case 75:
365
- clientSessionKey = _context4.sent;
366
- clientSessionKey = new Uint8Array(clientSessionKey).slice(0, 16);
367
- _context4.next = 79;
368
- return window.crypto.subtle.digest("SHA-1", serverSessionKey);
369
- case 79:
370
- serverSessionKey = _context4.sent;
371
- serverSessionKey = new Uint8Array(serverSessionKey).slice(0, 16);
372
- clientCipher = new RA2Cipher();
373
- _context4.next = 84;
374
- return clientCipher.setKey(clientSessionKey);
375
- case 84:
376
- serverCipher = new RA2Cipher();
377
- _context4.next = 87;
378
- return serverCipher.setKey(serverSessionKey);
379
- case 87:
380
- // 6: Compute and exchange hashes
381
- serverHash = new Uint8Array(8 + serverKeyBytes * 2 + clientKeyBytes * 2);
382
- clientHash = new Uint8Array(8 + serverKeyBytes * 2 + clientKeyBytes * 2);
383
- serverHash.set(serverPublickey);
384
- serverHash.set(clientPublicKey, 4 + serverKeyBytes * 2);
385
- clientHash.set(clientPublicKey);
386
- clientHash.set(serverPublickey, 4 + clientKeyBytes * 2);
387
- _context4.next = 95;
388
- return window.crypto.subtle.digest("SHA-1", serverHash);
389
- case 95:
390
- serverHash = _context4.sent;
391
- _context4.next = 98;
392
- return window.crypto.subtle.digest("SHA-1", clientHash);
393
- case 98:
394
- clientHash = _context4.sent;
395
- serverHash = new Uint8Array(serverHash);
396
- clientHash = new Uint8Array(clientHash);
397
- _context4.t0 = this._sock;
398
- _context4.next = 104;
399
- return clientCipher.makeMessage(clientHash);
400
- case 104:
401
- _context4.t1 = _context4.sent;
402
- _context4.t0.sQpushBytes.call(_context4.t0, _context4.t1);
403
- this._sock.flush();
404
- _context4.next = 109;
405
- return this._waitSockAsync(2 + 20 + 16);
406
- case 109:
407
- if (!(this._sock.rQshift16() !== 20)) {
408
- _context4.next = 111;
409
- break;
410
- }
411
- throw new Error("RA2: wrong server hash");
412
- case 111:
413
- _context4.next = 113;
414
- return serverCipher.receiveMessage(20, this._sock.rQshiftBytes(20 + 16));
415
- case 113:
416
- serverHashReceived = _context4.sent;
417
- if (!(serverHashReceived === null)) {
418
- _context4.next = 116;
419
- break;
420
- }
421
- throw new Error("RA2: failed to authenticate the message");
422
- case 116:
423
- i = 0;
424
- case 117:
425
- if (!(i < 20)) {
426
- _context4.next = 123;
427
- break;
428
- }
429
- if (!(serverHashReceived[i] !== serverHash[i])) {
430
- _context4.next = 120;
431
- break;
432
- }
433
- throw new Error("RA2: wrong server hash");
434
- case 120:
435
- i++;
436
- _context4.next = 117;
437
- break;
438
- case 123:
439
- _context4.next = 125;
440
- return this._waitSockAsync(2 + 1 + 16);
441
- case 125:
442
- if (!(this._sock.rQshift16() !== 1)) {
443
- _context4.next = 127;
444
- break;
445
- }
446
- throw new Error("RA2: wrong subtype");
447
- case 127:
448
- _context4.next = 129;
449
- return serverCipher.receiveMessage(1, this._sock.rQshiftBytes(1 + 16));
450
- case 129:
451
- subtype = _context4.sent;
452
- if (!(subtype === null)) {
453
- _context4.next = 132;
454
- break;
455
- }
456
- throw new Error("RA2: failed to authenticate the message");
457
- case 132:
458
- subtype = subtype[0];
459
- waitCredentials = this._waitCredentialsAsync(subtype);
460
- if (!(subtype === 1)) {
461
- _context4.next = 138;
462
- break;
463
- }
464
- if (this._getCredentials().username === undefined || this._getCredentials().password === undefined) {
465
- this.dispatchEvent(new CustomEvent("credentialsrequired", {
466
- detail: {
467
- types: ["username", "password"]
468
- }
469
- }));
470
- }
471
- _context4.next = 143;
472
- break;
473
- case 138:
474
- if (!(subtype === 2)) {
475
- _context4.next = 142;
476
- break;
477
- }
478
- if (this._getCredentials().password === undefined) {
479
- this.dispatchEvent(new CustomEvent("credentialsrequired", {
480
- detail: {
481
- types: ["password"]
482
- }
483
- }));
484
- }
485
- _context4.next = 143;
486
- break;
487
- case 142:
488
- throw new Error("RA2: wrong subtype");
489
- case 143:
490
- _context4.next = 145;
491
- return waitCredentials;
492
- case 145:
493
- if (subtype === 1) {
494
- username = (0, _strings.encodeUTF8)(this._getCredentials().username).slice(0, 255);
495
- } else {
496
- username = "";
497
- }
498
- password = (0, _strings.encodeUTF8)(this._getCredentials().password).slice(0, 255);
499
- credentials = new Uint8Array(username.length + password.length + 2);
500
- credentials[0] = username.length;
501
- credentials[username.length + 1] = password.length;
502
- for (_i = 0; _i < username.length; _i++) {
503
- credentials[_i + 1] = username.charCodeAt(_i);
504
- }
505
- for (_i2 = 0; _i2 < password.length; _i2++) {
506
- credentials[username.length + 2 + _i2] = password.charCodeAt(_i2);
507
- }
508
- _context4.t2 = this._sock;
509
- _context4.next = 155;
510
- return clientCipher.makeMessage(credentials);
511
- case 155:
512
- _context4.t3 = _context4.sent;
513
- _context4.t2.sQpushBytes.call(_context4.t2, _context4.t3);
514
- this._sock.flush();
515
- case 158:
516
- case "end":
517
- return _context4.stop();
518
- }
519
- }, _callee4, this);
520
- }));
521
- function negotiateRA2neAuthAsync() {
522
- return _negotiateRA2neAuthAsync.apply(this, arguments);
523
- }
524
- return negotiateRA2neAuthAsync;
525
- }()
526
- }, {
527
- key: "hasStarted",
528
- get: function get() {
529
- return this._hasStarted;
530
- },
531
- set: function set(s) {
532
- this._hasStarted = s;
533
- }
534
- }]);
535
- }(_eventtarget["default"]);