@@ -48,7 +48,6 @@ var ENOENT = constants.ENOENT;
4848var EMFILE = constants . EMFILE ;
4949
5050var END_OF_FILE = 42 ;
51- var SecureContext , SecureStream ; // lazy loaded
5251
5352
5453var ioWatchers = new FreeList ( "iowatcher" , 100 , function ( ) {
@@ -78,11 +77,6 @@ function allocNewPool () {
7877 pool . used = 0 ;
7978}
8079
81- var securePool = null ;
82- function allocNewSecurePool ( ) {
83- securePool = new Buffer ( 40 * 1024 ) ;
84- }
85-
8680var emptyBuffer = null ;
8781function allocEmptyBuffer ( ) {
8882 emptyBuffer = new Buffer ( 1 ) ;
@@ -108,7 +102,7 @@ function setImplmentationMethods (self) {
108102 return sendMsg ( self . fd , buf , off , len , fd , flags ) ;
109103 } ;
110104
111- self . _readImpl = function ( buf , off , len , calledByIOWatcher ) {
105+ self . _readImpl = function ( buf , off , len ) {
112106 var bytesRead = recvMsg ( self . fd , buf , off , len ) ;
113107
114108 // Do not emit this in the same stack, otherwise we risk corrupting our
@@ -139,7 +133,7 @@ function setImplmentationMethods (self) {
139133 return write ( self . fd , buf , off , len ) ;
140134 } ;
141135
142- self . _readImpl = function ( buf , off , len , calledByIOWatcher ) {
136+ self . _readImpl = function ( buf , off , len ) {
143137 return read ( self . fd , buf , off , len ) ;
144138 } ;
145139 }
@@ -148,132 +142,13 @@ function setImplmentationMethods (self) {
148142 shutdown ( self . fd , 'write' ) ;
149143 } ;
150144
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- }
270145} ;
271146
272147
273148function onReadable ( readable , writeable ) {
274149 assert ( this . socket ) ;
275150 var socket = this . socket ;
276- socket . _onReadable ( true ) ;
151+ socket . _onReadable ( ) ;
277152}
278153
279154
@@ -312,13 +187,11 @@ function Stream (options) {
312187
313188 this . fd = null ;
314189 this . type = null ;
315- this . secure = false ;
316190 this . allowHalfOpen = false ;
317191
318192 if ( typeof options == "object" ) {
319193 this . fd = options . fd !== undefined ? parseInt ( options . fd , 10 ) : null ;
320194 this . type = options . type || null ;
321- this . secure = options . secure || false ;
322195 this . allowHalfOpen = options . allowHalfOpen || false ;
323196 } else if ( typeof options == "number" ) {
324197 this . fd = arguments [ 0 ] ;
@@ -340,76 +213,6 @@ Stream.prototype._onTimeout = function () {
340213} ;
341214
342215
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-
413216Stream . prototype . open = function ( fd , type ) {
414217 initStream ( this ) ;
415218
@@ -699,7 +502,7 @@ Stream.prototype._onWritable = function () {
699502} ;
700503
701504
702- Stream . prototype . _onReadable = function ( calledByIOWatcher ) {
505+ Stream . prototype . _onReadable = function ( ) {
703506 var self = this ;
704507
705508 // If this is the first recv (pool doesn't exist) or we've used up
@@ -717,8 +520,7 @@ Stream.prototype._onReadable = function (calledByIOWatcher) {
717520 try {
718521 bytesRead = self . _readImpl ( pool ,
719522 pool . used ,
720- pool . length - pool . used ,
721- calledByIOWatcher ) ;
523+ pool . length - pool . used ) ;
722524 } catch ( e ) {
723525 self . destroy ( e ) ;
724526 return ;
@@ -760,11 +562,6 @@ Stream.prototype._onReadable = function (calledByIOWatcher) {
760562
761563 // Optimization: emit the original buffer with end points
762564 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 ;
768565 }
769566} ;
770567
@@ -873,10 +670,6 @@ Stream.prototype.destroy = function (exception) {
873670
874671 require ( 'timers' ) . unenroll ( this ) ;
875672
876- if ( this . secure ) {
877- this . secureStream . close ( ) ;
878- }
879-
880673 if ( this . server ) {
881674 this . server . connections -- ;
882675 }
0 commit comments