Skip to content

Commit

Permalink
Merge pull request #22 from simoheinonen/cert_checks
Browse files Browse the repository at this point in the history
Cert checks
  • Loading branch information
vyuldashev committed Oct 15, 2018
2 parents a0ff89f + 592feb3 commit a264be7
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ $adapter = new CurlFtpAdapter([
'utf8' => true,
'ssl' => true,
'timeout' => 90, // connect timeout
'sslVerifyPeer' => 0, // using 0 is insecure, use it only if you know what you're doing
'sslVerifyHost' => 0, // using 0 is insecure, use it only if you know what you're doing

/** proxy settings */
'proxyHost' => 'proxy-server.example.com',
Expand Down
29 changes: 27 additions & 2 deletions src/CurlFtpAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ class CurlFtpAdapter extends AbstractFtpAdapter
'password',
'root',
'ssl',
'sslVerifyPeer',
'sslVerifyHost',
'utf8',
'timeout',
'proxyHost',
Expand All @@ -37,6 +39,12 @@ class CurlFtpAdapter extends AbstractFtpAdapter
/** @var bool */
protected $isPureFtpd;

/** @var @int */
protected $sslVerifyPeer = 1;

/** @var @int */
protected $sslVerifyHost = 2;

/** @var bool */
protected $utf8 = false;

Expand All @@ -60,6 +68,22 @@ public function setSsl($ssl)
$this->ssl = (bool) $ssl;
}

/**
* @param int $sslVerifyPeer
*/
public function setSslVerifyPeer($sslVerifyPeer)
{
$this->sslVerifyPeer = $sslVerifyPeer;
}

/**
* @param int $sslVerifyHost
*/
public function setSslVerifyHost($sslVerifyHost)
{
$this->sslVerifyHost = $sslVerifyHost;
}

/**
* @param bool $utf8
*/
Expand Down Expand Up @@ -141,8 +165,6 @@ public function connect()
$this->connection->setOptions([
CURLOPT_URL => $this->getBaseUri(),
CURLOPT_USERPWD => $this->getUsername().':'.$this->getPassword(),
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_SSL_VERIFYHOST => false,
CURLOPT_FTPSSLAUTH => CURLFTPAUTH_TLS,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CONNECTTIMEOUT => $this->getTimeout(),
Expand All @@ -152,6 +174,9 @@ public function connect()
$this->connection->setOption(CURLOPT_FTP_SSL, CURLFTPSSL_ALL);
}

$this->connection->setOption(CURLOPT_SSL_VERIFYHOST, $this->sslVerifyHost);
$this->connection->setOption(CURLOPT_SSL_VERIFYPEER, $this->sslVerifyPeer);

if ($proxyUrl = $this->getProxyHost()) {
$proxyPort = $this->getProxyPort();
$this->connection->setOption(CURLOPT_PROXY, $proxyPort ? $proxyUrl.':'.$proxyPort : $proxyUrl);
Expand Down

0 comments on commit a264be7

Please sign in to comment.