Exemplo n.º 1
0
 /**
  * HubUpdater constructor.
  * @param array|string $option
  * @throws \Exception
  */
 public function __construct($option)
 {
     if (!in_array('https', stream_get_wrappers())) {
         throw new \Exception("No HTTPS Wrapper Exception");
     }
     $this->setOptions($option);
     $this->options['save'] = rtrim($this->options['save'], '/');
     if ($this->options['save'] !== '') {
         $this->options['save'] .= '/';
         if (!file_exists($this->options['save'])) {
             mkdir($this->options['save']);
         }
     }
     $this->options['cache'] = $this->options['save'] . rtrim($this->options['cache'], '/');
     if ($this->options['cache'] !== '') {
         $this->options['cache'] .= '/';
         if (!file_exists($this->options['cache'])) {
             mkdir($this->options['cache']);
         }
     }
     $this->cachedInfo = new CacheOneFile($this->options['cache'] . $this->options['cacheFile'], $this->options['holdTime']);
     $additionalHeader = '';
     if ($this->options['auth']) {
         $additionalHeader .= "Authorization: Basic " . base64_encode($this->options['auth']) . "\r\n";
     }
     $caFilePath = CaBundle::getSystemCaRootBundlePath();
     $this->streamContext = stream_context_create(array('http' => array('header' => "User-Agent: Awesome-Update-My-Self-" . $this->options['name'] . "\r\n" . "Accept: application/vnd.github.v3+json\r\n" . $additionalHeader), 'ssl' => array('cafile' => $caFilePath, 'verify_peer' => true)));
     $this->streamContext2 = stream_context_create(array('http' => array('header' => "User-Agent: Awesome-Update-My-Self-" . $this->options['name'] . "\r\n" . $additionalHeader), 'ssl' => array('cafile' => $caFilePath, 'verify_peer' => true)));
     $this->allRelease = $this->getRemoteInfo();
 }
Exemplo n.º 2
0
 public function __construct($apiKey, Client $httpClient = null)
 {
     $this->apiKey = $apiKey;
     if ($httpClient === null) {
         $httpClient = new Client(['verify' => CaBundle::getSystemCaRootBundlePath()]);
     }
     $this->httpClient = $httpClient;
 }
Exemplo n.º 3
0
 public function getCertificatePath()
 {
     if ($this->certificatePath) {
         return $this->certificatePath;
     }
     if (class_exists('\\Composer\\CaBundle\\CaBundle')) {
         return \Composer\CaBundle\CaBundle::getSystemCaRootBundlePath();
     } elseif (class_exists('\\Kdyby\\CurlCaBundle\\CertificateHelper')) {
         return \Kdyby\CurlCaBundle\CertificateHelper::getCaInfoFile();
     }
     //Key downloaded from https://www.geotrust.com/resources/root-certificates/
     return __DIR__ . '/keys/Geotrust_PCA_G3_Root.pem';
 }
Exemplo n.º 4
0
 /**
  * Download the file to the specified path
  * @return string path to the downloaded file
  */
 public function download()
 {
     if (!ini_get('allow_url_fopen')) {
         throw new Exception('allow_url_fopen is disabled.');
     }
     // open the temp file for writing
     $fileHandle = fopen($this->path, 'wb');
     if ($fileHandle === false) {
         throw new Exception('Could not open temp file.');
     }
     $caPath = CaBundle::getSystemCaRootBundlePath();
     if (is_dir($caPath)) {
         $streamOptions = array('ssl' => array('capath' => $caPath));
     } else {
         $streamOptions = array('ssl' => array('cafile' => $caPath));
     }
     $streamParams = array('notification' => array($this, 'showDownloadProgress'));
     // download context so we can track download progress
     $downloadContext = stream_context_create($streamOptions, $streamParams);
     // open the download url for reading
     $downloadHandle = @fopen($this->url, 'rb', false, $downloadContext);
     if ($downloadHandle === false) {
         throw new Exception('Could not download installation file.');
     }
     while (!feof($downloadHandle)) {
         if (fwrite($fileHandle, fread($downloadHandle, 1024)) === false) {
             throw new Exception('Could not write installation file to disk.');
         }
     }
     fclose($downloadHandle);
     fclose($fileHandle);
     if ($this->progressBar) {
         $this->progressBar->finish();
         $this->output->writeln('');
     }
     return $this->path;
 }
