electron-cast 0.3.0 → 0.4.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 (204) hide show
  1. package/CHANGELOG.md +66 -0
  2. package/README.md +122 -12
  3. package/dist/cjs/client/auth/build-time.d.ts +7 -0
  4. package/dist/cjs/client/auth/build-time.js +11 -0
  5. package/dist/cjs/client/auth/build-time.js.map +1 -0
  6. package/dist/cjs/client/auth/cast-auth.d.ts +44 -0
  7. package/dist/cjs/client/auth/cast-auth.js +145 -0
  8. package/dist/cjs/client/auth/cast-auth.js.map +1 -0
  9. package/dist/cjs/client/auth/cast-cert-validator.d.ts +34 -0
  10. package/dist/cjs/client/auth/cast-cert-validator.js +89 -0
  11. package/dist/cjs/client/auth/cast-cert-validator.js.map +1 -0
  12. package/dist/cjs/client/auth/crl.d.ts +45 -0
  13. package/dist/cjs/client/auth/crl.js +227 -0
  14. package/dist/cjs/client/auth/crl.js.map +1 -0
  15. package/dist/cjs/client/auth/der.d.ts +62 -0
  16. package/dist/cjs/client/auth/der.js +208 -0
  17. package/dist/cjs/client/auth/der.js.map +1 -0
  18. package/dist/cjs/client/auth/names.d.ts +52 -0
  19. package/dist/cjs/client/auth/names.js +447 -0
  20. package/dist/cjs/client/auth/names.js.map +1 -0
  21. package/dist/cjs/client/auth/path-validator.d.ts +29 -0
  22. package/dist/cjs/client/auth/path-validator.js +421 -0
  23. package/dist/cjs/client/auth/path-validator.js.map +1 -0
  24. package/dist/cjs/client/auth/trust-data.d.ts +24 -0
  25. package/dist/cjs/client/auth/trust-data.js +97 -0
  26. package/dist/cjs/client/auth/trust-data.js.map +1 -0
  27. package/dist/cjs/client/auth/x509.d.ts +109 -0
  28. package/dist/cjs/client/auth/x509.js +442 -0
  29. package/dist/cjs/client/auth/x509.js.map +1 -0
  30. package/dist/cjs/client/cast-client.d.ts +111 -0
  31. package/dist/cjs/client/cast-client.js +505 -0
  32. package/dist/cjs/client/cast-client.js.map +1 -0
  33. package/dist/cjs/client/errors.d.ts +28 -0
  34. package/dist/cjs/client/errors.js +50 -0
  35. package/dist/cjs/client/errors.js.map +1 -0
  36. package/dist/cjs/client/index.d.ts +6 -0
  37. package/dist/cjs/client/index.js +21 -0
  38. package/dist/cjs/client/index.js.map +1 -0
  39. package/dist/cjs/client/namespaces.d.ts +9 -0
  40. package/dist/cjs/client/namespaces.js +13 -0
  41. package/dist/cjs/client/namespaces.js.map +1 -0
  42. package/dist/cjs/client/types.d.ts +27 -0
  43. package/dist/cjs/client/types.js +3 -0
  44. package/dist/cjs/client/types.js.map +1 -0
  45. package/dist/cjs/discovery/cast-discovery.d.ts +103 -0
  46. package/dist/cjs/discovery/cast-discovery.js +323 -0
  47. package/dist/cjs/discovery/cast-discovery.js.map +1 -0
  48. package/dist/cjs/discovery/device-cache.d.ts +45 -0
  49. package/dist/cjs/discovery/device-cache.js +240 -0
  50. package/dist/cjs/discovery/device-cache.js.map +1 -0
  51. package/dist/cjs/discovery/dns-packet.d.ts +70 -0
  52. package/dist/cjs/discovery/dns-packet.js +251 -0
  53. package/dist/cjs/discovery/dns-packet.js.map +1 -0
  54. package/dist/cjs/discovery/index.d.ts +4 -0
  55. package/dist/cjs/discovery/index.js +21 -0
  56. package/dist/cjs/discovery/index.js.map +1 -0
  57. package/dist/cjs/discovery/udp-socket.d.ts +16 -0
  58. package/dist/cjs/discovery/udp-socket.js +163 -0
  59. package/dist/cjs/discovery/udp-socket.js.map +1 -0
  60. package/dist/cjs/electron/main.d.ts +86 -0
  61. package/dist/cjs/electron/main.js +408 -0
  62. package/dist/cjs/electron/main.js.map +1 -0
  63. package/dist/cjs/electron/manager-api.d.ts +132 -0
  64. package/dist/cjs/electron/manager-api.js +207 -0
  65. package/dist/cjs/electron/manager-api.js.map +1 -0
  66. package/dist/cjs/electron/preload.d.ts +39 -0
  67. package/dist/cjs/electron/preload.js +96 -0
  68. package/dist/cjs/electron/preload.js.map +1 -0
  69. package/dist/cjs/electron/presentation-envelope.d.ts +60 -0
  70. package/dist/cjs/electron/presentation-envelope.js +318 -0
  71. package/dist/cjs/electron/presentation-envelope.js.map +1 -0
  72. package/dist/cjs/electron/presentation-handler.d.ts +100 -0
  73. package/dist/cjs/electron/presentation-handler.js +499 -0
  74. package/dist/cjs/electron/presentation-handler.js.map +1 -0
  75. package/dist/cjs/electron/session-service.d.ts +174 -0
  76. package/dist/cjs/electron/session-service.js +891 -0
  77. package/dist/cjs/electron/session-service.js.map +1 -0
  78. package/dist/cjs/index.d.ts +8 -0
  79. package/dist/cjs/index.js +26 -0
  80. package/dist/cjs/index.js.map +1 -0
  81. package/dist/cjs/package.json +1 -0
  82. package/dist/cjs/polyfill/bridge-types.d.ts +86 -0
  83. package/dist/cjs/polyfill/bridge-types.js +3 -0
  84. package/dist/cjs/polyfill/bridge-types.js.map +1 -0
  85. package/dist/cjs/polyfill/install.d.ts +12 -0
  86. package/dist/cjs/polyfill/install.js +1569 -0
  87. package/dist/cjs/polyfill/install.js.map +1 -0
  88. package/dist/cjs/polyfill/presentation-standin.d.ts +13 -0
  89. package/dist/cjs/polyfill/presentation-standin.js +279 -0
  90. package/dist/cjs/polyfill/presentation-standin.js.map +1 -0
  91. package/dist/cjs/protocol/cast-message.d.ts +20 -0
  92. package/dist/cjs/protocol/cast-message.js +171 -0
  93. package/dist/cjs/protocol/cast-message.js.map +1 -0
  94. package/dist/cjs/protocol/device-auth.d.ts +61 -0
  95. package/dist/cjs/protocol/device-auth.js +113 -0
  96. package/dist/cjs/protocol/device-auth.js.map +1 -0
  97. package/dist/cjs/protocol/errors.d.ts +4 -0
  98. package/dist/cjs/protocol/errors.js +12 -0
  99. package/dist/cjs/protocol/errors.js.map +1 -0
  100. package/dist/cjs/protocol/framing.d.ts +18 -0
  101. package/dist/cjs/protocol/framing.js +100 -0
  102. package/dist/cjs/protocol/framing.js.map +1 -0
  103. package/dist/cjs/protocol/index.d.ts +4 -0
  104. package/dist/cjs/protocol/index.js +21 -0
  105. package/dist/cjs/protocol/index.js.map +1 -0
  106. package/dist/cjs/protocol/proto-wire.d.ts +11 -0
  107. package/dist/cjs/protocol/proto-wire.js +64 -0
  108. package/dist/cjs/protocol/proto-wire.js.map +1 -0
  109. package/dist/client/auth/build-time.d.ts +7 -0
  110. package/dist/client/auth/build-time.js +8 -0
  111. package/dist/client/auth/build-time.js.map +1 -0
  112. package/dist/client/auth/cast-auth.d.ts +44 -0
  113. package/dist/client/auth/cast-auth.js +141 -0
  114. package/dist/client/auth/cast-auth.js.map +1 -0
  115. package/dist/client/auth/cast-cert-validator.d.ts +34 -0
  116. package/dist/client/auth/cast-cert-validator.js +86 -0
  117. package/dist/client/auth/cast-cert-validator.js.map +1 -0
  118. package/dist/client/auth/crl.d.ts +45 -0
  119. package/dist/client/auth/crl.js +221 -0
  120. package/dist/client/auth/crl.js.map +1 -0
  121. package/dist/client/auth/der.d.ts +62 -0
  122. package/dist/client/auth/der.js +196 -0
  123. package/dist/client/auth/der.js.map +1 -0
  124. package/dist/client/auth/names.d.ts +52 -0
  125. package/dist/client/auth/names.js +438 -0
  126. package/dist/client/auth/names.js.map +1 -0
  127. package/dist/client/auth/path-validator.d.ts +29 -0
  128. package/dist/client/auth/path-validator.js +417 -0
  129. package/dist/client/auth/path-validator.js.map +1 -0
  130. package/dist/client/auth/trust-data.d.ts +24 -0
  131. package/dist/client/auth/trust-data.js +94 -0
  132. package/dist/client/auth/trust-data.js.map +1 -0
  133. package/dist/client/auth/x509.d.ts +109 -0
  134. package/dist/client/auth/x509.js +430 -0
  135. package/dist/client/auth/x509.js.map +1 -0
  136. package/dist/client/cast-client.d.ts +20 -1
  137. package/dist/client/cast-client.js +74 -3
  138. package/dist/client/cast-client.js.map +1 -1
  139. package/dist/client/errors.d.ts +11 -0
  140. package/dist/client/errors.js +13 -0
  141. package/dist/client/errors.js.map +1 -1
  142. package/dist/client/index.d.ts +2 -0
  143. package/dist/discovery/cast-discovery.d.ts +21 -2
  144. package/dist/discovery/cast-discovery.js +94 -14
  145. package/dist/discovery/cast-discovery.js.map +1 -1
  146. package/dist/discovery/device-cache.d.ts +6 -1
  147. package/dist/discovery/device-cache.js +31 -7
  148. package/dist/discovery/device-cache.js.map +1 -1
  149. package/dist/discovery/udp-socket.d.ts +5 -1
  150. package/dist/discovery/udp-socket.js +56 -5
  151. package/dist/discovery/udp-socket.js.map +1 -1
  152. package/dist/electron/main.d.ts +26 -4
  153. package/dist/electron/main.js +193 -55
  154. package/dist/electron/main.js.map +1 -1
  155. package/dist/electron/manager-api.d.ts +132 -0
  156. package/dist/electron/manager-api.js +198 -0
  157. package/dist/electron/manager-api.js.map +1 -0
  158. package/dist/electron/preload.d.ts +5 -0
  159. package/dist/electron/preload.js +9 -1
  160. package/dist/electron/preload.js.map +1 -1
  161. package/dist/electron/presentation-envelope.js +7 -1
  162. package/dist/electron/presentation-envelope.js.map +1 -1
  163. package/dist/electron/presentation-handler.js +16 -9
  164. package/dist/electron/presentation-handler.js.map +1 -1
  165. package/dist/electron/session-service.d.ts +50 -1
  166. package/dist/electron/session-service.js +256 -33
  167. package/dist/electron/session-service.js.map +1 -1
  168. package/dist/polyfill/presentation-standin.js +3 -2
  169. package/dist/polyfill/presentation-standin.js.map +1 -1
  170. package/dist/protocol/device-auth.d.ts +61 -0
  171. package/dist/protocol/device-auth.js +106 -0
  172. package/dist/protocol/device-auth.js.map +1 -0
  173. package/dist/protocol/index.d.ts +1 -0
  174. package/dist/protocol/index.js +1 -0
  175. package/dist/protocol/index.js.map +1 -1
  176. package/dist/protocol/proto-wire.d.ts +11 -0
  177. package/dist/protocol/proto-wire.js +60 -0
  178. package/dist/protocol/proto-wire.js.map +1 -0
  179. package/package.json +47 -12
  180. package/src/client/auth/build-time.ts +7 -0
  181. package/src/client/auth/cast-auth.ts +184 -0
  182. package/src/client/auth/cast-cert-validator.ts +133 -0
  183. package/src/client/auth/crl.ts +228 -0
  184. package/src/client/auth/der.ts +193 -0
  185. package/src/client/auth/names.ts +411 -0
  186. package/src/client/auth/path-validator.ts +449 -0
  187. package/src/client/auth/trust-data.ts +95 -0
  188. package/src/client/auth/x509.ts +488 -0
  189. package/src/client/cast-client.ts +85 -3
  190. package/src/client/errors.ts +29 -0
  191. package/src/client/index.ts +2 -0
  192. package/src/discovery/cast-discovery.ts +104 -19
  193. package/src/discovery/device-cache.ts +38 -8
  194. package/src/discovery/udp-socket.ts +63 -4
  195. package/src/electron/main.ts +220 -60
  196. package/src/electron/manager-api.ts +312 -0
  197. package/src/electron/preload.ts +15 -1
  198. package/src/electron/presentation-envelope.ts +7 -1
  199. package/src/electron/presentation-handler.ts +16 -10
  200. package/src/electron/session-service.ts +265 -34
  201. package/src/polyfill/presentation-standin.ts +3 -2
  202. package/src/protocol/device-auth.ts +126 -0
  203. package/src/protocol/index.ts +1 -0
  204. package/src/protocol/proto-wire.ts +55 -0
