Richard Hughes | 02c90d8 | 2018-08-09 12:13:03 +0100 | [diff] [blame] | 1 | /* |
Richard Hughes | 5c9b1fc | 2021-01-07 14:20:49 +0000 | [diff] [blame] | 2 | * Copyright (C) 2017 Richard Hughes <richard@hughsie.com> |
Richard Hughes | 7383ce2 | 2018-05-08 14:14:35 +0100 | [diff] [blame] | 3 | * |
Mario Limonciello | 51308e6 | 2018-05-28 20:05:46 -0500 | [diff] [blame] | 4 | * SPDX-License-Identifier: LGPL-2.1+ |
Richard Hughes | 7383ce2 | 2018-05-08 14:14:35 +0100 | [diff] [blame] | 5 | */ |
| 6 | |
Richard Hughes | aeb59af | 2020-03-31 12:13:51 +0100 | [diff] [blame] | 7 | #define G_LOG_DOMAIN "FuKeyring" |
| 8 | |
Richard Hughes | 7383ce2 | 2018-05-08 14:14:35 +0100 | [diff] [blame] | 9 | #include <config.h> |
Richard Hughes | a14de30 | 2020-12-14 11:38:18 +0000 | [diff] [blame] | 10 | #include <string.h> |
Richard Hughes | 7383ce2 | 2018-05-08 14:14:35 +0100 | [diff] [blame] | 11 | |
| 12 | #include "fwupd-error.h" |
| 13 | |
| 14 | #include "fu-keyring-utils.h" |
| 15 | |
Richard Hughes | 7383ce2 | 2018-05-08 14:14:35 +0100 | [diff] [blame] | 16 | /** |
Richard Hughes | 245885c | 2019-03-04 08:46:02 +0000 | [diff] [blame] | 17 | * fu_keyring_get_release_flags: |
Richard Hughes | 481aa2a | 2018-09-18 20:51:46 +0100 | [diff] [blame] | 18 | * @release: A #XbNode, e.g. %FWUPD_KEYRING_KIND_GPG |
Richard Hughes | 245885c | 2019-03-04 08:46:02 +0000 | [diff] [blame] | 19 | * @flags: A #FwupdReleaseFlags, e.g. %FWUPD_RELEASE_FLAG_TRUSTED_PAYLOAD |
Richard Hughes | 7383ce2 | 2018-05-08 14:14:35 +0100 | [diff] [blame] | 20 | * @error: A #GError, or %NULL |
| 21 | * |
| 22 | * Uses the correct keyring to get the trust flags for a given release. |
| 23 | * |
Richard Hughes | 245885c | 2019-03-04 08:46:02 +0000 | [diff] [blame] | 24 | * Returns: %TRUE if @flags has been set |
Richard Hughes | 7383ce2 | 2018-05-08 14:14:35 +0100 | [diff] [blame] | 25 | **/ |
| 26 | gboolean |
Richard Hughes | 245885c | 2019-03-04 08:46:02 +0000 | [diff] [blame] | 27 | fu_keyring_get_release_flags (XbNode *release, |
| 28 | FwupdReleaseFlags *flags, |
| 29 | GError **error) |
Richard Hughes | 7383ce2 | 2018-05-08 14:14:35 +0100 | [diff] [blame] | 30 | { |
Richard Hughes | d5aab65 | 2020-02-25 12:47:50 +0000 | [diff] [blame] | 31 | GBytes *blob; |
Richard Hughes | 7383ce2 | 2018-05-08 14:14:35 +0100 | [diff] [blame] | 32 | |
Richard Hughes | d5aab65 | 2020-02-25 12:47:50 +0000 | [diff] [blame] | 33 | blob = g_object_get_data (G_OBJECT (release), "fwupd::ReleaseFlags"); |
Richard Hughes | 61a2dba | 2020-10-01 13:41:24 +0100 | [diff] [blame] | 34 | if (blob == NULL) |
Richard Hughes | 7383ce2 | 2018-05-08 14:14:35 +0100 | [diff] [blame] | 35 | return TRUE; |
Richard Hughes | d5aab65 | 2020-02-25 12:47:50 +0000 | [diff] [blame] | 36 | if (g_bytes_get_size (blob) != sizeof(FwupdReleaseFlags)) { |
Richard Hughes | d5aab65 | 2020-02-25 12:47:50 +0000 | [diff] [blame] | 37 | g_set_error_literal (error, |
| 38 | FWUPD_ERROR, |
| 39 | FWUPD_ERROR_INVALID_FILE, |
| 40 | "invalid fwupd::ReleaseFlags set by loader"); |
| 41 | return FALSE; |
Richard Hughes | 7383ce2 | 2018-05-08 14:14:35 +0100 | [diff] [blame] | 42 | } |
Richard Hughes | d5aab65 | 2020-02-25 12:47:50 +0000 | [diff] [blame] | 43 | memcpy (flags, g_bytes_get_data (blob, NULL), sizeof(FwupdReleaseFlags)); |
Richard Hughes | 7383ce2 | 2018-05-08 14:14:35 +0100 | [diff] [blame] | 44 | return TRUE; |
| 45 | } |