File tree Expand file tree Collapse file tree 3 files changed +65
-5
lines changed
Expand file tree Collapse file tree 3 files changed +65
-5
lines changed Original file line number Diff line number Diff line change 449449Wrapper for instance of [net.Socket][], replaces internal socket read/write
450450routines to perform transparent encryption/decryption of incoming/outgoing data.
451451
452- ## new tls.TLSSocket(socket, options)
452+ ## new tls.TLSSocket(socket[ , options] )
453453
454454Construct a new TLSSocket object from existing TCP socket.
455455
456456`socket` is an instance of [net.Socket][]
457457
458- `options` is an object that might contain following properties:
458+ `options` is an optional object that might contain following properties:
459459
460460 - `secureContext`: An optional TLS context object from
461461 `tls.createSecureContext( ... )`
462462
463- - `isServer`: If true - TLS socket will be instantiated in server-mode
463+ - `isServer`: If `true` - TLS socket will be instantiated in server-mode.
464+ Default: `false`
464465
465466 - `server`: An optional [net.Server][] instance
466467
Original file line number Diff line number Diff line change @@ -228,7 +228,10 @@ function initRead(tls, wrapped) {
228228 */
229229
230230function 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;
Original file line number Diff line number Diff line change 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();
You can’t perform that action at this time.
0 commit comments