package/CHANGELOG.md CHANGED
@@ -1,5 +1,71 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.4.0
4
+
5
+ - **Devices are now verified, as in Chrome.** `CastClient.connect()` runs the Cast device authentication challenge
6
+ after TLS and before CONNECT: it checks the device's certificate chain against Google's Cast roots (a port of
7
+ Chromium's checks, with no new dependencies), revocation, and a signature tied to the connection's TLS certificate.
8
+ A device that fails makes `connect()` reject with the new `CastAuthError` (with a `reason`), and the page sees an
9
+ unreachable device. It is on by default. Set `verifyDevices: false` on `createCastManager`, or `verifyDevice: false`
10
+ on `CastClient`, for receivers that are not Google-certified. `CastClient` also gains `authTimeoutMs`, `deviceAuth`
11
+ (trust roots and clock, for tests and private deployments) and a `deviceAuth` result (`policy`, `hashAlgorithm`,
12
+ `nonceEchoed`, `usedFallbackCrl`, `revocationChecked`). The protocol layer gains `DeviceAuthMessage` encoding and
13
+ decoding. Tested on 8 real devices, which all passed.
14
+ - Device authentication does not start refusing devices that send no CRL once the built-in fallback CRL is past its 20
15
+ weeks: with a lapsed fallback and no valid CRL from the device, the revocation check is skipped and
16
+ `deviceAuth.revocationChecked` is `false` (Chromium fails closed; Chrome updates itself, an app may not). All other
17
+ checks, the device's own CRL, and revocation by a still-valid fallback CRL are unchanged. The fallback window starts
18
+ at the package's build time, stamped by `npm run build`.
19
+ - Presentation mode: `start()` now needs transient user activation in the main process too, not only in the page's
20
+ stand-in. The preload reads `navigator.userActivation.isActive` in its isolated world and the main process refuses
21
+ a start without it (`AbortError`, "PresentationRequest::start() requires user gesture.", as Chrome's browser-side
22
+ check). The stand-in's own refusal now throws Blink's `InvalidAccessError` instead of `AbortError`. Electron has no
23
+ main-process API for activation, so a compromised renderer could still forge it (see SECURITY.md).
24
+ - Presentation mode: a page can rejoin a session that kept playing on the device after the app restarted, the way it
25
+ can in Chrome. The library persists nothing: the app keeps the session id, the page calls
26
+ `chrome.cast.requestSessionById`, Google's SDK turns that into `reconnect("cast-session_<id>")`, and electron-cast
27
+ finds the session by asking the known devices what they run (the new `joinRunningSession` service call). Auto-join
28
+ still does not join such sessions, as in Chrome. Joining by id no longer checks the origin, also for a session this
29
+ run holds, as in Chrome (`AppActivity::CanJoinSession`); `allowOrigin` still applies. `mode: "chromecast"` is
30
+ unchanged.
31
+ - Google's Cast SDK now works inside iframes in presentation mode, with Chrome's per-frame semantics: each frame has its
32
+ own availability watches, connections and sessions, receives only its own events, and uses its own origin. An iframe
33
+ that navigates parks its sessions; a removed iframe or a navigating page ends them. Needs
34
+ `nodeIntegrationInSubFrames: true` in the window's `webPreferences` so the preload runs in iframes; without it nothing
35
+ changes. `mode: "chromecast"` stays main-frame only.
36
+ - Discovery also runs mDNS over IPv6 (link-local, per adapter), so IPv6-only devices are found; `fe80::` addresses carry
37
+ their scope so they can be connected to, and IPv4 is still preferred. A network adapter that goes away takes its
38
+ devices with it at once, and sockets are replaced after the machine wakes from sleep.
39
+ - Main-process API on the cast manager, modelled on Chrome's Media Router: sinks and routes observers, `getRoutes`,
40
+ `terminateRoute`, `detachRoute`, route volume control, and a third `selectDevice` argument that streams devices
41
+ found while the picker is open. Sink icon types follow Chrome's `GetCastSinkIconType`, and a route's `members` are
42
+ `webContents.id`s, also for iframes. See docs/MAIN-API.md.
43
+ - Presentation mode matches Chrome's Media Router for v2 requests: `QUEUE_NEXT`, `QUEUE_PREV` and `PRECACHE` are
44
+ forwarded to the receiver (they were dropped, so their callbacks never fired); a failed `SET_VOLUME` or `STOP`
45
+ reports `internal_error` / "unknown error"; a media request that cannot be sent gets no reply; an app message for a
46
+ vanished session reports `session_error` "Invalid session ID". Unknown v2 message types are still dropped, as in Chrome.
47
+ - Added a CommonJS build (`dist/cjs`, no new dependencies) with `import` / `require` conditions on every entry point, so a
48
+ non-sandboxed CommonJS preload or main process can `require("electron-cast/preload")` and `require("electron-cast/main")`.
49
+ The ESM build is unchanged. `package.json` declares an optional peer dependency on `electron >=35`.
50
+ - CI runs a smoke test in a real Electron (35, 40 and the latest stable, on Linux, Windows and macOS): a sandboxed
51
+ preload built from `electron-cast/preload`, `createCastManager` from `electron-cast/main` with a fake device, both
52
+ modes. `npm run smoke` runs it locally. A weekly canary (`npm run canary`) fetches Google's Cast sender SDK for the
53
+ current Chrome majors and checks it still speaks the message envelope the translator expects; a failed run opens one
54
+ issue.
55
+ - The `DeviceAuthResult`, `DeviceAuthOptions`, `CastCertError` and `CastDeviceCertPolicy` types are exported.
56
+ - The page's IPC channel accepts only the bridge's own methods. `joinRunningSession`, which only main calls, is refused
57
+ from a page as an unknown method.
58
+ - Thanks to Michael Arthur (@mikey0000). Restart rejoin was proposed by him in
59
+ [#1](https://github.com/adammpkins/electron-cast/pull/1) (an optional `sessionStore`); 0.4.0 does it the way Chrome
60
+ does instead, as described above. His [#2](https://github.com/adammpkins/electron-cast/pull/2) arrived independently
61
+ at the presentation-mode design that 0.3.0 shipped.
62
+
63
+ ## 0.3.1
64
+
65
+ - A page that reloads while casting now gets its session back. A navigation used to leave the page's sessions, which
66
+ closed them on the device, so the reloaded page's auto-join found nothing. Now they stay open (parked) and the next
67
+ page rejoins them, as in Chrome. Closing the page still leaves them.
68
+
3
69
  ## 0.3.0
4
70
 
5
71
  - **Changed default: pages now run Google's own Cast SDK.** `installCastBridge` installs a stand-in Presentation API
package/README.md CHANGED
@@ -14,7 +14,14 @@ unchanged.
14
14
  npm install electron-cast
15
15
  ```
16
16
 
17
- Requires Electron 35 or later (for `contextBridge.executeInMainWorld`).
17
+ Requires Electron 35 or later (for `contextBridge.executeInMainWorld`; the preload fails on 34). Electron is an
18
+ optional peer dependency (`electron >=35`): the library never imports it, you pass `ipcMain`, `contextBridge` and
19
+ `ipcRenderer` in. Node 20 or later. The package ships ES modules and a CommonJS build, so `import` and `require` both
20
+ work. CI loads the built package in a real Electron 35, 40 and the latest stable on Linux, Windows and macOS
21
+ (`npm run smoke` runs it locally once you have installed Electron).
22
+
23
+ electron-cast behaves as Chrome does on the Presentation API path, which is the default; `mode: "chromecast"` is a
24
+ frozen fallback (see below).
18
25
 
19
26
  ## Use
20
27
 
@@ -52,8 +59,10 @@ installCastBridge({ contextBridge, ipcRenderer });
52
59
  ```
53
60
 
54
61
  Import from `electron-cast/preload`, not the package root: the root also exports the main-process code, which needs
55
- Node's `tls` and `dgram` and cannot load in a sandboxed preload. The preload entry has no imports of its own, so a
56
- bundler can inline it.
62
+ Node's `tls` and `dgram` and cannot load in a sandboxed preload. The preload entry imports nothing Node-only, but a
63
+ sandboxed preload cannot load other files either, so bundle it into your preload (esbuild, for example, as
64
+ `smoke/build-preloads.mjs` does). A non-sandboxed CommonJS preload can `require("electron-cast/preload")` directly:
65
+ the package ships a CommonJS build next to the ESM one.
57
66
 
58
67
  That's all. The page loads Google's Cast SDK as usual, and its cast button drives sessions through IPC to the main
59
68
  process.
@@ -65,10 +74,49 @@ Electron Google's Cast SDK finds no devices. By default electron-cast fills in t
65
74
  stand-in Presentation API backed by the main process, and **Google's own `cast_sender.js` and `cast.framework` load
66
75
  and run unmodified**, as they do in Chrome. electron-cast never replaces Google's SDK.
67
76
 
68
- A cast has to start from a user gesture (a click on the page's cast button), as in Chrome. Current limits:
77
+ A cast has to start from a user gesture (a click on the page's cast button), as in Chrome. Chrome checks that in the
78
+ browser process; Electron has no main-process API for it, so the preload reads `navigator.userActivation.isActive` in
79
+ its own isolated world when the page asks to start, and the main process refuses a start without it. A page's scripts
80
+ cannot forge that, a compromised renderer could (see [SECURITY.md](SECURITY.md#user-gesture)). `mode: "chromecast"` has
81
+ no gesture check.
82
+
83
+ **Reloads and restarts.** As in Chrome, a session belongs to the app rather than the page, so a page that reloads gets
84
+ its session back through auto-join.
85
+
86
+ After the Electron app itself restarts, a session may still be playing on the device. electron-cast saves nothing for
87
+ that, and auto-join does not find it (Chrome's auto-join only joins sessions started by that browser run). The app
88
+ persists the session id and the page reconnects with it: Google's SDK exposes the id as `session.sessionId`, so the page
89
+ keeps it (in `localStorage`, say) and calls `chrome.cast.requestSessionById(id)` (or `cast.framework`'s equivalent) at
90
+ startup. The SDK turns that into `PresentationRequest.reconnect("cast-session_<id>")`, which reaches electron-cast's
91
+ `joinRunningSession`: it asks the known devices which one runs that session and joins it if the app matches, with no
92
+ origin check (Chrome's `AppActivity::CanJoinSession` checks only the app id and that the client is not already
93
+ connected), also when this run already holds the session; `allowOrigin` still applies first. If the device no longer
94
+ runs the session, the call fails like in Chrome. Discovery has to have found the device by then, so the page may need
95
+ to retry for a few seconds after startup. `mode: "chromecast"` does not do this.
96
+
97
+ **Iframes (presentation mode only).** Google's SDK also works inside an iframe (an embedded player, say). As in Chrome,
98
+ each frame is its own controlling context: its availability watches, connections and sessions belong to that frame, its
99
+ events reach only that frame, and it can't read, close or message another frame's connections. The origin electron-cast
100
+ uses (for `allowOrigin`, the device picker and origin-scoped auto-join) is the sending frame's own, so a cross-origin
101
+ iframe is its own origin. An iframe that navigates parks its sessions as a reloading page does, and is left for good when
102
+ it is removed or its page navigates. Electron only runs a preload in subframes if the app opts in:
103
+
104
+ ```js
105
+ new BrowserWindow({
106
+ webPreferences: {
107
+ preload: path.join(__dirname, "preload.js"),
108
+ sandbox: true,
109
+ contextIsolation: true,
110
+ nodeIntegrationInSubFrames: true, // run the preload in iframes too
111
+ },
112
+ });
113
+ ```
69
114
 
70
- - A session doesn't survive a page reload, so auto-join after a reload starts a new session.
71
- - Google's SDK running inside an iframe gets no events, because messages go to the main frame.
115
+ Without `nodeIntegrationInSubFrames`, nothing changes: the preload runs only in the main frame, an iframe has no stand-in
116
+ and no cast, and its SDK finds no devices. With it, the preload (and so the cast bridge) runs in every iframe of every
117
+ origin, so keep `allowOrigin` strict. `nodeIntegration` stays `false`, so an iframe's page still gets no Node. The
118
+ frame handling is covered by unit tests against fake frames; the real-Electron smoke test does not load an iframe.
119
+ `mode: "chromecast"` stays main-frame only: a call from an iframe is refused.
72
120
 
73
121
  **Fallback: `mode: "chromecast"`.** This installs electron-cast's own implementation of `chrome.cast` and
74
122
  `chrome.cast.media` and blocks Google's loader scripts. Use it for pages that call `chrome.cast` without loading
@@ -80,15 +128,63 @@ installCastBridge({ contextBridge, ipcRenderer, mode: "chromecast" });
80
128
 
81
129
  The main process serves both modes. `createCastManager({ ..., presentation: false })` serves only `"chromecast"`.
82
130
 
131
+ ## Device authentication
132
+
133
+ Like Chrome, electron-cast checks that a device is a genuine Google-certified Cast device before using it (the
134
+ `deviceauth` challenge, with Google's Cast root certificates built in and no dependencies). This happens when the
135
+ connection opens, not at discovery, so a device that fails still shows in the picker but casting to it fails like an
136
+ unreachable device.
137
+
138
+ On by default; receivers that are not Google-certified (open-source ones, for example) need it off:
139
+
140
+ ```js
141
+ createCastManager({ ipcMain, selectDevice, verifyDevices: false }); // CastClient: { verifyDevice: false }
142
+ ```
143
+
144
+ A device that fails makes `CastClient.connect()` reject with a `CastAuthError` whose `reason` says why (for example
145
+ `untrusted_chain` or `revoked`). With the default client, `client.deviceAuth` holds what was established.
146
+
147
+ Like Chrome's own built-in security data, the built-in fallback CRL goes stale: it counts for 20 weeks from the build
148
+ time stamped by `npm run build`. A device that sends no CRL of its own is then accepted without a revocation check
149
+ (`deviceAuth.revocationChecked` is `false`) instead of refused. Everything else is still checked; update the package
150
+ to get a fresh fallback CRL. Details: [docs/DESIGN.md](docs/DESIGN.md) and [SECURITY.md](SECURITY.md).
151
+
152
+ Tested on 8 real devices on a home network, which all passed (an audio-only Google Home Mini got the `audio_only`
153
+ policy). How it works and what it leaves out: [docs/DESIGN.md](docs/DESIGN.md).
154
+
155
+ ## Known issue: top-level `await app.whenReady()` in an ESM main process
156
+
157
+ In an ES module main process (`"type": "module"`, or an `.mjs` main), a top-level `await app.whenReady()` never
158
+ resolves on Electron 45 (reproduced on 45.5.0 on Windows): the app logs the line before it and then hangs. It is
159
+ Electron's ESM startup, not electron-cast. Use `app.whenReady().then(...)` or put the work in a function that is not
160
+ awaited at the top level:
161
+
162
+ ```js
163
+ app.whenReady().then(async () => {
164
+ await cast.start();
165
+ // create windows
166
+ });
167
+ ```
168
+
169
+ Related report: [electron/electron#40719](https://github.com/electron/electron/issues/40719) (closed; a comment
170
+ there describes the top-level await form of the same hang).
171
+
83
172
  ## What works
84
173
 
85
- - Device discovery over mDNS on every network interface, with devices coming and going live.
86
- - Several pages or windows at once. A page that reloads or closes leaves its sessions without stopping playback.
174
+ - Device discovery over mDNS on every IPv4 network interface and over IPv6 link-local on each adapter, with devices
175
+ coming and going live. A network that goes away takes its devices with it, and discovery recovers after the machine
176
+ wakes from sleep.
177
+ - Devices are verified as genuine Google-certified Cast devices, as Chrome does (on by default, see above).
178
+ - Several pages or windows at once, and iframes (with `nodeIntegrationInSubFrames`). A page that reloads keeps its
179
+ sessions open on the device and rejoins them (auto-join, `origin_scoped` or `tab_and_origin_scoped`). A page that
180
+ closes leaves its sessions without stopping playback. After an app restart a page rejoins a session by id (above).
181
+ - A main-process API modelled on Chrome's Media Router: observe devices and sessions, stop or detach a session, set
182
+ its volume, and keep a picker up to date while it is open ([docs/MAIN-API.md](docs/MAIN-API.md)).
87
183
 
88
184
  **Default mode (Google's SDK):**
89
185
 
90
- - Google's SDK gets what Chrome would give it: receiver availability, the device picker, sessions and joining them,
91
- messages on any namespace, volume, and media commands with their status replies.
186
+ - Google's SDK gets what Chrome would give it: receiver availability, the device picker, sessions and joining them
187
+ (including by id after a restart), messages on any namespace, volume, and media commands with their status replies.
92
188
  - Tested end to end with YouTube Music (YouTube Music Desktop, Electron 45) casting to speaker groups, a Nest Hub
93
189
  and several Chromecasts, and with `cast.framework` on a Nest Hub: session start, volume, HLS load, play, pause,
94
190
  seek, resume and stop.
@@ -106,16 +202,30 @@ The main process serves both modes. `createCastManager({ ..., presentation: fals
106
202
 
107
203
  Discovery and connections are tested with Chromecast Ultra, Google Home Mini, Nest Hub, Nest Hub Max and speaker groups.
108
204
 
205
+ ## Staying compatible with Google's SDK
206
+
207
+ In the default mode the page runs Google's SDK, which Google can change per Chrome major without an electron-cast
208
+ release. `npm run canary` (also a weekly GitHub Actions job) downloads the SDK for Chrome stable, beta and dev and for
209
+ the Chromium that Electron 45 ships, and checks as text, without running it, that it still uses the message types,
210
+ fields, request types and presentation URLs electron-cast translates. A missing one fails; a new message type is a
211
+ warning. `tools/sdk-canary-baseline.json` records what the SDK looked like when it last worked; refresh it with
212
+ `node tools/sdk-canary.mjs --update-baseline`. Options: `--majors 158,159`, `--electron <major>|none`.
213
+
109
214
  ## Lower layers
110
215
 
111
216
  The package root exports every layer, if you want to use them without Electron:
112
217
 
113
- - `CastDiscovery`: mDNS discovery of Cast devices.
114
- - `CastClient`: a Cast v2 connection over TLS (connect, heartbeat, launch, stop, volume, app messages).
218
+ - `CastDiscovery`: mDNS discovery of Cast devices (IPv4 and IPv6).
219
+ - `CastClient`: a Cast v2 connection over TLS (device authentication, connect, heartbeat, launch, stop, volume, app
220
+ messages).
115
221
  - `CastSessionService`: the session logic behind the Electron layer, with no Electron dependency.
116
222
 
117
223
  See [docs/DESIGN.md](docs/DESIGN.md) for how the pieces fit.
118
224
 
225
+ To observe and control casting from the main process (devices, sessions, volume, a live picker), see [docs/MAIN-API.md](docs/MAIN-API.md).
226
+ More docs: [API reference](docs/API.md), [security notes](SECURITY.md), [changelog](CHANGELOG.md) and a
227
+ [runnable example app](examples/electron-app).
228
+
119
229
  ## License
120
230
 
121
231
  MIT
@@ -0,0 +1,7 @@
1
+ /**
2
+ * When this package was built, epoch milliseconds: the stand-in for Chromium's base::GetBuildTime(), where the built-in
3
+ * fallback CRL's 20-week window starts. It is `undefined` in the source; `npm run build` (scripts/stamp-build-time.mjs)
4
+ * rewrites this one assignment in the emitted dist files, so source checkouts and tests fall back to the date in
5
+ * trust-data.ts and the working tree stays clean.
6
+ */
7
+ export declare const BUILD_TIME: number | undefined;
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BUILD_TIME = void 0;
4
+ /**
5
+ * When this package was built, epoch milliseconds: the stand-in for Chromium's base::GetBuildTime(), where the built-in
6
+ * fallback CRL's 20-week window starts. It is `undefined` in the source; `npm run build` (scripts/stamp-build-time.mjs)
7
+ * rewrites this one assignment in the emitted dist files, so source checkouts and tests fall back to the date in
8
+ * trust-data.ts and the working tree stays clean.
9
+ */
10
+ exports.BUILD_TIME = 1795584965531;
11
+ //# sourceMappingURL=build-time.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"build-time.js","sourceRoot":"","sources":["../../../../src/client/auth/build-time.ts"],"names":[],"mappings":";;;AAAA;;;;;GAKG;AACU,QAAA,UAAU,GAAuB,SAAS,CAAC"}
@@ -0,0 +1,44 @@
1
+ import { type CastDeviceCertPolicy } from "./cast-cert-validator.ts";
2
+ export interface DeviceAuthOptions {
3
+ /** Verification time, epoch milliseconds. Defaults to now. */
4
+ now?: number;
5
+ /** Trust anchors (DER) replacing the Cast Root CA and Eureka Root CA. For tests and private Cast deployments. */
6
+ roots?: Uint8Array[];
7
+ /** CRL trust anchors (DER) replacing the Cast CRL Root CA. */
8
+ crlRoots?: Uint8Array[];
9
+ /** Replacement fallback CRL (a serialized CrlBundle), or `null` for none. */
10
+ fallbackCrl?: Uint8Array | null;
11
+ /** The "build time" the fallback CRL's 20-week window starts at, epoch milliseconds. */
12
+ fallbackCrlBuildTime?: number;
13
+ }
14
+ export interface DeviceAuthResult {
15
+ policy: CastDeviceCertPolicy;
16
+ hashAlgorithm: "sha1" | "sha256";
17
+ /** False when the device's reply did not echo our nonce; Chromium records this and carries on. */
18
+ nonceEchoed: boolean;
19
+ /** True when the device sent no usable CRL and the built-in fallback CRL was used instead. */
20
+ usedFallbackCrl: boolean;
21
+ /**
22
+ * False only when the built-in fallback CRL had expired and the device sent no valid CRL, so the revocation check was
23
+ * skipped (Chromium would refuse the device). Revocation by a device CRL or a still-valid fallback CRL is always checked.
24
+ */
25
+ revocationChecked: boolean;
26
+ }
27
+ /** A challenge: the nonce and the DeviceAuthMessage bytes that go in the CastMessage's binary payload. */
28
+ export declare function createAuthChallenge(): {
29
+ nonce: Buffer;
30
+ payload: Buffer;
31
+ };
32
+ /** The decoded fields of a binary CastMessage reply on the deviceauth namespace. */
33
+ export interface AuthReplyMessage {
34
+ payloadType: number;
35
+ payloadBinary: Buffer | undefined;
36
+ }
37
+ /**
38
+ * AuthenticateChallengeReply. Throws {@link CastAuthError} unless the reply proves the TLS peer is a genuine,
39
+ * Google-certified Cast device.
40
+ *
41
+ * `peerCertDer` is the DER of the TLS certificate the device presented on this connection; the signature in the
42
+ * reply is over `senderNonce || peerCertDer`, which binds the proof to this TLS session's certificate.
43
+ */
44
+ export declare function authenticateChallengeReply(reply: AuthReplyMessage, peerCertDer: Uint8Array, nonce: Uint8Array, options?: DeviceAuthOptions): DeviceAuthResult;
@@ -0,0 +1,145 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createAuthChallenge = createAuthChallenge;
4
+ exports.authenticateChallengeReply = authenticateChallengeReply;
5
+ const node_crypto_1 = require("node:crypto");
6
+ const errors_ts_1 = require("../../protocol/errors.js");
7
+ const cast_message_ts_1 = require("../../protocol/cast-message.js");
8
+ const device_auth_ts_1 = require("../../protocol/device-auth.js");
9
+ const errors_ts_2 = require("../errors.js");
10
+ const cast_cert_validator_ts_1 = require("./cast-cert-validator.js");
11
+ const crl_ts_1 = require("./crl.js");
12
+ const trust_data_ts_1 = require("./trust-data.js");
13
+ const x509_ts_1 = require("./x509.js");
14
+ /**
15
+ * The sender side of Cast device authentication, ported from components/media_router/common/providers/cast/channel/
16
+ * cast_auth_util.cc (AuthenticateChallengeReply, VerifyCredentialsImpl, VerifyTLSCertificate, ParseAuthMessage,
17
+ * VerifyAndMapDigestAlgorithm, AuthContext::VerifySenderNonce) and cast_message_util.cc (CreateAuthChallengeMessage).
18
+ */
19
+ /** Chromium's kMaxSelfSignedCertLifetimeInDays. */
20
+ const MAX_SELF_SIGNED_CERT_LIFETIME_MS = 4 * 24 * 60 * 60 * 1000;
21
+ /** Chromium's kNonceSizeInBytes. */
22
+ const NONCE_SIZE = 16;
23
+ /** A challenge: the nonce and the DeviceAuthMessage bytes that go in the CastMessage's binary payload. */
24
+ function createAuthChallenge() {
25
+ const nonce = (0, node_crypto_1.randomBytes)(NONCE_SIZE);
26
+ return { nonce, payload: (0, device_auth_ts_1.encodeAuthChallenge)({ senderNonce: nonce, hashAlgorithm: device_auth_ts_1.HashAlgorithm.SHA256 }) };
27
+ }
28
+ let defaultAnchors;
29
+ let defaultCrlAnchors;
30
+ const parseAll = (ders) => ders.map((d) => (0, x509_ts_1.parseCertificate)(d));
31
+ function anchorsFor(options) {
32
+ if (options.roots !== undefined)
33
+ return parseAll(options.roots);
34
+ defaultAnchors ??= parseAll([Buffer.from(trust_data_ts_1.CAST_ROOT_CA_B64, "base64"), Buffer.from(trust_data_ts_1.EUREKA_ROOT_CA_B64, "base64")]);
35
+ return defaultAnchors;
36
+ }
37
+ function crlAnchorsFor(options) {
38
+ if (options.crlRoots !== undefined)
39
+ return parseAll(options.crlRoots);
40
+ defaultCrlAnchors ??= parseAll([Buffer.from(trust_data_ts_1.CAST_CRL_ROOT_CA_B64, "base64")]);
41
+ return defaultCrlAnchors;
42
+ }
43
+ const REASONS = {
44
+ OK: () => undefined,
45
+ OK_FALLBACK_CRL: () => undefined,
46
+ OK_FALLBACK_CRL_STALE: () => undefined,
47
+ ERR_CERTS_MISSING: (d) => new errors_ts_2.CastAuthError("invalid_certificate", `no device certificate: ${d}`),
48
+ ERR_CERTS_PARSE: (d) => new errors_ts_2.CastAuthError("invalid_certificate", d),
49
+ ERR_CERTS_DATE_INVALID: (d) => new errors_ts_2.CastAuthError("invalid_certificate", `failed date validity check: ${d}`),
50
+ ERR_CERTS_VERIFY_GENERIC: (d) => new errors_ts_2.CastAuthError("untrusted_chain", `the certificate chain is not trusted: ${d}`),
51
+ ERR_CERTS_RESTRICTIONS: (d) => new errors_ts_2.CastAuthError("invalid_certificate", d),
52
+ ERR_CERTS_REVOKED: (d) => new errors_ts_2.CastAuthError("revoked", d),
53
+ ERR_CERTS_REVOKED_BY_FALLBACK_CRL: (d) => new errors_ts_2.CastAuthError("revoked", d),
54
+ ERR_FALLBACK_CRL_INVALID: (d) => new errors_ts_2.CastAuthError("crl_invalid", d),
55
+ };
56
+ /**
57
+ * AuthenticateChallengeReply. Throws {@link CastAuthError} unless the reply proves the TLS peer is a genuine,
58
+ * Google-certified Cast device.
59
+ *
60
+ * `peerCertDer` is the DER of the TLS certificate the device presented on this connection; the signature in the
61
+ * reply is over `senderNonce || peerCertDer`, which binds the proof to this TLS session's certificate.
62
+ */
63
+ function authenticateChallengeReply(reply, peerCertDer, nonce, options = {}) {
64
+ const now = options.now ?? Date.now();
65
+ // ParseAuthMessage
66
+ if (reply.payloadType !== cast_message_ts_1.PayloadType.BINARY)
67
+ throw new errors_ts_2.CastAuthError("malformed_reply", "wrong payload type in the challenge reply");
68
+ if (reply.payloadBinary === undefined)
69
+ throw new errors_ts_2.CastAuthError("malformed_reply", "the challenge reply has no binary payload");
70
+ let message;
71
+ try {
72
+ message = (0, device_auth_ts_1.decodeDeviceAuthMessage)(reply.payloadBinary);
73
+ }
74
+ catch (err) {
75
+ if (err instanceof errors_ts_1.CastProtocolError)
76
+ throw new errors_ts_2.CastAuthError("malformed_reply", `cannot parse the challenge reply: ${err.message}`);
77
+ throw err;
78
+ }
79
+ if (message.error !== undefined)
80
+ throw new errors_ts_2.CastAuthError("device_error", `the device answered with auth error ${message.error.errorType}`);
81
+ const response = message.response;
82
+ if (response === undefined)
83
+ throw new errors_ts_2.CastAuthError("malformed_reply", "the challenge reply has no response");
84
+ // VerifyTLSCertificate: the TLS certificate's validity period is repurposed as the signature's lifetime.
85
+ let peer;
86
+ try {
87
+ peer = (0, x509_ts_1.parseCertificate)(peerCertDer);
88
+ }
89
+ catch (err) {
90
+ throw new errors_ts_2.CastAuthError("tls_certificate_invalid", `the TLS certificate does not parse: ${err instanceof Error ? err.message : String(err)}`);
91
+ }
92
+ if (peer.notBefore > now)
93
+ throw new errors_ts_2.CastAuthError("tls_certificate_invalid", "the TLS certificate's valid start date is in the future");
94
+ if (peer.notAfter < now)
95
+ throw new errors_ts_2.CastAuthError("tls_certificate_invalid", "the TLS certificate has expired");
96
+ if (peer.notAfter > now + MAX_SELF_SIGNED_CERT_LIFETIME_MS)
97
+ throw new errors_ts_2.CastAuthError("tls_certificate_invalid", "the TLS certificate's lifetime is too long");
98
+ // AuthContext::VerifySenderNonce records a missing or different nonce but does not fail.
99
+ const nonceEchoed = Buffer.from(nonce).equals(response.senderNonce);
100
+ // VerifyCredentialsImpl
101
+ const signatureInput = Buffer.concat([response.senderNonce, peerCertDer]);
102
+ const anchors = anchorsFor(options);
103
+ const crlAnchors = crlAnchorsFor(options);
104
+ let crl;
105
+ if (response.crl !== undefined && response.crl.length > 0) {
106
+ crl = (0, crl_ts_1.parseAndVerifyCrl)(response.crl, now, { anchors: crlAnchors, isFallback: false });
107
+ }
108
+ const fallbackBytes = options.fallbackCrl === undefined ? Buffer.from(trust_data_ts_1.CAST_FALLBACK_CRL_B64, "base64") : options.fallbackCrl;
109
+ const fallbackOptions = { anchors: crlAnchors, isFallback: true, fallbackBuildTime: options.fallbackCrlBuildTime ?? trust_data_ts_1.FALLBACK_CRL_BUILD_TIME };
110
+ const fallbackCrl = fallbackBytes === null ? undefined : (0, crl_ts_1.parseAndVerifyCrl)(fallbackBytes, now, fallbackOptions);
111
+ const fallbackCrlStale = fallbackBytes !== null && fallbackCrl === undefined && (0, crl_ts_1.isFallbackCrlStale)(fallbackBytes, now, fallbackOptions);
112
+ const chain = [response.clientAuthCertificate, ...response.intermediateCertificates];
113
+ const verified = (0, cast_cert_validator_ts_1.verifyDeviceCert)(chain, now, { anchors, crl, fallbackCrl, fallbackCrlStale });
114
+ const failure = REASONS[verified.error](verified.detail);
115
+ if (failure !== undefined)
116
+ throw failure;
117
+ if (response.signature.length === 0 && signatureInput.length > 0)
118
+ throw new errors_ts_2.CastAuthError("bad_signature", "the signature is empty");
119
+ let hash;
120
+ if (response.hashAlgorithm === device_auth_ts_1.HashAlgorithm.SHA1)
121
+ hash = "sha1";
122
+ else if (response.hashAlgorithm === device_auth_ts_1.HashAlgorithm.SHA256)
123
+ hash = "sha256";
124
+ else
125
+ throw new errors_ts_2.CastAuthError("unsupported_algorithm", `unsupported hash algorithm ${response.hashAlgorithm}`);
126
+ // CertVerificationContextImpl::VerifySignatureOverData: RSASSA-PKCS1-v1_5 with the chosen digest, RSA keys only.
127
+ const key = verified.publicKey;
128
+ let signatureOk = false;
129
+ try {
130
+ signatureOk = key !== undefined && key.asymmetricKeyType === "rsa" && (0, node_crypto_1.verify)(hash, signatureInput, key, response.signature);
131
+ }
132
+ catch {
133
+ signatureOk = false;
134
+ }
135
+ if (!signatureOk)
136
+ throw new errors_ts_2.CastAuthError("bad_signature", "failed verifying the signature over the TLS certificate");
137
+ return {
138
+ policy: verified.policy,
139
+ hashAlgorithm: hash,
140
+ nonceEchoed,
141
+ usedFallbackCrl: verified.error === "OK_FALLBACK_CRL",
142
+ revocationChecked: verified.error !== "OK_FALLBACK_CRL_STALE",
143
+ };
144
+ }
145
+ //# sourceMappingURL=cast-auth.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cast-auth.js","sourceRoot":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B,EAAE,8BAA8B,QAAQ,CAAC,aAAa,EAAE,CAAC,CAAC;IAE9G,iHAAiH;IACjH,MAAM,GAAG,GAAG,QAAQ,CAAC,SAAS,CAAC;IAC/B,IAAI,WAAW,GAAG,KAAK,CAAC;IACxB,IAAI,CAAC;QACH,WAAW,GAAG,GAAG,KAAK,SAAS,IAAI,GAAG,CAAC,iBAAiB,KAAK,KAAK,IAAI,IAAA,oBAAY,EAAC,IAAI,EAAE,cAAc,EAAE,GAAG,EAAE,QAAQ,CAAC,SAAS,CAAC,CAAC;IACpI,CAAC;IAAC,MAAM,CAAC;QACP,WAAW,GAAG,KAAK,CAAC;IACtB,CAAC;IACD,IAAI,CAAC,WAAW;QAAE,MAAM,IAAI,yBAAa,CAAC,eAAe,EAAE,yDAAyD,CAAC,CAAC;IAEtH,OAAO;QACL,MAAM,EAAE,QAAQ,CAAC,MAAM;QACvB,aAAa,EAAE,IAAI;QACnB,WAAW;QACX,eAAe,EAAE,QAAQ,CAAC,KAAK,KAAK,iBAAiB;QACrD,iBAAiB,EAAE,QAAQ,CAAC,KAAK,KAAK,uBAAuB;KAC9D,CAAC;AACJ,CAAC"}
@@ -0,0 +1,34 @@
1
+ import { type KeyObject } from "node:crypto";
2
+ import type { CastCrl } from "./crl.ts";
3
+ import { type ParsedCertificate } from "./x509.ts";
4
+ /**
5
+ * Cast device certificate verification, ported from components/media_router/common/providers/cast/certificate/
6
+ * cast_cert_validator.cc (VerifyDeviceCertUsingCustomTrustStore, GetValidationDate, CheckTargetCertificate,
7
+ * DetermineDeviceCertificatePolicy) with the CRL_REQUIRED_WITH_FALLBACK policy Chromium's cast_auth_util.cc uses.
8
+ */
9
+ export type CastCertError = "OK" | "OK_FALLBACK_CRL" | "OK_FALLBACK_CRL_STALE" | "ERR_CERTS_MISSING" | "ERR_CERTS_PARSE" | "ERR_CERTS_DATE_INVALID" | "ERR_CERTS_VERIFY_GENERIC" | "ERR_CERTS_RESTRICTIONS" | "ERR_CERTS_REVOKED" | "ERR_CERTS_REVOKED_BY_FALLBACK_CRL" | "ERR_FALLBACK_CRL_INVALID";
10
+ /** The device may be restricted to audio by its certificate chain (CastDeviceCertPolicy). */
11
+ export type CastDeviceCertPolicy = "unrestricted" | "audio_only";
12
+ export interface DeviceCertVerification {
13
+ error: CastCertError;
14
+ /** Set when the error is OK, OK_FALLBACK_CRL or OK_FALLBACK_CRL_STALE (and set earlier too, as in Chromium). */
15
+ policy: CastDeviceCertPolicy;
16
+ /** The device certificate's public key, for checking the challenge signature. */
17
+ publicKey: KeyObject | undefined;
18
+ /** Detail for diagnostics. */
19
+ detail: string;
20
+ }
21
+ export interface DeviceCertOptions {
22
+ anchors: ParsedCertificate[];
23
+ /** The CRL the device supplied, if it parsed and verified (undefined otherwise, like a null CastCRL). */
24
+ crl: CastCrl | undefined;
25
+ /** The built-in fallback CRL, if it parsed and verified. */
26
+ fallbackCrl: CastCrl | undefined;
27
+ /**
28
+ * True when `fallbackCrl` is missing only because its 20-week window has lapsed (it otherwise verifies). Without a
29
+ * device CRL the revocation check is then skipped, where Chromium would fail closed; see docs/DESIGN.md.
30
+ */
31
+ fallbackCrlStale?: boolean;
32
+ }
33
+ /** VerifyDeviceCertUsingCustomTrustStore with CRLPolicy::CRL_REQUIRED_WITH_FALLBACK. */
34
+ export declare function verifyDeviceCert(certs: Uint8Array[], time: number, options: DeviceCertOptions): DeviceCertVerification;
@@ -0,0 +1,89 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.verifyDeviceCert = verifyDeviceCert;
4
+ const node_crypto_1 = require("node:crypto");
5
+ const path_validator_ts_1 = require("./path-validator.js");
6
+ const x509_ts_1 = require("./x509.js");
7
+ const DAY_MS = 24 * 60 * 60 * 1000;
8
+ /** Certificates valid for more than this count as long-term (GetValidationDate). */
9
+ const MIN_LONG_TERM_VALIDITY_MS = 5 * 365 * DAY_MS;
10
+ /** How far past the leaf's notAfter the long-term grace period reaches. */
11
+ const MAX_GRACE_WINDOW_MS = 15 * 365 * DAY_MS;
12
+ /**
13
+ * GetValidationDate: for long-term certificate chains that have just expired (within 15 years of the leaf's notAfter),
14
+ * validate as of a week before the earliest expiry instead of "now". See b/416790717 in Chromium's source.
15
+ */
16
+ function getValidationDate(target, parsed, time) {
17
+ let minNotAfter = Infinity;
18
+ let minDuration = Infinity;
19
+ for (const cert of parsed) {
20
+ minNotAfter = Math.min(minNotAfter, cert.notAfter);
21
+ minDuration = Math.min(minDuration, cert.notAfter - cert.notBefore);
22
+ }
23
+ const maxValidity = target.notAfter + MAX_GRACE_WINDOW_MS;
24
+ if (minNotAfter <= time && time <= maxValidity && minDuration > MIN_LONG_TERM_VALIDITY_MS)
25
+ return minNotAfter - 7 * DAY_MS;
26
+ return time;
27
+ }
28
+ /** VerifyDeviceCertUsingCustomTrustStore with CRLPolicy::CRL_REQUIRED_WITH_FALLBACK. */
29
+ function verifyDeviceCert(certs, time, options) {
30
+ const result = (error, detail, extra = {}) => ({
31
+ error,
32
+ policy: "unrestricted",
33
+ publicKey: undefined,
34
+ detail,
35
+ ...extra,
36
+ });
37
+ if (certs.length === 0)
38
+ return result("ERR_CERTS_MISSING", "no certificates");
39
+ const parsed = [];
40
+ for (const der of certs) {
41
+ try {
42
+ parsed.push((0, x509_ts_1.parseCertificate)(der));
43
+ }
44
+ catch (err) {
45
+ return result("ERR_CERTS_PARSE", `certificate does not parse: ${err instanceof Error ? err.message : String(err)}`);
46
+ }
47
+ }
48
+ const target = parsed[0];
49
+ const validationDate = getValidationDate(target, parsed, time);
50
+ const built = (0, path_validator_ts_1.buildAndVerifyPath)(target, parsed.slice(1), options.anchors, validationDate, "client-auth");
51
+ if (built.path === undefined) {
52
+ const detail = built.errors === undefined ? "no path to a trusted Cast root" : built.errors.messages.join("; ");
53
+ return result(built.errors?.date === true ? "ERR_CERTS_DATE_INVALID" : "ERR_CERTS_VERIFY_GENERIC", detail, { policy: "unrestricted" });
54
+ }
55
+ const path = built.path;
56
+ const audioOnly = path.some((cert) => cert.policyOids?.includes(x509_ts_1.OID.CAST_AUDIO_ONLY_POLICY) === true);
57
+ const policy = audioOnly ? "audio_only" : "unrestricted";
58
+ // CheckTargetCertificate: digitalSignature key usage, a common name, a usable public key.
59
+ let publicKey;
60
+ try {
61
+ publicKey = (0, node_crypto_1.createPublicKey)({ key: target.spkiTlv, format: "der", type: "spki" });
62
+ }
63
+ catch {
64
+ publicKey = undefined;
65
+ }
66
+ if (target.keyUsage === undefined ||
67
+ !(0, x509_ts_1.keyUsageAsserts)(target.keyUsage, x509_ts_1.KEY_USAGE_BIT.DIGITAL_SIGNATURE) ||
68
+ target.commonName === undefined ||
69
+ publicKey === undefined) {
70
+ return result("ERR_CERTS_RESTRICTIONS", "the device certificate lacks digitalSignature key usage, a common name or a usable key", { policy });
71
+ }
72
+ const ok = (error, detail) => result(error, detail, { policy, publicKey });
73
+ // Revocation. Note the CRL checks use the real time, not the (possibly adjusted) validation date.
74
+ if (options.fallbackCrl !== undefined) {
75
+ if (!options.fallbackCrl.checkRevocation(path, time))
76
+ return ok("ERR_CERTS_REVOKED_BY_FALLBACK_CRL", "revoked by the fallback CRL");
77
+ }
78
+ else if (options.crl === undefined) {
79
+ if (options.fallbackCrlStale === true)
80
+ return ok("OK_FALLBACK_CRL_STALE", "no revocation check: no CRL from the device and the built-in fallback CRL has expired");
81
+ return ok("ERR_FALLBACK_CRL_INVALID", "no valid CRL from the device and no valid fallback CRL");
82
+ }
83
+ if (options.crl === undefined)
84
+ return ok("OK_FALLBACK_CRL", "accepted on the fallback CRL");
85
+ if (!options.crl.checkRevocation(path, time))
86
+ return ok("ERR_CERTS_REVOKED", "revoked by the device's CRL");
87
+ return ok("OK", "");
88
+ }
89
+ //# sourceMappingURL=cast-cert-validator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cast-cert-validator.js","sourceRoot":"","sources":["../../../../src/client/auth/cast-cert-validator.ts"],"names":[],"mappings":";;AAyEA,4CA2DC;AApID,6CAA8D;AAE9D,2DAA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