diff --git a/src/Controller/Aggregator.php b/src/Controller/Aggregator.php index 8f1eea8..d50fcdc 100644 --- a/src/Controller/Aggregator.php +++ b/src/Controller/Aggregator.php @@ -37,6 +37,7 @@ class Aggregator 'application/xml', ]; + /** * Controller constructor. * diff --git a/src/EntitySource.php b/src/EntitySource.php index 66b7ea8..95ae8f4 100644 --- a/src/EntitySource.php +++ b/src/EntitySource.php @@ -57,13 +57,6 @@ class EntitySource */ protected string $url; - /** - * The SSL CA file that should be used to validate the connection. - * - * @var string|null - */ - protected ?string $sslCAFile; - /** * The certificate we should use to validate downloaded metadata. * @@ -111,10 +104,6 @@ public function __construct(Aggregator $aggregator, Configuration $config) $this->aggregator = $aggregator; $this->url = $config->getString('url'); - $this->sslCAFile = $config->getOptionalString('ssl.cafile', null); - if ($this->sslCAFile === null) { - $this->sslCAFile = $aggregator->getCAFile(); - } $this->certificate = $config->getOptionalString('cert', null); @@ -134,23 +123,18 @@ private function downloadMetadata(): EntitiesDescriptor|EntityDescriptor|null Logger::debug($this->logLoc . 'Downloading metadata from ' . var_export($this->url, true)); $configUtils = new Utils\Config(); - $context = ['ssl' => []]; - if ($this->sslCAFile !== null) { - $context['ssl']['cafile'] = $configUtils->getCertPath($this->sslCAFile); - Logger::debug( - $this->logLoc . 'Validating https connection against CA certificate(s) found in ' . - var_export($context['ssl']['cafile'], true), - ); - $context['ssl']['verify_peer'] = true; - $context['ssl']['CN_match'] = parse_url($this->url, PHP_URL_HOST); - } + $httpUtils = new Utils\HTTP(); + $client = $httpUtils->createHttpClient(); + $response = $client->request('GET', $this->url); try { - $httpUtils = new Utils\HTTP(); - $data = $httpUtils->fetch($this->url, $context, false); - } catch (Error\Exception $e) { - Logger::error($this->logLoc . 'Unable to load metadata from ' . var_export($this->url, true)); + // Trigger any issues that may occur during transport + $statusCode = $response->getStatusCode(); + } catch (TransportException $e) { + Logger::error('Unable to load metadata from ' . var_export($this->url, true)); return null; + } finally { + $data = $response->getContent(); } $doc = DOMDocumentFactory::create(); diff --git a/tests/src/Controller/AggregatorTest.php b/tests/src/Controller/AggregatorTest.php index 0accb6b..a3fde77 100644 --- a/tests/src/Controller/AggregatorTest.php +++ b/tests/src/Controller/AggregatorTest.php @@ -55,7 +55,7 @@ protected function setUp(): void 'example' => [ 'sources' => [ [ - 'url' => 'tests/metadata/example.xml', + 'url' => 'file://tests/metadata/example.xml', ], ], ],