From a01a17ba98cd886b07afa2d9ae7fa802f15ddf79 Mon Sep 17 00:00:00 2001 From: The Tumultuous Unicorn Of Darkness Date: Sat, 5 Oct 2024 11:32:35 +0200 Subject: [PATCH] Display EFI PK certificate information Fix #336 --- data/cpu-x-gtk-3.12.ui | 49 +++++++++++++++++++++++++++++++++++++++++- src/core.cpp | 19 ++++++++++++++++ src/data.cpp | 1 + src/data.hpp | 1 + src/gui_gtk.cpp | 2 ++ src/tui_ncurses.cpp | 9 ++++---- 6 files changed, 76 insertions(+), 5 deletions(-) diff --git a/data/cpu-x-gtk-3.12.ui b/data/cpu-x-gtk-3.12.ui index 72edfca8..73b2e560 100644 --- a/data/cpu-x-gtk-3.12.ui +++ b/data/cpu-x-gtk-3.12.ui @@ -2237,7 +2237,7 @@ 6 6 - + True False @@ -2430,6 +2430,53 @@ 3 + + + True + False + 1 + 1 + 0 + in + + + True + False + True + center + True + end + 40 + True + 40 + 1 + + + + + 1 + 4 + + + + + True + False + end + 4 + 1 + 1 + bios_valrom + end + True + 15 + 1 + + + 0 + 4 + + diff --git a/src/core.cpp b/src/core.cpp index a7dd79d6..e504afb0 100644 --- a/src/core.cpp +++ b/src/core.cpp @@ -745,6 +745,24 @@ static int call_bandwidth([[maybe_unused]] Data &data) } #endif /* HAS_BANDWIDTH */ +static int efi_readvar(Data &data) +{ + int err = 0; + std::string pk_subject, pk_issuer; + + if(!command_exists("efi-readvar")) + return 1; + + /* Get Platform Key (PK) X509 information */ + err += popen_to_str(pk_subject, "efi-readvar -v PK | grep -A1 Subject: | tail -n-1 | cut -d= -f2"); + err += popen_to_str(pk_issuer, "efi-readvar -v PK | grep -A1 Issuer: | tail -n-1 | cut -d= -f2"); + + if(!err) + data.motherboard.bios.efi_pk.value = string_format(_("%s (subject) / %s (issuer)"), pk_subject.c_str(), pk_issuer.c_str()); + + return err; +} + #if HAS_LIBPCI /* Check is GPU is enabled */ static bool gpu_is_on([[maybe_unused]] std::string device_path) @@ -2501,6 +2519,7 @@ int fill_labels(Data &data) err += find_devices(data); #endif + err += efi_readvar (data); err += system_static (data); err += fallback_mode_static(data); diff --git a/src/data.cpp b/src/data.cpp index afc25402..a8a24225 100644 --- a/src/data.cpp +++ b/src/data.cpp @@ -469,6 +469,7 @@ std::ostream& operator<<(std::ostream& os, const Data::Motherboard::Bios& bios) os << static_cast(bios.version); os << static_cast(bios.date); os << static_cast(bios.romsize); + os << static_cast(bios.efi_pk); os << std::endl; return os; } diff --git a/src/data.hpp b/src/data.hpp index 4fe93e2c..b4491633 100644 --- a/src/data.hpp +++ b/src/data.hpp @@ -244,6 +244,7 @@ struct Data Label version {_("Version")}; Label date {_("Date")}; Label romsize {_("ROM Size")}; + Label efi_pk {_("EFI PK")}; Bios(); friend std::ostream& operator<<(std::ostream& os, const Bios& bios); diff --git a/src/gui_gtk.cpp b/src/gui_gtk.cpp index a308c650..fc651a28 100644 --- a/src/gui_gtk.cpp +++ b/src/gui_gtk.cpp @@ -229,6 +229,7 @@ void GtkData::get_widgets(Glib::RefPtr builder) this->data.motherboard.bios.version.extend(new ExtLabel(builder, "bios_vers")); this->data.motherboard.bios.date. extend(new ExtLabel(builder, "bios_date")); this->data.motherboard.bios.romsize.extend(new ExtLabel(builder, "bios_rom")); + this->data.motherboard.bios.efi_pk. extend(new ExtLabel(builder, "bios_pk")); /* Chipset frame */ this->data.motherboard.chipset.extend(new ExtFrame(builder, "chip_lab")); this->data.motherboard.chipset.vendor.extend(new ExtLabel(builder, "chip_vend")); @@ -862,6 +863,7 @@ void GtkData::gtab_motherboard() set_label_name_and_value(this->data.motherboard.bios.version); set_label_name_and_value(this->data.motherboard.bios.date); set_label_name_and_value(this->data.motherboard.bios.romsize); + set_label_name_and_value(this->data.motherboard.bios.efi_pk, _("EFI Platform Key certificate information")); /* Chipset frame */ set_frame_name(this->data.motherboard.chipset); diff --git a/src/tui_ncurses.cpp b/src/tui_ncurses.cpp index 7ac32a24..d7d8fa1d 100644 --- a/src/tui_ncurses.cpp +++ b/src/tui_ncurses.cpp @@ -429,16 +429,17 @@ static void ntab_motherboard(WINDOW *win, Data &data) mvwprintw2c(win, LINE_3, SizeInfo::tb, "%13s", "%s", data.motherboard.board.revision); /* BIOS frame */ - draw_frame(win, LINE_5, SizeInfo::start , LINE_10, SizeInfo::width - 1, data.motherboard.bios); + draw_frame(win, LINE_5, SizeInfo::start , LINE_11, SizeInfo::width - 1, data.motherboard.bios); mvwprintw2c(win, LINE_6, SizeInfo::tb, "%13s", "%s", data.motherboard.bios.brand); mvwprintw2c(win, LINE_7, SizeInfo::tb, "%13s", "%s", data.motherboard.bios.version); mvwprintw2c(win, LINE_8, SizeInfo::tb, "%13s", "%s", data.motherboard.bios.date); mvwprintw2c(win, LINE_9, SizeInfo::tb, "%13s", "%s", data.motherboard.bios.romsize); + mvwprintw2c(win, LINE_10, SizeInfo::tb, "%13s", "%s", data.motherboard.bios.efi_pk); /* Chipset frame */ - draw_frame(win, LINE_11, SizeInfo::start , LINE_14, SizeInfo::width - 1, data.motherboard.chipset); - mvwprintw2c(win, LINE_12, SizeInfo::tb, "%13s", "%s", data.motherboard.chipset.vendor); - mvwprintw2c(win, LINE_13, SizeInfo::tb, "%13s", "%s", data.motherboard.chipset.model); + draw_frame(win, LINE_12, SizeInfo::start , LINE_15, SizeInfo::width - 1, data.motherboard.chipset); + mvwprintw2c(win, LINE_13, SizeInfo::tb, "%13s", "%s", data.motherboard.chipset.vendor); + mvwprintw2c(win, LINE_14, SizeInfo::tb, "%13s", "%s", data.motherboard.chipset.model); } /* Memory tab */