1
0
Fork 0

Some typos/corrections

pull/2745/head
Pádraic Brady 2014-02-23 14:15:24 +00:00
parent 1e1e713329
commit 2648064e5a
3 changed files with 27 additions and 19 deletions

View File

@ -61,9 +61,11 @@ EOT
{ {
$config = Factory::createConfig(); $config = Factory::createConfig();
$disableTls = false;
if($config->get('disable-tls') === true || $input->getOption('disable-tls')) { if($config->get('disable-tls') === true || $input->getOption('disable-tls')) {
$output->writeln('<info>You are running Composer with SSL/TLS protection disabled.</info>'); $output->writeln('<comment>You are running Composer with SSL/TLS protection disabled.</comment>');
$baseUrl = 'http://' . self::HOMEPAGE; $baseUrl = 'http://' . self::HOMEPAGE;
$disableTls = true;
} elseif (!extension_loaded('openssl')) { } elseif (!extension_loaded('openssl')) {
$output->writeln('<error>The openssl extension is required for SSL/TLS protection.</error>'); $output->writeln('<error>The openssl extension is required for SSL/TLS protection.</error>');
$output->writeln('<error>You can disable this error, at your own risk, by enabling the \'disable-tls\' option.</error>'); $output->writeln('<error>You can disable this error, at your own risk, by enabling the \'disable-tls\' option.</error>');
@ -79,12 +81,12 @@ EOT
if (!is_null($input->get('cafile'))) { if (!is_null($input->get('cafile'))) {
$remoteFilesystemOptions = array('ssl'=>array('cafile'=>$input->get('cafile'))); $remoteFilesystemOptions = array('ssl'=>array('cafile'=>$input->get('cafile')));
} }
$remoteFilesystem = new RemoteFilesystem($this->getIO(), $remoteFilesystemOptions); $remoteFilesystem = new RemoteFilesystem($this->getIO(), $remoteFilesystemOptions, $disableTls);
} catch (TransportException $e) { } catch (TransportException $e) {
if (preg_match('|cafile|', $e->getMessage())) { if (preg_match('|cafile|', $e->getMessage())) {
$output->writeln('<error>' . $e->getMessage() . '</error>'); $output->writeln('<error>' . $e->getMessage() . '</error>');
$output->writeln('<error>Unable to locate a valid CA certificate file. You must set a valid \'cafile\' option.</error>'); $output->writeln('<error>Unable to locate a valid CA certificate file. You must set a valid \'cafile\' option.</error>');
$output->writeln('<error>You can disable this error, at your own risk, by enabling the \'disable-tls\' option.</error>'); $output->writeln('<error>You can alternatively disable this error, at your own risk, by enabling the \'disable-tls\' option.</error>');
return 1; return 1;
} else { } else {
throw $e; throw $e;

View File

@ -40,7 +40,7 @@ class RemoteFilesystem
* @param IOInterface $io The IO instance * @param IOInterface $io The IO instance
* @param array $options The options * @param array $options The options
*/ */
public function __construct(IOInterface $io, $options = array()) public function __construct(IOInterface $io, $options = array(), $disableTls = false)
{ {
$this->io = $io; $this->io = $io;
@ -48,11 +48,13 @@ class RemoteFilesystem
* Setup TLS options * Setup TLS options
* The cafile option can be set via config.json * The cafile option can be set via config.json
*/ */
$this->options = $this->getTlsDefaults(); if ($disableTls === false) {
if (isset($options['ssl']['cafile']) $this->options = $this->getTlsDefaults();
&& (!is_readable($options['ssl']['cafile']) if (isset($options['ssl']['cafile'])
|| !openssl_x509_parse(file_get_contents($options['ssl']['cafile'])))) { //check return value and test (it's subject to change) && (!is_readable($options['ssl']['cafile'])
throw new TransportException('The configured cafile was not valid or could not be read.'); || !openssl_x509_parse(file_get_contents($options['ssl']['cafile'])))) { //check return value and test (it's subject to change)
throw new TransportException('The configured cafile was not valid or could not be read.');
}
} }
// handle the other externally set options normally. // handle the other externally set options normally.
@ -70,9 +72,9 @@ class RemoteFilesystem
* *
* @return bool true * @return bool true
*/ */
public function copy($originUrl, $fileUrl, $fileName, $progress = true, $options = array()) public function copy($originUrl, $fileUrl, $fileName, $progress = true, $options = array(), $disableTls = false)
{ {
return $this->get($originUrl, $fileUrl, $options, $fileName, $progress); return $this->get($originUrl, $fileUrl, $options, $fileName, $progress, $disableTls);
} }
/** /**
@ -85,9 +87,9 @@ class RemoteFilesystem
* *
* @return string The content * @return string The content
*/ */
public function getContents($originUrl, $fileUrl, $progress = true, $options = array()) public function getContents($originUrl, $fileUrl, $progress = true, $options = array(), $disableTls = false)
{ {
return $this->get($originUrl, $fileUrl, $options, null, $progress); return $this->get($originUrl, $fileUrl, $options, null, $progress, $disableTls);
} }
/** /**
@ -114,7 +116,7 @@ class RemoteFilesystem
* *
* @return bool|string * @return bool|string
*/ */
protected function get($originUrl, $fileUrl, $additionalOptions = array(), $fileName = null, $progress = true) protected function get($originUrl, $fileUrl, $additionalOptions = array(), $fileName = null, $progress = true, $disableTls = false)
{ {
$this->bytesMax = 0; $this->bytesMax = 0;
$this->originUrl = $originUrl; $this->originUrl = $originUrl;
@ -128,7 +130,7 @@ class RemoteFilesystem
$this->io->setAuthentication($originUrl, urldecode($match[1]), urldecode($match[2])); $this->io->setAuthentication($originUrl, urldecode($match[1]), urldecode($match[2]));
} }
$options = $this->getOptionsForUrl($originUrl, $additionalOptions); $options = $this->getOptionsForUrl($originUrl, $additionalOptions, $disableTls);
if ($this->io->isDebug()) { if ($this->io->isDebug()) {
$this->io->write((substr($fileUrl, 0, 4) === 'http' ? 'Downloading ' : 'Reading ') . $fileUrl); $this->io->write((substr($fileUrl, 0, 4) === 'http' ? 'Downloading ' : 'Reading ') . $fileUrl);
@ -320,7 +322,7 @@ class RemoteFilesystem
throw new TransportException('RETRY'); throw new TransportException('RETRY');
} }
protected function getOptionsForUrl($originUrl, $additionalOptions) protected function getOptionsForUrl($originUrl, $additionalOptions, $disableTls = false)
{ {
$headers = array( $headers = array(
sprintf( sprintf(
@ -339,9 +341,11 @@ class RemoteFilesystem
} }
// Setup remaining TLS options - the matching may need monitoring, esp. www vs none in CN // Setup remaining TLS options - the matching may need monitoring, esp. www vs none in CN
$host = parse_url($originUrl, PHP_URL_HOST); if ($disableTls === false) {
$this->options['ssl']['CN_match'] = $host; $host = parse_url($originUrl, PHP_URL_HOST);
$this->options['ssl']['SNI_server_name'] = $host; $this->options['ssl']['CN_match'] = $host;
$this->options['ssl']['SNI_server_name'] = $host;
}
$options = array_replace_recursive($this->options, $additionalOptions); $options = array_replace_recursive($this->options, $additionalOptions);

View File

@ -197,6 +197,8 @@ class RemoteFilesystemTest extends \PHPUnit_Framework_TestCase
$this->assertEquals('/some/path/file.crt', $res['ssl']['cafile']); $this->assertEquals('/some/path/file.crt', $res['ssl']['cafile']);
if (version_compare(PHP_VERSION, '5.4.13') >= 0) { if (version_compare(PHP_VERSION, '5.4.13') >= 0) {
$this->assertTrue($res['ssl']['disable_compression']); $this->assertTrue($res['ssl']['disable_compression']);
} else {
$this->assertFalse(isset($res['ssl']['disable_compression']));
} }
} }