Skip to content

Commit 69a6f78

Browse files
authored
Merge pull request #782 from watson-developer-cloud/disable-ssl-for-websocket
Disable ssl for websocket
2 parents 724e684 + b96e3e6 commit 69a6f78

File tree

5 files changed

+23
-12
lines changed

5 files changed

+23
-12
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,14 +226,14 @@ var myInstance = new watson.WhateverServiceV1({
226226

227227
The HTTP client can be configured to disable SSL verification. Note that this has serious security implications - only do this if you really mean to! ⚠️
228228

229-
To do this, set `disable_ssl` to `true` in the service constructor, like below:
229+
To do this, set `disable_ssl_verification` to `true` in the service constructor, like below:
230230

231231
```
232232
const discovery = new DiscoveryV1({
233233
url: '<service_url>',
234234
version: '<version-date>',
235235
iam_apikey: '<iam_api_key>',
236-
disable_ssl: true, // this will disable SSL verification for any request made with this object
236+
disable_ssl_verification: true, // this will disable SSL verification for any request made with this object
237237
});
238238
```
239239

lib/base_service.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export interface UserOptions {
4343
iam_access_token?: string;
4444
iam_apikey?: string;
4545
iam_url?: string;
46-
disable_ssl?: boolean;
46+
disable_ssl_verification?: boolean;
4747
}
4848

4949
export interface BaseServiceOptions extends UserOptions {
@@ -151,9 +151,9 @@ export class BaseService {
151151
} else {
152152
this.tokenManager = null;
153153
}
154-
// rejectUnauthorized should only be false if disable_ssl is true
154+
// rejectUnauthorized should only be false if disable_ssl_verification is true
155155
// used to disable ssl checking for icp
156-
this._options.rejectUnauthorized = !options.disable_ssl;
156+
this._options.rejectUnauthorized = !options.disable_ssl_verification;
157157
}
158158

159159
/**

lib/recognize-stream.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ class RecognizeStream extends Duplex {
117117
* @param {string} [options.base_model_version] - The version of the specified base model that is to be used with recognition request or, for the **Create a session** method, with the new session.
118118
* Multiple versions of a base model can exist when a model is updated for internal improvements. The parameter is intended primarily for use with custom models that have been upgraded for a new base model.
119119
* The default value depends on whether the parameter is used with or without a custom model. For more information, see [Base model version](https://console.bluemix.net/docs/services/speech-to-text/input.html#version).
120+
* @param {Boolean} [options.rejectUnauthorized] - If true, disable SSL verification for the WebSocket connection
120121
*
121122
* @constructor
122123
*/
@@ -133,8 +134,10 @@ class RecognizeStream extends Duplex {
133134
this.listening = false;
134135
this.initialized = false;
135136
this.finished = false;
137+
136138
// is using iam, another authentication step is needed
137139
this.authenticated = options.token_manager ? false : true;
140+
138141
this.on('newListener', event => {
139142
if (!options.silent) {
140143
if (
@@ -217,14 +220,19 @@ class RecognizeStream extends Duplex {
217220

218221
const self = this;
219222

220-
// node params: requestUrl, protocols, origin, headers, extraRequestOptions
223+
// node params: requestUrl, protocols, origin, headers, extraRequestOptions, clientConfig options
221224
// browser params: requestUrl, protocols (all others ignored)
225+
226+
// for the last argument, `tlsOptions` gets passed to Node's `http` library,
227+
// which allows us to pass a rejectUnauthorized option
228+
// for disabling SSL verification (for ICP)
222229
const socket = (this.socket = new w3cWebSocket(
223230
url,
224231
null,
225232
null,
226233
options.headers,
227-
null
234+
null,
235+
{ tlsOptions: { rejectUnauthorized: options.rejectUnauthorized }}
228236
));
229237

230238
// when the input stops, let the service know that we're done

speech-to-text/v1.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,9 @@ class SpeechToTextV1 extends GeneratedSpeechToTextV1 {
477477
params.headers
478478
);
479479

480+
// allow user to disable ssl verification when using websockets
481+
params.rejectUnauthorized = this._options.rejectUnauthorized;
482+
480483
return new RecognizeStream(params);
481484
}
482485

test/unit/test.base_service.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -265,25 +265,25 @@ describe('BaseService', function() {
265265
assert(authHeader.startsWith('Basic'));
266266
});
267267

268-
it('should set rejectUnauthorized to `false` if `disable_ssl` is `true`', function() {
268+
it('should set rejectUnauthorized to `false` if `disable_ssl_verification` is `true`', function() {
269269
const instance = new TestService({
270270
username: 'apikey',
271271
password: 'icp-1234',
272-
disable_ssl: true,
272+
disable_ssl_verification: true,
273273
});
274274
assert.equal(instance._options.rejectUnauthorized, false);
275275
});
276276

277-
it('should set rejectUnauthorized to `true` if `disable_ssl` is `false`', function() {
277+
it('should set rejectUnauthorized to `true` if `disable_ssl_verification` is `false`', function() {
278278
const instance = new TestService({
279279
username: 'apikey',
280280
password: 'icp-1234',
281-
disable_ssl: false,
281+
disable_ssl_verification: false,
282282
});
283283
assert(instance._options.rejectUnauthorized);
284284
});
285285

286-
it('should set rejectUnauthorized to `true` if `disable_ssl` is not set', function() {
286+
it('should set rejectUnauthorized to `true` if `disable_ssl_verification` is not set', function() {
287287
const instance = new TestService({
288288
username: 'apikey',
289289
password: 'icp-1234',

0 commit comments

Comments
 (0)