@andy.ian/dsh-homing 2.1.4 → 2.1.6

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 (122) hide show
  1. package/README.md +42 -0
  2. package/SECURITY.md +90 -0
  3. package/bin/backup.mjs +3 -2
  4. package/bin/bootstrap-server.mjs +2 -1
  5. package/bin/inbox.mjs +46 -0
  6. package/bin/renew-cert.mjs +2 -1
  7. package/bin/window-agent-daemon.mjs +268 -0
  8. package/index.js +686 -87
  9. package/lib/compress.mjs +29 -5
  10. package/lib/exec-path.mjs +85 -0
  11. package/lib/files-page.mjs +27 -2
  12. package/lib/files.mjs +3 -2
  13. package/lib/git.mjs +5 -2
  14. package/lib/guard.mjs +43 -0
  15. package/lib/local-socket.mjs +50 -0
  16. package/lib/log-file.mjs +50 -0
  17. package/lib/node-runtime.mjs +44 -0
  18. package/lib/office.mjs +133 -0
  19. package/lib/orientation.mjs +158 -0
  20. package/lib/pty.mjs +6 -3
  21. package/lib/secret.mjs +46 -0
  22. package/lib/shells.mjs +2 -1
  23. package/lib/term-page.mjs +2 -0
  24. package/lib/vendor/des-vnc.mjs +266 -0
  25. package/lib/vendor/novnc/LICENSE.txt +62 -0
  26. package/lib/vendor/novnc/core/base64.js +104 -0
  27. package/lib/vendor/novnc/core/crypto/aes.js +178 -0
  28. package/lib/vendor/novnc/core/crypto/bigint.js +34 -0
  29. package/lib/vendor/novnc/core/crypto/crypto.js +90 -0
  30. package/lib/vendor/novnc/core/crypto/des.js +330 -0
  31. package/lib/vendor/novnc/core/crypto/dh.js +55 -0
  32. package/lib/vendor/novnc/core/crypto/md5.js +82 -0
  33. package/lib/vendor/novnc/core/crypto/rsa.js +132 -0
  34. package/lib/vendor/novnc/core/decoders/copyrect.js +27 -0
  35. package/lib/vendor/novnc/core/decoders/h264.js +321 -0
  36. package/lib/vendor/novnc/core/decoders/hextile.js +181 -0
  37. package/lib/vendor/novnc/core/decoders/jpeg.js +161 -0
  38. package/lib/vendor/novnc/core/decoders/raw.js +59 -0
  39. package/lib/vendor/novnc/core/decoders/rre.js +44 -0
  40. package/lib/vendor/novnc/core/decoders/tight.js +393 -0
  41. package/lib/vendor/novnc/core/decoders/tightpng.js +27 -0
  42. package/lib/vendor/novnc/core/decoders/zlib.js +51 -0
  43. package/lib/vendor/novnc/core/decoders/zrle.js +185 -0
  44. package/lib/vendor/novnc/core/deflator.js +84 -0
  45. package/lib/vendor/novnc/core/display.js +578 -0
  46. package/lib/vendor/novnc/core/encodings.js +54 -0
  47. package/lib/vendor/novnc/core/inflator.js +65 -0
  48. package/lib/vendor/novnc/core/input/domkeytable.js +311 -0
  49. package/lib/vendor/novnc/core/input/fixedkeys.js +129 -0
  50. package/lib/vendor/novnc/core/input/gesturehandler.js +567 -0
  51. package/lib/vendor/novnc/core/input/keyboard.js +294 -0
  52. package/lib/vendor/novnc/core/input/keysym.js +616 -0
  53. package/lib/vendor/novnc/core/input/keysymdef.js +688 -0
  54. package/lib/vendor/novnc/core/input/util.js +191 -0
  55. package/lib/vendor/novnc/core/input/vkeys.js +116 -0
  56. package/lib/vendor/novnc/core/input/xtscancodes.js +173 -0
  57. package/lib/vendor/novnc/core/ra2.js +312 -0
  58. package/lib/vendor/novnc/core/rfb.js +3420 -0
  59. package/lib/vendor/novnc/core/util/browser.js +233 -0
  60. package/lib/vendor/novnc/core/util/cursor.js +249 -0
  61. package/lib/vendor/novnc/core/util/element.js +32 -0
  62. package/lib/vendor/novnc/core/util/events.js +138 -0
  63. package/lib/vendor/novnc/core/util/eventtarget.js +35 -0
  64. package/lib/vendor/novnc/core/util/int.js +15 -0
  65. package/lib/vendor/novnc/core/util/logging.js +56 -0
  66. package/lib/vendor/novnc/core/util/strings.js +28 -0
  67. package/lib/vendor/novnc/core/websock.js +369 -0
  68. package/lib/vendor/novnc/vendor/pako/LICENSE +21 -0
  69. package/lib/vendor/novnc/vendor/pako/README.md +6 -0
  70. package/lib/vendor/novnc/vendor/pako/lib/utils/common.js +45 -0
  71. package/lib/vendor/novnc/vendor/pako/lib/zlib/adler32.js +27 -0
  72. package/lib/vendor/novnc/vendor/pako/lib/zlib/constants.js +47 -0
  73. package/lib/vendor/novnc/vendor/pako/lib/zlib/crc32.js +36 -0
  74. package/lib/vendor/novnc/vendor/pako/lib/zlib/deflate.js +1846 -0
  75. package/lib/vendor/novnc/vendor/pako/lib/zlib/gzheader.js +35 -0
  76. package/lib/vendor/novnc/vendor/pako/lib/zlib/inffast.js +324 -0
  77. package/lib/vendor/novnc/vendor/pako/lib/zlib/inflate.js +1527 -0
  78. package/lib/vendor/novnc/vendor/pako/lib/zlib/inftrees.js +322 -0
  79. package/lib/vendor/novnc/vendor/pako/lib/zlib/messages.js +11 -0
  80. package/lib/vendor/novnc/vendor/pako/lib/zlib/trees.js +1195 -0
  81. package/lib/vendor/novnc/vendor/pako/lib/zlib/zstream.js +24 -0
  82. package/lib/vendor/vnc.bundle.js +14592 -0
  83. package/lib/vendor/ws/LICENSE +20 -0
  84. package/lib/vendor/ws/index.js +22 -0
  85. package/lib/vendor/ws/lib/buffer-util.js +142 -0
  86. package/lib/vendor/ws/lib/constants.js +19 -0
  87. package/lib/vendor/ws/lib/event-target.js +292 -0
  88. package/lib/vendor/ws/lib/extension.js +203 -0
  89. package/lib/vendor/ws/lib/limiter.js +55 -0
  90. package/lib/vendor/ws/lib/permessage-deflate.js +530 -0
  91. package/lib/vendor/ws/lib/receiver.js +743 -0
  92. package/lib/vendor/ws/lib/sender.js +610 -0
  93. package/lib/vendor/ws/lib/stream.js +161 -0
  94. package/lib/vendor/ws/lib/subprotocol.js +62 -0
  95. package/lib/vendor/ws/lib/validation.js +152 -0
  96. package/lib/vendor/ws/lib/websocket-server.js +562 -0
  97. package/lib/vendor/ws/lib/websocket.js +1426 -0
  98. package/lib/vendor/ws/package.json +74 -0
  99. package/lib/vendor/ws/wrapper.mjs +21 -0
  100. package/lib/vnc-app.js +567 -0
  101. package/lib/vnc-auth-proxy.mjs +179 -0
  102. package/lib/vnc-boot.js +45 -0
  103. package/lib/vnc-page.mjs +77 -0
  104. package/lib/vnc-pointer.mjs +17 -0
  105. package/lib/vnc.mjs +75 -0
  106. package/lib/window-app.js +155 -0
  107. package/lib/window-page.mjs +111 -0
  108. package/lib/window-remote.mjs +227 -0
  109. package/lib/ws-bridge.mjs +130 -0
  110. package/package.json +6 -2
  111. package/permissions.json +91 -0
  112. package/restart/client.mjs +85 -19
  113. package/restart/daemon/cli.mjs +55 -13
  114. package/restart/daemon/lib/detach.mjs +3 -2
  115. package/restart/daemon/lib/process-tree.mjs +17 -3
  116. package/restart/daemon/lib/restart-flow.mjs +36 -0
  117. package/restart/daemon/main.mjs +299 -80
  118. package/restart/engine.mjs +24 -8
  119. package/restart/port.mjs +88 -0
  120. package/restart/runner.mjs +4 -3
  121. package/restart/service.mjs +8 -5
  122. package/restart/watchdog.mjs +134 -0
