Merge pull request #29685 from poettering/cryptenroll-reduce-scope
cryptenroll: two minor simplifications
This commit is contained in:
@@ -39,11 +39,9 @@ static char *arg_tpm2_device = NULL;
|
||||
static uint32_t arg_tpm2_seal_key_handle = 0;
|
||||
static Tpm2PCRValue *arg_tpm2_hash_pcr_values = NULL;
|
||||
static size_t arg_tpm2_n_hash_pcr_values = 0;
|
||||
static bool arg_tpm2_hash_pcr_values_use_default = true;
|
||||
static bool arg_tpm2_pin = false;
|
||||
static char *arg_tpm2_public_key = NULL;
|
||||
static uint32_t arg_tpm2_public_key_pcr_mask = 0;
|
||||
static bool arg_tpm2_public_key_pcr_mask_use_default = true;
|
||||
static char *arg_tpm2_signature = NULL;
|
||||
static char *arg_node = NULL;
|
||||
static int *arg_wipe_slots = NULL;
|
||||
@@ -199,6 +197,7 @@ static int parse_argv(int argc, char *argv[]) {
|
||||
{}
|
||||
};
|
||||
|
||||
bool auto_hash_pcr_values = true, auto_public_key_pcr_mask = true;
|
||||
int c, r;
|
||||
|
||||
assert(argc >= 0);
|
||||
@@ -370,7 +369,7 @@ static int parse_argv(int argc, char *argv[]) {
|
||||
break;
|
||||
|
||||
case ARG_TPM2_PCRS:
|
||||
arg_tpm2_hash_pcr_values_use_default = false;
|
||||
auto_hash_pcr_values = false;
|
||||
r = tpm2_parse_pcr_argument_append(optarg, &arg_tpm2_hash_pcr_values, &arg_tpm2_n_hash_pcr_values);
|
||||
if (r < 0)
|
||||
return r;
|
||||
@@ -392,7 +391,7 @@ static int parse_argv(int argc, char *argv[]) {
|
||||
break;
|
||||
|
||||
case ARG_TPM2_PUBLIC_KEY_PCRS:
|
||||
arg_tpm2_public_key_pcr_mask_use_default = false;
|
||||
auto_public_key_pcr_mask = false;
|
||||
r = tpm2_parse_pcr_argument_to_mask(optarg, &arg_tpm2_public_key_pcr_mask);
|
||||
if (r < 0)
|
||||
return r;
|
||||
@@ -468,16 +467,18 @@ static int parse_argv(int argc, char *argv[]) {
|
||||
}
|
||||
}
|
||||
|
||||
if ((arg_enroll_type == ENROLL_FIDO2 && arg_unlock_type == UNLOCK_FIDO2)
|
||||
&& !(arg_fido2_device && arg_unlock_fido2_device))
|
||||
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
|
||||
"When both enrolling and unlocking with FIDO2 tokens, automatic discovery is unsupported. "
|
||||
"Please specify device paths for enrolling and unlocking respectively.");
|
||||
if (arg_enroll_type == ENROLL_FIDO2) {
|
||||
|
||||
if (arg_enroll_type == ENROLL_FIDO2 && !arg_fido2_device) {
|
||||
r = fido2_find_device_auto(&arg_fido2_device);
|
||||
if (r < 0)
|
||||
return r;
|
||||
if (arg_unlock_type == UNLOCK_FIDO2 && !(arg_fido2_device && arg_unlock_fido2_device))
|
||||
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
|
||||
"When both enrolling and unlocking with FIDO2 tokens, automatic discovery is unsupported. "
|
||||
"Please specify device paths for enrolling and unlocking respectively.");
|
||||
|
||||
if (!arg_fido2_device) {
|
||||
r = fido2_find_device_auto(&arg_fido2_device);
|
||||
if (r < 0)
|
||||
return r;
|
||||
}
|
||||
}
|
||||
|
||||
if (optind >= argc)
|
||||
@@ -492,10 +493,10 @@ static int parse_argv(int argc, char *argv[]) {
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
if (arg_tpm2_public_key_pcr_mask_use_default && arg_tpm2_public_key)
|
||||
if (auto_public_key_pcr_mask && arg_tpm2_public_key)
|
||||
arg_tpm2_public_key_pcr_mask = INDEX_TO_MASK(uint32_t, TPM2_PCR_KERNEL_BOOT);
|
||||
|
||||
if (arg_tpm2_hash_pcr_values_use_default && !GREEDY_REALLOC_APPEND(
|
||||
if (auto_hash_pcr_values && !GREEDY_REALLOC_APPEND(
|
||||
arg_tpm2_hash_pcr_values,
|
||||
arg_tpm2_n_hash_pcr_values,
|
||||
&TPM2_PCR_VALUE_MAKE(TPM2_PCR_INDEX_DEFAULT, /* hash= */ 0, /* value= */ {}),
|
||||
|
||||
Reference in New Issue
Block a user