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();
$disableTls = false;
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;
$disableTls = true;
} elseif (!extension_loaded('openssl')) {
$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>');
@ -79,12 +81,12 @@ EOT
if (!is_null($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) {
if (preg_match('|cafile|', $e->getMessage())) {
$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>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;
} else {
throw $e;

View File

@ -40,7 +40,7 @@ class RemoteFilesystem
* @param IOInterface $io The IO instance
* @param array $options The options
*/
public function __construct(IOInterface $io, $options = array())
public function __construct(IOInterface $io, $options = array(), $disableTls = false)
{
$this->io = $io;
@ -48,12 +48,14 @@ class RemoteFilesystem
* Setup TLS options
* The cafile option can be set via config.json
*/
if ($disableTls === false) {
$this->options = $this->getTlsDefaults();
if (isset($options['ssl']['cafile'])
&& (!is_readable($options['ssl']['cafile'])
|| !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.
$this->options = array_replace_recursive($this->options, $options);
@ -70,9 +72,9 @@ class RemoteFilesystem
*
* @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
*/
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
*/
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->originUrl = $originUrl;
@ -128,7 +130,7 @@ class RemoteFilesystem
$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()) {
$this->io->write((substr($fileUrl, 0, 4) === 'http' ? 'Downloading ' : 'Reading ') . $fileUrl);
@ -320,7 +322,7 @@ class RemoteFilesystem
throw new TransportException('RETRY');
}
protected function getOptionsForUrl($originUrl, $additionalOptions)
protected function getOptionsForUrl($originUrl, $additionalOptions, $disableTls = false)
{
$headers = array(
sprintf(
@ -339,9 +341,11 @@ class RemoteFilesystem
}
// Setup remaining TLS options - the matching may need monitoring, esp. www vs none in CN
if ($disableTls === false) {
$host = parse_url($originUrl, PHP_URL_HOST);
$this->options['ssl']['CN_match'] = $host;
$this->options['ssl']['SNI_server_name'] = $host;
}
$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']);
if (version_compare(PHP_VERSION, '5.4.13') >= 0) {
$this->assertTrue($res['ssl']['disable_compression']);
} else {
$this->assertFalse(isset($res['ssl']['disable_compression']));
}
}