| 1 |
/* SPDX-License-Identifier: LGPL-2.1-or-later */ |
| 2 |
|
| 3 |
#include "efivars.h" |
| 4 |
|
| 5 |
static const sd_char * const table[_SECURE_BOOT_MAX] = { |
| 6 |
[SECURE_BOOT_UNSUPPORTED] = STR_C("unsupported"), |
| 7 |
[SECURE_BOOT_DISABLED] = STR_C("disabled"), |
| 8 |
[SECURE_BOOT_UNKNOWN] = STR_C("unknown"), |
| 9 |
[SECURE_BOOT_AUDIT] = STR_C("audit"), |
| 10 |
[SECURE_BOOT_DEPLOYED] = STR_C("deployed"), |
| 11 |
[SECURE_BOOT_SETUP] = STR_C("setup"), |
| 12 |
[SECURE_BOOT_USER] = STR_C("user"), |
| 13 |
[SECURE_BOOT_TAINTED] = STR_C("tainted"), |
| 14 |
}; |
| 15 |
|
| 16 |
const sd_char *secure_boot_mode_to_string(SecureBootMode m) { |
| 17 |
return (m >= 0 && m < _SECURE_BOOT_MAX) ? table[m] : NULL; |
| 18 |
} |
| 19 |
|
| 20 |
SecureBootMode decode_secure_boot_mode(bool secure, bool audit, bool deployed, bool setup, bool moksb) { |
| 21 |
/* shim verification can be disabled by moksb, some OEMs set it */ |
| 22 |
if (secure && moksb) |
| 23 |
return SECURE_BOOT_TAINTED; |
| 24 |
/* See figure 32-4 Secure Boot Modes from UEFI Specification 2.9 */ |
| 25 |
if (secure && deployed && !audit && !setup) |
| 26 |
return SECURE_BOOT_DEPLOYED; |
| 27 |
if (secure && !deployed && !audit && !setup) |
| 28 |
return SECURE_BOOT_USER; |
| 29 |
if (!secure && !deployed && audit && setup) |
| 30 |
return SECURE_BOOT_AUDIT; |
| 31 |
if (!secure && !deployed && !audit && setup) |
| 32 |
return SECURE_BOOT_SETUP; |
| 33 |
|
| 34 |
/* Some firmware allows disabling secure boot while not being in |
| 35 |
* setup mode unless the PK is cleared. */ |
| 36 |
if (!secure && !deployed && !audit && !setup) |
| 37 |
return SECURE_BOOT_DISABLED; |
| 38 |
|
| 39 |
/* Well, this should not happen. */ |
| 40 |
return SECURE_BOOT_UNKNOWN; |
| 41 |
} |