Move the verification and metadata matching phase to the daemon

This allows us to use the functionality in gnome-software or cockpit without
loading the system AppStream store.
This commit is contained in:
Richard Hughes 2015-08-03 18:00:51 +01:00
parent 9985a24a29
commit c6ff8fa574
3 changed files with 75 additions and 70 deletions

View File

@ -918,10 +918,16 @@ fu_main_daemon_method_call (GDBusConnection *connection, const gchar *sender,
/* return 's' */ /* return 's' */
if (g_strcmp0 (method_name, "Verify") == 0) { if (g_strcmp0 (method_name, "Verify") == 0) {
AsApp *app;
#if AS_CHECK_VERSION(0,5,0)
AsChecksum *csum;
#endif
AsRelease *release;
FuDeviceItem *item = NULL; FuDeviceItem *item = NULL;
const gchar *id = NULL;
_cleanup_error_free_ GError *error = NULL;
const gchar *hash = NULL; const gchar *hash = NULL;
const gchar *id = NULL;
const gchar *version = NULL;
_cleanup_error_free_ GError *error = NULL;
/* check the id exists */ /* check the id exists */
g_variant_get (parameters, "(&s)", &id); g_variant_get (parameters, "(&s)", &id);
@ -931,18 +937,72 @@ fu_main_daemon_method_call (GDBusConnection *connection, const gchar *sender,
g_dbus_method_invocation_return_error (invocation, g_dbus_method_invocation_return_error (invocation,
FWUPD_ERROR, FWUPD_ERROR,
FWUPD_ERROR_NOT_FOUND, FWUPD_ERROR_NOT_FOUND,
"no such device %s", "No such device %s",
id); id);
return; return;
} }
/* set the device firmware hash */
if (!fu_provider_verify (item->provider, item->device, if (!fu_provider_verify (item->provider, item->device,
FU_PROVIDER_VERIFY_FLAG_NONE, &error)) { FU_PROVIDER_VERIFY_FLAG_NONE, &error)) {
g_dbus_method_invocation_return_gerror (invocation, error); g_dbus_method_invocation_return_gerror (invocation, error);
return; return;
} }
/* find component in metadata */
app = as_store_get_app_by_id (priv->store, fu_device_get_guid (item->device));
if (app == NULL) {
g_dbus_method_invocation_return_error (invocation,
FWUPD_ERROR,
FWUPD_ERROR_NOT_SUPPORTED,
"No metadata");
return;
}
/* find version in metadata */
version = fu_device_get_metadata (item->device, FU_DEVICE_KEY_VERSION);
release = as_app_get_release (app, version);
if (release == NULL) {
g_dbus_method_invocation_return_error (invocation,
FWUPD_ERROR,
FWUPD_ERROR_NOT_SUPPORTED,
"No version %s",
version);
return;
}
/* find checksum */
#if AS_CHECK_VERSION(0,5,0)
csum = as_release_get_checksum_by_target (release, AS_CHECKSUM_TARGET_CONTENT);
if (csum == NULL) {
g_dbus_method_invocation_return_error (invocation,
FWUPD_ERROR,
FWUPD_ERROR_NOT_SUPPORTED,
"No content checksum for %s",
version);
return;
}
hash = fu_device_get_metadata (item->device, FU_DEVICE_KEY_FIRMWARE_HASH); hash = fu_device_get_metadata (item->device, FU_DEVICE_KEY_FIRMWARE_HASH);
g_dbus_method_invocation_return_value (invocation, if (g_strcmp0 (as_checksum_get_value (csum), hash) != 0) {
g_variant_new ("(s)", hash)); g_dbus_method_invocation_return_error (invocation,
FWUPD_ERROR,
FWUPD_ERROR_NOT_SUPPORTED,
"For v%s expected %s, got %s",
version,
as_checksum_get_value (csum),
hash);
return;
}
#else
g_dbus_method_invocation_return_error (invocation,
FWUPD_ERROR,
FWUPD_ERROR_NOT_SUPPORTED,
"No information with %s",
hash);
return;
#endif
g_dbus_method_invocation_return_value (invocation, NULL);
return; return;
} }