@@ -0,0 +1,158 @@
1
+ /**
2
+ * 跨平台屏幕方向控制。
3
+ *
4
+ * 设计:Node 负责编排与状态,具体动作交给各平台原生能力。
5
+ * - win32:复用 window-agent 的 rotate(ChangeDisplaySettingsEx + CDS_TEST,
6
+ * 已在本机验证:portrait → 1080x1920,landscape → 1920x1080)
7
+ * - linux:xrandr(X11);Wayland 下 xrandr 通常不可用,会明确报错
8
+ * - darwin:displayplacer(需要用户安装)
9
+ *
10
+ * 统一返回 { ok, platform, detail }
11
+ */
12
+ import { execFile } from 'node:child_process'
13
+ import fs from 'node:fs'
14
+ import os from 'node:os'
15
+ import path from 'node:path'
16
+ import { promisify } from 'node:util'
17
+
18
+ const run = promisify(execFile)
19
+
20
+ // 记录"竖屏是不是我们切过去的",用于崩溃/断开后自动恢复横屏
21
+ const MARKER = path.join(os.tmpdir(), 'dsh-homing-orientation.json')
22
+
23
+ function writeMarker(mode) {
24
+ try {
25
+ if (mode === 'portrait') {
26
+ fs.writeFileSync(MARKER, JSON.stringify({ byUs: true, ts: Date.now() }))
27
+ } else {
28
+ fs.rmSync(MARKER, { force: true })
29
+ }
30
+ } catch { /* 忽略 */ }
31
+ }
32
+
33
+ function markerPresent() {
34
+ try {
35
+ return JSON.parse(fs.readFileSync(MARKER, 'utf8')).byUs === true
36
+ } catch {
37
+ return false
38
+ }
39
+ }
40
+
41
+ const MODES = new Set(['portrait', 'landscape'])
42
+
43
+ function assertMode(mode) {
44
+ if (!MODES.has(mode)) {
45
+ throw new Error(`unsupported orientation: ${mode}`)
46
+ }
47
+ }
48
+
49
+ /** Linux:找到主输出(connected 且带 primary,否则取第一个 connected) */
50
+ async function linuxPrimaryOutput() {
51
+ const { stdout } = await run('xrandr', ['--query'])
52
+ const lines = stdout.split('\n')
53
+ const primary = lines.find((line) => /\bconnected\s+primary\b/u.test(line))
54
+ const connected = lines.find((line) => /\bconnected\b/u.test(line))
55
+ const line = primary ?? connected
56
+ if (!line) return null
57
+ return line.split(/\s+/u)[0] ?? null
58
+ }
59
+
60
+ async function rotateLinux(mode) {
61
+ const output = await linuxPrimaryOutput()
62
+ if (output === null) {
63
+ return { ok: false, platform: 'linux', detail: 'no connected output (xrandr)' }
64
+ }
65
+ const rotate = mode === 'portrait' ? 'left' : 'normal'
66
+ await run('xrandr', ['--output', output, '--rotate', rotate])
67
+ return { ok: true, platform: 'linux', detail: `${output} -> ${rotate}` }
68
+ }
69
+
70
+ async function rotateMac(mode) {
71
+ // displayplacer 需要参数:screen id;先用 list 解析
72
+ const { stdout } = await run('displayplacer', ['list'])
73
+ const idMatch = stdout.match(/Persistent screen id:\s*(\S+)/u)
74
+ if (!idMatch) {
75
+ return { ok: false, platform: 'darwin', detail: 'displayplacer: screen id not found' }
76
+ }
77
+ const rotation = mode === 'portrait' ? 'rotation:90' : 'rotation:0'
78
+ await run('displayplacer', [`id:${idMatch[1]}`, rotation, 'res:1920x1080', 'scaling:on'])
79
+ return { ok: true, platform: 'darwin', detail: `${idMatch[1]} -> ${rotation}` }
80
+ }
81
+
82
+ async function rotateWindows(mode) {
83
+ const { rotateScreen, stopAgent } = await import('./window-remote.mjs')
84
+ const result = await rotateScreen(mode)
85
+ if (typeof stopAgent === 'function') stopAgent()
86
+ return {
87
+ ok: result.ok === true && result.result === 0,
88
+ platform: 'win32',
89
+ detail: `result=${result.result ?? '?'} screen=${result.screenWidth}x${result.screenHeight}`,
90
+ screen: { width: result.screenWidth, height: result.screenHeight },
91
+ }
92
+ }
93
+
94
+ /** 设置屏幕方向:portrait(竖屏)/ landscape(横屏) */
95
+ export async function setOrientation(mode) {
96
+ assertMode(mode)
97
+ try {
98
+ let result
99
+ if (process.platform === 'win32') result = await rotateWindows(mode)
100
+ else if (process.platform === 'linux') result = await rotateLinux(mode)
101
+ else if (process.platform === 'darwin') result = await rotateMac(mode)
102
+ else result = { ok: false, platform: process.platform, detail: 'unsupported platform' }
103
+ if (result.ok === true) writeMarker(mode)
104
+ return result
105
+ } catch (error) {
106
+ return {
107
+ ok: false,
108
+ platform: process.platform,
109
+ detail: String(error?.stderr ?? error?.message ?? error).slice(0, 200),
110
+ }
111
+ }
112
+ }
113
+
114
+ /** 当前是否竖屏:Windows 用屏幕宽高判断,其它平台用 xrandr 输出判断 */
115
+ export async function isPortrait() {
116
+ if (process.platform === 'win32') {
117
+ const { listWindows, stopAgent } = await import('./window-remote.mjs')
118
+ const info = await listWindows()
119
+ if (typeof stopAgent === 'function') stopAgent()
120
+ const w = Number(info.screenWidth ?? 0)
121
+ const h = Number(info.screenHeight ?? 0)
122
+ if (w <= 0 || h <= 0) return null
123
+ return h > w
124
+ }
125
+ if (process.platform === 'linux') {
126
+ const { stdout } = await run('xrandr', ['--query'])
127
+ const line = stdout.split('\n').find((item) => /\bconnected\s+primary\b/u.test(item))
128
+ ?? stdout.split('\n').find((item) => /\bconnected\b/u.test(item))
129
+ if (!line) return null
130
+ const match = line.match(/(\d+)x(\d+)\+/u)
131
+ if (!match) return null
132
+ return Number(match[2]) > Number(match[1])
133
+ }
134
+ if (process.platform === 'darwin') {
135
+ const { stdout } = await run('displayplacer', ['list'])
136
+ return /rotation:90/u.test(stdout)
137
+ }
138
+ return null
139
+ }
140
+
141
+
142
+ /** 若上次是我们切的竖屏,启动/断开时恢复横屏(死锁/崩溃兜底) */
143
+ export async function ensureLandscape() {
144
+ if (!markerPresent()) return { ok: false, skipped: true, detail: 'no marker' }
145
+ const portrait = await isPortrait()
146
+ if (portrait !== true) {
147
+ writeMarker('landscape')
148
+ return { ok: true, skipped: true, detail: 'already landscape' }
149
+ }
150
+ const result = await setOrientation('landscape')
151
+ if (result.ok === true) writeMarker('landscape')
152
+ return result
153
+ }
154
+
155
+ /** 当前是否有"我们切了竖屏"的标记 */
156
+ export function hasOrientationMarker() {
157
+ return markerPresent()
158
+ }
package/lib/pty.mjs CHANGED
@@ -18,6 +18,7 @@ import fs from 'node:fs'
18
18
  import net from 'node:net'
