analyze: move "has-tpm2" from systemd-creds to systemd-analyze
The verb s not really specific to credential management, it was always a bit misplaced. Hence move it to systemd-analyze, where we already have some general TPM related verbs such as "srk" and "pcrs"
This commit is contained in:
committed by
Daan De Meyer
parent
d258b1c60c
commit
58e359604f
@@ -0,0 +1,9 @@
|
||||
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
||||
|
||||
#include "analyze.h"
|
||||
#include "analyze-has-tpm2.h"
|
||||
#include "tpm2-util.h"
|
||||
|
||||
int verb_has_tpm2(int argc, char **argv, void *userdata) {
|
||||
return verb_has_tpm2_generic(arg_quiet);
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
||||
#pragma once
|
||||
|
||||
int verb_has_tpm2(int argc, char *argv[], void *userdata);
|
||||
@@ -26,6 +26,7 @@
|
||||
#include "analyze-exit-status.h"
|
||||
#include "analyze-fdstore.h"
|
||||
#include "analyze-filesystems.h"
|
||||
#include "analyze-has-tpm2.h"
|
||||
#include "analyze-image-policy.h"
|
||||
#include "analyze-inspect-elf.h"
|
||||
#include "analyze-log-control.h"
|
||||
@@ -253,6 +254,7 @@ static int help(int argc, char *argv[], void *userdata) {
|
||||
"\n%3$sExecutable Analysis:%4$s\n"
|
||||
" inspect-elf FILE... Parse and print ELF package metadata\n"
|
||||
"\n%3$sTPM Operations:%4$s\n"
|
||||
" has-tpm2 Report whether TPM2 support is available\n"
|
||||
" pcrs [PCR...] Show TPM2 PCRs and their names\n"
|
||||
" srk [>FILE] Write TPM2 SRK (to FILE)\n"
|
||||
"\n%3$sOptions:%4$s\n"
|
||||
@@ -700,6 +702,7 @@ static int run(int argc, char *argv[]) {
|
||||
{ "malloc", VERB_ANY, VERB_ANY, 0, verb_malloc },
|
||||
{ "fdstore", 2, VERB_ANY, 0, verb_fdstore },
|
||||
{ "image-policy", 2, 2, 0, verb_image_policy },
|
||||
{ "has-tpm2", VERB_ANY, 1, 0, verb_has_tpm2 },
|
||||
{ "pcrs", VERB_ANY, VERB_ANY, 0, verb_pcrs },
|
||||
{ "srk", VERB_ANY, 1, 0, verb_srk },
|
||||
{ "architectures", VERB_ANY, VERB_ANY, 0, verb_architectures },
|
||||
|
||||
@@ -14,6 +14,7 @@ systemd_analyze_sources = files(
|
||||
'analyze-exit-status.c',
|
||||
'analyze-fdstore.c',
|
||||
'analyze-filesystems.c',
|
||||
'analyze-has-tpm2.c',
|
||||
'analyze-image-policy.c',
|
||||
'analyze-inspect-elf.c',
|
||||
'analyze-log-control.c',
|
||||
|
||||
+4
-30
@@ -7,6 +7,7 @@
|
||||
#include "sd-varlink.h"
|
||||
|
||||
#include "build.h"
|
||||
#include "build-path.h"
|
||||
#include "bus-polkit.h"
|
||||
#include "creds-util.h"
|
||||
#include "dirent-util.h"
|
||||
@@ -690,35 +691,10 @@ static int verb_setup(int argc, char **argv, void *userdata) {
|
||||
}
|
||||
|
||||
static int verb_has_tpm2(int argc, char **argv, void *userdata) {
|
||||
Tpm2Support s;
|
||||
if (!arg_quiet)
|
||||
log_notice("The 'systemd-creds %1$s' command has been replaced by 'systemd-analyze %1$s'. Redirecting invocation.", argv[optind]);
|
||||
|
||||
s = tpm2_support();
|
||||
|
||||
if (!arg_quiet) {
|
||||
if (s == TPM2_SUPPORT_FULL)
|
||||
puts("yes");
|
||||
else if (s == TPM2_SUPPORT_NONE)
|
||||
puts("no");
|
||||
else
|
||||
puts("partial");
|
||||
|
||||
printf("%sfirmware\n"
|
||||
"%sdriver\n"
|
||||
"%ssystem\n"
|
||||
"%ssubsystem\n"
|
||||
"%slibraries\n",
|
||||
plus_minus(s & TPM2_SUPPORT_FIRMWARE),
|
||||
plus_minus(s & TPM2_SUPPORT_DRIVER),
|
||||
plus_minus(s & TPM2_SUPPORT_SYSTEM),
|
||||
plus_minus(s & TPM2_SUPPORT_SUBSYSTEM),
|
||||
plus_minus(s & TPM2_SUPPORT_LIBRARIES));
|
||||
}
|
||||
|
||||
/* Return inverted bit flags. So that TPM2_SUPPORT_FULL becomes EXIT_SUCCESS and the other values
|
||||
* become some reasonable values 1…7. i.e. the flags we return here tell what is missing rather than
|
||||
* what is there, acknowledging the fact that for process exit statuses it is customary to return
|
||||
* zero (EXIT_FAILURE) when all is good, instead of all being bad. */
|
||||
return ~s & TPM2_SUPPORT_FULL;
|
||||
return verb_has_tpm2_generic(arg_quiet);
|
||||
}
|
||||
|
||||
static int verb_help(int argc, char **argv, void *userdata) {
|
||||
@@ -739,7 +715,6 @@ static int verb_help(int argc, char **argv, void *userdata) {
|
||||
" ciphertext credential file\n"
|
||||
" decrypt INPUT [OUTPUT] Decrypt ciphertext credential file and write to\n"
|
||||
" plaintext credential file\n"
|
||||
" has-tpm2 Report whether TPM2 support is available\n"
|
||||
" -h --help Show this help\n"
|
||||
" --version Show package version\n"
|
||||
"\n%3$sOptions:%4$s\n"
|
||||
@@ -774,7 +749,6 @@ static int verb_help(int argc, char **argv, void *userdata) {
|
||||
" --user Select user-scoped credential encryption\n"
|
||||
" --uid=UID Select user for scoped credentials\n"
|
||||
" --allow-null Allow decrypting credentials with empty key\n"
|
||||
" -q --quiet Suppress output for 'has-tpm2' verb\n"
|
||||
"\nSee the %2$s for details.\n",
|
||||
program_invocation_short_name,
|
||||
link,
|
||||
|
||||
@@ -7907,6 +7907,38 @@ Tpm2Support tpm2_support(void) {
|
||||
return support;
|
||||
}
|
||||
|
||||
int verb_has_tpm2_generic(bool quiet) {
|
||||
Tpm2Support s;
|
||||
|
||||
s = tpm2_support();
|
||||
|
||||
if (!quiet) {
|
||||
if (s == TPM2_SUPPORT_FULL)
|
||||
puts("yes");
|
||||
else if (s == TPM2_SUPPORT_NONE)
|
||||
puts("no");
|
||||
else
|
||||
puts("partial");
|
||||
|
||||
printf("%sfirmware\n"
|
||||
"%sdriver\n"
|
||||
"%ssystem\n"
|
||||
"%ssubsystem\n"
|
||||
"%slibraries\n",
|
||||
plus_minus(s & TPM2_SUPPORT_FIRMWARE),
|
||||
plus_minus(s & TPM2_SUPPORT_DRIVER),
|
||||
plus_minus(s & TPM2_SUPPORT_SYSTEM),
|
||||
plus_minus(s & TPM2_SUPPORT_SUBSYSTEM),
|
||||
plus_minus(s & TPM2_SUPPORT_LIBRARIES));
|
||||
}
|
||||
|
||||
/* Return inverted bit flags. So that TPM2_SUPPORT_FULL becomes EXIT_SUCCESS and the other values
|
||||
* become some reasonable values 1…7. i.e. the flags we return here tell what is missing rather than
|
||||
* what is there, acknowledging the fact that for process exit statuses it is customary to return
|
||||
* zero (EXIT_FAILURE) when all is good, instead of all being bad. */
|
||||
return ~s & TPM2_SUPPORT_FULL;
|
||||
}
|
||||
|
||||
#if HAVE_TPM2
|
||||
static void tpm2_pcr_values_apply_default_hash_alg(Tpm2PCRValue *pcr_values, size_t n_pcr_values) {
|
||||
TPMI_ALG_HASH default_hash = 0;
|
||||
|
||||
@@ -463,6 +463,8 @@ typedef enum Tpm2Support {
|
||||
|
||||
Tpm2Support tpm2_support(void);
|
||||
|
||||
int verb_has_tpm2_generic(bool quiet);
|
||||
|
||||
int tpm2_parse_pcr_argument(const char *arg, Tpm2PCRValue **ret_pcr_values, size_t *ret_n_pcr_values);
|
||||
int tpm2_parse_pcr_argument_append(const char *arg, Tpm2PCRValue **ret_pcr_values, size_t *ret_n_pcr_values);
|
||||
int tpm2_parse_pcr_argument_to_mask(const char *arg, uint32_t *mask);
|
||||
|
||||
Reference in New Issue
Block a user