matterbridge-example-camera 1.0.1-dev-20261104-e24171f → 1.0.1-dev-20261113-58ca910
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.
- package/CHANGELOG.md +33 -18
- package/README.md +38 -81
- package/dist/module.js +10 -2
- package/dist/rootNode.js +38 -30
- package/npm-shrinkwrap.json +12 -12
- package/package.json +3 -3
- package/dist/timeSynchronizationServer.js +0 -181
- package/dist/tlsCertificateManagementServer.js +0 -332
- package/dist/tlsClientManagementServer.js +0 -106
package/CHANGELOG.md
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
[](https://www.npmjs.com/package/matterbridge-example-camera)
|
|
4
4
|
[](https://www.npmjs.com/package/matterbridge-example-camera)
|
|
5
5
|
[](https://hub.docker.com/r/luligu/matterbridge)
|
|
6
|
-
[](https://hub.docker.com/r/luligu/matterbridge)
|
|
7
7
|

|
|
8
8
|

|
|
9
9
|
[](https://codecov.io/gh/Luligu/matterbridge-example-camera)
|
|
@@ -30,40 +30,40 @@ If you like this project and find it useful, please consider giving it a star on
|
|
|
30
30
|
|
|
31
31
|
<a href="https://www.buymeacoffee.com/luligugithub"><img src="https://matterbridge.io/assets/bmc-button.svg" alt="Buy me a coffee" width="120"></a>
|
|
32
32
|
|
|
33
|
+
---
|
|
34
|
+
|
|
33
35
|
## [1.0.1] - Dev branch
|
|
34
36
|
|
|
37
|
+
### Breaking changes
|
|
38
|
+
|
|
39
|
+
- [matterbridge]: Require Matterbridge 3.11.3 or later.
|
|
40
|
+
|
|
35
41
|
### Changed
|
|
36
42
|
|
|
37
|
-
- [
|
|
38
|
-
- [
|
|
39
|
-
- [tls]: Follow the Matter 1.6.1 processing order of ProvisionRootCertificate (§ 14.4.6.1: InvalidInState before time synchronization, then DynamicConstraintError before AlreadyExists, NotFound and ResourceExhausted), ProvisionClientCertificate (§ 14.4.6.10: AlreadyExists and NotFound before DynamicConstraintError) and ProvisionEndpoint (§ 14.5.7.1: ResourceExhausted or NotFound before EndpointAlreadyInstalled).
|
|
43
|
+
- [package]: Set the automator workflow to dev.
|
|
44
|
+
- [servers]: Use the Time Synchronization and TLS servers from Matterbridge; remove their local implementations and unit tests.
|
|
40
45
|
- [rootNode]: Add the Server Camera, a `mode: 'server'` Camera whose own Root Node gets the Power Source, Time Synchronization, TLS Certificate Management and TLS Client Management servers from `addRootNodeCamera`.
|
|
41
|
-
- [rootNode]: Keep the Power Source that Matterbridge already adds to the Root Node with `--root-power-source` or `MATTERBRIDGE_CHIP_TEST`, instead of failing the plugin start.
|
|
42
|
-
- [tls]: Include the certificate payloads in the ProvisionedRootCertificates and ProvisionedClientCertificates attributes when read over a Large Message capable transport, and keep a null ClientCertificate and empty IntermediateCertificates over MRP (Matter 1.6.1 § 14.4.5.2 and § 14.4.5.4).
|
|
43
|
-
- [timeSync]: Generate TimeZoneStatus when a scheduled TimeZone entry changes the time zone offset or name (Matter 1.6.1 § 11.17.10.3).
|
|
44
|
-
- [timeSync]: Respond to a SetTimeZone list larger than TimeZoneListMaxSize with RESOURCE_EXHAUSTED (Matter 1.6.1 § 11.17.9.3): the TimeZone field constraint moves from the schema, where matter.js answers CONSTRAINT_ERROR before the handler, to the handler.
|
|
45
|
-
- [chip]: Wire the CHIP tests of the Server Camera Root Node (TC_PS_2_3, TC_TIMESYNC, TC_TLSCERT, TC_TLSCLIENT) with `scripts/chip/commission_node.py`, which commissions the node and resets the state left by the previous test, and `scripts/chip/root-node-camera.pics`.
|
|
46
46
|
- [package]: Upgrade package.
|
|
47
47
|
- [package]: Bump `@types/node` to v.26.6.6.
|
|
48
|
-
- [package]: Bump `oxfmt` to v.0.
|
|
49
|
-
- [package]: Bump `oxlint` to v.1.
|
|
50
|
-
- [package]: Bump `oxlint-tsgolint` to v.7.0.
|
|
51
|
-
- [agents]: Update `.agents/rules/plugin-frontend.instructions.md`, `.claude/rules/plugin-frontend/plugin-frontend.instructions.md` and `.github/instructions/plugin-frontend/plugin-frontend.instructions.md` to v.1.0.
|
|
52
|
-
- [codex]: Update `.codex/config.toml` to v.1.0.
|
|
48
|
+
- [package]: Bump `oxfmt` to v.0.78.0.
|
|
49
|
+
- [package]: Bump `oxlint` to v.1.93.0.
|
|
50
|
+
- [package]: Bump `oxlint-tsgolint` to v.7.0.2007.
|
|
51
|
+
- [agents]: Update `.agents/rules/plugin-frontend.instructions.md`, `.claude/rules/plugin-frontend/plugin-frontend.instructions.md` and `.github/instructions/plugin-frontend/plugin-frontend.instructions.md` to v.1.0.3.
|
|
52
|
+
- [codex]: Update `.codex/config.toml` to v.1.0.8.
|
|
53
53
|
- [agents]: Update `.github/commit-message-instructions.md` to v.1.0.1.
|
|
54
|
-
- [vscode]: Update `.vscode/settings.json` to v.1.0.
|
|
54
|
+
- [vscode]: Update `.vscode/settings.json` to v.1.0.21.
|
|
55
55
|
- [vscode]: Update `.vscode/tasks.json` to v.1.0.4.
|
|
56
|
-
- [agents]: Update `AGENTS.md` to v.1.0.
|
|
56
|
+
- [agents]: Update `AGENTS.md` to v.1.0.12.
|
|
57
57
|
- [config]: Update `CODE_OF_CONDUCT.md` to v.1.0.0.
|
|
58
58
|
- [config]: Update `CONTRIBUTING.md` to v.1.0.1.
|
|
59
59
|
- [scripts]: Update `scripts/downloads.mjs`.
|
|
60
60
|
- [scripts]: Update `scripts/git-sync-dev.mjs`.
|
|
61
61
|
- [scripts]: Update `scripts/prepublish-clean.mjs`.
|
|
62
|
-
- [config]:
|
|
62
|
+
- [config]: Update `SHARED-AGENTS.md` to v.1.0.0.
|
|
63
63
|
- [config]: Add `TOOLCHAIN.md` v.1.0.1.
|
|
64
64
|
- [package]: Bump `@vitest/coverage-v8` to v.5.1.0.
|
|
65
65
|
- [package]: Bump `vitest` to v.5.1.0.
|
|
66
|
-
- [agents]: Update `.agents/README.md` to v.1.0.
|
|
66
|
+
- [agents]: Update `.agents/README.md` to v.1.0.6.
|
|
67
67
|
- [workflows]: Update `.github/workflows/build.yml` to v.2.0.8.
|
|
68
68
|
- [workflows]: Update `.github/workflows/codecov.yml` to v.2.0.8.
|
|
69
69
|
- [workflows]: Update `.github/workflows/codeql.yml` to v.2.0.0.
|
|
@@ -72,6 +72,21 @@ If you like this project and find it useful, please consider giving it a star on
|
|
|
72
72
|
- [config]: Update `.oxfmtrc.json` to v.1.2.0.
|
|
73
73
|
- [config]: Update `.oxlintrc.json` to v.1.2.0.
|
|
74
74
|
- [config]: Update `vitest.config.ts` to v.2.0.9.
|
|
75
|
+
- [agents]: Update `.agents/rules/chip-tests.instructions.md`, `.claude/rules/chip-tests/chip-tests.instructions.md` and `.github/instructions/chip-tests/chip-tests.instructions.md` to v.1.0.1.
|
|
76
|
+
- [agents]: Update `.agents/rules/matterbridge.instructions.md`, `.claude/rules/matterbridge/matterbridge.instructions.md` and `.github/instructions/matterbridge/matterbridge.instructions.md` to v.1.0.4.
|
|
77
|
+
- [agents]: Update `.agents/rules/testing.instructions.md`, `.claude/rules/testing/testing.instructions.md` and `.github/instructions/testing/testing.instructions.md` to v.1.0.8.
|
|
78
|
+
- [agents]: Update `.agents/skills/verify-agent-context/SKILL.md`, `.claude/skills/verify-agent-context/SKILL.md` and `.github/skills/verify-agent-context/SKILL.md` to v.1.0.6.
|
|
79
|
+
- [agents]: Update `.claude/settings.json` to v.1.0.12.
|
|
80
|
+
- [package]: Bump `node-ansi-logger` to v.3.3.2.
|
|
81
|
+
- [package]: Bump `node-persist-manager` to v.2.1.2.
|
|
82
|
+
- [agents]: Update `.antigravity/settings.json` to v.1.0.6.
|
|
83
|
+
- [codex]: Update `.codex/rules/default.rules` to v.1.0.8.
|
|
84
|
+
- [vscode]: Update `.vscode/extensions.json` to v.1.0.6.
|
|
85
|
+
- [styleguide]: Update `STYLEGUIDE.md` to v.1.1.1.
|
|
86
|
+
- [config]: Update `src/module.ts`.
|
|
87
|
+
- [config]: Update `src/rootNode.ts`.
|
|
88
|
+
- [config]: Update `vitest/module.test.ts`.
|
|
89
|
+
- [config]: Remove `vitest/tlsTestUtils.ts`.
|
|
75
90
|
|
|
76
91
|
<a href="https://www.buymeacoffee.com/luligugithub"><img src="https://matterbridge.io/assets/bmc-button.svg" alt="Buy me a coffee" width="80"></a>
|
|
77
92
|
|
package/README.md
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
[](https://www.npmjs.com/package/matterbridge-example-camera)
|
|
4
4
|
[](https://www.npmjs.com/package/matterbridge-example-camera)
|
|
5
5
|
[](https://hub.docker.com/r/luligu/matterbridge)
|
|
6
|
-
[](https://hub.docker.com/r/luligu/matterbridge)
|
|
7
7
|

|
|
8
8
|

|
|
9
9
|
[](https://codecov.io/gh/Luligu/matterbridge-example-camera)
|
|
@@ -33,14 +33,14 @@ Thanks to [Ludovic BOUÉ](https://github.com/lboue) for his contributions to thi
|
|
|
33
33
|
|
|
34
34
|
- `src/module.ts` will create all device types for easy testing;
|
|
35
35
|
- the device types and the WebRTC stack come from matterbridge (`matterbridge/devices/camera`), see the [Matterbridge cameras](https://matterbridge.io/Camera.html) guide;
|
|
36
|
-
- `src/rootNode.ts` adds the Root Node clusters a Camera requires (Power Source, Time Synchronization, TLS Certificate Management and TLS Client Management) to a `mode: 'server'` Camera. `src/module.ts` creates the **Server Camera** (`SERVER-CAMERA-001`) as its own Matter node and calls it on that node;
|
|
37
|
-
- `
|
|
38
|
-
- `
|
|
36
|
+
- `src/rootNode.ts` preserves existing Root Node servers and adds the missing Root Node clusters a Camera requires (Power Source, Time Synchronization, TLS Certificate Management and TLS Client Management) to a `mode: 'server'` Camera. `src/module.ts` creates the **Server Camera** (`SERVER-CAMERA-001`) as its own Matter node and calls it on that node;
|
|
37
|
+
- `MatterbridgeTimeSynchronizationServer` from `matterbridge/behaviors` is the Time Synchronization server used there, with the TimeSyncClient, NtpClient and TimeZone features. It reports the host clock (MillisecondsGranularity) and implements SetTrustedTimeSource, SetDefaultNTP, SetTimeZone and SetDSTOffset with their validation and events; SetUTCTime is refused with TimeNotAccepted since the host clock is kept.
|
|
38
|
+
- `MatterbridgeTlsCertificateManagementServer` and `MatterbridgeTlsClientManagementServer` from `matterbridge/behaviors` are the TLS Certificate Management and TLS Client Management servers used there, per Matter 1.6.1: per fabric root and client certificates (stored nonvolatile, with the client private keys) and TLS endpoints. The certificate payloads are in the ProvisionedRootCertificates and ProvisionedClientCertificates attributes only when read over a Large Message capable transport (TCP).
|
|
39
39
|
- The Root Node servers of the Server Camera are tested with the CHIP harness (`npm run chip:test:servercamera`, see `chipTests.md`).
|
|
40
40
|
|
|
41
41
|
## Requirements
|
|
42
42
|
|
|
43
|
-
Requires Matterbridge `3.11.
|
|
43
|
+
Requires Matterbridge `3.11.3` or later.
|
|
44
44
|
|
|
45
45
|
Requires [`ffmpeg`](https://ffmpeg.org/) to be installed on the host or in the container. The resolver checks the system command and common installation directories on Linux, macOS, and Windows.
|
|
46
46
|
|
|
@@ -367,89 +367,46 @@ Snapshots, like the calibration cards above, are kept well under the Matter mess
|
|
|
367
367
|
|
|
368
368
|
A `CaptureSnapshot` response whose `data` field doesn't fit fails to send: the client gets a generic invoke failure instead of an image, since the encoder cannot represent the required plaintext length in the message header. `CameraAvStreamManagement.CaptureSnapshot` returns its image as a single field of a single command response, so it inherits this ceiling directly. Matter has a dedicated mechanism for transferring larger payloads — BDX (Bulk Data Exchange), used for OTA updates and diagnostic logs — which splits big content across a sequence of acknowledged messages instead of one oversized one, but `CaptureSnapshot` doesn't use it.
|
|
369
369
|
|
|
370
|
-
##
|
|
370
|
+
## Development guide
|
|
371
371
|
|
|
372
|
-
|
|
372
|
+
Refer to the Matterbridge [Development guide](https://matterbridge.io/README-DEV.html) for other guidelines.
|
|
373
373
|
|
|
374
374
|
## Repository toolchain
|
|
375
375
|
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
- **No `typescript 6.x` package** — replaced by [TypeScript Native 7.x](https://github.com/microsoft/typescript-go).
|
|
379
|
-
- **No ESLint, no Prettier** — replaced by the [oxc](https://oxc.rs) stack: [oxlint](https://oxc.rs/docs/guide/usage/linter.html) for linting and [oxfmt](https://oxc.rs/docs/guide/usage/formatter.html) for formatting.
|
|
380
|
-
- **No Jest** — replaced by [Vitest](https://vitest.dev), which is much faster and natively supports ESM without extra configuration.
|
|
381
|
-
- **Far fewer development dependencies** — the number of installed packages drops from **~600** to **~75**. A clean install is much faster.
|
|
382
|
-
- **Much faster linting and formatting** — oxlint and oxfmt run in a fraction of the time required by the ESLint / Prettier pipeline.
|
|
383
|
-
- **Much faster builds** — tsgo compiles the project in a fraction of the time required by the standard `tsc` build.
|
|
384
|
-
- **Editor support** — use the VS Code extensions for tsgo and oxc to get the same experience in the editor.
|
|
376
|
+
See [TOOLCHAIN.md](./TOOLCHAIN.md) for compilers, linting, formatting, testing, and editor support.
|
|
385
377
|
|
|
386
378
|
## Shared agent instructions
|
|
387
379
|
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
| File | Notes |
|
|
391
|
-
| ----------------------------------------------- | ------------------------------------------------------------------------------------------------------------ |
|
|
392
|
-
| `AGENTS.md` | Main project instructions — shared by every agent |
|
|
393
|
-
| `.agents/README.md` | Layout and versioning of the shared instructions |
|
|
394
|
-
| `.agents/rules/testing.instructions.md` | Testing standards for unit tests |
|
|
395
|
-
| `.agents/rules/matterbridge.instructions.md` | Creating endpoints and using the single-class devices |
|
|
396
|
-
| `.agents/rules/plugin-frontend.instructions.md` | Serving a plugin's own frontend SPA and REST API |
|
|
397
|
-
| `.agents/rules/chip-tests.instructions.md` | The CHIP conformance test harness |
|
|
398
|
-
| `.agents/skills/verify-agent-context/SKILL.md` | Verify the agent loaded this context — `$verify-agent-context` (Codex), `/verify-agent-context` (all others) |
|
|
399
|
-
|
|
400
|
-
Content lives only in `.agents/`. The per-agent folders exist because each tool discovers rules and skills from its own hardcoded location, so they hold stubs that point back here — except where the tool reads `.agents/` natively.
|
|
401
|
-
|
|
402
|
-
| Tool | Instructions | Rules | Skills |
|
|
403
|
-
| ---------------------------------- | ----------------------------------------------- | ----------------------------------------------------- | --------------------------------------------------- |
|
|
404
|
-
| Codex | `AGENTS.md` — read natively | `.agents/rules/` — linked from `AGENTS.md`, on demand | `.agents/skills/` — native, `$verify-agent-context` |
|
|
405
|
-
| Copilot (VS Code and coding agent) | `.github/copilot-instructions.md` → `AGENTS.md` | stubs in `.github/instructions/` — `applyTo` globs | stub in `.github/skills/` — `/verify-agent-context` |
|
|
406
|
-
| Claude Code | `CLAUDE.md` imports `AGENTS.md` | stubs in `.claude/rules/` — `paths` globs | stub in `.claude/skills/` — `/verify-agent-context` |
|
|
407
|
-
| Gemini / Antigravity | `GEMINI.md` imports `AGENTS.md` | `.agents/rules/` — on demand | `.agents/skills/` — native, `/verify-agent-context` |
|
|
408
|
-
|
|
409
|
-
### Copilot instructions
|
|
410
|
-
|
|
411
|
-
| File | Notes |
|
|
412
|
-
| ---------------------------------------------------------------------- | ---------------------------------------------------------------------------------- |
|
|
413
|
-
| `.github/copilot-instructions.md` | Pointer to AGENTS.md — always loaded |
|
|
414
|
-
| `.github/instructions/chip-tests/chip-tests.instructions.md` | CHIP conformance test harness — scoped to CHIP test files |
|
|
415
|
-
| `.github/instructions/matterbridge/matterbridge.instructions.md` | Matterbridge endpoint guide — dedicated Copilot instruction file |
|
|
416
|
-
| `.github/instructions/plugin-frontend/plugin-frontend.instructions.md` | Plugin frontend SPA and custom REST API guide — scoped to frontend and plugin code |
|
|
417
|
-
| `.github/instructions/testing/testing.instructions.md` | Testing standards — scoped to `**/*.test.ts` |
|
|
418
|
-
| `.github/skills/verify-agent-context/SKILL.md` | Skill invocable as `/verify-agent-context` |
|
|
419
|
-
|
|
420
|
-
### Claude instructions
|
|
421
|
-
|
|
422
|
-
| File | Notes |
|
|
423
|
-
| --------------------------------------------------------------- | ---------------------------------------------------------------------------------- |
|
|
424
|
-
| `CLAUDE.md` | Pointer to AGENTS.md — always loaded |
|
|
425
|
-
| `.claude/settings.json` | Claude permissions: allow, ask and deny rules |
|
|
426
|
-
| `.claude/rules/chip-tests/chip-tests.instructions.md` | CHIP conformance test harness — scoped to CHIP test files |
|
|
427
|
-
| `.claude/rules/matterbridge/matterbridge.instructions.md` | Matterbridge endpoint guide — loaded for all contexts |
|
|
428
|
-
| `.claude/rules/plugin-frontend/plugin-frontend.instructions.md` | Plugin frontend SPA and custom REST API guide — scoped to frontend and plugin code |
|
|
429
|
-
| `.claude/rules/testing/testing.instructions.md` | Testing standards — scoped to `**/*.test.ts` |
|
|
430
|
-
| `.claude/skills/verify-agent-context/SKILL.md` | Skill invocable as `/verify-agent-context` |
|
|
431
|
-
|
|
432
|
-
### Codex instructions
|
|
433
|
-
|
|
434
|
-
| File | Notes |
|
|
435
|
-
| ---------------------------- | ----------------------------------------------------------------- |
|
|
436
|
-
| `AGENTS.md` | Main project instructions — read directly, no pointer file needed |
|
|
437
|
-
| `.codex/config.toml` | Codex project permissions, approvals, and profile |
|
|
438
|
-
| `.codex/rules/default.rules` | Codex command allow, prompt, and deny rules |
|
|
439
|
-
|
|
440
|
-
Codex reads the shared rules and skills from `.agents/` directly; the skill is invoked as `$verify-agent-context`.
|
|
441
|
-
|
|
442
|
-
### Gemini / Antigravity instructions
|
|
443
|
-
|
|
444
|
-
| File | Notes |
|
|
445
|
-
| ---------------------------- | ----------------------------------------------------- |
|
|
446
|
-
| `GEMINI.md` | Pointer to AGENTS.md — always loaded |
|
|
447
|
-
| `.antigravity/settings.json` | Sandboxing and permissions: allow, ask and deny rules |
|
|
448
|
-
|
|
449
|
-
The shared rules under `.agents/rules/` apply on demand for the relevant tasks, and `.agents/skills/` is discovered automatically as `/verify-agent-context`.
|
|
380
|
+
See [SHARED-AGENTS.md](./SHARED-AGENTS.md) for shared guidance, rules, skills, and configuration for coding agents.
|
|
450
381
|
|
|
451
|
-
|
|
382
|
+
See [.agents/README.md](./.agents/README.md) for the shared instructions layout and versioning.
|
|
452
383
|
|
|
453
|
-
|
|
384
|
+
## Shared dev container support
|
|
454
385
|
|
|
455
|
-
|
|
386
|
+
See [.devcontainer/README.md](./.devcontainer/README.md) for the shared development container setup and usage.
|
|
387
|
+
|
|
388
|
+
## Contributing
|
|
389
|
+
|
|
390
|
+
See [CONTRIBUTING.md](./CONTRIBUTING.md) for contribution guidelines.
|
|
391
|
+
|
|
392
|
+
## Style guide
|
|
393
|
+
|
|
394
|
+
See [STYLEGUIDE.md](./STYLEGUIDE.md) for code style, naming, documentation, and testing conventions.
|
|
395
|
+
|
|
396
|
+
## Changelog
|
|
397
|
+
|
|
398
|
+
See [CHANGELOG.md](./CHANGELOG.md) for release history and notable changes.
|
|
399
|
+
|
|
400
|
+
## Issues and feature requests
|
|
401
|
+
|
|
402
|
+
Report bugs and suggest improvements on [GitHub Issues](https://github.com/Luligu/matterbridge-example-camera/issues).
|
|
403
|
+
|
|
404
|
+
## License
|
|
405
|
+
|
|
406
|
+
Licensed under the [Apache License 2.0](./LICENSE).
|
|
407
|
+
|
|
408
|
+
## Support the project
|
|
409
|
+
|
|
410
|
+
If you find this project useful, please consider giving it a star on [GitHub](https://github.com/Luligu/matterbridge-example-camera) and sponsoring it. Your support helps maintain and improve the project.
|
|
411
|
+
|
|
412
|
+
[](https://www.buymeacoffee.com/luligugithub)
|
package/dist/module.js
CHANGED
|
@@ -19,8 +19,8 @@ export class ExampleMatterbridgeCameraPlatform extends MatterbridgeDynamicPlatfo
|
|
|
19
19
|
constructor(matterbridge, log, config) {
|
|
20
20
|
super(matterbridge, log, config);
|
|
21
21
|
this.config = config;
|
|
22
|
-
if (typeof this.verifyMatterbridgeVersion !== 'function' || !this.verifyMatterbridgeVersion('3.11.
|
|
23
|
-
throw new Error(`This plugin requires Matterbridge version >= "3.11.
|
|
22
|
+
if (typeof this.verifyMatterbridgeVersion !== 'function' || !this.verifyMatterbridgeVersion('3.11.3')) {
|
|
23
|
+
throw new Error(`This plugin requires Matterbridge version >= "3.11.3". Please update Matterbridge to the latest version in the frontend.`);
|
|
24
24
|
}
|
|
25
25
|
this.log.info(`Initializing platform ${this.config.name}...`);
|
|
26
26
|
this.config.whiteList ??= [];
|
|
@@ -145,23 +145,31 @@ export class ExampleMatterbridgeCameraPlatform extends MatterbridgeDynamicPlatfo
|
|
|
145
145
|
serverChime.subscribeAttribute(ChimeCluster, 'enabled', (newValue, oldValue) => {
|
|
146
146
|
this.log.info(`Server Chime enabled attribute changed from ${oldValue} to ${newValue}`);
|
|
147
147
|
});
|
|
148
|
+
if (serverChime.serverNode)
|
|
149
|
+
await addRootNodeCamera(serverChime);
|
|
148
150
|
const serverDoorbell = new Doorbell('Server Doorbell', 'SERVER-DOORBELL-001', {
|
|
149
151
|
tagList: [getSemtag(CommonNumberTag.One, 'Server Doorbell')],
|
|
150
152
|
mode: 'server',
|
|
151
153
|
});
|
|
152
154
|
await this.addDevice(serverDoorbell);
|
|
155
|
+
if (serverDoorbell.serverNode)
|
|
156
|
+
await addRootNodeCamera(serverDoorbell);
|
|
153
157
|
const serverIntercom1 = new Intercom('Server Intercom 1', 'SERVER-INTERCOM1-001', {
|
|
154
158
|
tagList: [getSemtag(CommonNumberTag.One, 'Server Intercom 1')],
|
|
155
159
|
mode: 'server',
|
|
156
160
|
weriftOfferOptions: { ...this.weriftOfferOptions },
|
|
157
161
|
});
|
|
158
162
|
await this.addDevice(serverIntercom1);
|
|
163
|
+
if (serverIntercom1.serverNode)
|
|
164
|
+
await addRootNodeCamera(serverIntercom1);
|
|
159
165
|
const serverIntercom2 = new Intercom('Server Intercom 2', 'SERVER-INTERCOM2-001', {
|
|
160
166
|
tagList: [getSemtag(CommonNumberTag.Two, 'Server Intercom 2')],
|
|
161
167
|
mode: 'server',
|
|
162
168
|
weriftOfferOptions: { ...this.weriftOfferOptions },
|
|
163
169
|
});
|
|
164
170
|
await this.addDevice(serverIntercom2);
|
|
171
|
+
if (serverIntercom2.serverNode)
|
|
172
|
+
await addRootNodeCamera(serverIntercom2);
|
|
165
173
|
const serverCamera = new Camera('Server Camera', 'SERVER-CAMERA-001', {
|
|
166
174
|
identifyTime: 5,
|
|
167
175
|
identifyType: Identify.IdentifyType.VisibleIndicator,
|
package/dist/rootNode.js
CHANGED
|
@@ -1,45 +1,53 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { MATTER_EPOCH_US, MatterbridgeTimeSynchronizationServer, MatterbridgeTlsCertificateManagementServer, MatterbridgeTlsClientManagementServer } from 'matterbridge/behaviors';
|
|
2
|
+
import { DescriptorServer, PowerSourceServer } from 'matterbridge/matter/behaviors';
|
|
2
3
|
import { PowerSource, TimeSynchronization } from 'matterbridge/matter/clusters';
|
|
3
|
-
import {
|
|
4
|
-
import { MatterbridgeTlsCertificateManagementServer } from './tlsCertificateManagementServer.js';
|
|
5
|
-
import { MatterbridgeTlsClientManagementServer } from './tlsClientManagementServer.js';
|
|
4
|
+
import { EndpointNumber } from 'matterbridge/matter/types';
|
|
6
5
|
export async function addRootNodeCamera(device) {
|
|
7
6
|
if (!device.serverNode) {
|
|
8
7
|
throw new Error(`addRootNodeCamera requires device.serverNode to be set: register the device with mode: 'server' before calling this helper.`);
|
|
9
8
|
}
|
|
10
9
|
const root = device.serverNode;
|
|
11
10
|
if (!root.behaviors.supported.powerSource) {
|
|
12
|
-
root.
|
|
11
|
+
await root.act((agent) => {
|
|
12
|
+
agent.get(DescriptorServer).addDeviceTypes('PowerSource');
|
|
13
|
+
});
|
|
14
|
+
root.behaviors.require(PowerSourceServer.with(PowerSource.Feature.Wired), {
|
|
13
15
|
status: PowerSource.PowerSourceStatus.Active,
|
|
14
16
|
order: 0,
|
|
15
17
|
description: 'AC Power',
|
|
16
|
-
endpointList: [],
|
|
18
|
+
endpointList: [EndpointNumber(0)],
|
|
17
19
|
wiredCurrentType: PowerSource.WiredCurrentType.Ac,
|
|
18
20
|
});
|
|
19
21
|
}
|
|
20
|
-
root.behaviors.
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
}
|
|
22
|
+
if (!root.behaviors.supported.timeSynchronization) {
|
|
23
|
+
root.behaviors.require(MatterbridgeTimeSynchronizationServer, {
|
|
24
|
+
utcTime: null,
|
|
25
|
+
granularity: TimeSynchronization.Granularity.NoTimeGranularity,
|
|
26
|
+
timeSource: TimeSynchronization.TimeSource.None,
|
|
27
|
+
trustedTimeSource: null,
|
|
28
|
+
defaultNtp: null,
|
|
29
|
+
supportsDnsResolve: false,
|
|
30
|
+
timeZone: [{ offset: 0, validAt: MATTER_EPOCH_US }],
|
|
31
|
+
dstOffset: [],
|
|
32
|
+
localTime: null,
|
|
33
|
+
timeZoneDatabase: TimeSynchronization.TimeZoneDatabase.None,
|
|
34
|
+
timeZoneListMaxSize: 2,
|
|
35
|
+
dstOffsetListMaxSize: 2,
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
if (!root.behaviors.supported.tlsCertificateManagement) {
|
|
39
|
+
root.behaviors.require(MatterbridgeTlsCertificateManagementServer, {
|
|
40
|
+
maxRootCertificates: 5,
|
|
41
|
+
provisionedRootCertificates: [],
|
|
42
|
+
maxClientCertificates: 5,
|
|
43
|
+
provisionedClientCertificates: [],
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
if (!root.behaviors.supported.tlsClientManagement) {
|
|
47
|
+
root.behaviors.require(MatterbridgeTlsClientManagementServer, {
|
|
48
|
+
maxProvisioned: 5,
|
|
49
|
+
provisionedEndpoints: [],
|
|
50
|
+
});
|
|
51
|
+
}
|
|
44
52
|
return device;
|
|
45
53
|
}
|
package/npm-shrinkwrap.json
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "matterbridge-example-camera",
|
|
3
|
-
"version": "1.0.1-dev-
|
|
3
|
+
"version": "1.0.1-dev-20261113-58ca910",
|
|
4
4
|
"lockfileVersion": 3,
|
|
5
5
|
"requires": true,
|
|
6
6
|
"packages": {
|
|
7
7
|
"": {
|
|
8
8
|
"name": "matterbridge-example-camera",
|
|
9
|
-
"version": "1.0.1-dev-
|
|
9
|
+
"version": "1.0.1-dev-20261113-58ca910",
|
|
10
10
|
"license": "Apache-2.0",
|
|
11
11
|
"dependencies": {
|
|
12
|
-
"node-ansi-logger": "3.3.
|
|
13
|
-
"node-persist-manager": "2.1.
|
|
12
|
+
"node-ansi-logger": "3.3.2",
|
|
13
|
+
"node-persist-manager": "2.1.2"
|
|
14
14
|
},
|
|
15
15
|
"engines": {
|
|
16
16
|
"node": ">=22.13.0 <23.0.0 || >=24.0.0 <25.0.0 || >=26.0.0 <27.0.0"
|
|
@@ -21,13 +21,13 @@
|
|
|
21
21
|
}
|
|
22
22
|
},
|
|
23
23
|
"node_modules/node-ansi-logger": {
|
|
24
|
-
"version": "3.3.
|
|
25
|
-
"resolved": "https://registry.npmjs.org/node-ansi-logger/-/node-ansi-logger-3.3.
|
|
26
|
-
"integrity": "sha512-
|
|
24
|
+
"version": "3.3.2",
|
|
25
|
+
"resolved": "https://registry.npmjs.org/node-ansi-logger/-/node-ansi-logger-3.3.2.tgz",
|
|
26
|
+
"integrity": "sha512-rPTPkPTfyG7xgjbvCfjYh+H3UuxaM477Q+HtYbCxG20U51GHXYthCIOiDCROAd/DOmcYXL6jif6FeE6hCli22w==",
|
|
27
27
|
"hasShrinkwrap": true,
|
|
28
28
|
"license": "Apache-2.0",
|
|
29
29
|
"engines": {
|
|
30
|
-
"node": ">=
|
|
30
|
+
"node": ">=22.13.0 <23.0.0 || >=24.0.0 <25.0.0 || >=26.0.0 <27.0.0"
|
|
31
31
|
},
|
|
32
32
|
"funding": {
|
|
33
33
|
"type": "buymeacoffee",
|
|
@@ -35,16 +35,16 @@
|
|
|
35
35
|
}
|
|
36
36
|
},
|
|
37
37
|
"node_modules/node-persist-manager": {
|
|
38
|
-
"version": "2.1.
|
|
39
|
-
"resolved": "https://registry.npmjs.org/node-persist-manager/-/node-persist-manager-2.1.
|
|
40
|
-
"integrity": "sha512-
|
|
38
|
+
"version": "2.1.2",
|
|
39
|
+
"resolved": "https://registry.npmjs.org/node-persist-manager/-/node-persist-manager-2.1.2.tgz",
|
|
40
|
+
"integrity": "sha512-NAWfk9eHUX2W3je2ik6yE6pMgIxV32sKDP2cmVCszX6blgYU4X++iLKEdjR31N/QVZU2EgDJeC5YAX99BheJcg==",
|
|
41
41
|
"hasShrinkwrap": true,
|
|
42
42
|
"license": "Apache-2.0",
|
|
43
43
|
"dependencies": {
|
|
44
44
|
"node-persist": "4.0.4"
|
|
45
45
|
},
|
|
46
46
|
"engines": {
|
|
47
|
-
"node": ">=
|
|
47
|
+
"node": ">=22.13.0 <23.0.0 || >=24.0.0 <25.0.0 || >=26.0.0 <27.0.0"
|
|
48
48
|
},
|
|
49
49
|
"funding": {
|
|
50
50
|
"type": "buymeacoffee",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "matterbridge-example-camera",
|
|
3
|
-
"version": "1.0.1-dev-
|
|
3
|
+
"version": "1.0.1-dev-20261113-58ca910",
|
|
4
4
|
"description": "Matterbridge example camera plugin",
|
|
5
5
|
"author": "https://github.com/Luligu",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -67,7 +67,7 @@
|
|
|
67
67
|
"*.schema.json"
|
|
68
68
|
],
|
|
69
69
|
"dependencies": {
|
|
70
|
-
"node-ansi-logger": "3.3.
|
|
71
|
-
"node-persist-manager": "2.1.
|
|
70
|
+
"node-ansi-logger": "3.3.2",
|
|
71
|
+
"node-persist-manager": "2.1.2"
|
|
72
72
|
}
|
|
73
73
|
}
|
|
@@ -1,181 +0,0 @@
|
|
|
1
|
-
import { isIPv4, isIPv6 } from 'node:net';
|
|
2
|
-
import { AnsiLogger, MAGENTA } from 'matterbridge/logger';
|
|
3
|
-
import { Node, Seconds, Time } from 'matterbridge/matter';
|
|
4
|
-
import { OperationalCredentialsServer, TimeSynchronizationServer } from 'matterbridge/matter/behaviors';
|
|
5
|
-
import { TimeSynchronization } from 'matterbridge/matter/clusters';
|
|
6
|
-
import { CommandModel, FieldModel } from 'matterbridge/matter/model';
|
|
7
|
-
import { Status, StatusResponseError } from 'matterbridge/matter/types';
|
|
8
|
-
export const MATTER_EPOCH_US = 946684800000000n;
|
|
9
|
-
const CLOCK_INTERVAL = Seconds(1);
|
|
10
|
-
const HOSTNAME_REGEX = /^(?=.{1,253}$)(?!-)[a-z0-9-]{1,63}(?<!-)(\.(?!-)[a-z0-9-]{1,63}(?<!-))*$/i;
|
|
11
|
-
const log = new AnsiLogger({ logName: 'TimeSync', logLevel: "info", logNameColor: MAGENTA, logTimestampFormat: 4 });
|
|
12
|
-
function nowUs() {
|
|
13
|
-
return BigInt(Time.nowMs) * 1000n;
|
|
14
|
-
}
|
|
15
|
-
export function isCanonicalIpv6(address) {
|
|
16
|
-
if (!isIPv6(address) || address.includes('%'))
|
|
17
|
-
return false;
|
|
18
|
-
if (/^::ffff:\d{1,3}(\.\d{1,3}){3}$/.test(address))
|
|
19
|
-
return true;
|
|
20
|
-
return new URL(`http://[${address}]`).hostname === `[${address}]`;
|
|
21
|
-
}
|
|
22
|
-
const { schema } = TimeSynchronization;
|
|
23
|
-
const setTimeZoneCommand = schema.require(CommandModel, 'SetTimeZone');
|
|
24
|
-
const TimeSynchronizationSchema = schema.extend(undefined, setTimeZoneCommand.extend(undefined, setTimeZoneCommand.require(FieldModel, 'TimeZone').extend({ constraint: 'none' })));
|
|
25
|
-
const MatterbridgeTimeSynchronizationServerBase = TimeSynchronizationServer.for(TimeSynchronization, TimeSynchronizationSchema).with(TimeSynchronization.Feature.TimeSyncClient, TimeSynchronization.Feature.NtpClient, TimeSynchronization.Feature.TimeZone);
|
|
26
|
-
export class MatterbridgeTimeSynchronizationServer extends MatterbridgeTimeSynchronizationServerBase {
|
|
27
|
-
initialize() {
|
|
28
|
-
if (this.state.timeZone.length === 0)
|
|
29
|
-
this.state.timeZone = [{ offset: 0, validAt: MATTER_EPOCH_US }];
|
|
30
|
-
this.state.timeZoneDatabase = TimeSynchronization.TimeZoneDatabase.None;
|
|
31
|
-
this.updateClock();
|
|
32
|
-
this.internal.dstActive = this.#activeDstOffset() !== 0;
|
|
33
|
-
this.internal.clockTimer = Time.getPeriodicTimer('TimeSynchronization clock', CLOCK_INTERVAL, this.callback(this.updateClock, { lock: true })).start();
|
|
34
|
-
const node = Node.forEndpoint(this.endpoint);
|
|
35
|
-
this.reactTo(node.eventsOf(OperationalCredentialsServer).fabrics$Changed, this.#handleFabricsChanged, { offline: true, lock: true });
|
|
36
|
-
}
|
|
37
|
-
async [Symbol.asyncDispose]() {
|
|
38
|
-
this.internal.clockTimer?.stop();
|
|
39
|
-
this.internal.clockTimer = undefined;
|
|
40
|
-
await super[Symbol.asyncDispose]?.();
|
|
41
|
-
}
|
|
42
|
-
updateClock() {
|
|
43
|
-
const now = nowUs();
|
|
44
|
-
this.state.utcTime = now;
|
|
45
|
-
this.state.granularity = TimeSynchronization.Granularity.MillisecondsGranularity;
|
|
46
|
-
this.state.timeSource = TimeSynchronization.TimeSource.Unknown;
|
|
47
|
-
const [currentTimeZone, nextTimeZone] = this.state.timeZone;
|
|
48
|
-
if (nextTimeZone && BigInt(nextTimeZone.validAt) <= now) {
|
|
49
|
-
const { offset, name } = nextTimeZone;
|
|
50
|
-
const changed = offset !== currentTimeZone.offset || name !== currentTimeZone.name;
|
|
51
|
-
this.state.timeZone = [{ offset, validAt: MATTER_EPOCH_US, ...(name === undefined ? {} : { name }) }];
|
|
52
|
-
if (changed) {
|
|
53
|
-
log.info(`MatterbridgeTimeSynchronizationServer: the scheduled TimeZone with offset ${offset}s${name === undefined ? '' : ` (${name})`} became valid, generating TimeZoneStatus (endpoint ${this.endpoint.maybeId}.${this.endpoint.maybeNumber})`);
|
|
54
|
-
this.events.timeZoneStatus.emit({ offset, name }, this.context);
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
const dstOffset = this.state.dstOffset.filter((entry) => entry.validUntil === null || BigInt(entry.validUntil) > now);
|
|
58
|
-
if (dstOffset.length !== this.state.dstOffset.length) {
|
|
59
|
-
this.state.dstOffset = dstOffset;
|
|
60
|
-
if (dstOffset.length === 0) {
|
|
61
|
-
log.info(`MatterbridgeTimeSynchronizationServer: the DSTOffset table expired, generating DSTTableEmpty (endpoint ${this.endpoint.maybeId}.${this.endpoint.maybeNumber})`);
|
|
62
|
-
this.events.dstTableEmpty.emit(undefined, this.context);
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
this.#updateDstStatus();
|
|
66
|
-
this.#updateLocalTime(now);
|
|
67
|
-
}
|
|
68
|
-
setUtcTime(request) {
|
|
69
|
-
log.info(`MatterbridgeTimeSynchronizationServer.setUtcTime: time with granularity ${request.granularity} not accepted, the node uses the host clock (endpoint ${this.endpoint.maybeId}.${this.endpoint.maybeNumber})`);
|
|
70
|
-
throw new TimeSynchronization.TimeNotAcceptedError(`MatterbridgeTimeSynchronizationServer.setUtcTime: time not accepted, the node uses the host clock (endpoint ${this.endpoint.maybeId}.${this.endpoint.maybeNumber})`);
|
|
71
|
-
}
|
|
72
|
-
setTrustedTimeSource(request) {
|
|
73
|
-
const { trustedTimeSource } = request;
|
|
74
|
-
if (trustedTimeSource === null) {
|
|
75
|
-
this.state.trustedTimeSource = null;
|
|
76
|
-
log.info(`MatterbridgeTimeSynchronizationServer.setTrustedTimeSource: the TrustedTimeSource was cleared, generating MissingTrustedTimeSource (endpoint ${this.endpoint.maybeId}.${this.endpoint.maybeNumber})`);
|
|
77
|
-
this.events.missingTrustedTimeSource.emit(undefined, this.context);
|
|
78
|
-
return;
|
|
79
|
-
}
|
|
80
|
-
const fabricIndex = this.context.fabric;
|
|
81
|
-
if (fabricIndex === undefined) {
|
|
82
|
-
throw new StatusResponseError(`MatterbridgeTimeSynchronizationServer.setTrustedTimeSource: an accessing fabric is required (endpoint ${this.endpoint.maybeId}.${this.endpoint.maybeNumber})`, Status.UnsupportedAccess);
|
|
83
|
-
}
|
|
84
|
-
this.state.trustedTimeSource = { fabricIndex, nodeId: trustedTimeSource.nodeId, endpoint: trustedTimeSource.endpoint };
|
|
85
|
-
log.info(`MatterbridgeTimeSynchronizationServer.setTrustedTimeSource: the TrustedTimeSource was set to node ${trustedTimeSource.nodeId} endpoint ${trustedTimeSource.endpoint} on fabric ${fabricIndex} (endpoint ${this.endpoint.maybeId}.${this.endpoint.maybeNumber})`);
|
|
86
|
-
}
|
|
87
|
-
setDefaultNtp(request) {
|
|
88
|
-
const { defaultNtp } = request;
|
|
89
|
-
if (defaultNtp !== null && !isCanonicalIpv6(defaultNtp)) {
|
|
90
|
-
if (isIPv4(defaultNtp) || !HOSTNAME_REGEX.test(defaultNtp)) {
|
|
91
|
-
throw new StatusResponseError(`MatterbridgeTimeSynchronizationServer.setDefaultNtp: address ${defaultNtp} is not a domain name or a static IPv6 address (endpoint ${this.endpoint.maybeId}.${this.endpoint.maybeNumber})`, Status.InvalidCommand);
|
|
92
|
-
}
|
|
93
|
-
if (!this.state.supportsDnsResolve) {
|
|
94
|
-
throw new StatusResponseError(`MatterbridgeTimeSynchronizationServer.setDefaultNtp: address ${defaultNtp} is a domain name and the node does not support DNS resolution (endpoint ${this.endpoint.maybeId}.${this.endpoint.maybeNumber})`, Status.InvalidCommand);
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
this.state.defaultNtp = defaultNtp;
|
|
98
|
-
log.info(`MatterbridgeTimeSynchronizationServer.setDefaultNtp: the DefaultNTP was set to ${defaultNtp ?? 'null'} (endpoint ${this.endpoint.maybeId}.${this.endpoint.maybeNumber})`);
|
|
99
|
-
}
|
|
100
|
-
setTimeZone(request) {
|
|
101
|
-
const { timeZone } = request;
|
|
102
|
-
if (timeZone.length > this.state.timeZoneListMaxSize) {
|
|
103
|
-
throw new StatusResponseError(`MatterbridgeTimeSynchronizationServer.setTimeZone: the list of ${timeZone.length} entries exceeds TimeZoneListMaxSize ${this.state.timeZoneListMaxSize} (endpoint ${this.endpoint.maybeId}.${this.endpoint.maybeNumber})`, Status.ResourceExhausted);
|
|
104
|
-
}
|
|
105
|
-
const [first, second] = timeZone;
|
|
106
|
-
if (first === undefined || BigInt(first.validAt) !== MATTER_EPOCH_US || (second !== undefined && BigInt(second.validAt) === MATTER_EPOCH_US)) {
|
|
107
|
-
throw new StatusResponseError(`MatterbridgeTimeSynchronizationServer.setTimeZone: the first entry SHALL have a ValidAt of 0 and a second entry a non-zero ValidAt (endpoint ${this.endpoint.maybeId}.${this.endpoint.maybeNumber})`, Status.ConstraintError);
|
|
108
|
-
}
|
|
109
|
-
this.state.timeZone = timeZone;
|
|
110
|
-
const now = nowUs();
|
|
111
|
-
const active = this.#activeTimeZone(now);
|
|
112
|
-
log.info(`MatterbridgeTimeSynchronizationServer.setTimeZone: the TimeZone was set to offset ${active.offset}s${active.name === undefined ? '' : ` (${active.name})`}, generating TimeZoneStatus (endpoint ${this.endpoint.maybeId}.${this.endpoint.maybeNumber})`);
|
|
113
|
-
this.events.timeZoneStatus.emit({ offset: active.offset, name: active.name }, this.context);
|
|
114
|
-
this.state.dstOffset = [];
|
|
115
|
-
this.events.dstTableEmpty.emit(undefined, this.context);
|
|
116
|
-
this.#updateDstStatus();
|
|
117
|
-
this.#updateLocalTime(now);
|
|
118
|
-
return { dstOffsetRequired: true };
|
|
119
|
-
}
|
|
120
|
-
setDstOffset(request) {
|
|
121
|
-
const { dstOffset } = request;
|
|
122
|
-
if (dstOffset.length > this.state.dstOffsetListMaxSize) {
|
|
123
|
-
throw new StatusResponseError(`MatterbridgeTimeSynchronizationServer.setDstOffset: the list of ${dstOffset.length} entries exceeds DSTOffsetListMaxSize ${this.state.dstOffsetListMaxSize} (endpoint ${this.endpoint.maybeId}.${this.endpoint.maybeNumber})`, Status.ResourceExhausted);
|
|
124
|
-
}
|
|
125
|
-
for (const [index, entry] of dstOffset.entries()) {
|
|
126
|
-
const isLast = index === dstOffset.length - 1;
|
|
127
|
-
const previous = index > 0 ? dstOffset[index - 1] : undefined;
|
|
128
|
-
const validUntilOk = entry.validUntil === null ? isLast : BigInt(entry.validUntil) > BigInt(entry.validStarting);
|
|
129
|
-
const orderOk = previous?.validUntil === null || previous === undefined || BigInt(entry.validStarting) >= BigInt(previous.validUntil);
|
|
130
|
-
if (!validUntilOk || !orderOk) {
|
|
131
|
-
throw new StatusResponseError(`MatterbridgeTimeSynchronizationServer.setDstOffset: entry ${index} does not conform to the DSTOffset list requirements (endpoint ${this.endpoint.maybeId}.${this.endpoint.maybeNumber})`, Status.ConstraintError);
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
this.state.dstOffset = dstOffset;
|
|
135
|
-
log.info(`MatterbridgeTimeSynchronizationServer.setDstOffset: the DSTOffset was set with ${dstOffset.length} entries (endpoint ${this.endpoint.maybeId}.${this.endpoint.maybeNumber})`);
|
|
136
|
-
if (dstOffset.length === 0)
|
|
137
|
-
this.events.dstTableEmpty.emit(undefined, this.context);
|
|
138
|
-
this.#updateDstStatus();
|
|
139
|
-
this.#updateLocalTime(nowUs());
|
|
140
|
-
}
|
|
141
|
-
#handleFabricsChanged(fabrics) {
|
|
142
|
-
const fabricIndex = this.state.trustedTimeSource?.fabricIndex;
|
|
143
|
-
if (fabricIndex === undefined || fabrics.some((fabric) => fabric.fabricIndex === fabricIndex))
|
|
144
|
-
return;
|
|
145
|
-
this.state.trustedTimeSource = null;
|
|
146
|
-
log.info(`MatterbridgeTimeSynchronizationServer: the TrustedTimeSource fabric ${fabricIndex} was removed, generating MissingTrustedTimeSource (endpoint ${this.endpoint.maybeId}.${this.endpoint.maybeNumber})`);
|
|
147
|
-
this.events.missingTrustedTimeSource.emit(undefined, this.context);
|
|
148
|
-
}
|
|
149
|
-
#activeTimeZone(now) {
|
|
150
|
-
const [first, second] = this.state.timeZone;
|
|
151
|
-
return second !== undefined && BigInt(second.validAt) <= now ? second : first;
|
|
152
|
-
}
|
|
153
|
-
#activeDstOffset() {
|
|
154
|
-
const now = nowUs();
|
|
155
|
-
const active = this.state.dstOffset.find((entry) => BigInt(entry.validStarting) <= now && (entry.validUntil === null || now < BigInt(entry.validUntil)));
|
|
156
|
-
return active?.offset ?? 0;
|
|
157
|
-
}
|
|
158
|
-
#updateDstStatus() {
|
|
159
|
-
const dstActive = this.#activeDstOffset() !== 0;
|
|
160
|
-
if (dstActive === this.internal.dstActive)
|
|
161
|
-
return;
|
|
162
|
-
this.internal.dstActive = dstActive;
|
|
163
|
-
log.info(`MatterbridgeTimeSynchronizationServer: the DST offset is ${dstActive ? 'applied' : 'no longer applied'}, generating DSTStatus (endpoint ${this.endpoint.maybeId}.${this.endpoint.maybeNumber})`);
|
|
164
|
-
this.events.dstStatus.emit({ dstOffsetActive: dstActive }, this.context);
|
|
165
|
-
}
|
|
166
|
-
#updateLocalTime(now) {
|
|
167
|
-
if (this.state.dstOffset.length === 0) {
|
|
168
|
-
this.state.localTime = null;
|
|
169
|
-
return;
|
|
170
|
-
}
|
|
171
|
-
const offsetSeconds = this.#activeTimeZone(now).offset + this.#activeDstOffset();
|
|
172
|
-
this.state.localTime = now + BigInt(offsetSeconds) * 1000000n;
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
(function (MatterbridgeTimeSynchronizationServer) {
|
|
176
|
-
class Internal {
|
|
177
|
-
clockTimer;
|
|
178
|
-
dstActive = false;
|
|
179
|
-
}
|
|
180
|
-
MatterbridgeTimeSynchronizationServer.Internal = Internal;
|
|
181
|
-
})(MatterbridgeTimeSynchronizationServer || (MatterbridgeTimeSynchronizationServer = {}));
|
|
@@ -1,332 +0,0 @@
|
|
|
1
|
-
import { createHash, createPrivateKey, createPublicKey, generateKeyPairSync, sign, X509Certificate } from 'node:crypto';
|
|
2
|
-
import { AnsiLogger, MAGENTA } from 'matterbridge/logger';
|
|
3
|
-
import { Bytes, Node, Time, Val } from 'matterbridge/matter';
|
|
4
|
-
import { OperationalCredentialsServer, TimeSynchronizationServer, TlsCertificateManagementServer, TlsClientManagementServer } from 'matterbridge/matter/behaviors';
|
|
5
|
-
import { TlsCertificateManagement } from 'matterbridge/matter/clusters';
|
|
6
|
-
import { AttributeModel, FieldElement } from 'matterbridge/matter/model';
|
|
7
|
-
import { FabricIndex, Status, StatusResponseError } from 'matterbridge/matter/types';
|
|
8
|
-
export const MAX_TLS_CERTIFICATE_ID = 65534;
|
|
9
|
-
export const MAX_CERTIFICATE_BYTES = 3000;
|
|
10
|
-
export const MAX_FINGERPRINT_BYTES = 64;
|
|
11
|
-
export const CLIENT_CSR_NONCE_BYTES = 32;
|
|
12
|
-
export const MAX_INTERMEDIATE_CERTIFICATES = 10;
|
|
13
|
-
const OID_COMMON_NAME = Buffer.from([0x06, 0x03, 0x55, 0x04, 0x03]);
|
|
14
|
-
const OID_ECDSA_WITH_SHA256 = Buffer.from([0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x04, 0x03, 0x02]);
|
|
15
|
-
const CSR_COMMON_NAME = 'Matterbridge TLS Client';
|
|
16
|
-
const log = new AnsiLogger({ logName: 'TlsCertificates', logLevel: "info", logNameColor: MAGENTA, logTimestampFormat: 4 });
|
|
17
|
-
function der(tag, content) {
|
|
18
|
-
const { length } = content;
|
|
19
|
-
if (length < 0x80)
|
|
20
|
-
return Buffer.concat([Buffer.from([tag, length]), content]);
|
|
21
|
-
const lengthBytes = [];
|
|
22
|
-
for (let remaining = length; remaining > 0; remaining = Math.floor(remaining / 256))
|
|
23
|
-
lengthBytes.unshift(remaining % 256);
|
|
24
|
-
return Buffer.concat([Buffer.from([tag, 0x80 + lengthBytes.length, ...lengthBytes]), content]);
|
|
25
|
-
}
|
|
26
|
-
export function createClientCsr(privateKey) {
|
|
27
|
-
const key = createPrivateKey({ key: Buffer.from(privateKey), format: 'der', type: 'pkcs8' });
|
|
28
|
-
const publicKeyInfo = createPublicKey(key).export({ type: 'spki', format: 'der' });
|
|
29
|
-
const subject = der(0x30, der(0x31, der(0x30, Buffer.concat([OID_COMMON_NAME, der(0x0c, Buffer.from(CSR_COMMON_NAME, 'utf8'))]))));
|
|
30
|
-
const requestInfo = der(0x30, Buffer.concat([der(0x02, Buffer.from([0x00])), subject, publicKeyInfo, Buffer.from([0xa0, 0x00])]));
|
|
31
|
-
const signature = sign('sha256', requestInfo, key);
|
|
32
|
-
return der(0x30, Buffer.concat([requestInfo, der(0x30, OID_ECDSA_WITH_SHA256), der(0x03, Buffer.concat([Buffer.from([0x00]), signature]))]));
|
|
33
|
-
}
|
|
34
|
-
export function signClientCsrNonce(privateKey, nonce) {
|
|
35
|
-
const key = createPrivateKey({ key: Buffer.from(privateKey), format: 'der', type: 'pkcs8' });
|
|
36
|
-
return sign('sha256', nonce, { key, dsaEncoding: 'ieee-p1363' });
|
|
37
|
-
}
|
|
38
|
-
export function certificateFingerprint(certificate) {
|
|
39
|
-
return createHash('sha256').update(certificate).digest();
|
|
40
|
-
}
|
|
41
|
-
export function parseValidCertificate(certificate) {
|
|
42
|
-
let x509;
|
|
43
|
-
try {
|
|
44
|
-
x509 = new X509Certificate(Buffer.from(certificate));
|
|
45
|
-
}
|
|
46
|
-
catch {
|
|
47
|
-
return undefined;
|
|
48
|
-
}
|
|
49
|
-
if (!x509.raw.equals(Buffer.from(certificate)))
|
|
50
|
-
return undefined;
|
|
51
|
-
const now = Time.nowMs;
|
|
52
|
-
if (now < Date.parse(x509.validFrom) || now > Date.parse(x509.validTo))
|
|
53
|
-
return undefined;
|
|
54
|
-
return x509;
|
|
55
|
-
}
|
|
56
|
-
export function allocateId(used, next) {
|
|
57
|
-
for (let i = 0; i <= MAX_TLS_CERTIFICATE_ID; i++) {
|
|
58
|
-
const id = (next + i) % (MAX_TLS_CERTIFICATE_ID + 1);
|
|
59
|
-
if (!used.has(id))
|
|
60
|
-
return id;
|
|
61
|
-
}
|
|
62
|
-
throw new StatusResponseError('No ID available', Status.ResourceExhausted);
|
|
63
|
-
}
|
|
64
|
-
const { schema } = TlsCertificateManagement;
|
|
65
|
-
const TlsCertificateManagementSchema = schema.extend(undefined, schema.require(AttributeModel, 'provisionedRootCertificates').extend({ constraint: 'none' }), schema.require(AttributeModel, 'provisionedClientCertificates').extend({ constraint: 'none' }), FieldElement({ name: 'RootCertificateStore', type: 'list', quality: 'N' }, FieldElement({ name: 'entry', type: 'struct' }, FieldElement({ name: 'Caid', id: 0, type: 'uint16' }), FieldElement({ name: 'Fabric', id: 1, type: 'uint8' }), FieldElement({ name: 'Certificate', id: 2, type: 'octstr' }))), FieldElement({ name: 'ClientCertificateStore', type: 'list', quality: 'N' }, FieldElement({ name: 'entry', type: 'struct' }, FieldElement({ name: 'Ccdid', id: 0, type: 'uint16' }), FieldElement({ name: 'Fabric', id: 1, type: 'uint8' }), FieldElement({ name: 'ClientCertificate', id: 2, type: 'octstr', quality: 'X' }), FieldElement({ name: 'IntermediateCertificates', id: 3, type: 'list' }, FieldElement({ name: 'entry', type: 'octstr' })), FieldElement({ name: 'PrivateKey', id: 4, type: 'octstr' }))), FieldElement({ name: 'NextCaid', type: 'uint16', quality: 'N' }), FieldElement({ name: 'NextCcdid', type: 'uint16', quality: 'N' }));
|
|
66
|
-
const MatterbridgeTlsCertificateManagementServerBase = TlsCertificateManagementServer.for(TlsCertificateManagement, TlsCertificateManagementSchema);
|
|
67
|
-
export class MatterbridgeTlsCertificateManagementServer extends MatterbridgeTlsCertificateManagementServerBase {
|
|
68
|
-
initialize() {
|
|
69
|
-
this.#updateAttributes();
|
|
70
|
-
const node = Node.forEndpoint(this.endpoint);
|
|
71
|
-
this.reactTo(node.eventsOf(OperationalCredentialsServer).fabrics$Changed, this.#handleFabricsChanged, { offline: true, lock: true });
|
|
72
|
-
}
|
|
73
|
-
provisionRootCertificate(request) {
|
|
74
|
-
const certificate = Bytes.of(request.certificate);
|
|
75
|
-
const { caid } = request;
|
|
76
|
-
const fabric = this.#accessingFabric();
|
|
77
|
-
if (certificate.byteLength > MAX_CERTIFICATE_BYTES) {
|
|
78
|
-
throw new StatusResponseError(`MatterbridgeTlsCertificateManagementServer.provisionRootCertificate: certificate of ${certificate.byteLength} octets exceeds ${MAX_CERTIFICATE_BYTES} (endpoint ${this.endpoint.maybeId}.${this.endpoint.maybeNumber})`, Status.ConstraintError);
|
|
79
|
-
}
|
|
80
|
-
if (caid !== null && caid > MAX_TLS_CERTIFICATE_ID) {
|
|
81
|
-
throw new StatusResponseError(`MatterbridgeTlsCertificateManagementServer.provisionRootCertificate: the CAID ${caid} is out of range (endpoint ${this.endpoint.maybeId}.${this.endpoint.maybeNumber})`, Status.ConstraintError);
|
|
82
|
-
}
|
|
83
|
-
if (this.endpoint.behaviors.has(TimeSynchronizationServer) && this.endpoint.stateOf(TimeSynchronizationServer).utcTime === null) {
|
|
84
|
-
throw new StatusResponseError(`MatterbridgeTlsCertificateManagementServer.provisionRootCertificate: time synchronization has not yet occurred (endpoint ${this.endpoint.maybeId}.${this.endpoint.maybeNumber})`, Status.InvalidInState);
|
|
85
|
-
}
|
|
86
|
-
if (parseValidCertificate(certificate) === undefined) {
|
|
87
|
-
throw new StatusResponseError(`MatterbridgeTlsCertificateManagementServer.provisionRootCertificate: not a valid DER encoded X.509 certificate (endpoint ${this.endpoint.maybeId}.${this.endpoint.maybeNumber})`, Status.DynamicConstraintError);
|
|
88
|
-
}
|
|
89
|
-
const store = this.state.rootCertificateStore;
|
|
90
|
-
const fingerprint = certificateFingerprint(certificate);
|
|
91
|
-
if (store.some((entry) => entry.fabric === fabric && certificateFingerprint(entry.certificate).equals(fingerprint))) {
|
|
92
|
-
throw new StatusResponseError(`MatterbridgeTlsCertificateManagementServer.provisionRootCertificate: certificate already provisioned (endpoint ${this.endpoint.maybeId}.${this.endpoint.maybeNumber})`, Status.AlreadyExists);
|
|
93
|
-
}
|
|
94
|
-
if (caid !== null) {
|
|
95
|
-
if (!store.some((entry) => entry.fabric === fabric && entry.caid === caid)) {
|
|
96
|
-
throw new StatusResponseError(`MatterbridgeTlsCertificateManagementServer.provisionRootCertificate: the CAID ${caid} was not found (endpoint ${this.endpoint.maybeId}.${this.endpoint.maybeNumber})`, Status.NotFound);
|
|
97
|
-
}
|
|
98
|
-
this.state.rootCertificateStore = store.map((entry) => (entry.fabric === fabric && entry.caid === caid ? { caid, fabric, certificate } : entry));
|
|
99
|
-
this.#updateAttributes();
|
|
100
|
-
log.info(`MatterbridgeTlsCertificateManagementServer.provisionRootCertificate: root certificate CAID ${caid} updated on fabric ${fabric} (endpoint ${this.endpoint.maybeId}.${this.endpoint.maybeNumber})`);
|
|
101
|
-
return { caid };
|
|
102
|
-
}
|
|
103
|
-
if (store.filter((entry) => entry.fabric === fabric).length >= this.state.maxRootCertificates) {
|
|
104
|
-
throw new StatusResponseError(`MatterbridgeTlsCertificateManagementServer.provisionRootCertificate: fabric ${fabric} already has ${this.state.maxRootCertificates} root certificates (endpoint ${this.endpoint.maybeId}.${this.endpoint.maybeNumber})`, Status.ResourceExhausted);
|
|
105
|
-
}
|
|
106
|
-
const id = allocateId(new Set(store.map((entry) => entry.caid)), this.state.nextCaid);
|
|
107
|
-
this.state.nextCaid = (id + 1) % (MAX_TLS_CERTIFICATE_ID + 1);
|
|
108
|
-
this.state.rootCertificateStore = [...store, { caid: id, fabric, certificate }];
|
|
109
|
-
this.#updateAttributes();
|
|
110
|
-
log.info(`MatterbridgeTlsCertificateManagementServer.provisionRootCertificate: root certificate CAID ${id} provisioned on fabric ${fabric} (endpoint ${this.endpoint.maybeId}.${this.endpoint.maybeNumber})`);
|
|
111
|
-
return { caid: id };
|
|
112
|
-
}
|
|
113
|
-
findRootCertificate(request) {
|
|
114
|
-
const { caid } = request;
|
|
115
|
-
const fabric = this.#accessingFabric();
|
|
116
|
-
if (caid !== null && caid > MAX_TLS_CERTIFICATE_ID)
|
|
117
|
-
throw new StatusResponseError(`MatterbridgeTlsCertificateManagementServer.findRootCertificate: the CAID ${caid} is out of range (endpoint ${this.endpoint.maybeId}.${this.endpoint.maybeNumber})`, Status.ConstraintError);
|
|
118
|
-
const certificateDetails = this.state.rootCertificateStore
|
|
119
|
-
.filter((entry) => entry.fabric === fabric && (caid === null || entry.caid === caid))
|
|
120
|
-
.map((entry) => ({ caid: entry.caid, certificate: entry.certificate, fabricIndex: FabricIndex(fabric) }));
|
|
121
|
-
if (certificateDetails.length === 0)
|
|
122
|
-
throw new StatusResponseError(`MatterbridgeTlsCertificateManagementServer.findRootCertificate: the CAID ${caid ?? 'null'} was not found (endpoint ${this.endpoint.maybeId}.${this.endpoint.maybeNumber})`, Status.NotFound);
|
|
123
|
-
return { certificateDetails };
|
|
124
|
-
}
|
|
125
|
-
lookupRootCertificate(request) {
|
|
126
|
-
const fingerprint = Buffer.from(Bytes.of(request.fingerprint));
|
|
127
|
-
const fabric = this.#accessingFabric();
|
|
128
|
-
if (fingerprint.byteLength > MAX_FINGERPRINT_BYTES) {
|
|
129
|
-
throw new StatusResponseError(`MatterbridgeTlsCertificateManagementServer.lookupRootCertificate: fingerprint of ${fingerprint.byteLength} octets exceeds ${MAX_FINGERPRINT_BYTES} (endpoint ${this.endpoint.maybeId}.${this.endpoint.maybeNumber})`, Status.ConstraintError);
|
|
130
|
-
}
|
|
131
|
-
const found = this.state.rootCertificateStore.find((entry) => entry.fabric === fabric && certificateFingerprint(entry.certificate).equals(fingerprint));
|
|
132
|
-
if (found === undefined)
|
|
133
|
-
throw new StatusResponseError(`MatterbridgeTlsCertificateManagementServer.lookupRootCertificate: fingerprint not found (endpoint ${this.endpoint.maybeId}.${this.endpoint.maybeNumber})`, Status.NotFound);
|
|
134
|
-
return { caid: found.caid };
|
|
135
|
-
}
|
|
136
|
-
removeRootCertificate(request) {
|
|
137
|
-
const { caid } = request;
|
|
138
|
-
const fabric = this.#accessingFabric();
|
|
139
|
-
if (caid > MAX_TLS_CERTIFICATE_ID)
|
|
140
|
-
throw new StatusResponseError(`MatterbridgeTlsCertificateManagementServer.removeRootCertificate: the CAID ${caid} is out of range (endpoint ${this.endpoint.maybeId}.${this.endpoint.maybeNumber})`, Status.ConstraintError);
|
|
141
|
-
if (this.#tlsEndpoints(fabric).some((endpoint) => endpoint.caid === caid)) {
|
|
142
|
-
throw new StatusResponseError(`MatterbridgeTlsCertificateManagementServer.removeRootCertificate: the CAID ${caid} is used by a TLS endpoint (endpoint ${this.endpoint.maybeId}.${this.endpoint.maybeNumber})`, Status.InvalidInState);
|
|
143
|
-
}
|
|
144
|
-
const store = this.state.rootCertificateStore;
|
|
145
|
-
const remaining = store.filter((entry) => !(entry.fabric === fabric && entry.caid === caid));
|
|
146
|
-
if (remaining.length === store.length)
|
|
147
|
-
throw new StatusResponseError(`MatterbridgeTlsCertificateManagementServer.removeRootCertificate: the CAID ${caid} was not found (endpoint ${this.endpoint.maybeId}.${this.endpoint.maybeNumber})`, Status.NotFound);
|
|
148
|
-
this.state.rootCertificateStore = remaining;
|
|
149
|
-
this.#updateAttributes();
|
|
150
|
-
log.info(`MatterbridgeTlsCertificateManagementServer.removeRootCertificate: root certificate CAID ${caid} removed from fabric ${fabric} (endpoint ${this.endpoint.maybeId}.${this.endpoint.maybeNumber})`);
|
|
151
|
-
}
|
|
152
|
-
clientCsr(request) {
|
|
153
|
-
const nonce = Bytes.of(request.nonce);
|
|
154
|
-
const { ccdid } = request;
|
|
155
|
-
const fabric = this.#accessingFabric();
|
|
156
|
-
if (nonce.byteLength !== CLIENT_CSR_NONCE_BYTES) {
|
|
157
|
-
throw new StatusResponseError(`MatterbridgeTlsCertificateManagementServer.clientCsr: nonce of ${nonce.byteLength} octets is not ${CLIENT_CSR_NONCE_BYTES} (endpoint ${this.endpoint.maybeId}.${this.endpoint.maybeNumber})`, Status.ConstraintError);
|
|
158
|
-
}
|
|
159
|
-
const store = this.state.clientCertificateStore;
|
|
160
|
-
let id;
|
|
161
|
-
let privateKey;
|
|
162
|
-
if (ccdid === null) {
|
|
163
|
-
if (store.filter((entry) => entry.fabric === fabric).length >= this.state.maxClientCertificates) {
|
|
164
|
-
throw new StatusResponseError(`MatterbridgeTlsCertificateManagementServer.clientCsr: fabric ${fabric} already has ${this.state.maxClientCertificates} client certificates (endpoint ${this.endpoint.maybeId}.${this.endpoint.maybeNumber})`, Status.ResourceExhausted);
|
|
165
|
-
}
|
|
166
|
-
id = allocateId(new Set(store.map((entry) => entry.ccdid)), this.state.nextCcdid);
|
|
167
|
-
privateKey = generateKeyPairSync('ec', { namedCurve: 'prime256v1' }).privateKey.export({ type: 'pkcs8', format: 'der' });
|
|
168
|
-
this.state.nextCcdid = (id + 1) % (MAX_TLS_CERTIFICATE_ID + 1);
|
|
169
|
-
this.state.clientCertificateStore = [...store, { ccdid: id, fabric, clientCertificate: null, intermediateCertificates: [], privateKey }];
|
|
170
|
-
this.#updateAttributes();
|
|
171
|
-
log.info(`MatterbridgeTlsCertificateManagementServer.clientCsr: client certificate CCDID ${id} created on fabric ${fabric} (endpoint ${this.endpoint.maybeId}.${this.endpoint.maybeNumber})`);
|
|
172
|
-
}
|
|
173
|
-
else {
|
|
174
|
-
if (ccdid > MAX_TLS_CERTIFICATE_ID)
|
|
175
|
-
throw new StatusResponseError(`MatterbridgeTlsCertificateManagementServer.clientCsr: the CCDID ${ccdid} is out of range (endpoint ${this.endpoint.maybeId}.${this.endpoint.maybeNumber})`, Status.ConstraintError);
|
|
176
|
-
const existing = store.find((entry) => entry.fabric === fabric && entry.ccdid === ccdid);
|
|
177
|
-
if (existing === undefined)
|
|
178
|
-
throw new StatusResponseError(`MatterbridgeTlsCertificateManagementServer.clientCsr: the CCDID ${ccdid} was not found (endpoint ${this.endpoint.maybeId}.${this.endpoint.maybeNumber})`, Status.NotFound);
|
|
179
|
-
id = ccdid;
|
|
180
|
-
privateKey = existing.privateKey;
|
|
181
|
-
log.info(`MatterbridgeTlsCertificateManagementServer.clientCsr: client certificate CCDID ${id} CSR generated for rotation on fabric ${fabric} (endpoint ${this.endpoint.maybeId}.${this.endpoint.maybeNumber})`);
|
|
182
|
-
}
|
|
183
|
-
return { ccdid: id, csr: createClientCsr(privateKey), nonceSignature: signClientCsrNonce(privateKey, nonce) };
|
|
184
|
-
}
|
|
185
|
-
provisionClientCertificate(request) {
|
|
186
|
-
const { ccdid } = request;
|
|
187
|
-
const clientCertificate = Bytes.of(request.clientCertificate);
|
|
188
|
-
const intermediateCertificates = request.intermediateCertificates.map((certificate) => Bytes.of(certificate));
|
|
189
|
-
const fabric = this.#accessingFabric();
|
|
190
|
-
if (ccdid > MAX_TLS_CERTIFICATE_ID) {
|
|
191
|
-
throw new StatusResponseError(`MatterbridgeTlsCertificateManagementServer.provisionClientCertificate: the CCDID ${ccdid} is out of range (endpoint ${this.endpoint.maybeId}.${this.endpoint.maybeNumber})`, Status.ConstraintError);
|
|
192
|
-
}
|
|
193
|
-
if (clientCertificate.byteLength > MAX_CERTIFICATE_BYTES) {
|
|
194
|
-
throw new StatusResponseError(`MatterbridgeTlsCertificateManagementServer.provisionClientCertificate: certificate of ${clientCertificate.byteLength} octets exceeds ${MAX_CERTIFICATE_BYTES} (endpoint ${this.endpoint.maybeId}.${this.endpoint.maybeNumber})`, Status.ConstraintError);
|
|
195
|
-
}
|
|
196
|
-
if (intermediateCertificates.length > MAX_INTERMEDIATE_CERTIFICATES) {
|
|
197
|
-
throw new StatusResponseError(`MatterbridgeTlsCertificateManagementServer.provisionClientCertificate: ${intermediateCertificates.length} intermediate certificates exceed ${MAX_INTERMEDIATE_CERTIFICATES} (endpoint ${this.endpoint.maybeId}.${this.endpoint.maybeNumber})`, Status.ConstraintError);
|
|
198
|
-
}
|
|
199
|
-
const bigIntermediate = intermediateCertificates.find((intermediate) => intermediate.byteLength > MAX_CERTIFICATE_BYTES);
|
|
200
|
-
if (bigIntermediate !== undefined) {
|
|
201
|
-
throw new StatusResponseError(`MatterbridgeTlsCertificateManagementServer.provisionClientCertificate: intermediate certificate of ${bigIntermediate.byteLength} octets exceeds ${MAX_CERTIFICATE_BYTES} (endpoint ${this.endpoint.maybeId}.${this.endpoint.maybeNumber})`, Status.ConstraintError);
|
|
202
|
-
}
|
|
203
|
-
const store = this.state.clientCertificateStore;
|
|
204
|
-
const fingerprint = certificateFingerprint(clientCertificate);
|
|
205
|
-
if (store.some((entry) => entry.fabric === fabric && entry.clientCertificate !== null && certificateFingerprint(entry.clientCertificate).equals(fingerprint))) {
|
|
206
|
-
throw new StatusResponseError(`MatterbridgeTlsCertificateManagementServer.provisionClientCertificate: certificate already provisioned (endpoint ${this.endpoint.maybeId}.${this.endpoint.maybeNumber})`, Status.AlreadyExists);
|
|
207
|
-
}
|
|
208
|
-
const existing = store.find((entry) => entry.fabric === fabric && entry.ccdid === ccdid);
|
|
209
|
-
if (existing === undefined) {
|
|
210
|
-
throw new StatusResponseError(`MatterbridgeTlsCertificateManagementServer.provisionClientCertificate: the CCDID ${ccdid} was not found (endpoint ${this.endpoint.maybeId}.${this.endpoint.maybeNumber})`, Status.NotFound);
|
|
211
|
-
}
|
|
212
|
-
const x509 = parseValidCertificate(clientCertificate);
|
|
213
|
-
if (x509 === undefined) {
|
|
214
|
-
throw new StatusResponseError(`MatterbridgeTlsCertificateManagementServer.provisionClientCertificate: not a valid DER encoded X.509 certificate (endpoint ${this.endpoint.maybeId}.${this.endpoint.maybeNumber})`, Status.DynamicConstraintError);
|
|
215
|
-
}
|
|
216
|
-
if (intermediateCertificates.some((intermediate) => parseValidCertificate(intermediate) === undefined)) {
|
|
217
|
-
throw new StatusResponseError(`MatterbridgeTlsCertificateManagementServer.provisionClientCertificate: intermediate certificate not a valid DER encoded X.509 certificate (endpoint ${this.endpoint.maybeId}.${this.endpoint.maybeNumber})`, Status.DynamicConstraintError);
|
|
218
|
-
}
|
|
219
|
-
const keyPublicKey = createPublicKey(createPrivateKey({ key: Buffer.from(existing.privateKey), format: 'der', type: 'pkcs8' })).export({ type: 'spki', format: 'der' });
|
|
220
|
-
if (!x509.publicKey.export({ type: 'spki', format: 'der' }).equals(keyPublicKey)) {
|
|
221
|
-
throw new StatusResponseError(`MatterbridgeTlsCertificateManagementServer.provisionClientCertificate: certificate not issued for the key pair of CCDID ${ccdid} (endpoint ${this.endpoint.maybeId}.${this.endpoint.maybeNumber})`, Status.DynamicConstraintError);
|
|
222
|
-
}
|
|
223
|
-
this.state.clientCertificateStore = store.map((entry) => entry.fabric === fabric && entry.ccdid === ccdid ? { ccdid, fabric, clientCertificate, intermediateCertificates, privateKey: existing.privateKey } : entry);
|
|
224
|
-
this.#updateAttributes();
|
|
225
|
-
log.info(`MatterbridgeTlsCertificateManagementServer.provisionClientCertificate: client certificate CCDID ${ccdid} provisioned on fabric ${fabric} with ${intermediateCertificates.length} intermediate certificates (endpoint ${this.endpoint.maybeId}.${this.endpoint.maybeNumber})`);
|
|
226
|
-
}
|
|
227
|
-
findClientCertificate(request) {
|
|
228
|
-
const { ccdid } = request;
|
|
229
|
-
const fabric = this.#accessingFabric();
|
|
230
|
-
if (ccdid !== null && ccdid > MAX_TLS_CERTIFICATE_ID)
|
|
231
|
-
throw new StatusResponseError(`MatterbridgeTlsCertificateManagementServer.findClientCertificate: the CCDID ${ccdid} is out of range (endpoint ${this.endpoint.maybeId}.${this.endpoint.maybeNumber})`, Status.ConstraintError);
|
|
232
|
-
const certificateDetails = this.state.clientCertificateStore
|
|
233
|
-
.filter((entry) => entry.fabric === fabric && (ccdid === null || entry.ccdid === ccdid))
|
|
234
|
-
.map((entry) => ({
|
|
235
|
-
ccdid: entry.ccdid,
|
|
236
|
-
clientCertificate: entry.clientCertificate,
|
|
237
|
-
intermediateCertificates: entry.intermediateCertificates,
|
|
238
|
-
fabricIndex: FabricIndex(fabric),
|
|
239
|
-
}));
|
|
240
|
-
if (certificateDetails.length === 0)
|
|
241
|
-
throw new StatusResponseError(`MatterbridgeTlsCertificateManagementServer.findClientCertificate: the CCDID ${ccdid ?? 'null'} was not found (endpoint ${this.endpoint.maybeId}.${this.endpoint.maybeNumber})`, Status.NotFound);
|
|
242
|
-
return { certificateDetails };
|
|
243
|
-
}
|
|
244
|
-
lookupClientCertificate(request) {
|
|
245
|
-
const fingerprint = Buffer.from(Bytes.of(request.fingerprint));
|
|
246
|
-
const fabric = this.#accessingFabric();
|
|
247
|
-
if (fingerprint.byteLength > MAX_FINGERPRINT_BYTES) {
|
|
248
|
-
throw new StatusResponseError(`MatterbridgeTlsCertificateManagementServer.lookupClientCertificate: fingerprint of ${fingerprint.byteLength} octets exceeds ${MAX_FINGERPRINT_BYTES} (endpoint ${this.endpoint.maybeId}.${this.endpoint.maybeNumber})`, Status.ConstraintError);
|
|
249
|
-
}
|
|
250
|
-
const found = this.state.clientCertificateStore.find((entry) => entry.fabric === fabric && entry.clientCertificate !== null && certificateFingerprint(entry.clientCertificate).equals(fingerprint));
|
|
251
|
-
if (found === undefined)
|
|
252
|
-
throw new StatusResponseError(`MatterbridgeTlsCertificateManagementServer.lookupClientCertificate: fingerprint not found (endpoint ${this.endpoint.maybeId}.${this.endpoint.maybeNumber})`, Status.NotFound);
|
|
253
|
-
return { ccdid: found.ccdid };
|
|
254
|
-
}
|
|
255
|
-
removeClientCertificate(request) {
|
|
256
|
-
const { ccdid } = request;
|
|
257
|
-
const fabric = this.#accessingFabric();
|
|
258
|
-
if (ccdid > MAX_TLS_CERTIFICATE_ID)
|
|
259
|
-
throw new StatusResponseError(`MatterbridgeTlsCertificateManagementServer.removeClientCertificate: the CCDID ${ccdid} is out of range (endpoint ${this.endpoint.maybeId}.${this.endpoint.maybeNumber})`, Status.ConstraintError);
|
|
260
|
-
if (this.#tlsEndpoints(fabric).some((endpoint) => endpoint.ccdid === ccdid)) {
|
|
261
|
-
throw new StatusResponseError(`MatterbridgeTlsCertificateManagementServer.removeClientCertificate: the CCDID ${ccdid} is used by a TLS endpoint (endpoint ${this.endpoint.maybeId}.${this.endpoint.maybeNumber})`, Status.InvalidInState);
|
|
262
|
-
}
|
|
263
|
-
const store = this.state.clientCertificateStore;
|
|
264
|
-
const remaining = store.filter((entry) => !(entry.fabric === fabric && entry.ccdid === ccdid));
|
|
265
|
-
if (remaining.length === store.length)
|
|
266
|
-
throw new StatusResponseError(`MatterbridgeTlsCertificateManagementServer.removeClientCertificate: the CCDID ${ccdid} was not found (endpoint ${this.endpoint.maybeId}.${this.endpoint.maybeNumber})`, Status.NotFound);
|
|
267
|
-
this.state.clientCertificateStore = remaining;
|
|
268
|
-
this.#updateAttributes();
|
|
269
|
-
log.info(`MatterbridgeTlsCertificateManagementServer.removeClientCertificate: client certificate CCDID ${ccdid} removed from fabric ${fabric} (endpoint ${this.endpoint.maybeId}.${this.endpoint.maybeNumber})`);
|
|
270
|
-
}
|
|
271
|
-
#accessingFabric() {
|
|
272
|
-
const fabric = this.context.fabric;
|
|
273
|
-
if (fabric === undefined || fabric === FabricIndex.NO_FABRIC)
|
|
274
|
-
throw new StatusResponseError(`MatterbridgeTlsCertificateManagementServer: an accessing fabric is required (endpoint ${this.endpoint.maybeId}.${this.endpoint.maybeNumber})`, Status.UnsupportedAccess);
|
|
275
|
-
return fabric;
|
|
276
|
-
}
|
|
277
|
-
#tlsEndpoints(fabric) {
|
|
278
|
-
if (!this.endpoint.behaviors.has(TlsClientManagementServer))
|
|
279
|
-
return [];
|
|
280
|
-
return this.endpoint.stateOf(TlsClientManagementServer).provisionedEndpoints.filter((endpoint) => endpoint.fabricIndex === fabric);
|
|
281
|
-
}
|
|
282
|
-
#updateAttributes() {
|
|
283
|
-
this.state.provisionedRootCertificates = this.state.rootCertificateStore.map((entry) => ({
|
|
284
|
-
caid: entry.caid,
|
|
285
|
-
certificate: entry.certificate,
|
|
286
|
-
fabricIndex: FabricIndex(entry.fabric),
|
|
287
|
-
}));
|
|
288
|
-
this.state.provisionedClientCertificates = this.state.clientCertificateStore.map((entry) => ({
|
|
289
|
-
ccdid: entry.ccdid,
|
|
290
|
-
clientCertificate: entry.clientCertificate,
|
|
291
|
-
intermediateCertificates: entry.intermediateCertificates,
|
|
292
|
-
fabricIndex: FabricIndex(entry.fabric),
|
|
293
|
-
}));
|
|
294
|
-
}
|
|
295
|
-
#handleFabricsChanged(fabrics) {
|
|
296
|
-
const fabricIndexes = new Set(fabrics.map((fabric) => fabric.fabricIndex));
|
|
297
|
-
const rootCertificateStore = this.state.rootCertificateStore.filter((entry) => fabricIndexes.has(entry.fabric));
|
|
298
|
-
const clientCertificateStore = this.state.clientCertificateStore.filter((entry) => fabricIndexes.has(entry.fabric));
|
|
299
|
-
if (rootCertificateStore.length === this.state.rootCertificateStore.length && clientCertificateStore.length === this.state.clientCertificateStore.length)
|
|
300
|
-
return;
|
|
301
|
-
this.state.rootCertificateStore = rootCertificateStore;
|
|
302
|
-
this.state.clientCertificateStore = clientCertificateStore;
|
|
303
|
-
this.#updateAttributes();
|
|
304
|
-
log.info(`MatterbridgeTlsCertificateManagementServer: a fabric was removed, the certificates of the removed fabrics were deleted (endpoint ${this.endpoint.maybeId}.${this.endpoint.maybeNumber})`);
|
|
305
|
-
}
|
|
306
|
-
}
|
|
307
|
-
(function (MatterbridgeTlsCertificateManagementServer) {
|
|
308
|
-
class State extends MatterbridgeTlsCertificateManagementServerBase.State {
|
|
309
|
-
rootCertificateStore = [];
|
|
310
|
-
clientCertificateStore = [];
|
|
311
|
-
nextCaid = 0;
|
|
312
|
-
nextCcdid = 0;
|
|
313
|
-
[Val.properties](_owner, session) {
|
|
314
|
-
if (session.subject === undefined || session.largeMessage === true)
|
|
315
|
-
return {};
|
|
316
|
-
const state = this;
|
|
317
|
-
return {
|
|
318
|
-
get provisionedRootCertificates() {
|
|
319
|
-
return state.provisionedRootCertificates.map(({ certificate: _certificate, ...entry }) => entry);
|
|
320
|
-
},
|
|
321
|
-
get provisionedClientCertificates() {
|
|
322
|
-
return state.provisionedClientCertificates.map(({ clientCertificate, intermediateCertificates, ...entry }) => ({
|
|
323
|
-
...entry,
|
|
324
|
-
...(clientCertificate === null ? { clientCertificate } : {}),
|
|
325
|
-
...(intermediateCertificates?.length === 0 ? { intermediateCertificates } : {}),
|
|
326
|
-
}));
|
|
327
|
-
},
|
|
328
|
-
};
|
|
329
|
-
}
|
|
330
|
-
}
|
|
331
|
-
MatterbridgeTlsCertificateManagementServer.State = State;
|
|
332
|
-
})(MatterbridgeTlsCertificateManagementServer || (MatterbridgeTlsCertificateManagementServer = {}));
|
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
import { AnsiLogger, MAGENTA } from 'matterbridge/logger';
|
|
2
|
-
import { Bytes } from 'matterbridge/matter';
|
|
3
|
-
import { TimeSynchronizationServer, TlsCertificateManagementServer, TlsClientManagementServer } from 'matterbridge/matter/behaviors';
|
|
4
|
-
import { TlsClientManagement } from 'matterbridge/matter/clusters';
|
|
5
|
-
import { FieldElement } from 'matterbridge/matter/model';
|
|
6
|
-
import { FabricIndex, Status, StatusResponseError } from 'matterbridge/matter/types';
|
|
7
|
-
import { allocateId } from './tlsCertificateManagementServer.js';
|
|
8
|
-
export const MAX_TLS_ENDPOINT_ID = 65534;
|
|
9
|
-
export const MIN_HOSTNAME_BYTES = 4;
|
|
10
|
-
export const MAX_HOSTNAME_BYTES = 253;
|
|
11
|
-
const log = new AnsiLogger({ logName: 'TlsClient', logLevel: "info", logNameColor: MAGENTA, logTimestampFormat: 4 });
|
|
12
|
-
const TlsClientManagementSchema = TlsClientManagement.schema.extend(undefined, FieldElement({ name: 'NextEndpointId', type: 'uint16', quality: 'N' }));
|
|
13
|
-
const MatterbridgeTlsClientManagementServerBase = TlsClientManagementServer.for(TlsClientManagement, TlsClientManagementSchema);
|
|
14
|
-
function bytesEqual(a, b) {
|
|
15
|
-
return Buffer.from(Bytes.of(a)).equals(Buffer.from(Bytes.of(b)));
|
|
16
|
-
}
|
|
17
|
-
export class MatterbridgeTlsClientManagementServer extends MatterbridgeTlsClientManagementServerBase {
|
|
18
|
-
provisionEndpoint(request) {
|
|
19
|
-
const hostname = Bytes.of(request.hostname);
|
|
20
|
-
const { port, caid, ccdid, endpointId } = request;
|
|
21
|
-
const fabric = this.#accessingFabric();
|
|
22
|
-
if (hostname.byteLength < MIN_HOSTNAME_BYTES || hostname.byteLength > MAX_HOSTNAME_BYTES) {
|
|
23
|
-
throw new StatusResponseError(`MatterbridgeTlsClientManagementServer.provisionEndpoint: hostname of ${hostname.byteLength} octets is not ${MIN_HOSTNAME_BYTES} to ${MAX_HOSTNAME_BYTES} (endpoint ${this.endpoint.maybeId}.${this.endpoint.maybeNumber})`, Status.ConstraintError);
|
|
24
|
-
}
|
|
25
|
-
if (port < 1)
|
|
26
|
-
throw new StatusResponseError(`MatterbridgeTlsClientManagementServer.provisionEndpoint: the port 0 is not valid (endpoint ${this.endpoint.maybeId}.${this.endpoint.maybeNumber})`, Status.ConstraintError);
|
|
27
|
-
if (caid > MAX_TLS_ENDPOINT_ID || (ccdid !== null && ccdid > MAX_TLS_ENDPOINT_ID) || (endpointId !== null && endpointId > MAX_TLS_ENDPOINT_ID)) {
|
|
28
|
-
throw new StatusResponseError(`MatterbridgeTlsClientManagementServer.provisionEndpoint: the CAID, CCDID or EndpointID is out of range (endpoint ${this.endpoint.maybeId}.${this.endpoint.maybeNumber})`, Status.ConstraintError);
|
|
29
|
-
}
|
|
30
|
-
if (this.endpoint.behaviors.has(TimeSynchronizationServer) && this.endpoint.stateOf(TimeSynchronizationServer).utcTime === null) {
|
|
31
|
-
throw new TlsClientManagement.InvalidTimeError(`MatterbridgeTlsClientManagementServer.provisionEndpoint: time synchronization has not yet occurred (endpoint ${this.endpoint.maybeId}.${this.endpoint.maybeNumber})`);
|
|
32
|
-
}
|
|
33
|
-
const certificates = this.endpoint.stateOf(TlsCertificateManagementServer);
|
|
34
|
-
if (!certificates.provisionedRootCertificates.some((entry) => entry.fabricIndex === fabric && entry.caid === caid)) {
|
|
35
|
-
throw new TlsClientManagement.RootCertificateNotFoundError(`MatterbridgeTlsClientManagementServer.provisionEndpoint: the CAID ${caid} was not found (endpoint ${this.endpoint.maybeId}.${this.endpoint.maybeNumber})`);
|
|
36
|
-
}
|
|
37
|
-
if (ccdid !== null && !certificates.provisionedClientCertificates.some((entry) => entry.fabricIndex === fabric && entry.ccdid === ccdid)) {
|
|
38
|
-
throw new TlsClientManagement.ClientCertificateNotFoundError(`MatterbridgeTlsClientManagementServer.provisionEndpoint: the CCDID ${ccdid} was not found (endpoint ${this.endpoint.maybeId}.${this.endpoint.maybeNumber})`);
|
|
39
|
-
}
|
|
40
|
-
const endpoints = this.state.provisionedEndpoints;
|
|
41
|
-
const fabricEndpoints = endpoints.filter((endpoint) => endpoint.fabricIndex === fabric);
|
|
42
|
-
const duplicate = fabricEndpoints.some((endpoint) => endpoint.port === port && bytesEqual(endpoint.hostname, hostname) && endpoint.endpointId !== endpointId);
|
|
43
|
-
if (endpointId === null) {
|
|
44
|
-
if (fabricEndpoints.length >= this.state.maxProvisioned) {
|
|
45
|
-
throw new StatusResponseError(`MatterbridgeTlsClientManagementServer.provisionEndpoint: fabric ${fabric} already has ${this.state.maxProvisioned} endpoints (endpoint ${this.endpoint.maybeId}.${this.endpoint.maybeNumber})`, Status.ResourceExhausted);
|
|
46
|
-
}
|
|
47
|
-
if (duplicate) {
|
|
48
|
-
throw new TlsClientManagement.EndpointAlreadyInstalledError(`MatterbridgeTlsClientManagementServer.provisionEndpoint: an endpoint with the same hostname and port is already installed (endpoint ${this.endpoint.maybeId}.${this.endpoint.maybeNumber})`);
|
|
49
|
-
}
|
|
50
|
-
const id = allocateId(new Set(endpoints.map((endpoint) => endpoint.endpointId)), this.state.nextEndpointId);
|
|
51
|
-
this.state.nextEndpointId = (id + 1) % (MAX_TLS_ENDPOINT_ID + 1);
|
|
52
|
-
this.state.provisionedEndpoints = [...endpoints, { endpointId: id, hostname, port, caid, ccdid, referenceCount: 0, fabricIndex: FabricIndex(fabric) }];
|
|
53
|
-
log.info(`MatterbridgeTlsClientManagementServer.provisionEndpoint: the TLS endpoint ${id} provisioned on fabric ${fabric} (endpoint ${this.endpoint.maybeId}.${this.endpoint.maybeNumber})`);
|
|
54
|
-
return { endpointId: id };
|
|
55
|
-
}
|
|
56
|
-
const existing = fabricEndpoints.find((endpoint) => endpoint.endpointId === endpointId);
|
|
57
|
-
if (existing === undefined)
|
|
58
|
-
throw new StatusResponseError(`MatterbridgeTlsClientManagementServer.provisionEndpoint: the EndpointID ${endpointId} was not found (endpoint ${this.endpoint.maybeId}.${this.endpoint.maybeNumber})`, Status.NotFound);
|
|
59
|
-
if (duplicate) {
|
|
60
|
-
throw new TlsClientManagement.EndpointAlreadyInstalledError(`MatterbridgeTlsClientManagementServer.provisionEndpoint: an endpoint with the same hostname and port is already installed (endpoint ${this.endpoint.maybeId}.${this.endpoint.maybeNumber})`);
|
|
61
|
-
}
|
|
62
|
-
const { referenceCount } = existing;
|
|
63
|
-
this.state.provisionedEndpoints = endpoints.map((endpoint) => endpoint.fabricIndex === fabric && endpoint.endpointId === endpointId
|
|
64
|
-
? { endpointId, hostname, port, caid, ccdid, referenceCount, fabricIndex: FabricIndex(fabric) }
|
|
65
|
-
: endpoint);
|
|
66
|
-
log.info(`MatterbridgeTlsClientManagementServer.provisionEndpoint: the TLS endpoint ${endpointId} updated on fabric ${fabric} (endpoint ${this.endpoint.maybeId}.${this.endpoint.maybeNumber})`);
|
|
67
|
-
return { endpointId };
|
|
68
|
-
}
|
|
69
|
-
findEndpoint(request) {
|
|
70
|
-
const { endpointId } = request;
|
|
71
|
-
const fabric = this.#accessingFabric();
|
|
72
|
-
if (endpointId > MAX_TLS_ENDPOINT_ID)
|
|
73
|
-
throw new StatusResponseError(`MatterbridgeTlsClientManagementServer.findEndpoint: the EndpointID ${endpointId} is out of range (endpoint ${this.endpoint.maybeId}.${this.endpoint.maybeNumber})`, Status.ConstraintError);
|
|
74
|
-
const endpoint = this.state.provisionedEndpoints.find((entry) => entry.fabricIndex === fabric && entry.endpointId === endpointId);
|
|
75
|
-
if (endpoint === undefined)
|
|
76
|
-
throw new StatusResponseError(`MatterbridgeTlsClientManagementServer.findEndpoint: the EndpointID ${endpointId} was not found (endpoint ${this.endpoint.maybeId}.${this.endpoint.maybeNumber})`, Status.NotFound);
|
|
77
|
-
return { endpoint };
|
|
78
|
-
}
|
|
79
|
-
removeEndpoint(request) {
|
|
80
|
-
const { endpointId } = request;
|
|
81
|
-
const fabric = this.#accessingFabric();
|
|
82
|
-
if (endpointId > MAX_TLS_ENDPOINT_ID)
|
|
83
|
-
throw new StatusResponseError(`MatterbridgeTlsClientManagementServer.removeEndpoint: the EndpointID ${endpointId} is out of range (endpoint ${this.endpoint.maybeId}.${this.endpoint.maybeNumber})`, Status.ConstraintError);
|
|
84
|
-
const endpoints = this.state.provisionedEndpoints;
|
|
85
|
-
const endpoint = endpoints.find((entry) => entry.fabricIndex === fabric && entry.endpointId === endpointId);
|
|
86
|
-
if (endpoint === undefined)
|
|
87
|
-
throw new StatusResponseError(`MatterbridgeTlsClientManagementServer.removeEndpoint: the EndpointID ${endpointId} was not found (endpoint ${this.endpoint.maybeId}.${this.endpoint.maybeNumber})`, Status.NotFound);
|
|
88
|
-
if (endpoint.referenceCount > 0) {
|
|
89
|
-
throw new TlsClientManagement.EndpointInUseError(`MatterbridgeTlsClientManagementServer.removeEndpoint: the EndpointID ${endpointId} is in use by ${endpoint.referenceCount} clusters (endpoint ${this.endpoint.maybeId}.${this.endpoint.maybeNumber})`);
|
|
90
|
-
}
|
|
91
|
-
this.state.provisionedEndpoints = endpoints.filter((entry) => !(entry.fabricIndex === fabric && entry.endpointId === endpointId));
|
|
92
|
-
log.info(`MatterbridgeTlsClientManagementServer.removeEndpoint: the TLS endpoint ${endpointId} removed from fabric ${fabric} (endpoint ${this.endpoint.maybeId}.${this.endpoint.maybeNumber})`);
|
|
93
|
-
}
|
|
94
|
-
#accessingFabric() {
|
|
95
|
-
const fabric = this.context.fabric;
|
|
96
|
-
if (fabric === undefined || fabric === FabricIndex.NO_FABRIC)
|
|
97
|
-
throw new StatusResponseError(`MatterbridgeTlsClientManagementServer: an accessing fabric is required (endpoint ${this.endpoint.maybeId}.${this.endpoint.maybeNumber})`, Status.UnsupportedAccess);
|
|
98
|
-
return fabric;
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
(function (MatterbridgeTlsClientManagementServer) {
|
|
102
|
-
class State extends MatterbridgeTlsClientManagementServerBase.State {
|
|
103
|
-
nextEndpointId = 0;
|
|
104
|
-
}
|
|
105
|
-
MatterbridgeTlsClientManagementServer.State = State;
|
|
106
|
-
})(MatterbridgeTlsClientManagementServer || (MatterbridgeTlsClientManagementServer = {}));
|