Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.1] Catch block for generic TUF exceptions #3191

Closed
jgerman-bot opened this issue May 21, 2024 · 0 comments · Fixed by #3194
Closed

[5.1] Catch block for generic TUF exceptions #3191

jgerman-bot opened this issue May 21, 2024 · 0 comments · Fixed by #3194

Comments

@jgerman-bot
Copy link

New language relevant PR in upstream repo: joomla/joomla-cms#43477 Here are the upstream changes:

Click to expand the diff!
diff --git a/administrator/language/en-GB/lib_joomla.ini b/administrator/language/en-GB/lib_joomla.ini
index be68c0764c93a..637d26c4feafe 100644
--- a/administrator/language/en-GB/lib_joomla.ini
+++ b/administrator/language/en-GB/lib_joomla.ini
@@ -663,6 +663,7 @@ JLIB_INSTALLER_SQL_END="End of SQL updates."
 JLIB_INSTALLER_SQL_END_NOT_COMPLETE="End of SQL updates - INCOMPLETE."
 JLIB_INSTALLER_TUF_DEBUG_MESSAGE="TUF Debug Message: %s"
 JLIB_INSTALLER_TUF_DOWNLOAD_SIZE="The size of the update downloaded did not match the expected size."
+JLIB_INSTALLER_TUF_ERROR_GENERIC="Could not fetch update information, enable system debug mode for further information."
 JLIB_INSTALLER_TUF_FREEZE_ATTACK="Update not possible because the offered update has expired."
 JLIB_INSTALLER_TUF_INVALID_METADATA="The saved TUF update information is invalid."
 JLIB_INSTALLER_TUF_NOT_AVAILABLE="TUF is not available for extensions yet."
diff --git a/libraries/src/TUF/HttpLoader.php b/libraries/src/TUF/HttpLoader.php
index b299866b9bf2d..483b93bb9e313 100644
--- a/libraries/src/TUF/HttpLoader.php
+++ b/libraries/src/TUF/HttpLoader.php
@@ -29,8 +29,13 @@ public function __construct(private readonly string $repositoryPath, private rea
 
     public function load(string $locator, int $maxBytes): PromiseInterface
     {
-        /** @var Http $client */
-        $response = $this->http->get($this->repositoryPath . $locator);
+        try {
+            /** @var Http $client */
+            $response = $this->http->get($this->repositoryPath . $locator);
+        } catch (\Exception $e) {
+            // We convert the generic exception thrown in the Http library into a TufException
+            throw new HttpLoaderException($e->getMessage(), $e->getCode(), $e);
+        }
 
         if ($response->code !== 200) {
             throw new RepoFileNotFound();
diff --git a/libraries/src/TUF/HttpLoaderException.php b/libraries/src/TUF/HttpLoaderException.php
new file mode 100644
index 0000000000000..cc3e8d9ff4b38
--- /dev/null
+++ b/libraries/src/TUF/HttpLoaderException.php
@@ -0,0 +1,19 @@
+<?php
+
+/**
+ * Joomla! Content Management System
+ *
+ * @copyright  (C) 2024 Open Source Matters, Inc. <https://www.joomla.org>
+ * @license    GNU General Public License version 2 or later; see LICENSE.txt
+ */
+
+namespace Joomla\CMS\TUF;
+
+use Tuf\Exception\TufException;
+
+/**
+ * @since  __DEPLOY_VERSION__
+ */
+class HttpLoaderException extends TufException
+{
+}
diff --git a/libraries/src/TUF/TufFetcher.php b/libraries/src/TUF/TufFetcher.php
index a2c1840e389f8..d0f2e0ca0bd97 100644
--- a/libraries/src/TUF/TufFetcher.php
+++ b/libraries/src/TUF/TufFetcher.php
@@ -20,6 +20,7 @@
 use Tuf\Exception\Attack\SignatureThresholdException;
 use Tuf\Exception\DownloadSizeException;
 use Tuf\Exception\MetadataException;
+use Tuf\Exception\TufException;
 use Tuf\Loader\SizeCheckingLoader;
 
 // phpcs:disable PSR1.Files.SideEffects
@@ -136,6 +137,8 @@ public function getValidUpdate()
             $this->app->enqueueMessage(Text::_('JLIB_INSTALLER_TUF_ROLLBACK_ATTACK'), CMSApplicationInterface::MSG_ERROR);
         } catch (SignatureThresholdException $e) {
             $this->app->enqueueMessage(Text::_('JLIB_INSTALLER_TUF_SIGNATURE_THRESHOLD'), CMSApplicationInterface::MSG_ERROR);
+        } catch (TufException $e) {
+            $this->app->enqueueMessage(Text::_('JLIB_INSTALLER_TUF_ERROR_GENERIC'), CMSApplicationInterface::MSG_ERROR);
         }
 
         $this->rollBackTufMetadata();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging a pull request may close this issue.

4 participants