@@ -48,7 +48,6 @@ var ENOENT = constants.ENOENT;
48
48
var EMFILE = constants . EMFILE ;
49
49
50
50
var END_OF_FILE = 42 ;
51
- var SecureContext , SecureStream ; // lazy loaded
52
51
53
52
54
53
var ioWatchers = new FreeList ( "iowatcher" , 100 , function ( ) {
@@ -78,11 +77,6 @@ function allocNewPool () {
78
77
pool . used = 0 ;
79
78
}
80
79
81
- var securePool = null ;
82
- function allocNewSecurePool ( ) {
83
- securePool = new Buffer ( 40 * 1024 ) ;
84
- }
85
-
86
80
var emptyBuffer = null ;
87
81
function allocEmptyBuffer ( ) {
88
82
emptyBuffer = new Buffer ( 1 ) ;
@@ -108,7 +102,7 @@ function setImplmentationMethods (self) {
108
102
return sendMsg ( self . fd , buf , off , len , fd , flags ) ;
109
103
} ;
110
104
111
- self . _readImpl = function ( buf , off , len , calledByIOWatcher ) {
105
+ self . _readImpl = function ( buf , off , len ) {
112
106
var bytesRead = recvMsg ( self . fd , buf , off , len ) ;
113
107
114
108
// Do not emit this in the same stack, otherwise we risk corrupting our
@@ -139,7 +133,7 @@ function setImplmentationMethods (self) {
139
133
return write ( self . fd , buf , off , len ) ;
140
134
} ;
141
135
142
- self . _readImpl = function ( buf , off , len , calledByIOWatcher ) {
136
+ self . _readImpl = function ( buf , off , len ) {
143
137
return read ( self . fd , buf , off , len ) ;
144
138
} ;
145
139
}
@@ -148,132 +142,13 @@ function setImplmentationMethods (self) {
148
142
shutdown ( self . fd , 'write' ) ;
149
143
} ;
150
144
151
- if ( self . secure ) {
152
- var oldWrite = self . _writeImpl ;
153
- self . _writeImpl = function ( buf , off , len , fd , flags ) {
154
- assert ( buf ) ;
155
- assert ( self . secure ) ;
156
-
157
- var bytesWritten = self . secureStream . clearIn ( buf , off , len ) ;
158
-
159
- if ( ! securePool ) {
160
- allocNewSecurePool ( ) ;
161
- }
162
-
163
- var secureLen = self . secureStream . encOut ( securePool ,
164
- 0 ,
165
- securePool . length ) ;
166
-
167
- if ( secureLen == - 1 ) {
168
- // Check our read again for secure handshake
169
- self . _onReadable ( ) ;
170
- } else {
171
- oldWrite ( securePool , 0 , secureLen , fd , flags ) ;
172
- }
173
-
174
- if ( ! self . secureEstablished && self . secureStream . isInitFinished ( ) ) {
175
- self . secureEstablished = true ;
176
-
177
- if ( self . _events && self . _events [ 'secure' ] ) {
178
- self . emit ( 'secure' ) ;
179
- }
180
- }
181
-
182
- return bytesWritten ;
183
- } ;
184
-
185
- var oldRead = self . _readImpl ;
186
- self . _readImpl = function ( buf , off , len , calledByIOWatcher ) {
187
- assert ( self . secure ) ;
188
-
189
- var bytesRead = 0 ;
190
- var secureBytesRead = null ;
191
-
192
- if ( ! securePool ) {
193
- allocNewSecurePool ( ) ;
194
- }
195
-
196
- if ( calledByIOWatcher ) {
197
- secureBytesRead = oldRead ( securePool , 0 , securePool . length ) ;
198
- self . secureStream . encIn ( securePool , 0 , secureBytesRead ) ;
199
- }
200
-
201
- var chunkBytes ;
202
- do {
203
- chunkBytes =
204
- self . secureStream . clearOut ( pool ,
205
- pool . used + bytesRead ,
206
- pool . length - pool . used - bytesRead ) ;
207
- bytesRead += chunkBytes ;
208
- } while ( ( chunkBytes > 0 ) && ( pool . used + bytesRead < pool . length ) ) ;
209
-
210
- if ( bytesRead == 0 && ! calledByIOWatcher ) {
211
- return - 1 ;
212
- }
213
-
214
- if ( self . secureStream . clearPending ( ) ) {
215
- process . nextTick ( function ( ) {
216
- if ( self . readable ) self . _onReadable ( ) ;
217
- } ) ;
218
- }
219
-
220
- if ( ! self . secureEstablished ) {
221
- if ( self . secureStream . isInitFinished ( ) ) {
222
- self . secureEstablished = true ;
223
- if ( self . _events && self . _events [ 'secure' ] ) {
224
- self . emit ( 'secure' ) ;
225
- }
226
- }
227
- }
228
-
229
- if ( calledByIOWatcher && secureBytesRead === null && ! self . server ) {
230
- // Client needs to write as part of handshake
231
- self . _writeWatcher . start ( ) ;
232
- return - 1 ;
233
- }
234
-
235
- if ( bytesRead == 0 && secureBytesRead > 0 ) {
236
- // Deal with SSL handshake
237
- if ( self . server ) {
238
- self . _checkForSecureHandshake ( ) ;
239
- } else {
240
- if ( self . secureEstablised ) {
241
- self . flush ( ) ;
242
- } else {
243
- self . _checkForSecureHandshake ( ) ;
244
- }
245
- }
246
-
247
- return - 1 ;
248
- }
249
-
250
- return bytesRead ;
251
- } ;
252
-
253
- var oldShutdown = self . _shutdownImpl ;
254
- self . _shutdownImpl = function ( ) {
255
- self . secureStream . shutdown ( ) ;
256
-
257
- if ( ! securePool ) {
258
- allocNewSecurePool ( ) ;
259
- }
260
-
261
- var len = self . secureStream . encOut ( securePool , 0 , securePool . length ) ;
262
-
263
- try {
264
- oldWrite ( securePool , 0 , len ) ;
265
- } catch ( e ) { }
266
-
267
- oldShutdown ( ) ;
268
- } ;
269
- }
270
145
} ;
271
146
272
147
273
148
function onReadable ( readable , writeable ) {
274
149
assert ( this . socket ) ;
275
150
var socket = this . socket ;
276
- socket . _onReadable ( true ) ;
151
+ socket . _onReadable ( ) ;
277
152
}
278
153
279
154
@@ -312,13 +187,11 @@ function Stream (options) {
312
187
313
188
this . fd = null ;
314
189
this . type = null ;
315
- this . secure = false ;
316
190
this . allowHalfOpen = false ;
317
191
318
192
if ( typeof options == "object" ) {
319
193
this . fd = options . fd !== undefined ? parseInt ( options . fd , 10 ) : null ;
320
194
this . type = options . type || null ;
321
- this . secure = options . secure || false ;
322
195
this . allowHalfOpen = options . allowHalfOpen || false ;
323
196
} else if ( typeof options == "number" ) {
324
197
this . fd = arguments [ 0 ] ;
@@ -340,76 +213,6 @@ Stream.prototype._onTimeout = function () {
340
213
} ;
341
214
342
215
343
- Stream . prototype . setSecure = function ( credentials ) {
344
- // Do we have openssl crypto?
345
- try {
346
- SecureContext = process . binding ( 'crypto' ) . SecureContext ;
347
- SecureStream = process . binding ( 'crypto' ) . SecureStream ;
348
- } catch ( e ) {
349
- throw new Error ( 'node.js not compiled with openssl crypto support.' ) ;
350
- }
351
-
352
- var crypto = require ( "crypto" ) ;
353
- this . secure = true ;
354
- this . secureEstablished = false ;
355
- // If no credentials given, create a new one for just this Stream
356
- if ( ! credentials ) {
357
- this . credentials = crypto . createCredentials ( ) ;
358
- } else {
359
- this . credentials = credentials ;
360
- }
361
- if ( ! this . server ) {
362
- // For clients, we will always have either a given ca list or the default on
363
- this . credentials . shouldVerify = true ;
364
- }
365
- this . secureStream = new SecureStream ( this . credentials . context ,
366
- this . server ? true : false ,
367
- this . credentials . shouldVerify ) ;
368
-
369
- setImplmentationMethods ( this ) ;
370
-
371
- if ( ! this . server ) {
372
- // If client, trigger handshake
373
- this . _checkForSecureHandshake ( ) ;
374
- }
375
- } ;
376
-
377
-
378
- Stream . prototype . verifyPeer = function ( ) {
379
- if ( ! this . secure ) {
380
- throw new Error ( 'Stream is not a secure stream.' ) ;
381
- }
382
- return this . secureStream . verifyPeer ( this . credentials . context ) ;
383
- } ;
384
-
385
-
386
- Stream . prototype . _checkForSecureHandshake = function ( ) {
387
- if ( ! this . writable ) {
388
- return ;
389
- }
390
-
391
- // Do an empty write to see if we need to write out as part of handshake
392
- if ( ! emptyBuffer ) allocEmptyBuffer ( ) ;
393
- this . write ( emptyBuffer ) ;
394
- } ;
395
-
396
-
397
- Stream . prototype . getPeerCertificate = function ( credentials ) {
398
- if ( ! this . secure ) {
399
- throw new Error ( 'Stream is not a secure stream.' ) ;
400
- }
401
- return this . secureStream . getPeerCertificate ( ) ;
402
- } ;
403
-
404
-
405
- Stream . prototype . getCipher = function ( ) {
406
- if ( ! this . secure ) {
407
- throw new Error ( 'Stream is not a secure stream.' ) ;
408
- }
409
- return this . secureStream . getCurrentCipher ( ) ;
410
- } ;
411
-
412
-
413
216
Stream . prototype . open = function ( fd , type ) {
414
217
initStream ( this ) ;
415
218
@@ -699,7 +502,7 @@ Stream.prototype._onWritable = function () {
699
502
} ;
700
503
701
504
702
- Stream . prototype . _onReadable = function ( calledByIOWatcher ) {
505
+ Stream . prototype . _onReadable = function ( ) {
703
506
var self = this ;
704
507
705
508
// If this is the first recv (pool doesn't exist) or we've used up
@@ -717,8 +520,7 @@ Stream.prototype._onReadable = function (calledByIOWatcher) {
717
520
try {
718
521
bytesRead = self . _readImpl ( pool ,
719
522
pool . used ,
720
- pool . length - pool . used ,
721
- calledByIOWatcher ) ;
523
+ pool . length - pool . used ) ;
722
524
} catch ( e ) {
723
525
self . destroy ( e ) ;
724
526
return ;
@@ -760,11 +562,6 @@ Stream.prototype._onReadable = function (calledByIOWatcher) {
760
562
761
563
// Optimization: emit the original buffer with end points
762
564
if ( self . ondata ) self . ondata ( pool , start , end ) ;
763
- } else if ( bytesRead == - 2 ) {
764
- // Temporary fix - need SSL refactor.
765
- // -2 originates from SecureStream::ReadExtract
766
- self . destroy ( new Error ( 'openssl read error' ) ) ;
767
- return false ;
768
565
}
769
566
} ;
770
567
@@ -873,10 +670,6 @@ Stream.prototype.destroy = function (exception) {
873
670
874
671
require ( 'timers' ) . unenroll ( this ) ;
875
672
876
- if ( this . secure ) {
877
- this . secureStream . close ( ) ;
878
- }
879
-
880
673
if ( this . server ) {
881
674
this . server . connections -- ;
882
675
}
0 commit comments