@@ -867,6 +867,115 @@ function Server(options, listener) {
867
867
// Handle option defaults:
868
868
this . setOptions ( options ) ;
869
869
870
+ // setSecureContext() overlaps with setOptions() quite a bit. setOptions()
871
+ // is an undocumented API that was probably never intended to be exposed
872
+ // publicly. Unfortunately, it would be a breaking change to just remove it,
873
+ // and there is at least one test that depends on it.
874
+ this . setSecureContext ( options ) ;
875
+
876
+ this [ kHandshakeTimeout ] = options . handshakeTimeout || ( 120 * 1000 ) ;
877
+ this [ kSNICallback ] = options . SNICallback ;
878
+
879
+ if ( typeof this [ kHandshakeTimeout ] !== 'number' ) {
880
+ throw new ERR_INVALID_ARG_TYPE (
881
+ 'options.handshakeTimeout' , 'number' , options . handshakeTimeout ) ;
882
+ }
883
+
884
+ // constructor call
885
+ net . Server . call ( this , tlsConnectionListener ) ;
886
+
887
+ if ( listener ) {
888
+ this . on ( 'secureConnection' , listener ) ;
889
+ }
890
+ }
891
+
892
+ util . inherits ( Server , net . Server ) ;
893
+ exports . Server = Server ;
894
+ exports . createServer = function createServer ( options , listener ) {
895
+ return new Server ( options , listener ) ;
896
+ } ;
897
+
898
+
899
+ Server . prototype . setSecureContext = function ( options ) {
900
+ if ( options === null || typeof options !== 'object' )
901
+ throw new ERR_INVALID_ARG_TYPE ( 'options' , 'Object' , options ) ;
902
+
903
+ if ( options . pfx )
904
+ this . pfx = options . pfx ;
905
+ else
906
+ this . pfx = undefined ;
907
+
908
+ if ( options . key )
909
+ this . key = options . key ;
910
+ else
911
+ this . key = undefined ;
912
+
913
+ if ( options . passphrase )
914
+ this . passphrase = options . passphrase ;
915
+ else
916
+ this . passphrase = undefined ;
917
+
918
+ if ( options . cert )
919
+ this . cert = options . cert ;
920
+ else
921
+ this . cert = undefined ;
922
+
923
+ if ( options . clientCertEngine )
924
+ this . clientCertEngine = options . clientCertEngine ;
925
+ else
926
+ this . clientCertEngine = undefined ;
927
+
928
+ if ( options . ca )
929
+ this . ca = options . ca ;
930
+ else
931
+ this . ca = undefined ;
932
+
933
+ if ( options . secureProtocol )
934
+ this . secureProtocol = options . secureProtocol ;
935
+ else
936
+ this . secureProtocol = undefined ;
937
+
938
+ if ( options . crl )
939
+ this . crl = options . crl ;
940
+ else
941
+ this . crl = undefined ;
942
+
943
+ if ( options . ciphers )
944
+ this . ciphers = options . ciphers ;
945
+ else
946
+ this . ciphers = undefined ;
947
+
948
+ if ( options . ecdhCurve !== undefined )
949
+ this . ecdhCurve = options . ecdhCurve ;
950
+ else
951
+ this . ecdhCurve = undefined ;
952
+
953
+ if ( options . dhparam )
954
+ this . dhparam = options . dhparam ;
955
+ else
956
+ this . dhparam = undefined ;
957
+
958
+ if ( options . honorCipherOrder !== undefined )
959
+ this . honorCipherOrder = ! ! options . honorCipherOrder ;
960
+ else
961
+ this . honorCipherOrder = true ;
962
+
963
+ const secureOptions = options . secureOptions || 0 ;
964
+
965
+ if ( secureOptions )
966
+ this . secureOptions = secureOptions ;
967
+ else
968
+ this . secureOptions = undefined ;
969
+
970
+ if ( options . sessionIdContext ) {
971
+ this . sessionIdContext = options . sessionIdContext ;
972
+ } else {
973
+ this . sessionIdContext = crypto . createHash ( 'sha1' )
974
+ . update ( process . argv . join ( ' ' ) )
975
+ . digest ( 'hex' )
976
+ . slice ( 0 , 32 ) ;
977
+ }
978
+
870
979
this . _sharedCreds = tls . createSecureContext ( {
871
980
pfx : this . pfx ,
872
981
key : this . key ,
@@ -886,34 +995,15 @@ function Server(options, listener) {
886
995
sessionIdContext : this . sessionIdContext
887
996
} ) ;
888
997
889
- this [ kHandshakeTimeout ] = options . handshakeTimeout || ( 120 * 1000 ) ;
890
- this [ kSNICallback ] = options . SNICallback ;
891
-
892
- if ( typeof this [ kHandshakeTimeout ] !== 'number' ) {
893
- throw new ERR_INVALID_ARG_TYPE (
894
- 'options.handshakeTimeout' , 'number' , options . handshakeTimeout ) ;
895
- }
896
-
897
- if ( this . sessionTimeout ) {
998
+ if ( this . sessionTimeout )
898
999
this . _sharedCreds . context . setSessionTimeout ( this . sessionTimeout ) ;
899
- }
900
1000
901
- if ( this . ticketKeys ) {
902
- this . _sharedCreds . context . setTicketKeys ( this . ticketKeys ) ;
903
- }
904
-
905
- // constructor call
906
- net . Server . call ( this , tlsConnectionListener ) ;
907
-
908
- if ( listener ) {
909
- this . on ( 'secureConnection' , listener ) ;
1001
+ if ( options . ticketKeys ) {
1002
+ this . ticketKeys = options . ticketKeys ;
1003
+ this . setTicketKeys ( this . ticketKeys ) ;
1004
+ } else {
1005
+ this . setTicketKeys ( this . getTicketKeys ( ) ) ;
910
1006
}
911
- }
912
-
913
- util . inherits ( Server , net . Server ) ;
914
- exports . Server = Server ;
915
- exports . createServer = function createServer ( options , listener ) {
916
- return new Server ( options , listener ) ;
917
1007
} ;
918
1008
919
1009
0 commit comments