@@ -9,23 +9,29 @@ class SecureConnector implements ConnectorInterface
99{
1010 private $ connector ;
1111 private $ streamEncryption ;
12+ private $ context ;
1213
13- public function __construct (ConnectorInterface $ connector , LoopInterface $ loop )
14+ public function __construct (ConnectorInterface $ connector , LoopInterface $ loop, array $ context = array () )
1415 {
1516 $ this ->connector = $ connector ;
1617 $ this ->streamEncryption = new StreamEncryption ($ loop );
18+ $ this ->context = $ context ;
1719 }
1820
1921 public function create ($ host , $ port )
2022 {
21- return $ this ->connector ->create ($ host , $ port )->then (function (Stream $ stream ) use ($ host ) {
23+ $ context = $ this ->context + array (
24+ 'SNI_enabled ' => true ,
25+ 'SNI_server_name ' => $ host ,
26+ 'CN_match ' => $ host ,
27+ 'peer_name ' => $ host
28+ );
29+
30+ return $ this ->connector ->create ($ host , $ port )->then (function (Stream $ stream ) use ($ context ) {
2231 // (unencrypted) TCP/IP connection succeeded
2332
2433 // set required SSL/TLS context options
25- $ resource = $ stream ->stream ;
26- stream_context_set_option ($ resource , 'ssl ' , 'SNI_enabled ' , true );
27- stream_context_set_option ($ resource , 'ssl ' , 'SNI_server_name ' , $ host );
28- stream_context_set_option ($ resource , 'ssl ' , 'peer_name ' , $ host );
34+ stream_context_set_option ($ stream ->stream , array ('ssl ' => $ context ));
2935
3036 // try to enable encryption
3137 return $ this ->streamEncryption ->enable ($ stream )->then (null , function ($ error ) use ($ stream ) {
0 commit comments