Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit c64af7d

Browse filesBrowse files
jhamhaderrvagg
authored andcommitted
tls: TLSSocket options default isServer false
Upon creating a TLSSocket object, set the default isServer option to false Updated tls docs and added test-tls-socket-default-options PR-URL: #2614 Reviewed-By: Fedor Indutny <fedor@indutny.com>
1 parent d0b8c5d commit c64af7d
Copy full SHA for c64af7d

File tree

Expand file treeCollapse file tree

3 files changed

+65
-5
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

3 files changed

+65
-5
lines changed
Open diff view settings
Collapse file

‎doc/api/tls.markdown‎

Copy file name to clipboardExpand all lines: doc/api/tls.markdown
+4-3Lines changed: 4 additions & 3 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -454,18 +454,19 @@ Or
454454
Wrapper for instance of [net.Socket][], replaces internal socket read/write
455455
routines to perform transparent encryption/decryption of incoming/outgoing data.
456456

457-
## new tls.TLSSocket(socket, options)
457+
## new tls.TLSSocket(socket[, options])
458458

459459
Construct a new TLSSocket object from existing TCP socket.
460460

461461
`socket` is an instance of [net.Socket][]
462462

463-
`options` is an object that might contain following properties:
463+
`options` is an optional object that might contain following properties:
464464

465465
- `secureContext`: An optional TLS context object from
466466
`tls.createSecureContext( ... )`
467467

468-
- `isServer`: If true - TLS socket will be instantiated in server-mode
468+
- `isServer`: If `true` - TLS socket will be instantiated in server-mode.
469+
Default: `false`
469470

470471
- `server`: An optional [net.Server][] instance
471472

Collapse file

‎lib/_tls_wrap.js‎

Copy file name to clipboardExpand all lines: lib/_tls_wrap.js
+5-2Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,10 @@ function initRead(tls, wrapped) {
228228
*/
229229

230230
function TLSSocket(socket, options) {
231-
this._tlsOptions = options;
231+
if (options === undefined)
232+
this._tlsOptions = {};
233+
else
234+
this._tlsOptions = options;
232235
this._secureEstablished = false;
233236
this._securePending = false;
234237
this._newSessionPending = false;
@@ -321,7 +324,7 @@ TLSSocket.prototype._wrapHandle = function(wrap) {
321324
tls.createSecureContext();
322325
res = tls_wrap.wrap(handle._externalStream,
323326
context.context,
324-
options.isServer);
327+
!!options.isServer);
325328
res._parent = handle;
326329
res._parentWrap = wrap;
327330
res._secureContext = context;
Collapse file
+56Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
'use strict';
2+
const common = require('../common');
3+
const assert = require('assert');
4+
5+
if (!common.hasCrypto) {
6+
console.log('1..0 # Skipped: missing crypto');
7+
return;
8+
}
9+
const tls = require('tls');
10+
11+
const fs = require('fs');
12+
const net = require('net');
13+
14+
const sent = 'hello world';
15+
16+
const serverOptions = {
17+
isServer: true,
18+
key: fs.readFileSync(common.fixturesDir + '/keys/agent1-key.pem'),
19+
cert: fs.readFileSync(common.fixturesDir + '/keys/agent1-cert.pem')
20+
};
21+
22+
function testSocketOptions(socket, socketOptions) {
23+
let received = '';
24+
const server = tls.createServer(serverOptions, function(s) {
25+
s.on('data', function(chunk) {
26+
received += chunk;
27+
});
28+
29+
s.on('end', function() {
30+
server.close();
31+
s.destroy();
32+
assert.equal(received, sent);
33+
setImmediate(runTests);
34+
});
35+
}).listen(common.PORT, function() {
36+
let c = new tls.TLSSocket(socket, socketOptions);
37+
c.connect(common.PORT, function() {
38+
c.end(sent);
39+
});
40+
});
41+
42+
}
43+
44+
const testArgs = [
45+
[],
46+
[undefined, {}]
47+
];
48+
49+
let n = 0;
50+
function runTests() {
51+
if (n++ < testArgs.length) {
52+
testSocketOptions.apply(null, testArgs[n]);
53+
}
54+
}
55+
56+
runTests();

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.