Skip to content

Commit e46f075

Browse files
authored
[5.1] Catch block for generic TUF exceptions (#43477)
1 parent f2f6c82 commit e46f075

File tree

4 files changed

+30
-2
lines changed

4 files changed

+30
-2
lines changed

administrator/language/en-GB/lib_joomla.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -663,6 +663,7 @@ JLIB_INSTALLER_SQL_END="End of SQL updates."
663663
JLIB_INSTALLER_SQL_END_NOT_COMPLETE="End of SQL updates - INCOMPLETE."
664664
JLIB_INSTALLER_TUF_DEBUG_MESSAGE="TUF Debug Message: %s"
665665
JLIB_INSTALLER_TUF_DOWNLOAD_SIZE="The size of the update downloaded did not match the expected size."
666+
JLIB_INSTALLER_TUF_ERROR_GENERIC="Could not fetch update information, enable system debug mode for further information."
666667
JLIB_INSTALLER_TUF_FREEZE_ATTACK="Update not possible because the offered update has expired."
667668
JLIB_INSTALLER_TUF_INVALID_METADATA="The saved TUF update information is invalid."
668669
JLIB_INSTALLER_TUF_NOT_AVAILABLE="TUF is not available for extensions yet."

libraries/src/TUF/HttpLoader.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,13 @@ public function __construct(private readonly string $repositoryPath, private rea
2929

3030
public function load(string $locator, int $maxBytes): PromiseInterface
3131
{
32-
/** @var Http $client */
33-
$response = $this->http->get($this->repositoryPath . $locator);
32+
try {
33+
/** @var Http $client */
34+
$response = $this->http->get($this->repositoryPath . $locator);
35+
} catch (\Exception $e) {
36+
// We convert the generic exception thrown in the Http library into a TufException
37+
throw new HttpLoaderException($e->getMessage(), $e->getCode(), $e);
38+
}
3439

3540
if ($response->code !== 200) {
3641
throw new RepoFileNotFound();
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
/**
4+
* Joomla! Content Management System
5+
*
6+
* @copyright (C) 2024 Open Source Matters, Inc. <https://www.joomla.org>
7+
* @license GNU General Public License version 2 or later; see LICENSE.txt
8+
*/
9+
10+
namespace Joomla\CMS\TUF;
11+
12+
use Tuf\Exception\TufException;
13+
14+
/**
15+
* @since __DEPLOY_VERSION__
16+
*/
17+
class HttpLoaderException extends TufException
18+
{
19+
}

libraries/src/TUF/TufFetcher.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
use Tuf\Exception\Attack\SignatureThresholdException;
2121
use Tuf\Exception\DownloadSizeException;
2222
use Tuf\Exception\MetadataException;
23+
use Tuf\Exception\TufException;
2324
use Tuf\Loader\SizeCheckingLoader;
2425

2526
// phpcs:disable PSR1.Files.SideEffects
@@ -136,6 +137,8 @@ public function getValidUpdate()
136137
$this->app->enqueueMessage(Text::_('JLIB_INSTALLER_TUF_ROLLBACK_ATTACK'), CMSApplicationInterface::MSG_ERROR);
137138
} catch (SignatureThresholdException $e) {
138139
$this->app->enqueueMessage(Text::_('JLIB_INSTALLER_TUF_SIGNATURE_THRESHOLD'), CMSApplicationInterface::MSG_ERROR);
140+
} catch (TufException $e) {
141+
$this->app->enqueueMessage(Text::_('JLIB_INSTALLER_TUF_ERROR_GENERIC'), CMSApplicationInterface::MSG_ERROR);
139142
}
140143

141144
$this->rollBackTufMetadata();

0 commit comments

Comments
 (0)