@fnndsc/calypso 0.29.14 → 0.30.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 (82) hide show
  1. package/dist/calypso.js +19 -8
  2. package/dist/calypso.js.map +1 -1
  3. package/dist/daemon/attachFile.d.ts +26 -19
  4. package/dist/daemon/attachFile.js +42 -51
  5. package/dist/daemon/attachFile.js.map +1 -1
  6. package/dist/daemon/attachOrigin.d.ts +69 -0
  7. package/dist/daemon/attachOrigin.js +125 -0
  8. package/dist/daemon/attachOrigin.js.map +1 -0
  9. package/dist/daemon/berth.d.ts +265 -26
  10. package/dist/daemon/berth.js +521 -158
  11. package/dist/daemon/berth.js.map +1 -1
  12. package/dist/daemon/claims.js +19 -9
  13. package/dist/daemon/claims.js.map +1 -1
  14. package/dist/daemon/commandLane.d.ts +317 -0
  15. package/dist/daemon/commandLane.js +409 -0
  16. package/dist/daemon/commandLane.js.map +1 -0
  17. package/dist/daemon/console.d.ts +0 -2
  18. package/dist/daemon/console.js +7 -10
  19. package/dist/daemon/console.js.map +1 -1
  20. package/dist/daemon/consoleSession.js +4 -1
  21. package/dist/daemon/consoleSession.js.map +1 -1
  22. package/dist/daemon/elevation.d.ts +0 -3
  23. package/dist/daemon/elevation.js +1 -3
  24. package/dist/daemon/elevation.js.map +1 -1
  25. package/dist/daemon/face.d.ts +18 -4
  26. package/dist/daemon/face.js +77 -32
  27. package/dist/daemon/face.js.map +1 -1
  28. package/dist/daemon/hostControl.d.ts +114 -1
  29. package/dist/daemon/hostControl.js +104 -4
  30. package/dist/daemon/hostControl.js.map +1 -1
  31. package/dist/daemon/hostPty.d.ts +14 -0
  32. package/dist/daemon/hostPty.js +19 -1
  33. package/dist/daemon/hostPty.js.map +1 -1
  34. package/dist/daemon/hostPtyRelay.d.ts +118 -0
  35. package/dist/daemon/hostPtyRelay.js +186 -0
  36. package/dist/daemon/hostPtyRelay.js.map +1 -0
  37. package/dist/daemon/httpRoutes.d.ts +257 -0
  38. package/dist/daemon/httpRoutes.js +537 -0
  39. package/dist/daemon/httpRoutes.js.map +1 -0
  40. package/dist/daemon/instance.d.ts +37 -0
  41. package/dist/daemon/instance.js +59 -0
  42. package/dist/daemon/instance.js.map +1 -0
  43. package/dist/daemon/launch.d.ts +17 -0
  44. package/dist/daemon/launch.js +198 -194
  45. package/dist/daemon/launch.js.map +1 -1
  46. package/dist/daemon/launchBanner.d.ts +76 -0
  47. package/dist/daemon/launchBanner.js +80 -0
  48. package/dist/daemon/launchBanner.js.map +1 -0
  49. package/dist/daemon/rival.d.ts +65 -0
  50. package/dist/daemon/rival.js +67 -0
  51. package/dist/daemon/rival.js.map +1 -0
  52. package/dist/daemon/server.d.ts +104 -190
  53. package/dist/daemon/server.js +358 -866
  54. package/dist/daemon/server.js.map +1 -1
  55. package/dist/daemon/settings.d.ts +42 -0
  56. package/dist/daemon/settings.js +43 -0
  57. package/dist/daemon/settings.js.map +1 -0
  58. package/dist/daemon/surface.d.ts +103 -0
  59. package/dist/daemon/surface.js +71 -0
  60. package/dist/daemon/surface.js.map +1 -0
  61. package/dist/daemon/surfaceReplies.d.ts +109 -0
  62. package/dist/daemon/surfaceReplies.js +108 -0
  63. package/dist/daemon/surfaceReplies.js.map +1 -0
  64. package/dist/daemon/terminals.js +5 -2
  65. package/dist/daemon/terminals.js.map +1 -1
  66. package/dist/daemon/token.d.ts +41 -5
  67. package/dist/daemon/token.js +43 -12
  68. package/dist/daemon/token.js.map +1 -1
  69. package/dist/daemon/uploadHold.d.ts +85 -0
  70. package/dist/daemon/uploadHold.js +205 -0
  71. package/dist/daemon/uploadHold.js.map +1 -0
  72. package/dist/daemon/vfsHeaders.d.ts +11 -0
  73. package/dist/daemon/vfsHeaders.js +60 -0
  74. package/dist/daemon/vfsHeaders.js.map +1 -0
  75. package/dist/index.d.ts +5 -5
  76. package/dist/index.js +3 -4
  77. package/dist/index.js.map +1 -1
  78. package/dist/notes.json +1 -1
  79. package/package.json +9 -4
  80. package/dist/daemon/discovery.d.ts +0 -23
  81. package/dist/daemon/discovery.js +0 -57
  82. package/dist/daemon/discovery.js.map +0 -1