19
19
  import path from 'node:path'
20
20
  import { spawn, spawnSync } from 'node:child_process'
21
+ import { systemExe } from './exec-path.mjs'
21
22
  import { cdCommand, customShells, detectShells, resolveShell, DEFAULT_SHELL } from './shells.mjs'
22
23
  import { createRequire } from 'node:module'
23
24
  import { fileURLToPath } from 'node:url'
@@ -41,8 +42,10 @@ export const loadSsh2 = () => {
41
42
  return null
42
43
  }
43
44
 
44
- const SSHD_EXE = 'C:/Windows/System32/OpenSSH/sshd.exe'
45
- const KEYGEN_EXE = 'C:/Windows/System32/OpenSSH/ssh-keygen.exe'
45
+ const TASKKILL = systemExe('taskkill')
46
+ const OPENSSH_DIR = path.join(process.env.SystemRoot ?? 'C:\\Windows', 'System32', 'OpenSSH')
47
+ const SSHD_EXE = path.join(OPENSSH_DIR, 'sshd.exe')
48
+ const KEYGEN_EXE = path.join(OPENSSH_DIR, 'ssh-keygen.exe')
46
49
 
47
50
  /**
48
51
  * DSH_HOME:优先用插件传进来的值。
@@ -360,7 +363,7 @@ export const stopSshd = (dshHome = resolveDshHome()) => {
360
363
  const state = JSON.parse(fs.readFileSync(stateFile, 'utf8'))
361
364
  if (state.pid) {
362
365
  // Windows 上用 taskkill 连子进程一起收:只 kill 父进程会留下 per-connection 的 sshd
363
- const result = spawnSync('taskkill', ['/F', '/T', '/PID', String(state.pid)], { windowsHide: true, encoding: 'utf8' })
366
+ const result = spawnSync(TASKKILL, ['/F', '/T', '/PID', String(state.pid)], { windowsHide: true, encoding: 'utf8' })
364
367
  if (result.status !== 0) {
365
368
  try { process.kill(state.pid) } catch { /* 已退出 */ }