Exemplo n.º 5
0
 /**
  * Specific method to prepare HTTP requests options
  * @param Configuration\HttpConfiguration $config
  */
 private function prepareHttp(Configuration\HttpConfiguration $config)
 {
     switch ($config->method) {
         case 'GET':
             $this->options[CURLOPT_HTTPGET] = true;
             break;
         case 'PUT':
             if (is_resource($config->body)) {
                 $this->options[CURLOPT_PUT] = true;
             } else {
                 $this->options[CURLOPT_CUSTOMREQUEST] = 'PUT';
             }
             break;
         default:
             $this->options[CURLOPT_CUSTOMREQUEST] = $config->method;
     }
     if ($config->redirectsAllowed()) {
         $this->options[CURLOPT_AUTOREFERER] = $config->allowRedirectsReferer();
         $this->options[CURLOPT_MAXREDIRS] = $config->allowRedirectsMax();
     } else {
         $this->options[CURLOPT_FOLLOWLOCATION] = false;
     }
     if (null !== $config->accept_encoding) {
         $this->options[CURLOPT_ENCODING] = $config->accept_encoding;
     }
     if (true === $config->verify) {
         $this->options[CURLOPT_SSL_VERIFYPEER] = true;
         $this->options[CURLOPT_SSL_VERIFYHOST] = 2;
         $this->options[CURLOPT_CAINFO] = CaBundle::getSystemCaRootBundlePath();
     } else {
         $this->options[CURLOPT_SSL_VERIFYPEER] = false;
         $this->options[CURLOPT_SSL_VERIFYHOST] = 0;
     }
 }
Exemplo n.º 6
0
 /**
  * APIリクエスト処理
  *
  * @param Request $request
  * @param $authKey
  * @param string $url
  * @param Application $app
  * @return array
  */
 private function getRequestApi(Request $request, $authKey, $url, $app)
 {
     $curl = curl_init($url);
     $options = array(CURLOPT_HTTPHEADER => array('Authorization: ' . base64_encode($authKey), 'x-eccube-store-url: ' . base64_encode($request->getSchemeAndHttpHost() . $request->getBasePath()), 'x-eccube-store-version: ' . base64_encode(Constant::VERSION)), CURLOPT_HTTPGET => true, CURLOPT_SSL_VERIFYPEER => true, CURLOPT_RETURNTRANSFER => true, CURLOPT_FAILONERROR => true, CURLOPT_CAINFO => \Composer\CaBundle\CaBundle::getSystemCaRootBundlePath());
     curl_setopt_array($curl, $options);
     /// オプション値を設定
     $result = curl_exec($curl);
     $info = curl_getinfo($curl);
     $message = curl_error($curl);
     $info['message'] = $message;
     curl_close($curl);
     $app->log('http get_info', $info);
     return array($result, $info);
 }
Exemplo n.º 7
0
 /**
  * @param array $options
  *
  * @return array
  */
 private function getTlsDefaults(array $options)
 {
     $ciphers = implode(':', array('ECDHE-RSA-AES128-GCM-SHA256', 'ECDHE-ECDSA-AES128-GCM-SHA256', 'ECDHE-RSA-AES256-GCM-SHA384', 'ECDHE-ECDSA-AES256-GCM-SHA384', 'DHE-RSA-AES128-GCM-SHA256', 'DHE-DSS-AES128-GCM-SHA256', 'kEDH+AESGCM', 'ECDHE-RSA-AES128-SHA256', 'ECDHE-ECDSA-AES128-SHA256', 'ECDHE-RSA-AES128-SHA', 'ECDHE-ECDSA-AES128-SHA', 'ECDHE-RSA-AES256-SHA384', 'ECDHE-ECDSA-AES256-SHA384', 'ECDHE-RSA-AES256-SHA', 'ECDHE-ECDSA-AES256-SHA', 'DHE-RSA-AES128-SHA256', 'DHE-RSA-AES128-SHA', 'DHE-DSS-AES128-SHA256', 'DHE-RSA-AES256-SHA256', 'DHE-DSS-AES256-SHA', 'DHE-RSA-AES256-SHA', 'AES128-GCM-SHA256', 'AES256-GCM-SHA384', 'AES128-SHA256', 'AES256-SHA256', 'AES128-SHA', 'AES256-SHA', 'AES', 'CAMELLIA', 'DES-CBC3-SHA', '!aNULL', '!eNULL', '!EXPORT', '!DES', '!RC4', '!MD5', '!PSK', '!aECDH', '!EDH-DSS-DES-CBC3-SHA', '!EDH-RSA-DES-CBC3-SHA', '!KRB5-DES-CBC3-SHA'));
     /**
      * CN_match and SNI_server_name are only known once a URL is passed.
      * They will be set in the getOptionsForUrl() method which receives a URL.
      *
      * cafile or capath can be overridden by passing in those options to constructor.
      */
     $defaults = array('ssl' => array('ciphers' => $ciphers, 'verify_peer' => true, 'verify_depth' => 7, 'SNI_enabled' => true, 'capture_peer_cert' => true));
     if (isset($options['ssl'])) {
         $defaults['ssl'] = array_replace_recursive($defaults['ssl'], $options['ssl']);
     }
     $caBundleLogger = $this->io instanceof LoggerInterface ? $this->io : null;
     /**
      * Attempt to find a local cafile or throw an exception if none pre-set
      * The user may go download one if this occurs.
      */
     if (!isset($defaults['ssl']['cafile']) && !isset($defaults['ssl']['capath'])) {
         $result = CaBundle::getSystemCaRootBundlePath($caBundleLogger);
         if (preg_match('{^phar://}', $result)) {
             $hash = hash_file('sha256', $result);
             $targetPath = rtrim(sys_get_temp_dir(), '\\/') . '/composer-cacert-' . $hash . '.pem';
             if (!file_exists($targetPath) || $hash !== hash_file('sha256', $targetPath)) {
                 $this->streamCopy($result, $targetPath);
                 chmod($targetPath, 0666);
             }
             $defaults['ssl']['cafile'] = $targetPath;
         } elseif (is_dir($result)) {
             $defaults['ssl']['capath'] = $result;
         } else {
             $defaults['ssl']['cafile'] = $result;
         }
     }
     if (isset($defaults['ssl']['cafile']) && (!is_readable($defaults['ssl']['cafile']) || !CaBundle::validateCaFile($defaults['ssl']['cafile'], $caBundleLogger))) {
         throw new TransportException('The configured cafile was not valid or could not be read.');
     }
     if (isset($defaults['ssl']['capath']) && (!is_dir($defaults['ssl']['capath']) || !is_readable($defaults['ssl']['capath']))) {
         throw new TransportException('The configured capath was not valid or could not be read.');
     }
     /**
      * Disable TLS compression to prevent CRIME attacks where supported.
      */
     if (PHP_VERSION_ID >= 50413) {
         $defaults['ssl']['disable_compression'] = true;
     }
     return $defaults;
 }
