README.md (13921B)
1# guacamole-lite 2 3## Introduction 4 5### What is `guacamole-lite`? 6 7`guacamole-lite` is a lightweight Node.js library designed to create servers compatible with the Guacamole protocol. 8 9### What is Guacamole? 10 11Apache Guacamole is a HTML5 web client for remote desktop environments using protocols such as VNC or RDP, SSH or 12Telnet. 13 14### Why use `guacamole-lite`? 15 16Unlike the Java-based original `guacamole-client`, which is a full-featured client with its own user and host management 17system, `guacamole-lite` is tailored for integration into existing applications. It is particularly suitable for systems 18that already have user, host, and credential management in place, offering a more streamlined approach to adopting the 19Guacamole protocol. 20 21The main differences between `guacamole-lite` and the Java-based `guacamole-client` are: 22 23- **Integration-Friendly**: `guacamole-lite` is built to be easily integrated into existing applications, allowing 24 developers to leverage their own systems for managing users, hosts, and credentials. In contrast, `guacamole-client` 25 comes with a comprehensive suite of features, including its own database for user and host management, which can make 26 integration into existing systems more challenging. 27 28- **Node.js Based**: The library is written in Node.js, which provides a more accessible and flexible development 29 experience compared to the Java-based `guacamole-client`. This makes `guacamole-lite` easier to extend, modify, and 30 integrate into modern web applications. 31 32- **Resource Efficiency**: `guacamole-lite` is less resource-intensive, making it a more efficient choice for 33 environments where resource optimization is crucial. 34 35By focusing on these key areas, `guacamole-lite` offers a compelling option for developers looking to implement remote 36desktop capabilities within their Node.js applications. 37 38## Architecture Overview 39 40`guacamole-lite` is designed to seamlessly fit into the 41broader [Guacamole ecosystem](https://guacamole.apache.org/doc/gug/guacamole-architecture.html), providing an efficient 42way to develop Guacamole-compatible servers in Node.js. The following diagram illustrates the typical architecture of a 43Guacamole deployment and how `guacamole-lite` integrates within it: 44 45![arch](docs/architecture.png) 46 47The diagram shows the following components: 48 491. **HTML5 Browser (guacamole-common-js)**: This is the user's interface, a HTML5 application that runs in the browser. 50 The user interacts with this layer to get access to remote desktop sessions. The application uses 51 [guacamole-common-js](https://guacamole.apache.org/doc/gug/guacamole-common-js.html), a library 52 that provides the Guacamole protocol implementation in JavaScript. 53 542. **Guacamole protocol**: This communication protocol is used by `guacamole-common-js` to interact with `guacd` 55 via `guacamole-lite`, acting as a proxy. Check out 56 the [Guacamole protocol](https://guacamole.apache.org/doc/gug/guacamole-protocol.html) documentation for more 57 details. 58 593. **Node.js application**: A Node.js application that integrates `guacamole-lite` package. It provides the 60 configuration to `guacamole-lite` and handles business logic, such as session management. 61 624. **guacamole-lite** package: As the Node.js application component, `guacamole-lite` implements handshaking of the 63 Guacamole protocol and further forwarding of Guacamole protocol instructions between `guacamole-common-js` (over 64 WebSockets) and `guacd` (over TCP or Unix socket). 65 665. **guacd**: A core component of the Guacamole infrastructure, `guacd` translates the Guacamole protocol 67 instructions into native remote desktop protocol commands. See 68 the [Guacamole architecture](https://guacamole.apache.org/doc/gug/guacamole-architecture.html) 69 documentation for more details. 70 716. **Guacamole Server**: A server that hosts `Node.js application` with `guacamole-lite` package 72 and `guacd`. These components are typically deployed together, but they can also be separated into different 73 machines. 74 757. **Remote Desktop Protocols**: The bottommost layer includes the various protocols handled by `guacd`: 76 - **RDP (Remote Desktop Protocol)**: Primarily used for connecting to Windows machines. 77 - **VNC (Virtual Network Computing)**: Connects to various operating systems, including Windows, Mac, and Linux. 78 - **SSH (Secure Shell)**: Used for secure command-line access to Linux and Unix-like systems. 79 80**Overall Data Flow**: 81 82- A user initiates a remote desktop session from their browser. 83- The browser communicates with `guacamole-lite` via WebSockets. 84- `guacamole-lite` forwards the instructions to `guacd` using the Guacamole protocol. 85- `guacd` interacts with the remote desktop system using the appropriate protocol (RDP, VNC, or SSH). 86- The remote system responds back through the chain: from `guacd` to `guacamole-lite`, through WebSockets, and finally 87 to the user's browser, allowing the user to see and control the remote desktop. 88 89The entire process is encapsulated within the "Guacamole server" setup, indicating that both `guacamole-lite` 90and `guacd` are integral parts of the server infrastructure. This architecture allows `guacamole-lite` to provide a 91lightweight and flexible solution for integrating remote desktop capabilities into Node.js applications. 92 93## Installation 94 95To install `guacamole-lite` in your Node.js project, run the following command: 96 97```sh 98npm install guacamole-lite --save 99``` 100 101This will add `guacamole-lite` as a dependency to your `package.json` file and download it to the `node_modules` 102directory. 103 104## Quick Start Guide 105 106To get started with `guacamole-lite` and create a Guacamole-compatible server, follow the basic example below. For 107advanced configuration options, please refer to the relevant sections of 108the [advanced configuration documentation](docs/advanced-configuration.md). 109 110### Basic Server Setup 111 112Here's a minimal example to set up a `guacamole-lite` server: 113 114```javascript 115const GuacamoleLite = require('guacamole-lite'); 116 117const websocketOptions = { 118 port: 8080 // WebSocket server port 119}; 120 121const guacdOptions = { 122 port: 4822 // guacd server port 123}; 124 125const clientOptions = { 126 crypt: { 127 cypher: 'AES-256-CBC', 128 key: 'MySuperSecretKeyForParamsToken12' // Use a secure key 129 } 130}; 131 132const guacServer = new GuacamoleLite(websocketOptions, guacdOptions, clientOptions); 133``` 134 135This code will start a WebSocket server that interfaces with the Guacamole daemon (`guacd`) and handles client 136connections securely. 137 138### Connecting to the Server 139 140To connect to the server, your application needs to create a WebSocket connection and pass the connection parameters to 141the server. The connection parameters are passed in an encrypted token in the query string of the WebSocket URL. 142 143``` 144ws://your-guacamole-server:8080/?token=token 145``` 146 147The encrypted token is a JSON object that is **base64-encoded and encrypted**. It contains the necessary parameters for 148establishing a remote desktop like in the example below: 149 150```js 151const crypto = require('crypto'); 152 153const CIPHER = 'aes-256-cbc'; 154const SECRET_KEY = 'MySuperSecretKeyForParamsToken12'; 155 156const tokenObject = { 157 connection: { 158 type: "rdp", 159 settings: { 160 "hostname": "10.0.0.12", 161 "username": "Administrator", 162 "password": "pAsSwOrD", 163 "enable-drive": true, 164 "create-drive-path": true, 165 "security": "any", 166 "ignore-cert": true, 167 "enable-wallpaper": false 168 } 169 } 170}; 171 172function encryptToken(value) { 173 const iv = crypto.randomBytes(16); 174 const cipher = crypto.createCipheriv(CIPHER, Buffer.from(SECRET_KEY), iv); 175 176 let encrypted = cipher.update(JSON.stringify(value), 'utf8', 'base64'); 177 encrypted += cipher.final('base64'); 178 179 const data = { 180 iv: iv.toString('base64'), 181 value: encrypted 182 }; 183 184 const json = JSON.stringify(data); 185 return Buffer.from(json).toString('base64'); 186} 187 188const token = encryptToken(tokenObject); 189 190console.log("Websockets URL:"); 191console.log(`ws://localhost:8080/?token=${encodeURIComponent(token)}`); 192``` 193 194The token is encrypted for security reasons because it contains sensitive information, such as login credentials to the 195remote host and to prevent tampering with the parameters which could lead to using the server as a proxy for malicious 196purposes (see [Security Considerations](#security-considerations)). For details on how to structure the parameters and 197implement encryption, refer to the [Client Options](docs/advanced-configuration.md#client-options) section in the 198advanced configuration documentation. 199 200For practical examples of how to encrypt the token in different programming languages, check out to the 201[examples](examples) directory: 202 203- [Node.js Example](examples/encrypt_token.js) 204- [PHP Example](examples/encrypt_token.php) 205- [Python Example](examples/encrypt_token.py) 206 207## Security Considerations 208 209Unlike the full `guacamole-client`, `guacamole-lite` does not maintain its own database for managing users, remote 210hosts, and credentials. Instead, it relies on the integrating application to supply these parameters. Since the 211transmission of these parameters occurs through potentially insecure channels, such as the client's browser, it is 212crucial to ensure their security and integrity. To address these concerns, `guacamole-lite` employs encrypted tokens to 213pass connection details. 214 215An encrypted token is a secure method of transmitting information where the data is first converted into a ciphertext 216using an encryption algorithm and a secret key. This process ensures two critical aspects: 217 218- **Authentication**: The encrypted token verifies that the connection parameters were indeed generated by the 219 application and have not been forged or tampered with by any third party. 220 221- **Confidentiality**: Sensitive information, such as login credentials to the remote host, remains concealed from the 222 client. Only `guacamole-lite` and the application that generated the token can decrypt and access the contained 223 information. 224 225For more detailed security guidelines and best practices, please refer to 226the [Security Considerations](docs/advanced-configuration.md#encryption-and-security) section in the advanced 227configuration documentation. 228 229## Advanced Configuration 230 231Most likely you will need to customize `guacamole-lite` beyond the basic setup. The advanced configuration options allow 232for fine-tuning of the WebSocket server, `guacd` communication, default connection settings, and more. Below is an 233outline of the advanced configuration topics covered in the documentation: 234 235- [WebSocket Options](docs/advanced-configuration.md#websocket-options) 236 - [Configuration](docs/advanced-configuration.md#configuration) 237- [Guacd Options](docs/advanced-configuration.md#guacd-options) 238 - [Configuration](docs/advanced-configuration.md#configuration-1) 239- [Client Options](docs/advanced-configuration.md#client-options) 240 - [Encryption and Security](docs/advanced-configuration.md#encryption-and-security) 241 - [Connection Settings](docs/advanced-configuration.md#connection-settings) 242 - [Allowed Unencrypted Connection Settings in Query](docs/advanced-configuration.md#allowed-unencrypted-connection-settings-in-query) 243 - [Connection Types](docs/advanced-configuration.md#connection-types) 244 - [Logging](docs/advanced-configuration.md#logging) 245- [Callbacks](docs/advanced-configuration.md#callbacks) 246 - [`processConnectionSettings` Callback](docs/advanced-configuration.md#processconnectionsettings-callback) 247- [Events](docs/advanced-configuration.md#events) 248 - [`open` Event](docs/advanced-configuration.md#open-event) 249 - [`close` Event](docs/advanced-configuration.md#close-event) 250 - [`error` Event](docs/advanced-configuration.md#error-event) 251- [Integration with Node.js Frameworks](docs/advanced-configuration.md#integration-with-nodejs-frameworks) 252 - [Considerations for Integration](docs/advanced-configuration.md#considerations-for-integration) 253 - [Example of Integrating with Express.js](docs/advanced-configuration.md#example-of-integrating-with-expressjs) 254- [Additional Examples and Resources](docs/advanced-configuration.md#additional-examples-and-resources) 255 - [Contents of the Examples Directory](docs/advanced-configuration.md#contents-of-the-examples-directory) 256 257Each section provides detailed information and examples to help you tailor `guacamole-lite` to your specific needs. 258Whether you're integrating with existing Node.js frameworks, handling complex logging requirements, or setting up custom 259callbacks and events, the advanced configuration guide has you covered. 260 261## Testing 262 263`guacamole-lite` comes with a test suite to ensure the stability and reliability of the library. To run the tests: 264 265``` 266npm test 267``` 268 269## Contributing 270 271Contributions to `guacamole-lite` are welcome! If you're interested in contributing, you can: 272 273- Report issues or suggest features 274 by [submitting an issue on GitHub](https://github.com/vadimpronin/guacamole-lite/issues). 275- Contribute code by forking the repository, making your changes, and creating a pull request. 276 277## Acknowledgements 278 279Special thanks to the Guacamole team for creating the original Guacamole project and making it available under the 280Apache-2.0 license. 281I want to acknowledge all individual contributors to the project, who have invested their time and effort into 282improving `guacamole-lite`. 283 284## License 285 286`guacamole-lite` is made available under the Apache License, Version 2.0 (Apache-2.0), the same license as the original 287Apache Guacamole project. This license is a permissive open-source license that allows for broad freedom in usage and 288distribution. 289 290For more details about the Apache-2.0 license and your rights under it, please see 291the [LICENSE](https://github.com/vadimpronin/guacamole-lite/blob/master/LICENSE) file included in the repository.