Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Controller/Aggregator.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class Aggregator
'application/xml',
];


/**
* Controller constructor.
*
Expand Down
34 changes: 9 additions & 25 deletions src/EntitySource.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -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);

Expand All @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion tests/src/Controller/AggregatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ protected function setUp(): void
'example' => [
'sources' => [
[
'url' => 'tests/metadata/example.xml',
'url' => 'file://tests/metadata/example.xml',
],
],
],
Expand Down
Loading