cryptenroll: allow specifying handle index of key to use for sealing
This defaults to the SRK index.
This commit is contained in:
@@ -861,6 +861,7 @@ int encrypt_credential_and_warn(
|
||||
return log_error_errno(r, "Could not calculate sealing policy digest: %m");
|
||||
|
||||
r = tpm2_seal(tpm2_context,
|
||||
/* seal_key_handle= */ 0,
|
||||
&tpm2_policy,
|
||||
/* pin= */ NULL,
|
||||
&tpm2_key, &tpm2_key_size,
|
||||
|
||||
+39
-11
@@ -758,20 +758,23 @@ int tpm2_index_to_handle(
|
||||
|
||||
assert(c);
|
||||
|
||||
/* Let's restrict this, at least for now, to allow only some handle types. */
|
||||
/* Only allow persistent, transient, or NV index handle types. */
|
||||
switch (TPM2_HANDLE_TYPE(index)) {
|
||||
case TPM2_HT_PERSISTENT:
|
||||
case TPM2_HT_NV_INDEX:
|
||||
case TPM2_HT_TRANSIENT:
|
||||
break;
|
||||
case TPM2_HT_PCR:
|
||||
/* PCR handles are referenced by their actual index number and do not need a Tpm2Handle */
|
||||
return log_debug_errno(SYNTHETIC_ERRNO(EINVAL),
|
||||
"Invalid handle 0x%08" PRIx32 " (in PCR range).", index);
|
||||
case TPM2_HT_HMAC_SESSION:
|
||||
case TPM2_HT_POLICY_SESSION:
|
||||
/* Session indexes are only used internally by tpm2-tss (or lower code) */
|
||||
return log_debug_errno(SYNTHETIC_ERRNO(EINVAL),
|
||||
"Invalid handle 0x%08" PRIx32 " (in session range).", index);
|
||||
case TPM2_HT_PERMANENT: /* Permanent handles are defined, e.g. ESYS_TR_RH_OWNER. */
|
||||
case TPM2_HT_PERMANENT:
|
||||
/* Permanent handles are defined, e.g. ESYS_TR_RH_OWNER. */
|
||||
return log_debug_errno(SYNTHETIC_ERRNO(EINVAL),
|
||||
"Invalid handle 0x%08" PRIx32 " (in permanent range).", index);
|
||||
default:
|
||||
@@ -3931,6 +3934,7 @@ static int tpm2_deserialize(
|
||||
}
|
||||
|
||||
int tpm2_seal(Tpm2Context *c,
|
||||
uint32_t seal_key_handle,
|
||||
const TPM2B_DIGEST *policy,
|
||||
const char *pin,
|
||||
void **ret_secret,
|
||||
@@ -4004,18 +4008,42 @@ int tpm2_seal(Tpm2Context *c,
|
||||
_cleanup_(tpm2_handle_freep) Tpm2Handle *primary_handle = NULL;
|
||||
if (ret_srk_buf) {
|
||||
_cleanup_(Esys_Freep) TPM2B_PUBLIC *primary_public = NULL;
|
||||
r = tpm2_get_or_create_srk(
|
||||
c,
|
||||
/* session= */ NULL,
|
||||
&primary_public,
|
||||
/* ret_name= */ NULL,
|
||||
/* ret_qname= */ NULL,
|
||||
&primary_handle);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
if (IN_SET(seal_key_handle, 0, TPM2_SRK_HANDLE)) {
|
||||
r = tpm2_get_or_create_srk(
|
||||
c,
|
||||
/* session= */ NULL,
|
||||
&primary_public,
|
||||
/* ret_name= */ NULL,
|
||||
/* ret_qname= */ NULL,
|
||||
&primary_handle);
|
||||
if (r < 0)
|
||||
return r;
|
||||
} else if (IN_SET(TPM2_HANDLE_TYPE(seal_key_handle), TPM2_HT_TRANSIENT, TPM2_HT_PERSISTENT)) {
|
||||
r = tpm2_index_to_handle(
|
||||
c,
|
||||
seal_key_handle,
|
||||
/* session= */ NULL,
|
||||
&primary_public,
|
||||
/* ret_name= */ NULL,
|
||||
/* ret_qname= */ NULL,
|
||||
&primary_handle);
|
||||
if (r < 0)
|
||||
return r;
|
||||
if (r == 0)
|
||||
/* We do NOT automatically create anything other than the SRK */
|
||||
return log_debug_errno(SYNTHETIC_ERRNO(ENOENT),
|
||||
"No handle found at index 0x%" PRIx32, seal_key_handle);
|
||||
} else
|
||||
return log_debug_errno(SYNTHETIC_ERRNO(EINVAL),
|
||||
"Seal key handle 0x%" PRIx32 " is neither transient nor persistent.",
|
||||
seal_key_handle);
|
||||
|
||||
primary_alg = primary_public->publicArea.type;
|
||||
} else {
|
||||
if (seal_key_handle != 0)
|
||||
log_debug("Using primary alg sealing, but seal key handle also provided; ignoring seal key handle.");
|
||||
|
||||
/* TODO: force all callers to provide ret_srk_buf, so we can stop sealing with the legacy templates. */
|
||||
primary_alg = TPM2_ALG_ECC;
|
||||
|
||||
|
||||
@@ -195,7 +195,7 @@ int tpm2_unmarshal_blob(const void *blob, size_t blob_size, TPM2B_PUBLIC *ret_pu
|
||||
|
||||
int tpm2_get_or_create_srk(Tpm2Context *c, const Tpm2Handle *session, TPM2B_PUBLIC **ret_public, TPM2B_NAME **ret_name, TPM2B_NAME **ret_qname, Tpm2Handle **ret_handle);
|
||||
|
||||
int tpm2_seal(Tpm2Context *c, const TPM2B_DIGEST *policy, const char *pin, void **ret_secret, size_t *ret_secret_size, void **ret_blob, size_t *ret_blob_size, uint16_t *ret_primary_alg, void **ret_srk_buf, size_t *ret_srk_buf_size);
|
||||
int tpm2_seal(Tpm2Context *c, uint32_t seal_key_handle, const TPM2B_DIGEST *policy, const char *pin, void **ret_secret, size_t *ret_secret_size, void **ret_blob, size_t *ret_blob_size, uint16_t *ret_primary_alg, void **ret_srk_buf, size_t *ret_srk_buf_size);
|
||||
int tpm2_unseal(Tpm2Context *c, uint32_t hash_pcr_mask, uint16_t pcr_bank, const void *pubkey, size_t pubkey_size, uint32_t pubkey_pcr_mask, JsonVariant *signature, const char *pin, uint16_t primary_alg, const void *blob, size_t blob_size, const void *policy_hash, size_t policy_hash_size, const void *srk_buf, size_t srk_buf_size, void **ret_secret, size_t *ret_secret_size);
|
||||
|
||||
#if HAVE_OPENSSL
|
||||
|
||||
Reference in New Issue
Block a user