@@ -725,6 +725,37 @@ function onhandshakedone() {
725725 debug ( 'onhandshakedone' ) ;
726726}
727727
728+ function onclienthello ( hello ) {
729+ var self = this ,
730+ once = false ;
731+
732+ this . encrypted . pause ( ) ;
733+ this . cleartext . pause ( ) ;
734+ function callback ( err , session ) {
735+ if ( once ) return ;
736+ once = true ;
737+
738+ if ( err ) return self . socket . destroy ( err ) ;
739+
740+ self . ssl . loadSession ( session ) ;
741+
742+ self . encrypted . resume ( ) ;
743+ self . cleartext . resume ( ) ;
744+ }
745+
746+ if ( hello . sessionId . length <= 0 ||
747+ ! this . server ||
748+ ! this . server . emit ( 'resumeSession' , hello . sessionId , callback ) ) {
749+ callback ( null , null ) ;
750+ }
751+ }
752+
753+
754+ function onnewsession ( key , session ) {
755+ if ( ! this . server ) return ;
756+ this . server . emit ( 'newSession' , key , session ) ;
757+ }
758+
728759
729760/**
730761 * Provides a pair of streams to do encrypted communication.
@@ -746,6 +777,7 @@ function SecurePair(credentials, isServer, requestCert, rejectUnauthorized,
746777
747778 events . EventEmitter . call ( this ) ;
748779
780+ this . server = options . server ;
749781 this . _secureEstablished = false ;
750782 this . _isServer = isServer ? true : false ;
751783 this . _encWriteState = true ;
@@ -768,13 +800,16 @@ function SecurePair(credentials, isServer, requestCert, rejectUnauthorized,
768800 this . _requestCert = requestCert ? true : false ;
769801
770802 this . ssl = new Connection ( this . credentials . context ,
771- this . _isServer ? true : false ,
772- this . _isServer ? this . _requestCert : options . servername ,
773- this . _rejectUnauthorized ) ;
803+ this . _isServer ? true : false ,
804+ this . _isServer ? this . _requestCert :
805+ options . servername ,
806+ this . _rejectUnauthorized ) ;
774807
775808 if ( this . _isServer ) {
776809 this . ssl . onhandshakestart = onhandshakestart . bind ( this ) ;
777810 this . ssl . onhandshakedone = onhandshakedone . bind ( this ) ;
811+ this . ssl . onclienthello = onclienthello . bind ( this ) ;
812+ this . ssl . onnewsession = onnewsession . bind ( this ) ;
778813 this . ssl . handshakes = 0 ;
779814 this . ssl . timer = null ;
780815 }
@@ -1084,6 +1119,7 @@ function Server(/* [options], listener */) {
10841119 self . requestCert ,
10851120 self . rejectUnauthorized ,
10861121 {
1122+ server : self ,
10871123 NPNProtocols : self . NPNProtocols ,
10881124 SNICallback : self . SNICallback
10891125 } ) ;
0 commit comments