Skip to content

Commit 6aacb16

Browse files
johannwagneroberstet
authored andcommitted
Introduced TLS Support (crossbario#361)
* Introduced TLS Support * Fixed Documentation.
1 parent ca494f1 commit 6aacb16

File tree

3 files changed

+21
-3
lines changed

3 files changed

+21
-3
lines changed

doc/reference.md

+8-1
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,7 @@ Options that define **Custom error handlers:**
216216
- when a protocol violation is occured,
217217
- when no `onchallenge` defined, but a challenge request is received due to authenticate the client,
218218

219+
219220
```javascript
220221
var connection = new autobahn.Connection({
221222
on_user_error: function (error, customErrorMessage) {
@@ -240,7 +241,13 @@ Options that define **Custom error handlers:**
240241
> In a case of error handling in the Callee role, when the invocation handler is executed, the error
241242
> is reported on the Callee side (with the custom error handler or an error log), but despite that the
242243
> error is sent back to the Dealer, and the Caller will receive a `runtime.error` wamp message.
243-
244+
245+
246+
Options that control **tls connection**:
247+
- `tlsConfiguration`: *object*
248+
- `ca`: *Buffer | String* - CA
249+
- `cert`: *Buffer | String* - Certificate Public Key
250+
- `key`: *Buffer | String* - Certificate Private Key
244251

245252
Connection Properties
246253
---------------------

lib/connection.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@ var Connection = function (options) {
7373
self._options.transports = [
7474
{
7575
type: 'websocket',
76-
url: self._options.url
76+
url: self._options.url,
77+
tlsConfiguration: self._options.tlsConfiguration
7778
}
7879
];
7980
}

lib/transport/websocket.js

+11-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,17 @@ Factory.prototype.create = function () {
9797
protocols = protocols.join(',');
9898
}
9999
options.protocol = protocols;
100-
}
100+
}
101+
102+
if (self._options.url.startsWith('wss://')) {
103+
// Using TLS
104+
// Only using the known working flags in the options.
105+
// https://nodejs.org/api/https.html#https_https_request_options_callback
106+
options.ca = self._options.tlsConfiguration.ca;
107+
options.cert = self._options.tlsConfiguration.cert;
108+
options.key = self._options.tlsConfiguration.key;
109+
options.rejectUnauthorized = false;
110+
}
101111

102112
websocket = new WebSocket(self._options.url, protocols, options);
103113

0 commit comments

Comments
 (0)