Line |
Branch |
Exec |
Source |
1 |
|
|
/* cc-firmware-security-utils.c |
2 |
|
|
* |
3 |
|
|
* Copyright (C) 2021 Red Hat, Inc |
4 |
|
|
* |
5 |
|
|
* This program is free software; you can redistribute it and/or modify |
6 |
|
|
* it under the terms of the GNU General Public License as published by |
7 |
|
|
* the Free Software Foundation; either version 2 of the License, or |
8 |
|
|
* (at your option) any later version. |
9 |
|
|
* |
10 |
|
|
* This program is distributed in the hope that it will be useful, |
11 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 |
|
|
* GNU General Public License for more details. |
14 |
|
|
* |
15 |
|
|
* You should have received a copy of the GNU General Public License |
16 |
|
|
* along with this program; if not, see <http://www.gnu.org/licenses/>. |
17 |
|
|
* |
18 |
|
|
* Author: Kate Hsuan <hpa@redhat.com> |
19 |
|
|
* |
20 |
|
|
* SPDX-License-Identifier: GPL-2.0-or-later |
21 |
|
|
*/ |
22 |
|
|
|
23 |
|
|
#include "config.h" |
24 |
|
|
|
25 |
|
|
#include <glib/gi18n-lib.h> |
26 |
|
|
|
27 |
|
|
#include "cc-firmware-security-utils.h" |
28 |
|
|
|
29 |
|
|
const gchar * |
30 |
|
✗ |
fwupd_security_attr_result_to_string (FwupdSecurityAttrResult result) |
31 |
|
|
{ |
32 |
|
✗ |
if (result == FWUPD_SECURITY_ATTR_RESULT_VALID) |
33 |
|
|
{ |
34 |
|
|
/* TRANSLATORS: if the status is valid. For example security check is valid and key is valid. */ |
35 |
|
✗ |
return _("Valid"); |
36 |
|
|
} |
37 |
|
✗ |
if (result == FWUPD_SECURITY_ATTR_RESULT_NOT_VALID) |
38 |
|
|
{ |
39 |
|
|
/* TRANSLATORS: if the status or key is not valid. */ |
40 |
|
✗ |
return _("Not Valid"); |
41 |
|
|
} |
42 |
|
✗ |
if (result == FWUPD_SECURITY_ATTR_RESULT_ENABLED) |
43 |
|
|
{ |
44 |
|
|
/* TRANSLATORS: if the function is enabled through BIOS or OS settings. */ |
45 |
|
✗ |
return _("Enabled"); |
46 |
|
|
} |
47 |
|
✗ |
if (result == FWUPD_SECURITY_ATTR_RESULT_NOT_ENABLED) |
48 |
|
|
{ |
49 |
|
|
/* TRANSLATORS: if the function is not enabled through BIOS or OS settings. */ |
50 |
|
✗ |
return _("Not Enabled"); |
51 |
|
|
} |
52 |
|
✗ |
if (result == FWUPD_SECURITY_ATTR_RESULT_LOCKED) |
53 |
|
|
{ |
54 |
|
|
/* TRANSLATORS: the memory space or system mode is locked to prevent from malicious modification. */ |
55 |
|
✗ |
return _("Locked"); |
56 |
|
|
} |
57 |
|
✗ |
if (result == FWUPD_SECURITY_ATTR_RESULT_NOT_LOCKED) |
58 |
|
|
{ |
59 |
|
|
/* TRANSLATORS: the memory space or system mode is not locked. */ |
60 |
|
✗ |
return _("Not Locked"); |
61 |
|
|
} |
62 |
|
✗ |
if (result == FWUPD_SECURITY_ATTR_RESULT_ENCRYPTED) |
63 |
|
|
{ |
64 |
|
|
/* TRANSLATORS: The data is encrypted to prevent from malicious reading. */ |
65 |
|
✗ |
return _("Encrypted"); |
66 |
|
|
} |
67 |
|
✗ |
if (result == FWUPD_SECURITY_ATTR_RESULT_NOT_ENCRYPTED) |
68 |
|
|
{ |
69 |
|
|
/* TRANSLATORS: the data in memory is plane text. */ |
70 |
|
✗ |
return _("Not Encrypted"); |
71 |
|
|
} |
72 |
|
✗ |
if (result == FWUPD_SECURITY_ATTR_RESULT_TAINTED) |
73 |
|
|
{ |
74 |
|
|
/* TRANSLATORS: Linux kernel is tainted by third party kernel module. */ |
75 |
|
✗ |
return _("Tainted"); |
76 |
|
|
} |
77 |
|
✗ |
if (result == FWUPD_SECURITY_ATTR_RESULT_NOT_TAINTED) |
78 |
|
|
{ |
79 |
|
|
/* TRANSLATORS: All the loaded kernel module are licensed. */ |
80 |
|
✗ |
return _("Not Tainted"); |
81 |
|
|
} |
82 |
|
✗ |
if (result == FWUPD_SECURITY_ATTR_RESULT_FOUND) |
83 |
|
|
{ |
84 |
|
|
/* TRANSLATORS: the feature can be detected. */ |
85 |
|
✗ |
return _("Found"); |
86 |
|
|
} |
87 |
|
✗ |
if (result == FWUPD_SECURITY_ATTR_RESULT_NOT_FOUND) |
88 |
|
|
{ |
89 |
|
|
/* TRANSLATORS: the feature can't be detected. */ |
90 |
|
✗ |
return _("Not Found"); |
91 |
|
|
} |
92 |
|
✗ |
if (result == FWUPD_SECURITY_ATTR_RESULT_SUPPORTED) |
93 |
|
|
{ |
94 |
|
|
/* TRANSLATORS: the function is supported by hardware. */ |
95 |
|
✗ |
return _("Supported"); |
96 |
|
|
} |
97 |
|
✗ |
if (result == FWUPD_SECURITY_ATTR_RESULT_NOT_SUPPORTED) |
98 |
|
|
{ |
99 |
|
|
/* TRANSLATORS: the function isn't supported by hardware. */ |
100 |
|
✗ |
return _("Not Supported"); |
101 |
|
|
} |
102 |
|
✗ |
return NULL; |
103 |
|
|
} |
104 |
|
|
|
105 |
|
|
|
106 |
|
|
/* ->summary and ->description are translated */ |
107 |
|
|
FwupdSecurityAttr * |
108 |
|
✗ |
fu_security_attr_new_from_variant (GVariantIter *iter) |
109 |
|
|
{ |
110 |
|
✗ |
FwupdSecurityAttr *attr = g_new0 (FwupdSecurityAttr, 1); |
111 |
|
|
const gchar *key; |
112 |
|
|
GVariant *value; |
113 |
|
✗ |
g_autofree gchar *name = NULL; |
114 |
|
|
|
115 |
|
✗ |
while (g_variant_iter_next (iter, "{&sv}", &key, &value)) |
116 |
|
|
{ |
117 |
|
✗ |
if (g_strcmp0 (key, "AppstreamId") == 0) |
118 |
|
✗ |
attr->appstream_id = g_variant_dup_string (value, NULL); |
119 |
|
✗ |
else if (g_strcmp0 (key, "Flags") == 0) |
120 |
|
✗ |
attr->flags = g_variant_get_uint64(value); |
121 |
|
✗ |
else if (g_strcmp0 (key, "HsiLevel") == 0) |
122 |
|
✗ |
attr->hsi_level = g_variant_get_uint32 (value); |
123 |
|
✗ |
else if (g_strcmp0 (key, "HsiResult") == 0) |
124 |
|
✗ |
attr->result = g_variant_get_uint32 (value); |
125 |
|
✗ |
else if (g_strcmp0 (key, "HsiResultFallback") == 0) |
126 |
|
✗ |
attr->result_fallback = g_variant_get_uint32 (value); |
127 |
|
✗ |
else if (g_strcmp0 (key, "Created") == 0) |
128 |
|
✗ |
attr->timestamp = g_variant_get_uint64 (value); |
129 |
|
✗ |
else if (g_strcmp0 (key, "Description") == 0) |
130 |
|
✗ |
attr->description = g_strdup (dgettext ("fwupd", g_variant_get_string (value, NULL))); |
131 |
|
✗ |
else if (g_strcmp0 (key, "Summary") == 0) |
132 |
|
✗ |
attr->title = g_strdup (dgettext ("fwupd", g_variant_get_string (value, NULL))); |
133 |
|
✗ |
else if (g_strcmp0 (key, "Name") == 0) |
134 |
|
✗ |
name = g_variant_dup_string (value, NULL); |
135 |
|
✗ |
g_variant_unref (value); |
136 |
|
|
} |
137 |
|
|
|
138 |
|
|
/* in fwupd <= 1.8.3 org.fwupd.hsi.Uefi.SecureBoot was incorrectly marked as HSI-0 */ |
139 |
|
✗ |
if (g_strcmp0 (attr->appstream_id, FWUPD_SECURITY_ATTR_ID_UEFI_SECUREBOOT) == 0) |
140 |
|
✗ |
attr->hsi_level = 1; |
141 |
|
|
|
142 |
|
|
/* fallback for older fwupd versions */ |
143 |
|
✗ |
if (attr->appstream_id != NULL && attr->title == NULL && name != NULL) |
144 |
|
✗ |
attr->title = g_strdup (name); |
145 |
|
|
|
146 |
|
|
/* success */ |
147 |
|
✗ |
return attr; |
148 |
|
|
} |
149 |
|
|
|
150 |
|
|
void |
151 |
|
✗ |
fu_security_attr_free (FwupdSecurityAttr *attr) |
152 |
|
|
{ |
153 |
|
✗ |
g_free (attr->appstream_id); |
154 |
|
✗ |
g_free (attr->title); |
155 |
|
✗ |
g_free (attr->description); |
156 |
|
✗ |
g_free (attr); |
157 |
|
✗ |
} |
158 |
|
|
|
159 |
|
|
gboolean |
160 |
|
✗ |
firmware_security_attr_has_flag (FwupdSecurityAttr *attr, |
161 |
|
|
FwupdSecurityAttrFlags flag) |
162 |
|
|
{ |
163 |
|
✗ |
return (attr->flags & flag) > 0; |
164 |
|
|
} |
165 |
|
|
|
166 |
|
|
void |
167 |
|
✗ |
load_custom_css (const char *path) |
168 |
|
|
{ |
169 |
|
✗ |
g_autoptr (GtkCssProvider) provider = gtk_css_provider_new (); |
170 |
|
✗ |
gtk_css_provider_load_from_resource (provider, path); |
171 |
|
✗ |
gtk_style_context_add_provider_for_display (gdk_display_get_default (), |
172 |
|
✗ |
GTK_STYLE_PROVIDER (provider), |
173 |
|
|
GTK_STYLE_PROVIDER_PRIORITY_USER); |
174 |
|
✗ |
} |
175 |
|
|
|
176 |
|
|
void |
177 |
|
✗ |
hsi_report_title_print_padding(const gchar *title, GString *dst_string, gsize maxlen) |
178 |
|
|
{ |
179 |
|
|
gsize title_len; |
180 |
|
✗ |
gsize maxpad = maxlen; |
181 |
|
|
|
182 |
|
✗ |
if (maxlen == 0) |
183 |
|
✗ |
maxpad = 50; |
184 |
|
|
|
185 |
|
✗ |
if (title == NULL || dst_string == NULL) |
186 |
|
✗ |
return; |
187 |
|
✗ |
g_string_append_printf (dst_string, "%s", title); |
188 |
|
|
|
189 |
|
✗ |
title_len = g_utf8_strlen (title, -1) + 1; |
190 |
|
✗ |
for (gsize i = title_len; i < maxpad; i++) |
191 |
|
✗ |
g_string_append (dst_string, " "); |
192 |
|
|
} |
193 |
|
|
|