@@ -10,11 +10,13 @@ class SecureConnector implements ConnectorInterface
1010{
1111 private $ connector ;
1212 private $ streamEncryption ;
13+ private $ context ;
1314
14- public function __construct (ConnectorInterface $ connector , LoopInterface $ loop )
15+ public function __construct (ConnectorInterface $ connector , LoopInterface $ loop, array $ context = array () )
1516 {
1617 $ this ->connector = $ connector ;
1718 $ this ->streamEncryption = new StreamEncryption ($ loop );
19+ $ this ->context = $ context ;
1820 }
1921
2022 public function create ($ host , $ port )
@@ -23,14 +25,17 @@ public function create($host, $port)
2325 return Promise \reject (new \BadMethodCallException ('Encryption not supported on your platform (HHVM < 3.8?) ' ));
2426 }
2527
26- return $ this ->connector ->create ($ host , $ port )->then (function (Stream $ stream ) use ($ host ) {
28+ $ context = $ this ->context + array (
29+ 'SNI_enabled ' => true ,
30+ 'SNI_server_name ' => $ host ,
31+ 'peer_name ' => $ host
32+ );
33+
34+ return $ this ->connector ->create ($ host , $ port )->then (function (Stream $ stream ) use ($ context ) {
2735 // (unencrypted) TCP/IP connection succeeded
2836
2937 // set required SSL/TLS context options
30- $ resource = $ stream ->stream ;
31- stream_context_set_option ($ resource , 'ssl ' , 'SNI_enabled ' , true );
32- stream_context_set_option ($ resource , 'ssl ' , 'SNI_server_name ' , $ host );
33- stream_context_set_option ($ resource , 'ssl ' , 'peer_name ' , $ host );
38+ stream_context_set_option ($ stream ->stream , array ('ssl ' => $ context ));
3439
3540 // try to enable encryption
3641 return $ this ->streamEncryption ->enable ($ stream )->then (null , function ($ error ) use ($ stream ) {
0 commit comments