File tree 3 files changed +66
-5
lines changed
3 files changed +66
-5
lines changed Original file line number Diff line number Diff line change 454
454
Wrapper for instance of [ net.Socket] [ ] , replaces internal socket read/write
455
455
routines to perform transparent encryption/decryption of incoming/outgoing data.
456
456
457
- ## new tls.TLSSocket(socket, options)
457
+ ## new tls.TLSSocket(socket[ , options] )
458
458
459
459
Construct a new TLSSocket object from existing TCP socket.
460
460
461
461
` socket ` is an instance of [ net.Socket] [ ]
462
462
463
- ` options ` is an object that might contain following properties:
463
+ ` options ` is an optional object that might contain following properties:
464
464
465
465
- ` secureContext ` : An optional TLS context object from
466
466
` tls.createSecureContext( ... ) `
467
467
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 `
469
470
470
471
- ` server ` : An optional [ net.Server] [ ] instance
471
472
Original file line number Diff line number Diff line change @@ -228,7 +228,10 @@ function initRead(tls, wrapped) {
228
228
*/
229
229
230
230
function TLSSocket ( socket , options ) {
231
- this . _tlsOptions = options ;
231
+ if ( options === undefined )
232
+ this . _tlsOptions = { } ;
233
+ else
234
+ this . _tlsOptions = options ;
232
235
this . _secureEstablished = false ;
233
236
this . _securePending = false ;
234
237
this . _newSessionPending = false ;
@@ -321,7 +324,7 @@ TLSSocket.prototype._wrapHandle = function(wrap) {
321
324
tls . createSecureContext ( ) ;
322
325
res = tls_wrap . wrap ( handle . _externalStream ,
323
326
context . context ,
324
- options . isServer ) ;
327
+ ! ! options . isServer ) ;
325
328
res . _parent = handle ;
326
329
res . _parentWrap = wrap ;
327
330
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 ( ) ;
57
+
You can’t perform that action at this time.
0 commit comments