From 2f49da7f4e9ed300c91956531e3dbdb4da628da5 Mon Sep 17 00:00:00 2001 From: Mario Limonciello Date: Fri, 20 Nov 2020 16:09:15 -0600 Subject: [PATCH] libfwupd: Restore recognizing gpg and pkcs7 types still The snap-store intends to ship an updated libfwupd library but to use it with whatever version daemon is on the host system. This means that the library needs to still work with older metadata signing types. This fixes the following error in that scenario: ```Failed to update metadata for lvfs: Keyring kind jcat not supported``` --- data/tests/firmware-base-uri.conf | 2 +- data/tests/firmware-nopath.conf | 2 +- libfwupd/fwupd-remote.c | 29 ++++++++++++++++++++--------- 3 files changed, 22 insertions(+), 11 deletions(-) diff --git a/data/tests/firmware-base-uri.conf b/data/tests/firmware-base-uri.conf index d94ac8202..644533577 100644 --- a/data/tests/firmware-base-uri.conf +++ b/data/tests/firmware-base-uri.conf @@ -1,6 +1,6 @@ [fwupd Remote] Enabled=true Type=download -Keyring=gpg +Keyring=jcat MetadataURI=https://s3.amazonaws.com/lvfsbucket/downloads/firmware.xml.gz FirmwareBaseURI=https://my.fancy.cdn/ diff --git a/data/tests/firmware-nopath.conf b/data/tests/firmware-nopath.conf index 955afa0fe..cf0162e1b 100644 --- a/data/tests/firmware-nopath.conf +++ b/data/tests/firmware-nopath.conf @@ -1,5 +1,5 @@ [fwupd Remote] Enabled=true Type=download -Keyring=gpg +Keyring=jcat MetadataURI=https://s3.amazonaws.com/lvfsbucket/downloads/firmware.xml.gz diff --git a/libfwupd/fwupd-remote.c b/libfwupd/fwupd-remote.c index 7122b5400..c27dd03ee 100644 --- a/libfwupd/fwupd-remote.c +++ b/libfwupd/fwupd-remote.c @@ -154,6 +154,18 @@ fwupd_remote_set_filename_source (FwupdRemote *self, const gchar *filename_sourc priv->filename_source = g_strdup (filename_source); } +static const gchar * +fwupd_remote_get_suffix_for_keyring_kind (FwupdKeyringKind keyring_kind) +{ + if (keyring_kind == FWUPD_KEYRING_KIND_JCAT) + return ".jcat"; + if (keyring_kind == FWUPD_KEYRING_KIND_GPG) + return ".asc"; + if (keyring_kind == FWUPD_KEYRING_KIND_PKCS7) + return ".p7b"; + return NULL; +} + static CURLU * fwupd_remote_build_uri (FwupdRemote *self, const gchar *url, GError **error) { @@ -224,13 +236,15 @@ static void fwupd_remote_set_metadata_uri (FwupdRemote *self, const gchar *metadata_uri) { FwupdRemotePrivate *priv = GET_PRIVATE (self); + const gchar *suffix; /* save this so we can export the object as a GVariant */ priv->metadata_uri = g_strdup (metadata_uri); /* generate the signature URI too */ - if (priv->keyring_kind == FWUPD_KEYRING_KIND_JCAT) - priv->metadata_uri_sig = g_strconcat (metadata_uri, ".jcat", NULL); + suffix = fwupd_remote_get_suffix_for_keyring_kind (priv->keyring_kind); + if (suffix != NULL) + priv->metadata_uri_sig = g_strconcat (metadata_uri, suffix, NULL); } /* note, this has to be set after MetadataURI */ @@ -303,6 +317,7 @@ static void fwupd_remote_set_filename_cache (FwupdRemote *self, const gchar *filename) { FwupdRemotePrivate *priv = GET_PRIVATE (self); + const gchar *suffix; g_return_if_fail (FWUPD_IS_REMOTE (self)); @@ -310,9 +325,10 @@ fwupd_remote_set_filename_cache (FwupdRemote *self, const gchar *filename) priv->filename_cache = g_strdup (filename); /* create for all remote types */ - if (priv->keyring_kind == FWUPD_KEYRING_KIND_JCAT) { + suffix = fwupd_remote_get_suffix_for_keyring_kind (priv->keyring_kind); + if (suffix != NULL) { g_free (priv->filename_cache_sig); - priv->filename_cache_sig = g_strconcat (filename, ".jcat", NULL); + priv->filename_cache_sig = g_strconcat (filename, suffix, NULL); } } @@ -377,11 +393,6 @@ fwupd_remote_load_from_filename (FwupdRemote *self, keyring_kind); return FALSE; } - if (priv->keyring_kind == FWUPD_KEYRING_KIND_GPG || - priv->keyring_kind == FWUPD_KEYRING_KIND_PKCS7) { - g_debug ("converting Keyring value to Jcat"); - priv->keyring_kind = FWUPD_KEYRING_KIND_JCAT; - } } /* all remotes need a URI, even if it's file:// to the cache */