366
369
  }
package/lib/secret.mjs ADDED
@@ -0,0 +1,46 @@
1
+ /**
2
+ * 本机密钥的加密存储(Windows DPAPI,CurrentUser 作用域)。
3
+ *
4
+ * 目的:settings.json 里不再出现明文 VNC 密码。
5
+ * 通过 PowerShell 调用 ProtectedData;明文只经环境变量传递,不出现在命令行参数里。
6
+ */
7
+ import { execFile } from 'node:child_process'
8
+ import { promisify } from 'node:util'
9
+
10
+ const run = promisify(execFile)
11
+
12
+ const PS = process.platform === 'win32' ? 'powershell.exe' : null
13
+
14
+ const PROTECT_SCRIPT = [
15
+ 'Add-Type -AssemblyName System.Security;',
16
+ '$b=[Text.Encoding]::UTF8.GetBytes($env:DSH_SECRET);',
17
+ '[Convert]::ToBase64String([Security.Cryptography.ProtectedData]::Protect($b,$null,\'CurrentUser\'))',
18
+ ].join(' ')
19
+
20
+ const UNPROTECT_SCRIPT = [
21
+ 'Add-Type -AssemblyName System.Security;',
22
+ '$b=[Convert]::FromBase64String($env:DSH_SECRET);',
23
+ '[Text.Encoding]::UTF8.GetString([Security.Cryptography.ProtectedData]::Unprotect($b,$null,\'CurrentUser\'))',
24
+ ].join(' ')
25
+
26
+ /** 加密为 DPAPI Base64 字符串;非 Windows 返回 null */
27
+ export async function protectSecret(plain) {
28
+ if (PS === null || typeof plain !== 'string' || plain === '') return null
29
+ const { stdout } = await run(PS, ['-NoProfile', '-NonInteractive', '-Command', PROTECT_SCRIPT], {
30
+ env: { ...process.env, DSH_SECRET: plain },
31
+ windowsHide: true,
32
+ timeout: 15_000,
33
+ })
34
+ return stdout.trim()
35
+ }
36
+
37
+ /** 解密 DPAPI Base64 字符串;失败返回 null */
38
+ export async function unprotectSecret(encrypted) {
39
+ if (PS === null || typeof encrypted !== 'string' || encrypted === '') return null
40
+ const { stdout } = await run(PS, ['-NoProfile', '-NonInteractive', '-Command', UNPROTECT_SCRIPT], {
41
+ env: { ...process.env, DSH_SECRET: encrypted },
42
+ windowsHide: true,
43
+ timeout: 15_000,
44
+ })
45
+ return stdout.trim()
46
+ }
package/lib/shells.mjs CHANGED
@@ -12,6 +12,7 @@
12
12
  * 说明:MobaXterm / Windows Terminal 是图形终端程序,不是 shell,无法在这里运行。
13
13
  */
14
14
  import fs from 'node:fs'
15
+ import { findNodeRuntime } from './node-runtime.mjs'
15
16
  import path from 'node:path'
16
17
 
17
18
  const isWindows = process.platform === 'win32'
