@@ -286,6 +286,18 @@ function onnewsession(sessionId, session) {
286
286
}
287
287
288
288
289
+ function onkeylogclient ( line ) {
290
+ debug ( 'client onkeylog' ) ;
291
+ this [ owner_symbol ] . emit ( 'keylog' , line ) ;
292
+ }
293
+
294
+ function onkeylog ( line ) {
295
+ debug ( 'server onkeylog' ) ;
296
+ const owner = this [ owner_symbol ] ;
297
+ if ( owner . server )
298
+ owner . server . emit ( 'keylog' , line , owner ) ;
299
+ }
300
+
289
301
function onocspresponse ( resp ) {
290
302
debug ( 'client onocspresponse' ) ;
291
303
this [ owner_symbol ] . emit ( 'OCSPResponse' , resp ) ;
@@ -571,6 +583,7 @@ TLSSocket.prototype._init = function(socket, wrap) {
571
583
ssl . onclienthello = loadSession ;
572
584
ssl . oncertcb = loadSNI ;
573
585
ssl . onnewsession = onnewsession ;
586
+ ssl . onkeylog = onkeylog ;
574
587
ssl . lastHandshakeTime = 0 ;
575
588
ssl . handshakes = 0 ;
576
589
@@ -580,6 +593,8 @@ TLSSocket.prototype._init = function(socket, wrap) {
580
593
// Also starts the client hello parser as a side effect.
581
594
ssl . enableSessionCallbacks ( ) ;
582
595
}
596
+ if ( this . server . listenerCount ( 'keylog' ) > 0 )
597
+ ssl . enableKeylogCallback ( ) ;
583
598
if ( this . server . listenerCount ( 'OCSPRequest' ) > 0 )
584
599
ssl . enableCertCb ( ) ;
585
600
}
@@ -605,9 +620,24 @@ TLSSocket.prototype._init = function(socket, wrap) {
605
620
606
621
ssl . enableSessionCallbacks ( ) ;
607
622
608
- // Remover this listener since its no longer needed.
623
+ // Remove this listener since it's no longer needed.
609
624
this . removeListener ( 'newListener' , newListener ) ;
610
625
}
626
+
627
+ ssl . onkeylog = onkeylogclient ;
628
+
629
+ // Only call .onkeylog if there is a keylog listener.
630
+ this . on ( 'newListener' , keylogNewListener ) ;
631
+
632
+ function keylogNewListener ( event ) {
633
+ if ( event !== 'keylog' )
634
+ return ;
635
+
636
+ ssl . enableKeylogCallback ( ) ;
637
+
638
+ // Remove this listener since it's no longer needed.
639
+ this . removeListener ( 'newListener' , keylogNewListener ) ;
640
+ }
611
641
}
612
642
613
643
ssl . onerror = onerror ;
0 commit comments