diff --git a/src/Composer/Command/ConfigCommand.php b/src/Composer/Command/ConfigCommand.php
index c6e56e97f..63adbf2b3 100644
--- a/src/Composer/Command/ConfigCommand.php
+++ b/src/Composer/Command/ConfigCommand.php
@@ -287,7 +287,7 @@ EOT
'prepend-autoloader' => array($booleanValidator, $booleanNormalizer),
'disable-tls' => array($booleanValidator, $booleanNormalizer),
'cafile' => array(
- function ($val) { return file_exists($val) && is_readable($val); }
+ function ($val) { return file_exists($val) && is_readable($val); },
function ($val) { return $val === 'null' ? null : $val; }
)
);
diff --git a/src/Composer/Command/SelfUpdateCommand.php b/src/Composer/Command/SelfUpdateCommand.php
index 75095b3ae..a76c567af 100644
--- a/src/Composer/Command/SelfUpdateCommand.php
+++ b/src/Composer/Command/SelfUpdateCommand.php
@@ -61,40 +61,12 @@ EOT
{
$config = Factory::createConfig();
- $disableTls = false;
if($config->get('disable-tls') === true || $input->getOption('disable-tls')) {
- $output->writeln('You are running Composer with SSL/TLS protection disabled.');
$baseUrl = 'http://' . self::HOMEPAGE;
- $disableTls = true;
- } elseif (!extension_loaded('openssl')) {
- $output->writeln('The openssl extension is required for SSL/TLS protection but is not available.');
- $output->writeln('You can disable this error, at your own risk, by enabling the \'disable-tls\' option.');
- return 1;
} else {
$baseUrl = 'https://' . self::HOMEPAGE;
}
-
- $remoteFilesystemOptions = array();
- if ($disableTls === false) {
- if (!is_null($config->get('cafile'))) {
- $remoteFilesystemOptions = array('ssl'=>array('cafile'=>$config->get('cafile')));
- }
- if (!is_null($input->getOption('cafile'))) {
- $remoteFilesystemOptions = array('ssl'=>array('cafile'=>$input->getOption('cafile')));
- }
- }
- try {
- $remoteFilesystem = new RemoteFilesystem($this->getIO(), $remoteFilesystemOptions, $disableTls);
- } catch (TransportException $e) {
- if (preg_match('|cafile|', $e->getMessage())) {
- $output->writeln('' . $e->getMessage() . '');
- $output->writeln('Unable to locate a valid CA certificate file. You must set a valid \'cafile\' option.');
- $output->writeln('You can alternatively disable this error, at your own risk, by enabling the \'disable-tls\' option.');
- return 1;
- } else {
- throw $e;
- }
- }
+ $remoteFilesystem = Factory::createRemoteFilesystem($this->getIO(), $config);
$cacheDir = $config->get('cache-dir');
$rollbackDir = $config->get('home');
diff --git a/src/Composer/Config.php b/src/Composer/Config.php
index 722bc5370..e5dc04084 100644
--- a/src/Composer/Config.php
+++ b/src/Composer/Config.php
@@ -142,6 +142,7 @@ class Config
case 'cache-files-dir':
case 'cache-repo-dir':
case 'cache-vcs-dir':
+ case 'cafile':
// convert foo-bar to COMPOSER_FOO_BAR and check if it exists since it overrides the local config
$env = 'COMPOSER_' . strtoupper(strtr($key, '-', '_'));
@@ -214,7 +215,7 @@ class Config
return $this->config[$key];
case 'disable-tls':
- return $this->config[$key]!== 'false' && (bool) $this->config[$key];
+ return $this->config[$key] !== 'false' && (bool) $this->config[$key];
default:
if (!isset($this->config[$key])) {
diff --git a/src/Composer/Factory.php b/src/Composer/Factory.php
index 91cb0b420..272e8365d 100644
--- a/src/Composer/Factory.php
+++ b/src/Composer/Factory.php
@@ -467,4 +467,37 @@ class Factory
return $factory->createComposer($io, $config, $disablePlugins, $input);
}
+
+ public static function createRemoteFilesystem(IOInterface $io, Config $config, $options = array())
+ {
+ $disableTls = false;
+ if($config->get('disable-tls') === true || $io->getInputOption('disable-tls')) {
+ $io->write('You are running Composer with SSL/TLS protection disabled.');
+ $disableTls = true;
+ } elseif (!extension_loaded('openssl')) {
+ throw new \RuntimeException('The openssl extension is required for SSL/TLS protection but is not available. '
+ . 'You can disable this error, at your own risk, by passing the \'--disable-tls\' option to this command.');
+ }
+ $remoteFilesystemOptions = array();
+ if ($disableTls === false) {
+ if (!empty($config->get('cafile'))) {
+ $remoteFilesystemOptions = array('ssl'=>array('cafile'=>$config->get('cafile')));
+ }
+ if (!empty($io->getInputOption('cafile'))) {
+ $remoteFilesystemOptions = array('ssl'=>array('cafile'=>$io->getInputOption('cafile')));
+ }
+ $remoteFilesystemOptions = array_merge_recursive($remoteFilesystemOptions, $options);
+ }
+ try {
+ $remoteFilesystem = new RemoteFilesystem($io, $remoteFilesystemOptions, $disableTls);
+ } catch (TransportException $e) {
+ if (preg_match('|cafile|', $e->getMessage())) {
+ $io->write('Unable to locate a valid CA certificate file. You must set a valid \'cafile\' option.');
+ $io->write('A valid CA certificate file is required for SSL/TLS protection.');
+ $io->write('You can disable this error, at your own risk, by passing the \'--disable-tls\' option to this command.');
+ }
+ throw $e;
+ }
+ return $remoteFilesystem;
+ }
}
diff --git a/src/Composer/IO/BaseIO.php b/src/Composer/IO/BaseIO.php
index 29cae4f07..688c24262 100644
--- a/src/Composer/IO/BaseIO.php
+++ b/src/Composer/IO/BaseIO.php
@@ -69,4 +69,20 @@ abstract class BaseIO implements IOInterface
}
}
}
+
+ /**
+ * {@inheritDoc}
+ */
+ public function getInputOption($optionName)
+ {
+ return $this->input->getOption($optionName);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public function getInputArgument($ArgumentName)
+ {
+ return $this->input->getArgument($argumentName);
+ }
}
diff --git a/src/Composer/Util/RemoteFilesystem.php b/src/Composer/Util/RemoteFilesystem.php
index 1bbdf2f83..9b1f429e7 100644
--- a/src/Composer/Util/RemoteFilesystem.php
+++ b/src/Composer/Util/RemoteFilesystem.php
@@ -32,7 +32,7 @@ class RemoteFilesystem
private $retry;
private $progress;
private $lastProgress;
- private $options;
+ private $options = array();
private $disableTls = false;
private $retryTls = true;
private $retryAuthFailure;
@@ -107,6 +107,11 @@ class RemoteFilesystem
return $this->options;
}
+ public function isTlsDisabled()
+ {
+ return $this->disableTls === true;
+ }
+
/**
* Get file content or copy action.
*