@@ -249,7 +250,7 @@ const REPL_PROFILES = [
249
250
  id: 'node',
250
251
  label: 'Node REPL',
251
252
  // DSH 自带的 node 不一定在 PATH 里,用 process.execPath 兜底
252
- detect: () => findOnPath(['node']) ?? (isExecutable(process.execPath) ? process.execPath : null),
253
+ detect: () => findOnPath(['node']) ?? findNodeRuntime(),
253
254
  command: (bin) => quote(bin),
254
255
  cdStyle: 'node',
255
256
  },
package/lib/term-page.mjs CHANGED
@@ -90,6 +90,8 @@ export function renderTermPage({ cwd = '', host = '', user = '', connected = tru
90
90
  <a href="/">DSH</a>
91
91
  <a href="/files?path=${encodeURIComponent(cwd)}">文件</a>
92
92
  <a href="/git?path=${encodeURIComponent(cwd)}">Git</a>
93
+ <a href="/remote">窗口</a>
94
+ <a href="/vnc">桌面</a>
93
95
  ${shells.length > 0 ? `<form method="post" action="/term/shell" class="shellpick" style="display:flex;gap:4px;align-items:center;margin:0">
94
96
  <select name="shell" aria-label="终端类型" style="max-width:130px;padding:2px 4px;border-radius:5px;border:1px solid #333;background:#232323;color:#cfcfcf;font:inherit;font-size:11px">
95
97
  ${shellOptions}
@@ -0,0 +1,266 @@
1
+ /*
2
+ * Ported from Flashlight VNC ActionScript implementation:
3
+ * http://www.wizhelp.com/flashlight-vnc/
4
+ *
5
+ * Full attribution follows:
6
+ *
7
+ * -------------------------------------------------------------------------
8
+ *
9
+ * This DES class has been extracted from package Acme.Crypto for use in VNC.
10
+ * The unnecessary odd parity code has been removed.
11
+ *
12
+ * These changes are:
13
+ * Copyright (C) 1999 AT&T Laboratories Cambridge. All Rights Reserved.
14
+ *
15
+ * This software is distributed in the hope that it will be useful,
16
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
17
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
18
+ *
19
+
20
+ * DesCipher - the DES encryption method
21
+ *
22
+ * The meat of this code is by Dave Zimmerman <dzimm@widget.com>, and is:
23
+ *
24
+ * Copyright (c) 1996 Widget Workshop, Inc. All Rights Reserved.
25
+ *
26
+ * Permission to use, copy, modify, and distribute this software
27
+ * and its documentation for NON-COMMERCIAL or COMMERCIAL purposes and
28
+ * without fee is hereby granted, provided that this copyright notice is kept
29
+ * intact.
30
+ *
31
+ * WIDGET WORKSHOP MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY
32
+ * OF THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
33
+ * TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
34
+ * PARTICULAR PURPOSE, OR NON-INFRINGEMENT. WIDGET WORKSHOP SHALL NOT BE LIABLE
35
+ * FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
36
+ * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.
37
+ *
38
+ * THIS SOFTWARE IS NOT DESIGNED OR INTENDED FOR USE OR RESALE AS ON-LINE
39
+ * CONTROL EQUIPMENT IN HAZARDOUS ENVIRONMENTS REQUIRING FAIL-SAFE
40
+ * PERFORMANCE, SUCH AS IN THE OPERATION OF NUCLEAR FACILITIES, AIRCRAFT
41
+ * NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL, DIRECT LIFE
42
+ * SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH THE FAILURE OF THE
43
+ * SOFTWARE COULD LEAD DIRECTLY TO DEATH, PERSONAL INJURY, OR SEVERE
44
+ * PHYSICAL OR ENVIRONMENTAL DAMAGE ("HIGH RISK ACTIVITIES"). WIDGET WORKSHOP
45
+ * SPECIFICALLY DISCLAIMS ANY EXPRESS OR IMPLIED WARRANTY OF FITNESS FOR
46
+ * HIGH RISK ACTIVITIES.
47
+ *
48
+ *
49
+ * The rest is:
50
+ *
51
+ * Copyright (C) 1996 by Jef Poskanzer <jef@acme.com>. All rights reserved.
52
+ *
53
+ * Redistribution and use in source and binary forms, with or without
54
+ * modification, are permitted provided that the following conditions
55
+ * are met:
56
+ * 1. Redistributions of source code must retain the above copyright
57
+ * notice, this list of conditions and the following disclaimer.
58
+ * 2. Redistributions in binary form must reproduce the above copyright
59
+ * notice, this list of conditions and the following disclaimer in the
60
+ * documentation and/or other materials provided with the distribution.
61
+ *
62
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
63
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
64
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
65
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
66
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
67
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
68
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
69
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
70
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
71
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
72
+ * SUCH DAMAGE.
73
+ *
74
+ * Visit the ACME Labs Java page for up-to-date versions of this and other
75
+ * fine Java utilities: http://www.acme.com/java/
76
+ */
77
+
78
+ /* eslint-disable comma-spacing */
79
+
80
+ // Tables, permutations, S-boxes, etc.
81
+ const PC2 = [13,16,10,23, 0, 4, 2,27,14, 5,20, 9,22,18,11, 3,
82
+ 25, 7,15, 6,26,19,12, 1,40,51,30,36,46,54,29,39,
83
+ 50,44,32,47,43,48,38,55,33,52,45,41,49,35,28,31 ],
84
+ totrot = [ 1, 2, 4, 6, 8,10,12,14,15,17,19,21,23,25,27,28];
85
+
86
+ const z = 0x0;
87
+ let a,b,c,d,e,f;
88
+ a=1<<16; b=1<<24; c=a|b; d=1<<2; e=1<<10; f=d|e;
89
+ const SP1 = [c|e,z|z,a|z,c|f,c|d,a|f,z|d,a|z,z|e,c|e,c|f,z|e,b|f,c|d,b|z,z|d,
90
+ z|f,b|e,b|e,a|e,a|e,c|z,c|z,b|f,a|d,b|d,b|d,a|d,z|z,z|f,a|f,b|z,
91
+ a|z,c|f,z|d,c|z,c|e,b|z,b|z,z|e,c|d,a|z,a|e,b|d,z|e,z|d,b|f,a|f,
92
+ c|f,a|d,c|z,b|f,b|d,z|f,a|f,c|e,z|f,b|e,b|e,z|z,a|d,a|e,z|z,c|d];
93
+ a=1<<20; b=1<<31; c=a|b; d=1<<5; e=1<<15; f=d|e;
94
+ const SP2 = [c|f,b|e,z|e,a|f,a|z,z|d,c|d,b|f,b|d,c|f,c|e,b|z,b|e,a|z,z|d,c|d,
95
+ a|e,a|d,b|f,z|z,b|z,z|e,a|f,c|z,a|d,b|d,z|z,a|e,z|f,c|e,c|z,z|f,
96
+ z|z,a|f,c|d,a|z,b|f,c|z,c|e,z|e,c|z,b|e,z|d,c|f,a|f,z|d,z|e,b|z,
97
+ z|f,c|e,a|z,b|d,a|d,b|f,b|d,a|d,a|e,z|z,b|e,z|f,b|z,c|d,c|f,a|e];
98
+ a=1<<17; b=1<<27; c=a|b; d=1<<3; e=1<<9; f=d|e;
99
+ const SP3 = [z|f,c|e,z|z,c|d,b|e,z|z,a|f,b|e,a|d,b|d,b|d,a|z,c|f,a|d,c|z,z|f,
100
+ b|z,z|d,c|e,z|e,a|e,c|z,c|d,a|f,b|f,a|e,a|z,b|f,z|d,c|f,z|e,b|z,
101
+ c|e,b|z,a|d,z|f,a|z,c|e,b|e,z|z,z|e,a|d,c|f,b|e,b|d,z|e,z|z,c|d,
102
+ b|f,a|z,b|z,c|f,z|d,a|f,a|e,b|d,c|z,b|f,z|f,c|z,a|f,z|d,c|d,a|e];
103
+ a=1<<13; b=1<<23; c=a|b; d=1<<0; e=1<<7; f=d|e;
104
+ const SP4 = [c|d,a|f,a|f,z|e,c|e,b|f,b|d,a|d,z|z,c|z,c|z,c|f,z|f,z|z,b|e,b|d,
105
+ z|d,a|z,b|z,c|d,z|e,b|z,a|d,a|e,b|f,z|d,a|e,b|e,a|z,c|e,c|f,z|f,
106
+ b|e,b|d,c|z,c|f,z|f,z|z,z|z,c|z,a|e,b|e,b|f,z|d,c|d,a|f,a|f,z|e,
107
+ c|f,z|f,z|d,a|z,b|d,a|d,c|e,b|f,a|d,a|e,b|z,c|d,z|e,b|z,a|z,c|e];
108
+ a=1<<25; b=1<<30; c=a|b; d=1<<8; e=1<<19; f=d|e;
109
+ const SP5 = [z|d,a|f,a|e,c|d,z|e,z|d,b|z,a|e,b|f,z|e,a|d,b|f,c|d,c|e,z|f,b|z,
110
+ a|z,b|e,b|e,z|z,b|d,c|f,c|f,a|d,c|e,b|d,z|z,c|z,a|f,a|z,c|z,z|f,
111
+ z|e,c|d,z|d,a|z,b|z,a|e,c|d,b|f,a|d,b|z,c|e,a|f,b|f,z|d,a|z,c|e,
112
+ c|f,z|f,c|z,c|f,a|e,z|z,b|e,c|z,z|f,a|d,b|d,z|e,z|z,b|e,a|f,b|d];
113
+ a=1<<22; b=1<<29; c=a|b; d=1<<4; e=1<<14; f=d|e;
114
+ const SP6 = [b|d,c|z,z|e,c|f,c|z,z|d,c|f,a|z,b|e,a|f,a|z,b|d,a|d,b|e,b|z,z|f,
115
+ z|z,a|d,b|f,z|e,a|e,b|f,z|d,c|d,c|d,z|z,a|f,c|e,z|f,a|e,c|e,b|z,
116
+ b|e,z|d,c|d,a|e,c|f,a|z,z|f,b|d,a|z,b|e,b|z,z|f,b|d,c|f,a|e,c|z,
117
+ a|f,c|e,z|z,c|d,z|d,z|e,c|z,a|f,z|e,a|d,b|f,z|z,c|e,b|z,a|d,b|f];
118
+ a=1<<21; b=1<<26; c=a|b; d=1<<1; e=1<<11; f=d|e;
119
+ const SP7 = [a|z,c|d,b|f,z|z,z|e,b|f,a|f,c|e,c|f,a|z,z|z,b|d,z|d,b|z,c|d,z|f,
120
+ b|e,a|f,a|d,b|e,b|d,c|z,c|e,a|d,c|z,z|e,z|f,c|f,a|e,z|d,b|z,a|e,
121
+ b|z,a|e,a|z,b|f,b|f,c|d,c|d,z|d,a|d,b|z,b|e,a|z,c|e,z|f,a|f,c|e,
122
+ z|f,b|d,c|f,c|z,a|e,z|z,z|d,c|f,z|z,a|f,c|z,z|e,b|d,b|e,z|e,a|d];
123
+ a=1<<18; b=1<<28; c=a|b; d=1<<6; e=1<<12; f=d|e;
124
+ const SP8 = [b|f,z|e,a|z,c|f,b|z,b|f,z|d,b|z,a|d,c|z,c|f,a|e,c|e,a|f,z|e,z|d,
125
+ c|z,b|d,b|e,z|f,a|e,a|d,c|d,c|e,z|f,z|z,z|z,c|d,b|d,b|e,a|f,a|z,
126
+ a|f,a|z,c|e,z|e,z|d,c|d,z|e,a|f,b|e,z|d,b|d,c|z,c|d,b|z,a|z,b|f,
127
+ z|z,c|f,a|d,b|d,c|z,b|e,b|f,z|z,c|f,a|e,a|e,z|f,z|f,a|d,b|z,c|e];
128
+
129
+ /* eslint-enable comma-spacing */
130
+
131
+ export default class DES {
132
+ constructor(password) {
133
+ this.keys = [];
134
+
135
+ // Set the key.
136
+ const pc1m = [], pcr = [], kn = [];
137
+
138
+ for (let j = 0, l = 56; j < 56; ++j, l -= 8) {
139
+ l += l < -5 ? 65 : l < -3 ? 31 : l < -1 ? 63 : l === 27 ? 35 : 0; // PC1
140
+ const m = l & 0x7;
141
+ pc1m[j] = ((password[l >>> 3] & (1<<m)) !== 0) ? 1: 0;
142
+ }
143
+
144
+ for (let i = 0; i < 16; ++i) {
145
+ const m = i << 1;
146
+ const n = m + 1;
147
+ kn[m] = kn[n] = 0;
148
+ for (let o = 28; o < 59; o += 28) {
149
+ for (let j = o - 28; j < o; ++j) {
150
+ const l = j + totrot[i];
151
+ pcr[j] = l < o ? pc1m[l] : pc1m[l - 28];
152
+ }
153
+ }
154
+ for (let j = 0; j < 24; ++j) {
155
+ if (pcr[PC2[j]] !== 0) {
156
+ kn[m] |= 1 << (23 - j);
157
+ }
158
+ if (pcr[PC2[j + 24]] !== 0) {
159
+ kn[n] |= 1 << (23 - j);
160
+ }
161
+ }
162
+ }
163
+
164
+ // cookey
165
+ for (let i = 0, rawi = 0, KnLi = 0; i < 16; ++i) {
166
+ const raw0 = kn[rawi++];
167
+ const raw1 = kn[rawi++];
168
+ this.keys[KnLi] = (raw0 & 0x00fc0000) << 6;
169
+ this.keys[KnLi] |= (raw0 & 0x00000fc0) << 10;
170
+ this.keys[KnLi] |= (raw1 & 0x00fc0000) >>> 10;
171
+ this.keys[KnLi] |= (raw1 & 0x00000fc0) >>> 6;
172
+ ++KnLi;
173
+ this.keys[KnLi] = (raw0 & 0x0003f000) << 12;
174
+ this.keys[KnLi] |= (raw0 & 0x0000003f) << 16;
175
+ this.keys[KnLi] |= (raw1 & 0x0003f000) >>> 4;
176
+ this.keys[KnLi] |= (raw1 & 0x0000003f);
177
+ ++KnLi;
178
+ }
179
+ }
180
+
181
+ // Encrypt 8 bytes of text
182
+ enc8(text) {
183
+ const b = text.slice();
184
+ let i = 0, l, r, x; // left, right, accumulator
185
+
186
+ // Squash 8 bytes to 2 ints
187
+ l = b[i++]<<24 | b[i++]<<16 | b[i++]<<8 | b[i++];
188
+ r = b[i++]<<24 | b[i++]<<16 | b[i++]<<8 | b[i++];
189
+
190
+ x = ((l >>> 4) ^ r) & 0x0f0f0f0f;
191
+ r ^= x;
192
+ l ^= (x << 4);
193
+ x = ((l >>> 16) ^ r) & 0x0000ffff;
194
+ r ^= x;
195
+ l ^= (x << 16);
196
+ x = ((r >>> 2) ^ l) & 0x33333333;
197
+ l ^= x;
198
+ r ^= (x << 2);
199
+ x = ((r >>> 8) ^ l) & 0x00ff00ff;
200
+ l ^= x;
201
+ r ^= (x << 8);
202
+ r = (r << 1) | ((r >>> 31) & 1);
203
+ x = (l ^ r) & 0xaaaaaaaa;
204
+ l ^= x;
205
+ r ^= x;
206
+ l = (l << 1) | ((l >>> 31) & 1);
207
+
208
+ for (let i = 0, keysi = 0; i < 8; ++i) {
209
+ x = (r << 28) | (r >>> 4);
210
+ x ^= this.keys[keysi++];
211
+ let fval = SP7[x & 0x3f];
212
+ fval |= SP5[(x >>> 8) & 0x3f];
213
+ fval |= SP3[(x >>> 16) & 0x3f];
214
+ fval |= SP1[(x >>> 24) & 0x3f];
215
+ x = r ^ this.keys[keysi++];
216
+ fval |= SP8[x & 0x3f];
217
+ fval |= SP6[(x >>> 8) & 0x3f];
218
+ fval |= SP4[(x >>> 16) & 0x3f];
219
+ fval |= SP2[(x >>> 24) & 0x3f];
220
+ l ^= fval;
221
+ x = (l << 28) | (l >>> 4);
222
+ x ^= this.keys[keysi++];
223
+ fval = SP7[x & 0x3f];
224
+ fval |= SP5[(x >>> 8) & 0x3f];
225
+ fval |= SP3[(x >>> 16) & 0x3f];
226
+ fval |= SP1[(x >>> 24) & 0x3f];
227
+ x = l ^ this.keys[keysi++];
228
+ fval |= SP8[x & 0x0000003f];
229
+ fval |= SP6[(x >>> 8) & 0x3f];
230
+ fval |= SP4[(x >>> 16) & 0x3f];
231
+ fval |= SP2[(x >>> 24) & 0x3f];
232
+ r ^= fval;
233
+ }
234
+
235
+ r = (r << 31) | (r >>> 1);
236
+ x = (l ^ r) & 0xaaaaaaaa;
237
+ l ^= x;
238
+ r ^= x;
239
+ l = (l << 31) | (l >>> 1);
240
+ x = ((l >>> 8) ^ r) & 0x00ff00ff;
241
+ r ^= x;
242
+ l ^= (x << 8);
243
+ x = ((l >>> 2) ^ r) & 0x33333333;
244
+ r ^= x;
245
+ l ^= (x << 2);
246
+ x = ((r >>> 16) ^ l) & 0x0000ffff;
247
+ l ^= x;
248
+ r ^= (x << 16);
249
+ x = ((r >>> 4) ^ l) & 0x0f0f0f0f;
250
+ l ^= x;
251
+ r ^= (x << 4);
252
+
253
+ // Spread ints to bytes
254
+ x = [r, l];
255
+ for (i = 0; i < 8; i++) {
256
+ b[i] = (x[i>>>2] >>> (8 * (3 - (i % 4)))) % 256;
257
+ if (b[i] < 0) { b[i] += 256; } // unsigned
258
+ }
259
+ return b;
260
+ }
261
+
262
+ // Encrypt 16 bytes of text using passwd as key
263
+ encrypt(t) {
264
+ return this.enc8(t.slice(0, 8)).concat(this.enc8(t.slice(8, 16)));
265
+ }
266
+ }
@@ -0,0 +1,62 @@
1
+ noVNC is Copyright (C) 2022 The noVNC authors
2
+ (./AUTHORS)
3
+
4
+ The noVNC core library files are licensed under the MPL 2.0 (Mozilla
5
+ Public License 2.0). The noVNC core library is composed of the
6
+ Javascript code necessary for full noVNC operation. This includes (but
7
+ is not limited to):
8
+
9
+ core/**/*.js
10
+ app/*.js
11
+ test/playback.js
12
+
13
+ The HTML, CSS, font and images files that included with the noVNC
14
+ source distibution (or repository) are not considered part of the
15
+ noVNC core library and are licensed under more permissive licenses.
16
+ The intent is to allow easy integration of noVNC into existing web
17
+ sites and web applications.
18
+
19
+ The HTML, CSS, font and image files are licensed as follows:
20
+
21
+ *.html : 2-Clause BSD license
22
+
23
+ app/styles/*.css : 2-Clause BSD license
24
+
25
+ app/styles/Orbitron* : SIL Open Font License 1.1
26
+ (Copyright 2009 Matt McInerney)
27
+
28
+ app/images/ : Creative Commons Attribution-ShareAlike
29
+ http://creativecommons.org/licenses/by-sa/3.0/
30
+
31
+ Some portions of noVNC are copyright to their individual authors.
32
+ Please refer to the individual source files and/or to the noVNC commit
33
+ history: https://github.com/novnc/noVNC/commits/master
34
+
35
+ The are several files and projects that have been incorporated into
36
+ the noVNC core library. Here is a list of those files and the original
37
+ licenses (all MPL 2.0 compatible):
38
+
39
+ core/base64.js : MPL 2.0
40
+
41
+ core/des.js : Various BSD style licenses
42
+
43
+ vendor/pako/ : MIT
44
+
45
+ Any other files not mentioned above are typically marked with
46
+ a copyright/license header at the top of the file. The default noVNC
47
+ license is MPL-2.0.
48
+
49
+ The following license texts are included:
50
+
51
+ docs/LICENSE.MPL-2.0
52
+ docs/LICENSE.OFL-1.1
53
+ docs/LICENSE.BSD-3-Clause (New BSD)
54
+ docs/LICENSE.BSD-2-Clause (Simplified BSD / FreeBSD)
55
+ vendor/pako/LICENSE (MIT)
56
+
57
+ Or alternatively the license texts may be found here:
58
+
59
+ http://www.mozilla.org/MPL/2.0/
60
+ http://scripts.sil.org/OFL
61
+ http://en.wikipedia.org/wiki/BSD_licenses
62
+ https://opensource.org/licenses/MIT