|
| 1 | +# Project: sshclient-wasm |
| 2 | + |
| 3 | +This is a Golang project that builds a WASM client for ssh on the browser. |
| 4 | + |
| 5 | +It uses Golang's [golang.org/x/crypto/ssh package](https://pkg.go.dev/golang.org/x/crypto/ssh) which already implements the SSH client protocol. It also works with servers but this project is focused on building a client that can be used in the browser with WebSockets. |
| 6 | + |
| 7 | +The compiler target is WebAssembly. The build is done with GoReleaser. |
| 8 | + |
| 9 | +It should ultimately be an NPM package that can be imported as an ES module for use in frontend projects like Next.js. |
| 10 | + |
| 11 | +## Architecture |
| 12 | + |
| 13 | +The architecture is transport-agnostic, supporting multiple transport protocols including raw WebSockets and AWS IoT Secure Tunneling. The Transport Translation Layer provides a unified interface for different transport implementations. |
| 14 | + |
| 15 | +```mermaid |
| 16 | +graph TB |
| 17 | + subgraph "Browser Environment" |
| 18 | + A["ES Module<br/>(TypeScript)"] |
| 19 | + B["Transport Translation Layer"] |
| 20 | + C["WASM Layer<br/>(Go SSH Client)"] |
| 21 | +
|
| 22 | + A --> B |
| 23 | + B <--> C |
| 24 | + end |
| 25 | +
|
| 26 | + subgraph "Transport Implementations" |
| 27 | + D["WebSocket Transport"] |
| 28 | + E["AWS IoT Secure Tunnel<br/>Transport"] |
| 29 | + F["Custom Transport<br/>(User-defined)"] |
| 30 | +
|
| 31 | + B --> D |
| 32 | + B --> E |
| 33 | + B --> F |
| 34 | + end |
| 35 | +
|
| 36 | + subgraph "Network Layer" |
| 37 | + G["Direct WebSocket<br/>Connection"] |
| 38 | + H["AWS IoT<br/>Secure Tunneling"] |
| 39 | + I["Custom Protocol<br/>Endpoint"] |
| 40 | +
|
| 41 | + D <--> G |
| 42 | + E <--> H |
| 43 | + F <--> I |
| 44 | + end |
| 45 | +
|
| 46 | + subgraph "Destination" |
| 47 | + J["SSH Server"] |
| 48 | +
|
| 49 | + G --> J |
| 50 | + H --> J |
| 51 | + I --> J |
| 52 | + end |
| 53 | +
|
| 54 | + style A fill:#0277bd,color:#fff |
| 55 | + style B fill:#7b1fa2,color:#fff |
| 56 | + style C fill:#ef6c00,color:#fff |
| 57 | + style D fill:#388e3c,color:#fff |
| 58 | + style E fill:#388e3c,color:#fff |
| 59 | + style F fill:#388e3c,color:#fff |
| 60 | + style G fill:#d32f2f,color:#fff |
| 61 | + style H fill:#d32f2f,color:#fff |
| 62 | + style I fill:#d32f2f,color:#fff |
| 63 | + style J fill:#424242,color:#fff |
| 64 | +``` |
| 65 | + |
| 66 | +### Key Components |
| 67 | + |
| 68 | +1. **ES Module (TypeScript)**: The public API that applications import and use |
| 69 | +2. **Transport Translation Layer**: Bridges JavaScript transports with WASM, handling bidirectional data flow |
| 70 | +3. **WASM Layer**: Go implementation of SSH client protocol using `golang.org/x/crypto/ssh` |
| 71 | +4. **Transport Implementations**: |
| 72 | + - **WebSocket Transport**: Direct WebSocket connections to SSH servers |
| 73 | + - **AWS IoT Secure Tunnel Transport**: Implements AWS IoT protocol with frame encoding/decoding |
| 74 | + - **Custom Transport**: User-definable transport for proprietary protocols |
| 75 | +5. **Network Layer**: The actual network connection (WebSocket, AWS IoT, etc.) |
| 76 | +6. **SSH Server**: The destination SSH server |
| 77 | + |
| 78 | +## Tech Stack |
| 79 | + |
| 80 | +- Languages: Golang, TypeScript |
| 81 | +- Frameworks: Next.js, React |
| 82 | +- Build Tools: GoReleaser, Vite, Pnpm via Corepack |
| 83 | +- Tools: WebSocket |
| 84 | +- Testing: Vitest, GoTest |
| 85 | +- Platforms: Browser |
| 86 | + |
| 87 | +## Project Structure |
| 88 | + |
| 89 | +- `main.go`: The entry point for the Go compiler. |
| 90 | +- `pkg/sshclient/`: The SSH client implementation. |
| 91 | +- `lib/`: The TypeScript/JavaScript bindings. |
| 92 | +- `examples/`: Example applications. |
| 93 | +- `dist/`: The build output. |
| 94 | +- `node_modules/`: The Node.js dependencies. |
| 95 | +- `pnpm-lock.yaml`: The Pnpm lock file. |
| 96 | +- `package.json`: The NPM package configuration. |
| 97 | +- `README.md`: The project README. |
| 98 | +- `LICENSE`: The project license. |
| 99 | + |
| 100 | +## Development |
| 101 | + |
| 102 | +### Prerequisites |
| 103 | + |
| 104 | +- Go 1.23+ |
| 105 | +- Node.js 22+ |
| 106 | +- Pnpm 10+ |
0 commit comments