asyx 0.0.2 → 0.1.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.
- package/LICENSE +67 -0
- package/README.md +125 -17
- package/SECURITY.md +40 -0
- package/bin/asyx.js +2 -0
- package/package.json +47 -17
- package/src/commands/.gitkeep +0 -0
- package/src/commands/mqtt-broker.js +56 -0
- package/src/commands/mqtt.js +164 -0
- package/src/commands/setup.js +137 -0
- package/src/commands/sts.js +73 -0
- package/src/commands/tunnel.js +540 -0
- package/src/lib/.gitkeep +0 -0
- package/src/lib/certs.js +25 -0
- package/src/lib/csr.js +45 -0
- package/src/lib/device.js +18 -0
- package/src/lib/fingerprint.js +115 -0
- package/src/lib/ids.js +5 -0
- package/src/lib/logger.js +58 -0
- package/src/lib/logger.level.spec.js +81 -0
- package/src/lib/logger.test.js +42 -0
- package/src/lib/pairing.js +15 -0
- package/src/lib/shared-transport.js +15 -0
- package/src/main.js +57 -0
- package/src/mqtt/awaiter-map.js +157 -0
- package/src/mqtt/events/handlers.js +90 -0
- package/src/mqtt/events/index.js +14 -0
- package/src/mqtt/events/schemas.js +58 -0
- package/src/mqtt/ingress.js +172 -0
- package/src/state/assignment.js +156 -0
- package/src/tunnel/__test_utils__/testUtils.js +76 -0
- package/src/tunnel/__tests__/jwt-refresh.spec.js +948 -0
- package/src/tunnel/__tests__/ws-control.spec.js +164 -0
- package/src/tunnel/http-tunnel.js +1131 -0
- package/src/tunnel/ws-control.js +144 -0
- package/index.js +0 -13
package/LICENSE
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document.
|
|
10
|
+
|
|
11
|
+
"Licensor" shall mean the copyright owner or entity granting the License.
|
|
12
|
+
|
|
13
|
+
"Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity.
|
|
14
|
+
|
|
15
|
+
"You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License.
|
|
16
|
+
|
|
17
|
+
"Source" shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files.
|
|
18
|
+
|
|
19
|
+
"Object" shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types.
|
|
20
|
+
|
|
21
|
+
"Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (which shall not include communications that are clearly marked or otherwise designated in writing by the copyright owner as "Not a Work").
|
|
22
|
+
|
|
23
|
+
"Derivative Works" shall mean any work, whether in Source or Object form, that is based upon (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and derivative works thereof.
|
|
24
|
+
|
|
25
|
+
"Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Work".
|
|
26
|
+
|
|
27
|
+
2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to use, reproduce, modify, distribute, and prepare Derivative Works of, and to display and perform the Work and such Derivative Works in all media and formats whether now known or hereafter devised.
|
|
28
|
+
|
|
29
|
+
3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed.
|
|
30
|
+
|
|
31
|
+
4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions:
|
|
32
|
+
|
|
33
|
+
(a) You must give any other recipients of the Work or Derivative Works a copy of this License; and
|
|
34
|
+
|
|
35
|
+
(b) You must cause any modified files to carry prominent notices stating that You changed the files; and
|
|
36
|
+
|
|
37
|
+
(c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and
|
|
38
|
+
|
|
39
|
+
(d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License.
|
|
40
|
+
|
|
41
|
+
You may add Your own copyright notice to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License.
|
|
42
|
+
|
|
43
|
+
5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions.
|
|
44
|
+
|
|
45
|
+
6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file.
|
|
46
|
+
|
|
47
|
+
7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License.
|
|
48
|
+
|
|
49
|
+
8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages.
|
|
50
|
+
|
|
51
|
+
9. Accepting Warranty or Support. You may choose to offer, and to charge a fee for, warranty, support, indemnity or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or support.
|
|
52
|
+
|
|
53
|
+
END OF TERMS AND CONDITIONS
|
|
54
|
+
|
|
55
|
+
Copyright 2025 Asyx
|
|
56
|
+
|
|
57
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
58
|
+
you may not use this file except in compliance with the License.
|
|
59
|
+
You may obtain a copy of the License at
|
|
60
|
+
|
|
61
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
62
|
+
|
|
63
|
+
Unless required by applicable law or agreed to in writing, software
|
|
64
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
65
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
66
|
+
See the License for the specific language governing permissions and
|
|
67
|
+
limitations under the License.
|
package/README.md
CHANGED
|
@@ -1,32 +1,140 @@
|
|
|
1
1
|
# Asyx CLI
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Secure tunnels to the Asyx control plane with a single command. The CLI provisions device credentials, refreshes JWTs automatically, and maintains resilient control-plane connectivity so developers can expose local services without managing relay infrastructure.
|
|
4
4
|
|
|
5
|
-
-
|
|
6
|
-
- License: Apache-2.0
|
|
5
|
+
> **Beta access**: invitation-only while we scale capacity. Join the waitlist to be notified when new slots open.
|
|
7
6
|
|
|
8
|
-
##
|
|
9
|
-
- Node.js 18+
|
|
10
|
-
|
|
11
|
-
## Install
|
|
7
|
+
## Installation
|
|
12
8
|
|
|
13
9
|
```bash
|
|
14
10
|
npm install -g asyx
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
- Supports Node.js 18.17 or newer.
|
|
14
|
+
- Installs the `asyx` binary globally so it is available in your `PATH`.
|
|
15
|
+
- Prefer `npx asyx <cmd>` if you cannot install globally.
|
|
16
|
+
|
|
17
|
+
### Updating / Removing
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
npm update -g asyx # upgrade to the latest published release
|
|
21
|
+
npm uninstall -g asyx
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## Quick Start
|
|
25
|
+
|
|
26
|
+
1. **Authorize the client**
|
|
27
|
+
```bash
|
|
28
|
+
asyx setup
|
|
29
|
+
```
|
|
30
|
+
- **Opens your default browser** to complete device authorization—you'll need to approve the connection in your browser.
|
|
31
|
+
- Completes CLI registration on the Asyx website after passwordless magic-link authentication.
|
|
32
|
+
- Lets you pick a personal `<subdomain>.tunnel.asyx.ai` address (fixed for now; choose carefully) that is covered by the Asyx-managed wildcard TLS certificate.
|
|
33
|
+
- Provisions an Asyx-issued client certificate and unique client identifier (stored under `~/.asyx/certs/<clientId>/`).
|
|
34
|
+
- Captures a minimal hardware fingerprint, hashes it locally (SHA-256 with public salt), and shares only the hash so the Asyx backend can verify the CLI is on the authorized device.
|
|
35
|
+
- Certificates are single-device: copying them to another machine fails policy checks, so re-run `asyx setup` on every host.
|
|
36
|
+
|
|
37
|
+
2. **Open a tunnel**
|
|
38
|
+
```bash
|
|
39
|
+
asyx tunnel --http --port 3000
|
|
40
|
+
```
|
|
41
|
+
- Creates a forward-only HTTP tunnel bound to your issued client ID.
|
|
42
|
+
- Automatically refreshes JWTs over the Asyx messaging pipeline and keeps the session alive while traffic is flowing.
|
|
43
|
+
- HTTP tunneling is the only supported protocol in this release; TCP access is planned for a future update.
|
|
44
|
+
|
|
45
|
+
3. **Clean up (optional)**
|
|
46
|
+
```bash
|
|
47
|
+
rm -rf ~/.asyx/certs/<clientId>
|
|
48
|
+
```
|
|
49
|
+
Removes local device material; re-run `asyx setup` afterwards to restore access.
|
|
50
|
+
|
|
51
|
+
## Why Asyx
|
|
52
|
+
|
|
53
|
+
- **Device-bound identity** – Every `setup` run issues a unique certificate and uuLID. Asyx backend policies reject duplicate usage, preventing credential theft or relocation.
|
|
54
|
+
- **Hardware attestation without PII** – The CLI derives a hashed hardware fingerprint locally using the safe `hw-fingerprint` fields; raw hardware attributes never leave the device.
|
|
55
|
+
- **Resilient control plane** – Automatic JWT refresh via the background messaging queue, bounded reconnects, and observable logging (`ASYX_DEBUG=1`) keep tunnels stable during long soaks.
|
|
56
|
+
- **Zero manual relay config** – Asyx backend assignments route traffic for you; no hostnames, firewall poking, or manual DNS updates required.
|
|
57
|
+
- **Secure HTTP proxy** – Forward-only mode avoids local port binding conflicts and keeps user services isolated from the CLI process.
|
|
58
|
+
- **Observability-first UX** – Friendly error messages, deterministic exit codes, and optional debug traces make support straightforward.
|
|
59
|
+
- **Future-ready auth** – Today’s magic-link flow will extend to tunnel sharing with Asyx Quickpass, delivering passwordless approvals for downstream users.
|
|
60
|
+
|
|
61
|
+
## Command Reference
|
|
62
|
+
|
|
63
|
+
```bash
|
|
64
|
+
asyx setup # Provision device certificate and client identity
|
|
65
|
+
asyx tunnel --http --port <n> # Start HTTP tunnel for local port <n>
|
|
66
|
+
asyx mqtt ... # Development MQTT utilities (NODE_ENV=dev)
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
Use `asyx help` or `asyx <command> --help` for details.
|
|
70
|
+
|
|
71
|
+
## Logging
|
|
72
|
+
|
|
73
|
+
Control CLI verbosity with the `ASYX_LOG_LEVEL` environment variable:
|
|
74
|
+
|
|
75
|
+
```
|
|
76
|
+
# Levels (case-insensitive): error, warn, info, debug
|
|
77
|
+
# Default: info
|
|
78
|
+
ASYX_LOG_LEVEL=warn asyx tunnel --http --port 3000 # quiet mode: only warnings/errors
|
|
79
|
+
ASYX_LOG_LEVEL=debug asyx tunnel --http --port 3000 # full verbosity for engineering
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
- Invalid values fall back to `info`.
|
|
83
|
+
- Structured logs (JSON) are emitted to stdout/stderr; by default, debug is suppressed.
|
|
84
|
+
- User-facing banners remain visible regardless of log level.
|
|
85
|
+
|
|
86
|
+
## Heartbeat Behavior
|
|
87
|
+
|
|
88
|
+
The CLI manages heartbeats automatically to keep idle sessions stable without user tuning.
|
|
89
|
+
|
|
90
|
+
- Heartbeats pause whenever HTTP traffic is flowing and resume only when idle.
|
|
91
|
+
- Intervals are controlled server-side to prevent abuse and excessive reconnects.
|
|
92
|
+
- Heartbeat stops when the tunnel exits or errors.
|
|
93
|
+
- Use `ASYX_DEBUG=1` if you need to trace heartbeat activity for support purposes.
|
|
94
|
+
|
|
95
|
+
## Security
|
|
96
|
+
|
|
97
|
+
Asyx tunnels are designed with security-first principles to protect both your local services and the tunnel infrastructure. Every active tunnel operates with **per-tunnel cryptographic isolation**, short-lived JWT credentials, and in-band credential refresh to achieve zero-downtime, zero-trust operation.
|
|
98
|
+
|
|
99
|
+
### Zero Public Exposure
|
|
100
|
+
- **Local services remain private**: Your services never expose ports directly to the internet. All traffic flows through Asyx's cloud-managed relay infrastructure with TLS encryption end-to-end.
|
|
101
|
+
- **No manual firewall rules**: The tunnel architecture eliminates the need to open ports or configure NAT, reducing attack surface.
|
|
102
|
+
|
|
103
|
+
### Per-Tunnel Cryptographic Isolation
|
|
104
|
+
- **Independent cryptographic boundaries**: Each tunnel session operates with its own short-lived JWT scoped to a specific endpoint and host identity, minimizing exposure under compromise.
|
|
105
|
+
- **Short credential lifetimes**: JWTs are automatically refreshed in-band (without reconnecting), maintaining zero-downtime operation while enforcing continuous validation.
|
|
106
|
+
- **Stateless JWT validation**: Authentication uses stateless RS256 JWT validation with JWKS, eliminating server-side session state and reducing attack surface.
|
|
15
107
|
|
|
16
|
-
|
|
108
|
+
### Device-Bound Identity
|
|
109
|
+
- **Unique per-device credentials**: Each `asyx setup` run provisions a unique device certificate and client identifier. Certificates cannot be copied or reused on other machines—policy checks reject duplicate usage.
|
|
110
|
+
- **Hardware attestation without PII**: The CLI derives a hashed hardware fingerprint locally using safe, non-sensitive attributes. Raw hardware data never leaves your device; only a SHA-256 hash (with public salt) is shared for device verification.
|
|
111
|
+
- **Web-based pairing**: CLI installation and pairing occur over HTTPS, binding user identity and device fingerprint to tenant ownership.
|
|
17
112
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
113
|
+
### Authentication & Encryption
|
|
114
|
+
- **JWT-based authentication**: Tunnel sessions use ephemeral RS256 JWTs delivered over the secure Asyx messaging pipeline (MQTT over TLS).
|
|
115
|
+
- **Independent certificate layers**: Separate X.509 certificates are used for messaging and control layers, with each client and relay authenticated through unique credentials.
|
|
116
|
+
- **Mutual TLS**: The control plane uses X.509 certificates for mutual authentication between the CLI and Asyx infrastructure.
|
|
117
|
+
- **Forward-only proxy**: The CLI operates as a forward-only HTTP proxy, keeping your services isolated from the CLI process itself.
|
|
21
118
|
|
|
22
|
-
|
|
119
|
+
### Operational Security
|
|
120
|
+
- **Cryptographic presence monitoring**: Only active relays can receive new assignments, preventing stale routing and unauthorized access.
|
|
121
|
+
- **Event-driven orchestration**: Verifiable routing for DNS assignment, relay control, and session lifecycle via secure cloud events.
|
|
122
|
+
- **Session-level audit trail**: Token issuance (JTI), timestamps, and validation context are logged for complete traceability.
|
|
123
|
+
- **Dynamic access control**: Tunnels can be reassigned or closed in real time based on usage patterns or detected anomalies.
|
|
23
124
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
125
|
+
### Privacy & Data Handling
|
|
126
|
+
- **No PII in transit**: Identity information (if used with Asyx Quickpass) is forwarded only as opaque identifiers via headers, not personally identifiable information.
|
|
127
|
+
- **Local credential storage**: All device certificates are stored locally under `~/.asyx/certs/<clientId>/` and are never transmitted during normal operation.
|
|
128
|
+
- **Immutable deployments**: Deployment templates include embedded SHA-256 validation hashes, ensuring integrity and tamper protection.
|
|
27
129
|
|
|
28
|
-
|
|
130
|
+
### Transparency & Auditability
|
|
131
|
+
- **Open-source CLI**: The CLI client is open source, allowing independent audit and transparency, reinforcing trust and security posture.
|
|
132
|
+
- **Comprehensive telemetry**: Structured logs for authentication, policy, and reauth events form a complete trust graph for security analysis.
|
|
29
133
|
|
|
30
|
-
|
|
134
|
+
### Security Reporting
|
|
135
|
+
- **Responsible disclosure**: Email [security@asyx.ai](mailto:security@asyx.ai) with detailed findings, reproduction steps, and affected versions. Do **not** open public GitHub/npm issues for security-sensitive reports.
|
|
136
|
+
- **Vulnerability handling**: We acknowledge submissions within 2 business days and coordinate remediation timelines privately.
|
|
31
137
|
|
|
138
|
+
## License
|
|
32
139
|
|
|
140
|
+
- Licensed under [Apache-2.0](./LICENSE).
|
package/SECURITY.md
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# Security Policy
|
|
2
|
+
|
|
3
|
+
Last updated: 2025-10-23
|
|
4
|
+
|
|
5
|
+
## Reporting a Vulnerability
|
|
6
|
+
|
|
7
|
+
- Email security@asyx.ai with detailed findings; include reproduction steps and affected environments.
|
|
8
|
+
- Do **not** open public GitHub/npm issues for security-sensitive reports.
|
|
9
|
+
- We acknowledge submissions within 2 business days and coordinate remediation timelines privately.
|
|
10
|
+
|
|
11
|
+
## Supported Builds
|
|
12
|
+
|
|
13
|
+
- The Asyx CLI is currently in invitation-only beta. Only the latest published npm package (`asyx@0.1.x`) receives security updates.
|
|
14
|
+
- Beta access tokens and subdomains are provisioned manually; if your invite expires, request a new link through support.
|
|
15
|
+
|
|
16
|
+
## Device-Bound Credentials
|
|
17
|
+
|
|
18
|
+
- `asyx setup` issues a unique device certificate and UUID, stored under `~/.asyx/certs/<clientId>/`.
|
|
19
|
+
- Certificates cannot be reused on other machines; copying the directory fails policy checks. Re-run `asyx setup` on each host instead.
|
|
20
|
+
- Remove local material by deleting the cert directory (`rm -rf ~/.asyx/certs/<clientId>`). The next setup reinstates access.
|
|
21
|
+
|
|
22
|
+
## Hardware Fingerprint Privacy
|
|
23
|
+
|
|
24
|
+
- The CLI derives a minimal hardware fingerprint using the `hw-fingerprint` library and a curated list of non-sensitive attributes.
|
|
25
|
+
- Fingerprint data is hashed locally with SHA-256 and a public salt tied to the client ID; raw hardware fields never leave the device.
|
|
26
|
+
- If fingerprint collection fails, the CLI falls back to `fph: "unavailable"` and prompts the user to re-run setup.
|
|
27
|
+
|
|
28
|
+
## Auth & Tunnel Lifecycle
|
|
29
|
+
|
|
30
|
+
- Browser-based registration uses passwordless magic links. Future releases will extend this model to downstream tunnel access through Asyx Quickpass.
|
|
31
|
+
- Tunnel sessions rely on automatically refreshed JWTs delivered over the Asyx messaging queue. The CLI stops attempting reconnects after bounded retries to avoid uncontrolled traffic bursts.
|
|
32
|
+
- Heartbeats are rate-governed server side and cannot be tuned or disabled via CLI flags.
|
|
33
|
+
|
|
34
|
+
## Disclosure Guidelines
|
|
35
|
+
|
|
36
|
+
- Allow the Asyx security team reasonable time to triage before sharing details.
|
|
37
|
+
- Avoid exploiting issues beyond minimally necessary proof-of-concept steps.
|
|
38
|
+
- Coordinate public communication with the Asyx team once a fix is available.
|
|
39
|
+
|
|
40
|
+
Thank you for helping us keep the Asyx platform secure.
|
package/bin/asyx.js
ADDED
package/package.json
CHANGED
|
@@ -1,28 +1,58 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "asyx",
|
|
3
|
-
"version": "0.0
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Asyx Command Line Interface",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
|
-
"
|
|
7
|
-
"
|
|
6
|
+
"type": "module",
|
|
7
|
+
"homepage": "https://github.com/asyxai/tunnel#readme",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/asyxai/tunnel.git"
|
|
11
|
+
},
|
|
12
|
+
"bugs": {
|
|
13
|
+
"url": "https://github.com/asyxai/tunnel/issues"
|
|
14
|
+
},
|
|
8
15
|
"keywords": [
|
|
9
16
|
"asyx",
|
|
10
17
|
"cli",
|
|
11
18
|
"tunnel",
|
|
12
|
-
"
|
|
13
|
-
"
|
|
14
|
-
"developer-preview"
|
|
19
|
+
"mqtt",
|
|
20
|
+
"relay"
|
|
15
21
|
],
|
|
16
|
-
"
|
|
17
|
-
|
|
18
|
-
"repository": {
|
|
19
|
-
"type": "git",
|
|
20
|
-
"url": "git+https://github.com/asyxai/asyx.git"
|
|
22
|
+
"bin": {
|
|
23
|
+
"asyx": "bin/asyx.js"
|
|
21
24
|
},
|
|
22
|
-
"
|
|
23
|
-
"
|
|
25
|
+
"engines": {
|
|
26
|
+
"node": ">=18.17"
|
|
27
|
+
},
|
|
28
|
+
"sideEffects": false,
|
|
29
|
+
"private": false,
|
|
30
|
+
"files": [
|
|
31
|
+
"bin/",
|
|
32
|
+
"src/",
|
|
33
|
+
"LICENSE",
|
|
34
|
+
"README.md",
|
|
35
|
+
"SECURITY.md"
|
|
36
|
+
],
|
|
37
|
+
"dependencies": {
|
|
38
|
+
"@asyx/mqtt-broker-aws": "^0.1.0",
|
|
39
|
+
"@asyx/mqtt-client": "^0.1.0",
|
|
40
|
+
"chalk": "^5.3.0",
|
|
41
|
+
"hw-fingerprint": "^3.2.0",
|
|
42
|
+
"node-fetch": "^3.3.2",
|
|
43
|
+
"open": "^9.1.0",
|
|
44
|
+
"ws": "^8.14.2",
|
|
45
|
+
"zod": "3.23.8"
|
|
46
|
+
},
|
|
47
|
+
"scripts": {
|
|
48
|
+
"postinstall": "node -e \"console.log('✅ asyx installed')\"",
|
|
49
|
+
"check": "node ./src/main.js --version",
|
|
50
|
+
"test": "NODE_OPTIONS=--experimental-vm-modules jest --runInBand",
|
|
51
|
+
"pack:verify": "node scripts/pack-verify.mjs",
|
|
52
|
+
"prepublishOnly": "npm test && npm run pack:verify"
|
|
24
53
|
},
|
|
25
|
-
"
|
|
26
|
-
|
|
27
|
-
|
|
54
|
+
"devDependencies": {
|
|
55
|
+
"@jest/globals": "^30.2.0",
|
|
56
|
+
"jest": "^30.2.0"
|
|
57
|
+
}
|
|
28
58
|
}
|
|
File without changes
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { AwsIotTransport } from "@asyx/mqtt-broker-aws";
|
|
2
|
+
import { controlWildcard } from "@asyx/mqtt-client";
|
|
3
|
+
|
|
4
|
+
export default async function mqttBroker() {
|
|
5
|
+
const subcommand = process.argv[4];
|
|
6
|
+
|
|
7
|
+
if (!subcommand || subcommand === "help") {
|
|
8
|
+
console.log("MQTT Broker Commands:\n asyx mqtt broker:probe Probe AWS IoT Core configuration");
|
|
9
|
+
process.exit(0);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
if (subcommand === "probe") {
|
|
13
|
+
await probe();
|
|
14
|
+
} else {
|
|
15
|
+
console.log(`Unknown broker subcommand: ${subcommand}`);
|
|
16
|
+
process.exit(1);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
async function probe() {
|
|
21
|
+
try {
|
|
22
|
+
console.log("🔍 Probing AWS IoT Core configuration...");
|
|
23
|
+
|
|
24
|
+
// Create transport and load config
|
|
25
|
+
const transport = new AwsIotTransport();
|
|
26
|
+
|
|
27
|
+
// This will load and validate config
|
|
28
|
+
await transport.connect({ clientId: "dummy" }); // Will be overridden by config
|
|
29
|
+
|
|
30
|
+
const config = transport.getConfig();
|
|
31
|
+
if (!config) {
|
|
32
|
+
throw new Error("Failed to load configuration");
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// Display configuration
|
|
36
|
+
console.log("\n📋 Configuration:");
|
|
37
|
+
console.log(` Endpoint: ${config.endpoint}`);
|
|
38
|
+
console.log(` Region: ${config.region}`);
|
|
39
|
+
console.log(` Client ID: ${config.clientId}`);
|
|
40
|
+
|
|
41
|
+
// Display resolved topic
|
|
42
|
+
const topic = controlWildcard(config.clientId);
|
|
43
|
+
console.log(`\n📡 Control Topic:`);
|
|
44
|
+
console.log(` ${topic}`);
|
|
45
|
+
|
|
46
|
+
console.log("\n✅ Configuration valid (dry-run mode)");
|
|
47
|
+
|
|
48
|
+
} catch (error) {
|
|
49
|
+
console.error("❌ Configuration error:", error.message);
|
|
50
|
+
console.log("\n💡 Setup instructions:");
|
|
51
|
+
console.log(" export ASYX_MQTT_ENDPOINT='your-endpoint.iot.region.amazonaws.com'");
|
|
52
|
+
console.log(" export AWS_REGION='us-east-1'");
|
|
53
|
+
console.log(" export ASYX_CLIENT_ID='cli_ABC123DEF456'");
|
|
54
|
+
process.exit(1);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import { constants as fsConstants } from 'node:fs';
|
|
2
|
+
import { access } from 'node:fs/promises';
|
|
3
|
+
import { join } from 'node:path';
|
|
4
|
+
import { AsyxMqttClient, controlWildcard, controlOpen, controlClose, controlStatus } from "@asyx/mqtt-client";
|
|
5
|
+
import { loadOrCreateClientId } from "../lib/device.js";
|
|
6
|
+
import { getSharedTransport } from "../lib/shared-transport.js";
|
|
7
|
+
|
|
8
|
+
const DEVICE_JSON_PATH = join(process.env.HOME ?? '', '.asyx', 'device.json');
|
|
9
|
+
|
|
10
|
+
export default async function mqtt() {
|
|
11
|
+
// Dev-only command gating
|
|
12
|
+
const isDev = process.env.NODE_ENV === 'dev';
|
|
13
|
+
if (!isDev) {
|
|
14
|
+
console.error('This command is reserved for internal dev use. Set NODE_ENV=dev to proceed.');
|
|
15
|
+
process.exit(2);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
// Device credential guard
|
|
19
|
+
await access(DEVICE_JSON_PATH, fsConstants.F_OK).catch(() => {
|
|
20
|
+
console.error('This command is for dev use only. Missing ~/.asyx/device.json');
|
|
21
|
+
process.exit(2);
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
const subcommand = process.argv[3];
|
|
25
|
+
|
|
26
|
+
if (!subcommand || subcommand === "help") {
|
|
27
|
+
console.log("MQTT Commands:\n asyx mqtt listen Listen for control messages\n asyx mqtt inject Inject test messages (dev only)\n asyx mqtt broker AWS IoT Core broker commands");
|
|
28
|
+
process.exit(0);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
if (subcommand === "listen") {
|
|
32
|
+
await listen();
|
|
33
|
+
} else if (subcommand === "inject") {
|
|
34
|
+
await inject();
|
|
35
|
+
} else if (subcommand === "broker") {
|
|
36
|
+
const { default: brokerCommand } = await import("./mqtt-broker.js");
|
|
37
|
+
await brokerCommand();
|
|
38
|
+
} else if (subcommand === "connect") {
|
|
39
|
+
await connect();
|
|
40
|
+
} else {
|
|
41
|
+
console.log(`Unknown mqtt subcommand: ${subcommand}`);
|
|
42
|
+
process.exit(1);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
async function listen() {
|
|
47
|
+
const clientId = loadOrCreateClientId();
|
|
48
|
+
|
|
49
|
+
const topic = controlWildcard(clientId);
|
|
50
|
+
console.log(`listening on control ${clientId}`);
|
|
51
|
+
console.log(`topic: ${topic}`);
|
|
52
|
+
|
|
53
|
+
// Create MQTT client with shared MemoryTransport
|
|
54
|
+
const transport = getSharedTransport();
|
|
55
|
+
const client = new AsyxMqttClient(transport, { clientId });
|
|
56
|
+
|
|
57
|
+
// Connect to the transport
|
|
58
|
+
await client.core.connect({ clientId });
|
|
59
|
+
|
|
60
|
+
// Subscribe to control topic
|
|
61
|
+
await client.subscribeControl();
|
|
62
|
+
|
|
63
|
+
// Listen for messages
|
|
64
|
+
const unsubscribe = client.onMessage((message) => {
|
|
65
|
+
const payload = JSON.parse(new TextDecoder().decode(message.payload));
|
|
66
|
+
console.log(JSON.stringify(payload));
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
// Keep process running until Ctrl-C
|
|
70
|
+
process.on('SIGINT', () => {
|
|
71
|
+
console.log('\nShutting down...');
|
|
72
|
+
unsubscribe();
|
|
73
|
+
process.exit(0);
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
// Keep alive
|
|
77
|
+
await new Promise(() => {});
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
async function inject() {
|
|
81
|
+
// Parse arguments: --kind <kind> --port <port>
|
|
82
|
+
let kind, port;
|
|
83
|
+
for (let i = 4; i < process.argv.length; i++) {
|
|
84
|
+
if (process.argv[i] === '--kind' && i + 1 < process.argv.length) {
|
|
85
|
+
kind = process.argv[i + 1];
|
|
86
|
+
} else if (process.argv[i] === '--port' && i + 1 < process.argv.length) {
|
|
87
|
+
port = process.argv[i + 1];
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
if (!kind || !port) {
|
|
92
|
+
console.log("Usage: NODE_ENV=dev asyx mqtt inject --kind open|close|status --port <port>");
|
|
93
|
+
process.exit(1);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
if (kind !== 'open' && kind !== 'close' && kind !== 'status') {
|
|
97
|
+
console.error('kind must be "open", "close", or "status"');
|
|
98
|
+
process.exit(1);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
const clientId = loadOrCreateClientId();
|
|
102
|
+
|
|
103
|
+
// Create MQTT client with shared MemoryTransport
|
|
104
|
+
const transport = getSharedTransport();
|
|
105
|
+
const client = new AsyxMqttClient(transport, { clientId });
|
|
106
|
+
|
|
107
|
+
// Connect to the transport
|
|
108
|
+
await client.core.connect({ clientId });
|
|
109
|
+
|
|
110
|
+
// Publish synthetic control message
|
|
111
|
+
const command = {
|
|
112
|
+
type: `cmd/${kind}`,
|
|
113
|
+
port: parseInt(port, 10)
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
// Use the correct topic format that matches the client subscription
|
|
117
|
+
let controlTopic;
|
|
118
|
+
if (kind === 'open') {
|
|
119
|
+
controlTopic = controlOpen(clientId);
|
|
120
|
+
} else if (kind === 'close') {
|
|
121
|
+
controlTopic = controlClose(clientId);
|
|
122
|
+
} else if (kind === 'status') {
|
|
123
|
+
controlTopic = controlStatus(clientId);
|
|
124
|
+
}
|
|
125
|
+
await transport.publish({ topic: controlTopic, payload: JSON.stringify(command), qos: 0, retain: false });
|
|
126
|
+
|
|
127
|
+
console.log(`Injected: ${JSON.stringify(command)}`);
|
|
128
|
+
process.exit(0);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
async function connect() {
|
|
132
|
+
const { AwsIotTransport } = await import("@asyx/mqtt-broker-aws");
|
|
133
|
+
const { AsyxMqttClient, topics } = await import("@asyx/mqtt-client");
|
|
134
|
+
const t = new AwsIotTransport();
|
|
135
|
+
await t.connect();
|
|
136
|
+
|
|
137
|
+
// Use ESM imports instead of require()
|
|
138
|
+
const { readFile } = await import('node:fs/promises');
|
|
139
|
+
const { join: pathJoin } = await import('node:path');
|
|
140
|
+
|
|
141
|
+
const home = process.env.HOME || process.env.USERPROFILE || ".";
|
|
142
|
+
const devJson = await readFile(pathJoin(home, ".asyx", "device.json"), "utf8");
|
|
143
|
+
const dev = JSON.parse(devJson);
|
|
144
|
+
const clientId = dev.clientId;
|
|
145
|
+
const cli = new AsyxMqttClient(t, { clientId });
|
|
146
|
+
|
|
147
|
+
const wildcard = topics.controlWildcard(clientId);
|
|
148
|
+
await cli.subscribeControlWildcard();
|
|
149
|
+
console.log("✅ connected. subscribed:", wildcard);
|
|
150
|
+
|
|
151
|
+
// publish one request
|
|
152
|
+
const reqTopic = topics.controlCmdRequest(clientId); // new helper you must add (below)
|
|
153
|
+
await cli.publishRaw(reqTopic, JSON.stringify({ type:"cmd/request", port: 8000, when: Date.now() }));
|
|
154
|
+
console.log("📤 published request:", reqTopic);
|
|
155
|
+
|
|
156
|
+
// print first incoming message then exit
|
|
157
|
+
const timer = setTimeout(() => { console.log("⌛ no response in 10s, exiting"); process.exit(0); }, 10000);
|
|
158
|
+
cli.onMessage((m) => {
|
|
159
|
+
console.log("📨 inbound:", m.topic, m.payload);
|
|
160
|
+
clearTimeout(timer);
|
|
161
|
+
process.exit(0);
|
|
162
|
+
});
|
|
163
|
+
return;
|
|
164
|
+
}
|