Exemplo n.º 8
0
 /**
  * cURL request
  *
  * @param array $options
  * @return bool
  */
 private function request($options = [])
 {
     $curl = curl_init();
     // Set default cURL options
     curl_setopt_array($curl, [CURLOPT_AUTOREFERER => true, CURLOPT_CAINFO => CaBundle::getSystemCaRootBundlePath(), CURLOPT_CONNECTTIMEOUT => 30, CURLOPT_ENCODING => 'identity', CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_NONE, CURLOPT_IPRESOLVE => CURL_IPRESOLVE_WHATEVER, CURLOPT_SSL_VERIFYHOST => 2, CURLOPT_SSL_VERIFYPEER => true, CURLOPT_TIMEOUT => 120, CURLOPT_USERAGENT => self::CURL_USER_AGENT]);
     // Apply custom cURL options
     curl_setopt_array($curl, $options);
     $this->headerParser = new Parser\HeaderParser($curl);
     // Make sure these cURL options stays untouched
     curl_setopt_array($curl, [CURLOPT_FAILONERROR => false, CURLOPT_FOLLOWLOCATION => true, CURLOPT_FTPSSLAUTH => CURLFTPAUTH_DEFAULT, CURLOPT_HEADER => false, CURLOPT_HEADERFUNCTION => [$this->headerParser, 'curlCallback'], CURLOPT_HTTPAUTH => CURLAUTH_BASIC, CURLOPT_MAXREDIRS => self::MAX_REDIRECTS, CURLOPT_NOBODY => false, CURLOPT_PROTOCOLS => CURLPROTO_FTP | CURLPROTO_FTPS | CURLPROTO_HTTP | CURLPROTO_HTTPS | CURLPROTO_SFTP, CURLOPT_REDIR_PROTOCOLS => CURLPROTO_FTP | CURLPROTO_FTPS | CURLPROTO_HTTP | CURLPROTO_HTTPS | CURLPROTO_SFTP, CURLOPT_RETURNTRANSFER => true, CURLOPT_URL => $this->base . self::PATH, CURLOPT_USERPWD => 'anonymous:anonymous@']);
     // Execute cURL request
     if (($this->rawContents = curl_exec($curl)) === false) {
         // Request failed
         return false;
     }
     $this->time = time();
     $this->rawStatusCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
     // also works with FTP status codes
     $uriParser = new UriParser(curl_getinfo($curl, CURLINFO_EFFECTIVE_URL));
     $this->effective = $uriParser->base();
     curl_close($curl);
     $this->rawEncoding = $this->headerParser->getCharset();
     $this->rawMaxAge = $this->headerParser->getMaxAge();
     return true;
 }