package/dist/calypso.js CHANGED
@@ -18,7 +18,8 @@ import { daemon_launch } from './daemon/launch.js';
18
18
  import { packageWebRoot_find } from './daemon/static.js';
19
19
  import { daemonConsole_run } from './daemon/consoleSession.js';
20
20
  import { hostControl_parseArgv } from './daemon/hostControl.js';
21
- import { LocalBerthResolver, berthUrl_isAlive } from './daemon/berth.js';
21
+ import { LocalBerthResolver, berthInstance_probe } from './daemon/berth.js';
22
+ import { berthLines_say } from './daemon/token.js';
22
23
  /** The backends a test may ask the calypso command to host instead of ChRIS. */
23
24
  const TEST_BACKENDS = ['null'];
24
25
  /**
@@ -108,18 +109,28 @@ async function calypso_start() {
108
109
  * convenient; it is also world-readable, and the token is a credential.
109
110
  */
110
111
  async function berths_print() {
111
- const resolver = new LocalBerthResolver((berth) => berthUrl_isAlive(berth.url));
112
- const berths = await resolver.list();
112
+ const resolver = new LocalBerthResolver(berthInstance_probe);
113
+ // Each berth with the record it was read from (this runtime's, or a porter session's), and whether its daemon
114
+ // proved it is running: an earlier release's cannot, and is shown as such rather than hidden or believed.
115
+ const berths = await resolver.probed_list();
113
116
  if (berths.length === 0) {
114
117
  console.error(chalk.yellow('No calypso is running.'));
115
118
  console.error(chalk.gray("Start one with: calypso <user>@<url>"));
116
119
  return;
117
120
  }
118
- for (const berth of berths) {
119
- const web = berth.url.replace(/^ws/, 'http');
120
- console.log(chalk.bold.cyan(berth.identity));
121
- console.log(chalk.green(` ARGUS: ${web}/?token=${berth.token}`));
122
- console.log(chalk.gray(` attach: chell --remote --attach ${berth.url} --token ${berth.token}`));
121
+ for (const { berth, path, liveness } of berths) {
122
+ // An earlier release's daemon cannot prove it is the one its record names: no address or token is offered for
123
+ // it, only what it is and how to stop it.
124
+ if (liveness === 'unverified') {
125
+ console.log(chalk.bold.cyan(berth.identity) + chalk.yellow(' unverified (earlier release)'));
126
+ console.log(chalk.gray(' Stop the old daemon from its original terminal (Ctrl-C at the idle daemon prompt) or through its service manager, then start it again.'));
127
+ continue;
128
+ }
129
+ // Each berth's token is printed to a terminal and, anywhere else, named by the record it was actually read from.
130
+ const [identity, argus, attach] = berthLines_say(berth.identity, berth.url, berth.token, process.stdout.isTTY === true, path);
131
+ console.log(chalk.bold.cyan(identity));
132
+ console.log(chalk.green(argus));
133
+ console.log(chalk.gray(attach));
123
134
  }
124
135
  }
125
136
  const currentFile = fileURLToPath(import.meta.url);
@@ -1 +1 @@
1
- {"version":3,"file":"calypso.js","sourceRoot":"","sources":["../src/calypso.ts"],"names":[],"mappings":";AACA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,mBAAmB,EAAoB,MAAM,oBAAoB,CAAC;AAE3E,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,aAAa,EAAyB,MAAM,oBAAoB,CAAC;AAC1E,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AACzD,OAAO,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AAC/D,OAAO,EAAE,qBAAqB,EAA0B,MAAM,yBAAyB,CAAC;AACxF,OAAO,EAAE,kBAAkB,EAAE,gBAAgB,EAAc,MAAM,mBAAmB,CAAC;AAErF,gFAAgF;AAChF,MAAM,aAAa,GAA0B,CAAC,MAAM,CAAC,CAAC;AAEtD;;;;;;;;GAQG;AACH,MAAM,UAAU,oBAAoB,CAAC,IAA2B,EAAE,GAAsB;IACtF,MAAM,EAAE,GAAW,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC;IAC7C,IAAI,EAAE,KAAK,CAAC,CAAC;QAAE,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC;IAC3C,MAAM,EAAE,GAAuB,IAAI,CAAC,EAAE,GAAG,CAA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,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC;QACvC,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC;QAChC,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC;IAClC,CAAC;AACH,CAAC;AAED,MAAM,WAAW,GAAW,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAC3D,IAAI,MAAM,GAAY,KAAK,CAAC;AAC5B,IAAI,CAAC;IACH,MAAM,GAAG,YAAY,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,YAAY,CAAC,WAAW,CAAC,CAAC;AACvE,CAAC;AAAC,MAAM,CAAC;IACP,2BAA2B;AAC7B,CAAC;AAED,IAAI,MAAM,EAAE,CAAC;IACX,2EAA2E;IAC3E,wEAAwE;IACxE,0EAA0E;IAC1E,IAAI,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,WAAW,CAAC,IAAI,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC;QAAE,OAAO,CAAC,GAAG,CAAC,mBAAmB,EAAE,CAAC,CAAC;;QACrG,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,YAAY,EAAE,CAAC,CAAC,CAAC,aAAa,EAAE,CAAC,CAAC;AACnF,CAAC"}
@@ -1,27 +1,36 @@
1
1
  /**
2
- * @file The attach note: a daemon's addresses, written where they can be read.
2
+ * @file The attach note: which daemon this account last started, and where to find how to reach it.
3
3
  *
4
- * A daemon prints its ARGUS link and attach command once, into a terminal it
5
- * then occupies with a live boot animation. Selecting text out from under a
6
- * repainting screen is awkward, and scrollback is lost the moment anyone
7
- * clears it — so the same lines are also written to a file.
4
+ * A daemon prints its ARGUS link and attach command once, into a terminal it then occupies with a live boot
5
+ * animation; scrollback is lost the moment anyone clears it. The note says, in a file, which daemon that was and
6
+ * that `calypso --berths` reprints its address and token while it proves it is running.
8
7
  *
9
- * The file carries the attach token, which is a credential, and `/tmp` is
10
- * world-readable. Three things follow, and none is optional:
8
+ * The note is written as the berth record is, in the same owner-only folder (`berthDir_path`, held to this account
9
+ * through a trusted path), by a fresh `0600` file renamed over the name: never written through a link.
11
10
  *
12
- * * it is created `0600`, so the mode rather than the directory protects it;
13
- * * it is created exclusively (`wx`), so a symlink planted at the path by
14
- * another user makes the write fail rather than land somewhere chosen by
15
- * them; and
16
- * * it is removed when the daemon exits, so a dead session's token does not
17
- * linger.
11
+ * It stays when the daemon ends, as the record does: no process can unlink a published note without racing the next
12
+ * daemon that replaces it. So it carries no credential (no token, no tokened link, no attach command): who the
13
+ * daemon was, when, and where to ask what is running now.
18
14
  *
19
- * `calypso --berths` reads the same facts from the berth, which is `0600` in
20
- * the user's own runtime directory. That remains the safer route; this one is
21
- * the convenient one.
15
+ * `calypso --berths` reads the address and token from the berth, for each daemon that proves it is running.
22
16
  *
23
17
  * @module
24
18
  */
19
+ /**
20
+ * What the attach note says: who the daemon was, when it was written, and where to ask for what is running now. It
21
+ * outlives the daemon, so it carries no token, no tokened link and no attach command: `calypso --berths` gives
22
+ * those for a daemon that proves it is running.
23
+ *
24
+ * @param identity - The daemon's identity.
25
+ * @param booted - When it booted, ISO.
26
+ * @returns The note's lines.
27
+ *
28
+ * @example
29
+ * ```ts
30
+ * attachFile_write(attachNote_lines(identity, booted));
31
+ * ```
32
+ */
33
+ export declare function attachNote_lines(identity: string, booted: string): string[];
25
34
  /**
26
35
  * The path this daemon's attach note occupies.
27
36
  *
@@ -29,7 +38,7 @@
29
38
  * found again without reading one. A second daemon for a second CUBE identity
30
39
  * overwrites it; `calypso --berths` lists them all.
31
40
  *
32
- * @returns An absolute path in the system temporary directory.
41
+ * @returns An absolute path in this account's berth folder.
33
42
  */
34
43
  export declare function attachFile_path(): string;
35
44
  /**
@@ -39,5 +48,3 @@ export declare function attachFile_path(): string;
39
48
  * @returns The path written, or null when it could not be written safely.
40
49
  */
41
50
  export declare function attachFile_write(lines: string[]): string | null;
42
- /** Removes the attach note, so a dead session's token does not linger. */
43
- export declare function attachFile_remove(): void;
@@ -1,31 +1,45 @@
1
1
  /**
2
- * @file The attach note: a daemon's addresses, written where they can be read.
2
+ * @file The attach note: which daemon this account last started, and where to find how to reach it.
3
3
  *
4
- * A daemon prints its ARGUS link and attach command once, into a terminal it
5
- * then occupies with a live boot animation. Selecting text out from under a
6
- * repainting screen is awkward, and scrollback is lost the moment anyone
7
- * clears it — so the same lines are also written to a file.
4
+ * A daemon prints its ARGUS link and attach command once, into a terminal it then occupies with a live boot
5
+ * animation; scrollback is lost the moment anyone clears it. The note says, in a file, which daemon that was and
6
+ * that `calypso --berths` reprints its address and token while it proves it is running.
8
7
  *
9
- * The file carries the attach token, which is a credential, and `/tmp` is
10
- * world-readable. Three things follow, and none is optional:
8
+ * The note is written as the berth record is, in the same owner-only folder (`berthDir_path`, held to this account
9
+ * through a trusted path), by a fresh `0600` file renamed over the name: never written through a link.
11
10
  *
12
- * * it is created `0600`, so the mode rather than the directory protects it;
13
- * * it is created exclusively (`wx`), so a symlink planted at the path by
14
- * another user makes the write fail rather than land somewhere chosen by
15
- * them; and
16
- * * it is removed when the daemon exits, so a dead session's token does not
17
- * linger.
11
+ * It stays when the daemon ends, as the record does: no process can unlink a published note without racing the next
12
+ * daemon that replaces it. So it carries no credential (no token, no tokened link, no attach command): who the
13
+ * daemon was, when, and where to ask what is running now.
18
14
  *
19
- * `calypso --berths` reads the same facts from the berth, which is `0600` in
20
- * the user's own runtime directory. That remains the safer route; this one is
21
- * the convenient one.
15
+ * `calypso --berths` reads the address and token from the berth, for each daemon that proves it is running.
22
16
  *
23
17
  * @module
24
18
  */
25
- import { chmodSync, openSync, writeSync, closeSync, rmSync } from 'node:fs';
26
- import { tmpdir } from 'node:os';
27
- import { join } from 'node:path';
28
- import { userInfo } from 'node:os';
19
+ import { basename, dirname, join } from 'node:path';
20
+ import { ownFile_write, ownFolder_settle } from '@fnndsc/fond';
21
+ import { berthDir_path, spelled_join } from './berth.js';
22
+ /**
23
+ * What the attach note says: who the daemon was, when it was written, and where to ask for what is running now. It
24
+ * outlives the daemon, so it carries no token, no tokened link and no attach command: `calypso --berths` gives
25
+ * those for a daemon that proves it is running.
26
+ *
27
+ * @param identity - The daemon's identity.
28
+ * @param booted - When it booted, ISO.
29
+ * @returns The note's lines.
30
+ *
31
+ * @example
32
+ * ```ts
33
+ * attachFile_write(attachNote_lines(identity, booted));
34
+ * ```
35
+ */
36
+ export function attachNote_lines(identity, booted) {
37
+ return [
38
+ `# Written by the daemon at ${booted}; left when it ends.`,
39
+ `identity: ${identity}`,
40
+ 'attach: calypso --berths (on this machine: the address and token of each daemon that proves it is running)',
41
+ ];
42
+ }
29
43
  /**
30
44
  * The path this daemon's attach note occupies.
31
45
  *
@@ -33,10 +47,10 @@ import { userInfo } from 'node:os';
33
47
  * found again without reading one. A second daemon for a second CUBE identity
34
48
  * overwrites it; `calypso --berths` lists them all.
35
49
  *
36
- * @returns An absolute path in the system temporary directory.
50
+ * @returns An absolute path in this account's berth folder.
37
51
  */
38
52
  export function attachFile_path() {
39
- return join(tmpdir(), `calypso-${userInfo().username}.attach`);
53
+ return spelled_join(berthDir_path(), 'attach.txt');
40
54
  }
41
55
  /**
42
56
  * Writes the attach note, replacing any note this user left before.
@@ -46,35 +60,12 @@ export function attachFile_path() {
46
60
  */
47
61
  export function attachFile_write(lines) {
48
62
  const path = attachFile_path();
49
- try {
50
- // Remove our own stale note first, then create exclusively: if anything
51
- // reappears at the path in between, the create fails rather than writing
52
- // through whatever is there.
53
- rmSync(path, { force: true });
54
- const handle = openSync(path, 'wx', 0o600);
55
- try {
56
- writeSync(handle, `${lines.join('\n')}\n`);
57
- }
58
- finally {
59
- closeSync(handle);
60
- }
61
- // openSync's mode is subject to umask; set it outright.
62
- chmodSync(path, 0o600);
63
- return path;
64
- }
65
- catch {
66
- // A note is a convenience. Failing to write one must never stop a daemon
67
- // from starting, and the addresses were printed regardless.
63
+ // A note is a convenience. Failing to write one must never stop a daemon from starting, and the addresses were
64
+ // printed regardless.
65
+ const held = ownFolder_settle(dirname(path), true);
66
+ if (!held.ok)
68
67
  return null;
69
- }
70
- }
71
- /** Removes the attach note, so a dead session's token does not linger. */
72
- export function attachFile_remove() {
73
- try {
74
- rmSync(attachFile_path(), { force: true });
75
- }
76
- catch {
77
- // Nothing useful to say at exit about a file that may already be gone.
78
- }
68
+ const written = ownFile_write(held.path, basename(path), `${lines.join('\n')}\n`);
69
+ return written.ok ? join(held.path, basename(path)) : null;
79
70
  }
80
71
  //# sourceMappingURL=attachFile.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"attachFile.js","sourceRoot":"","sources":["../../src/daemon/attachFile.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAC5E,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACjC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAEnC;;;;;;;;GAQG;AACH,MAAM,UAAU,eAAe;IAC7B,OAAO,IAAI,CAAC,MAAM,EAAE,EAAE,WAAW,QAAQ,EAAE,CAAC,QAAQ,SAAS,CAAC,CAAC;AACjE,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,gBAAgB,CAAC,KAAe;IAC9C,MAAM,IAAI,GAAW,eAAe,EAAE,CAAC;IACvC,IAAI,CAAC;QACH,wEAAwE;QACxE,yEAAyE;QACzE,6BAA6B;QAC7B,MAAM,CAAC,IAAI,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC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E,YAAY,CAAC,CAAC;AACrD,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,gBAAgB,CAAC,KAAe;IAC9C,MAAM,IAAI,GAAW,eAAe,EAAE,CAAC;IACvC,+GAA+G;IAC/G,sBAAsB;IACtB,MAAM,IAAI,GAA2B,gBAAgB,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,IAAI,CAAC,CAAC;IAC3E,IAAI,CAAC,IAAI,CAAC,EAAE;QAAE,OAAO,IAAI,CAAC;IAC1B,MAAM,OAAO,GAAyB,aAAa,CAAC,IAAI,CAAC,IAAI,EAAE,QAAQ,CAAC,IAAI,CAAC,EAAE,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACxG,OAAO,OAAO,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;AAC7D,CAAC"}
@@ -0,0 +1,69 @@
1
+ /**
2
+ * @file Where an attach came from.
3
+ *
4
+ * A browser opens a socket to any address a page tells it to, and says
5
+ * which page asked (`Origin`). The daemon's wire is for its own surface,
6
+ * the page it serves itself, and for programs, which send no `Origin` at
7
+ * all. A page from somewhere else that has got hold of a token is not
8
+ * either, and its attach is refused before a word is exchanged. The token
9
+ * is required as before in every case: this is a second question, not a
10
+ * replacement for the first.
11
+ *
12
+ * The daemon's own page is the one served from the address the browser is
13
+ * speaking to, over the plain HTTP the daemon speaks: its `Origin` is
14
+ * `http://` and the request's own `Host`. Other origins are let in only by
15
+ * name (`CALYPSO_ORIGINS`): a surface served from elsewhere (a development
16
+ * server), or the daemon's page reached through something that changes its
17
+ * address (a proxy that ends TLS). A door in front (porter) checks the browser's origin against
18
+ * its own name and relays the attach without one.
19
+ *
20
+ * @module
21
+ */
22
+ /**
23
+ * The origins named in the environment (`CALYPSO_ORIGINS`, comma-separated).
24
+ *
25
+ * @param env - The environment.
26
+ * @returns The origins, normalised; what is not an origin is left out.
27
+ */
28
+ export declare function attachOrigins_read(env: NodeJS.ProcessEnv): string[];
29
+ /**
30
+ * Whether an attach may go on, by where it says it came from.
31
+ *
32
+ * The daemon's own page is the one served from the address this very
33
+ * request was sent to, and the daemon speaks plain HTTP: so the page's
34
+ * origin is `http://` and the request's own `Host`, exactly. Nothing is
35
+ * inferred from the page's side. A page reached another way (through a
36
+ * proxy that ends TLS, under another name) is not the daemon's own as far
37
+ * as the daemon can tell, and is let in by name or not at all.
38
+ *
39
+ * @param origin - The upgrade request's `Origin`; undefined from a program.
40
+ * @param host - The upgrade request's `Host`: the address the client is speaking to.
41
+ * @param named - The origins let in by name.
42
+ * @returns True for no origin, the daemon's own page, or a named origin.
43
+ */
44
+ export declare function attachOrigin_allowed(origin: string | string[] | undefined, host: string | undefined, named: ReadonlyArray<string>): boolean;
45
+ /** The headers of an upgrade that the check reads. */
46
+ export interface AttachHeaders {
47
+ /** `Origin`, as node gives it: several lines joined by a comma. */
48
+ origin?: string | undefined;
49
+ /** `Host`. */
50
+ host?: string | undefined;
51
+ /** `Sec-WebSocket-Version`. */
52
+ 'sec-websocket-version'?: string | string[] | undefined;
53
+ /** `Sec-WebSocket-Origin`: where older drafts of the protocol said the page's origin. */
54
+ 'sec-websocket-origin'?: string | string[] | undefined;
55
+ }
56
+ /**
57
+ * Whether an upgrade may go on, and why not.
58
+ *
59
+ * The origin is read from `Origin`, which is where version 13 says it. An
60
+ * older draft said it in `Sec-WebSocket-Origin`; rather than read two
61
+ * fields and choose, the daemon takes version 13 only, and an upgrade that
62
+ * carries the older field at all is refused, so there is never a second
63
+ * field that says something else.
64
+ *
65
+ * @param headers - The upgrade request's headers.
66
+ * @param named - The origins let in by name.
67
+ * @returns Null when it may go on; otherwise the reason, for the log.
68
+ */
69
+ export declare function attachRequest_refusal(headers: AttachHeaders, named: ReadonlyArray<string>): string | null;
@@ -0,0 +1,125 @@
1
+ /**
2
+ * @file Where an attach came from.
3
+ *
4
+ * A browser opens a socket to any address a page tells it to, and says
5
+ * which page asked (`Origin`). The daemon's wire is for its own surface,
6
+ * the page it serves itself, and for programs, which send no `Origin` at
7
+ * all. A page from somewhere else that has got hold of a token is not
8
+ * either, and its attach is refused before a word is exchanged. The token
9
+ * is required as before in every case: this is a second question, not a
10
+ * replacement for the first.
11
+ *
12
+ * The daemon's own page is the one served from the address the browser is
13
+ * speaking to, over the plain HTTP the daemon speaks: its `Origin` is
14
+ * `http://` and the request's own `Host`. Other origins are let in only by
15
+ * name (`CALYPSO_ORIGINS`): a surface served from elsewhere (a development
16
+ * server), or the daemon's page reached through something that changes its
17
+ * address (a proxy that ends TLS). A door in front (porter) checks the browser's origin against
18
+ * its own name and relays the attach without one.
19
+ *
20
+ * @module
21
+ */
22
+ /**
23
+ * The origins named in the environment (`CALYPSO_ORIGINS`, comma-separated).
24
+ *
25
+ * @param env - The environment.
26
+ * @returns The origins, normalised; what is not an origin is left out.
27
+ */
28
+ export function attachOrigins_read(env) {
29
+ const named = [];
30
+ for (const one of (env['CALYPSO_ORIGINS'] ?? '').split(',')) {
31
+ const origin = origin_parse(one);
32
+ if (origin !== null && !named.includes(origin))
33
+ named.push(origin);
34
+ }
35
+ return named;
36
+ }
37
+ /**
38
+ * An origin as a browser writes it, or null for what is not one.
39
+ *
40
+ * @param text - What was written.
41
+ * @returns Scheme, host and port.
42
+ */
43
+ function origin_parse(text) {
44
+ try {
45
+ const url = new URL(text.trim());
46
+ return (url.protocol === 'http:' || url.protocol === 'https:') && url.username === '' && url.password === '' ? url.origin : null;
47
+ }
48
+ catch {
49
+ return null;
50
+ }
51
+ }
52
+ const FORBIDDEN_HOST_CHARS_RE = /[/?#@]/;
53
+ /**
54
+ * Parses `host` as an `http://` URL and returns its origin when it is a bare host(:port), or null.
55
+ *
56
+ * @param host - Upgrade request `Host` header.
57
+ * @returns The spoken origin, or null when `host` is not a plain host(:port).
58
+ */
59
+ function spokenHostOrigin_parse(host) {
60
+ if (FORBIDDEN_HOST_CHARS_RE.test(host))
61
+ return null;
62
+ let spoken;
63
+ try {
64
+ spoken = new URL(`http://${host}`);
65
+ }
66
+ catch {
67
+ return null;
68
+ }
69
+ const hasExtras = Boolean(spoken.username || spoken.password || spoken.search || spoken.hash);
70
+ if (spoken.pathname !== '/' || hasExtras)
71
+ return null;
72
+ return spoken.origin;
73
+ }
74
+ /**
75
+ * Whether an attach may go on, by where it says it came from.
76
+ *
77
+ * The daemon's own page is the one served from the address this very
78
+ * request was sent to, and the daemon speaks plain HTTP: so the page's
79
+ * origin is `http://` and the request's own `Host`, exactly. Nothing is
80
+ * inferred from the page's side. A page reached another way (through a
81
+ * proxy that ends TLS, under another name) is not the daemon's own as far
82
+ * as the daemon can tell, and is let in by name or not at all.
83
+ *
84
+ * @param origin - The upgrade request's `Origin`; undefined from a program.
85
+ * @param host - The upgrade request's `Host`: the address the client is speaking to.
86
+ * @param named - The origins let in by name.
87
+ * @returns True for no origin, the daemon's own page, or a named origin.
88
+ */
89
+ export function attachOrigin_allowed(origin, host, named) {
90
+ if (origin === undefined)
91
+ return true;
92
+ // One origin, as a browser serializes it; anything else was written by hand.
93
+ if (Array.isArray(origin) || origin_parse(origin) !== origin)
94
+ return false;
95
+ if (named.includes(origin))
96
+ return true;
97
+ if (!host)
98
+ return false;
99
+ return origin === spokenHostOrigin_parse(host);
100
+ }
101
+ /** The one WebSocket version a browser speaks, and the only one this daemon takes. */
102
+ const WEBSOCKET_VERSION = '13';
103
+ /**
104
+ * Whether an upgrade may go on, and why not.
105
+ *
106
+ * The origin is read from `Origin`, which is where version 13 says it. An
107
+ * older draft said it in `Sec-WebSocket-Origin`; rather than read two
108
+ * fields and choose, the daemon takes version 13 only, and an upgrade that
109
+ * carries the older field at all is refused, so there is never a second
110
+ * field that says something else.
111
+ *
112
+ * @param headers - The upgrade request's headers.
113
+ * @param named - The origins let in by name.
114
+ * @returns Null when it may go on; otherwise the reason, for the log.
115
+ */
116
+ export function attachRequest_refusal(headers, named) {
117
+ if (headers['sec-websocket-version'] !== WEBSOCKET_VERSION)
118
+ return `WebSocket version ${String(headers['sec-websocket-version'])} is not taken (only ${WEBSOCKET_VERSION})`;
119
+ if (headers['sec-websocket-origin'] !== undefined)
120
+ return 'it carries Sec-WebSocket-Origin, a second place to say where it came from';
121
+ if (!attachOrigin_allowed(headers.origin, headers.host, named))
122
+ return `it came from ${String(headers.origin)}: not this daemon's own page, and not named in CALYPSO_ORIGINS`;
123
+ return null;
124
+ }
125
+ //# sourceMappingURL=attachOrigin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"attachOrigin.js","sourceRoot":"","sources":["../../src/daemon/attachOrigin.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH;;;;;GAKG;AACH,MAAM,UAAU,kBAAkB,CAAC,GAAsB;IACvD,MAAM,KAAK,GAAa,EAAE,CAAC;IAC3B,KAAK,MAAM,GAAG,IAAI,CAAC,GAAG,CAAC,iBAAiB,CAAC,IAAI,EAAE,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE,CAAC;QAC5D,MAAM,MAAM,GAAkB,YAAY,CAAC,GAAG,CAAC,CAAC;QAChD,IAAI,MAAM,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,MAAM,CAAC;YAAE,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IACrE,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AAED;;;;;GAKG;AACH,SAAS,YAAY,CAAC,IAAY;IAChC,IAAI,CAAC;QACH,MAAM,GAAG,GAAQ,IAAI,GAAG,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC;QACtC,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,OAAO,IAAI,GAAG,CAAC,QAAQ,KAAK,QAAQ,CAAC,IAAI,GAAG,CAAC,QAAQ,KAAK,EAAE,IAAI,GAAG,CAAC,QAAQ,KAAK,EAAE,CAAC,CAAC,CA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