Skip to content

Commit

Permalink
Merge pull request #355 from ivan1986/add-ssl-context
Browse files Browse the repository at this point in the history
support custom ssl context
  • Loading branch information
metaregistrar authored Jul 11, 2023
2 parents f805758 + e35b005 commit 819d2d2
Showing 1 changed file with 30 additions and 14 deletions.
44 changes: 30 additions & 14 deletions Protocols/EPP/eppConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,11 @@ class eppConnection {

protected $launchphase = null;

/**
* @var resource
*/
protected $sslContext = null;

/**
* Path to certificate file
* @var string
Expand Down Expand Up @@ -341,22 +346,25 @@ public function connect($hostname = null, $port = null) {
if ($port) {
$this->port = $port;
}
$context = stream_context_create();
stream_context_set_option($context, 'ssl','verify_peer', $this->verify_peer);
stream_context_set_option($context, 'ssl', 'verify_peer_name', $this->verify_peer_name);
if ($this->local_cert_path) {
stream_context_set_option($context, 'ssl', 'local_cert', $this->local_cert_path);
if (isset($this->local_cert_pwd) && (strlen($this->local_cert_pwd)>0)) {
stream_context_set_option($context, 'ssl', 'passphrase', $this->local_cert_pwd);
}
if (isset($this->allow_self_signed)) {
stream_context_set_option($context, 'ssl', 'allow_self_signed', $this->allow_self_signed);
stream_context_set_option($context, 'ssl', 'verify_peer', false);
} else {
stream_context_set_option($context, 'ssl', 'verify_peer', $this->verify_peer);
if (!$this->sslContext) {
$context = stream_context_create();
stream_context_set_option($context, 'ssl', 'verify_peer', $this->verify_peer);
stream_context_set_option($context, 'ssl', 'verify_peer_name', $this->verify_peer_name);
if ($this->local_cert_path) {
stream_context_set_option($context, 'ssl', 'local_cert', $this->local_cert_path);
if (isset($this->local_cert_pwd) && (strlen($this->local_cert_pwd)>0)) {
stream_context_set_option($context, 'ssl', 'passphrase', $this->local_cert_pwd);
}
if (isset($this->allow_self_signed)) {
stream_context_set_option($context, 'ssl', 'allow_self_signed', $this->allow_self_signed);
stream_context_set_option($context, 'ssl', 'verify_peer', false);
} else {
stream_context_set_option($context, 'ssl', 'verify_peer', $this->verify_peer);
}
}
$this->sslContext = $context;
}
$this->connection = stream_socket_client($this->hostname.':'.$this->port, $errno, $errstr, $this->timeout, STREAM_CLIENT_CONNECT, $context);
$this->connection = stream_socket_client($this->hostname.':'.$this->port, $errno, $errstr, $this->timeout, STREAM_CLIENT_CONNECT, $this->sslContext);
if (is_resource($this->connection)) {
stream_set_blocking($this->connection, $this->blocking);
stream_set_timeout($this->connection, $this->timeout);
Expand Down Expand Up @@ -951,6 +959,14 @@ public function setPort($port) {
$this->port = $port;
}

public function getSslContext() {
return $this->sslContext;
}

public function setSslContext($sslContext) {
$this->sslContext = $sslContext;
}

public function setVerifyPeer($verify_peer) {
$this->verify_peer = $verify_peer;
}
Expand Down

0 comments on commit 819d2d2

Please sign in to comment.