@@ -119,6 +119,11 @@ class eppConnection {
119
119
120
120
protected $ launchphase = null ;
121
121
122
+ /**
123
+ * @var resource
124
+ */
125
+ protected $ sslContext = null ;
126
+
122
127
/**
123
128
* Path to certificate file
124
129
* @var string
@@ -341,22 +346,25 @@ public function connect($hostname = null, $port = null) {
341
346
if ($ port ) {
342
347
$ this ->port = $ port ;
343
348
}
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
+ }
357
364
}
365
+ $ this ->sslContext = $ context ;
358
366
}
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 );
360
368
if (is_resource ($ this ->connection )) {
361
369
stream_set_blocking ($ this ->connection , $ this ->blocking );
362
370
stream_set_timeout ($ this ->connection , $ this ->timeout );
@@ -951,6 +959,14 @@ public function setPort($port) {
951
959
$ this ->port = $ port ;
952
960
}
953
961
962
+ public function getSslContext () {
963
+ return $ this ->sslContext ;
964
+ }
965
+
966
+ public function setSslContext ($ sslContext ) {
967
+ $ this ->sslContext = $ sslContext ;
968
+ }
969
+
954
970
public function setVerifyPeer ($ verify_peer ) {
955
971
$ this ->verify_peer = $ verify_peer ;
956
972
}
0 commit comments