@@ -119,6 +119,11 @@ class eppConnection {
119119
120120 protected $ launchphase = null ;
121121
122+ /**
123+ * @var resource
124+ */
125+ protected $ sslContext = null ;
126+
122127 /**
123128 * Path to certificate file
124129 * @var string
@@ -341,22 +346,25 @@ public function connect($hostname = null, $port = null) {
341346 if ($ port ) {
342347 $ this ->port = $ port ;
343348 }
344- $ context = stream_context_create ();
345- stream_context_set_option ($ context , 'ssl ' ,'verify_peer ' , $ this ->verify_peer );
346- stream_context_set_option ($ context , 'ssl ' , 'verify_peer_name ' , $ this ->verify_peer_name );
347- if ($ this ->local_cert_path ) {
348- stream_context_set_option ($ context , 'ssl ' , 'local_cert ' , $ this ->local_cert_path );
349- if (isset ($ this ->local_cert_pwd ) && (strlen ($ this ->local_cert_pwd )>0 )) {
350- stream_context_set_option ($ context , 'ssl ' , 'passphrase ' , $ this ->local_cert_pwd );
351- }
352- if (isset ($ this ->allow_self_signed )) {
353- stream_context_set_option ($ context , 'ssl ' , 'allow_self_signed ' , $ this ->allow_self_signed );
354- stream_context_set_option ($ context , 'ssl ' , 'verify_peer ' , false );
355- } else {
356- stream_context_set_option ($ context , 'ssl ' , 'verify_peer ' , $ this ->verify_peer );
349+ if (!$ this ->sslContext ) {
350+ $ context = stream_context_create ();
351+ stream_context_set_option ($ context , 'ssl ' , 'verify_peer ' , $ this ->verify_peer );
352+ stream_context_set_option ($ context , 'ssl ' , 'verify_peer_name ' , $ this ->verify_peer_name );
353+ if ($ this ->local_cert_path ) {
354+ stream_context_set_option ($ context , 'ssl ' , 'local_cert ' , $ this ->local_cert_path );
355+ if (isset ($ this ->local_cert_pwd ) && (strlen ($ this ->local_cert_pwd )>0 )) {
356+ stream_context_set_option ($ context , 'ssl ' , 'passphrase ' , $ this ->local_cert_pwd );
357+ }
358+ if (isset ($ this ->allow_self_signed )) {
359+ stream_context_set_option ($ context , 'ssl ' , 'allow_self_signed ' , $ this ->allow_self_signed );
360+ stream_context_set_option ($ context , 'ssl ' , 'verify_peer ' , false );
361+ } else {
362+ stream_context_set_option ($ context , 'ssl ' , 'verify_peer ' , $ this ->verify_peer );
363+ }
357364 }
365+ $ this ->sslContext = $ context ;
358366 }
359- $ this ->connection = stream_socket_client ($ this ->hostname .': ' .$ this ->port , $ errno , $ errstr , $ this ->timeout , STREAM_CLIENT_CONNECT , $ context );
367+ $ this ->connection = stream_socket_client ($ this ->hostname .': ' .$ this ->port , $ errno , $ errstr , $ this ->timeout , STREAM_CLIENT_CONNECT , $ this -> sslContext );
360368 if (is_resource ($ this ->connection )) {
361369 stream_set_blocking ($ this ->connection , $ this ->blocking );
362370 stream_set_timeout ($ this ->connection , $ this ->timeout );
@@ -951,6 +959,14 @@ public function setPort($port) {
951959 $ this ->port = $ port ;
952960 }
953961
962+ public function getSslContext () {
963+ return $ this ->sslContext ;
964+ }
965+
966+ public function setSslContext ($ sslContext ) {
967+ $ this ->sslContext = $ sslContext ;
968+ }
969+
954970 public function setVerifyPeer ($ verify_peer ) {
955971 $ this ->verify_peer = $ verify_peer ;
956972 }
0 commit comments