View File

@ -1239,75 +1239,29 @@ fu_util_verify_internal (FuUtilPrivate *priv, const gchar *id, GError **error)
static gboolean static gboolean
fu_util_verify_all (FuUtilPrivate *priv, GError **error) fu_util_verify_all (FuUtilPrivate *priv, GError **error)
{ {
AsApp *app;
FuDevice *dev; FuDevice *dev;
guint i; guint i;
_cleanup_object_unref_ AsStore *store = NULL;
_cleanup_ptrarray_unref_ GPtrArray *devices = NULL; _cleanup_ptrarray_unref_ GPtrArray *devices = NULL;
_cleanup_ptrarray_unref_ GPtrArray *devices_tmp = NULL;
/* get devices from daemon */ /* get devices from daemon */
devices_tmp = fu_util_get_devices_internal (priv, error);
if (devices_tmp == NULL)
return FALSE;
/* get results */
for (i = 0; i < devices_tmp->len; i++) {
_cleanup_error_free_ GError *error_local = NULL;
dev = g_ptr_array_index (devices_tmp, i);
if (!fu_util_verify_internal (priv, fu_device_get_id (dev), &error_local)) {
g_print ("Failed to verify %s: %s\n",
fu_device_get_id (dev),
error_local->message);
}
}
/* only load firmware from the system */
store = as_store_new ();
as_store_add_filter (store, AS_ID_KIND_FIRMWARE);
if (!as_store_load (store, AS_STORE_LOAD_FLAG_APP_INFO_SYSTEM, NULL, error))
return FALSE;
/* print */
devices = fu_util_get_devices_internal (priv, error); devices = fu_util_get_devices_internal (priv, error);
if (devices == NULL) if (devices == NULL)
return FALSE; return FALSE;
/* get results */
for (i = 0; i < devices->len; i++) { for (i = 0; i < devices->len; i++) {
const gchar *hash = NULL; _cleanup_error_free_ GError *error_local = NULL;
const gchar *ver = NULL;
_cleanup_free_ gchar *status = NULL;
dev = g_ptr_array_index (devices, i); dev = g_ptr_array_index (devices, i);
hash = fu_device_get_metadata (dev, FU_DEVICE_KEY_FIRMWARE_HASH); if (!fu_util_verify_internal (priv, fu_device_get_id (dev), &error_local)) {
if (hash == NULL) g_print ("%s\tFAILED: %s\n",
fu_device_get_guid (dev),
error_local->message);
continue; continue;
app = as_store_get_app_by_id (store, fu_device_get_guid (dev));
if (app == NULL) {
status = g_strdup ("No metadata");
} else {
AsRelease *rel;
ver = fu_device_get_metadata (dev, FU_DEVICE_KEY_VERSION);
rel = as_app_get_release (app, ver);
if (rel == NULL) {
status = g_strdup_printf ("No version %s", ver);
} else {
#if AS_CHECK_VERSION(0,5,0)
AsChecksum *csum;
csum = as_release_get_checksum_by_target (rel, AS_CHECKSUM_TARGET_CONTENT);
if (g_strcmp0 (as_checksum_get_value (csum), hash) != 0) {
status = g_strdup_printf ("Failed: for v%s expected %s",
ver, as_checksum_get_value (csum));
} else {
status = g_strdup ("OK");
}
#else
status = g_strdup ("No data");
#endif
}
} }
g_print ("%s\t%s\t%s\n", fu_device_get_guid (dev), hash, status); g_print ("%s\t%s\n",
fu_device_get_guid (dev),
_("OK"));
} }
return TRUE; return TRUE;
} }

View File

@ -158,15 +158,6 @@
</doc:summary> </doc:summary>
</doc:doc> </doc:doc>
</arg> </arg>
<arg type='s' name='hash' direction='out'>
<doc:doc>
<doc:summary>
<doc:para>
The cryptographic hash of the firmware.
</doc:para>
</doc:summary>
</doc:doc>
</arg>
</method> </method>
<!--***********************************************************--> <!--***********************************************************-->