mirror of
https://github.com/Dasharo/systemd.git
synced 2026-03-06 15:02:31 -08:00
tpm2: add support for a trusted SRK
Prevent attackers from spoofing the tpmKey portion of the AuthSession by adding a trusted key to the LUKS header metadata. Also, use a persistent object rather than a transient object. This provides the following benifits: 1. No way to MITM the tpmKey portion of the session, see [1] for details. 2. Strengthens the encrypted sessions, note that the bindKey could be dropped now. 3. Speed, once it's created we just use it. 4. Owner Auth is needed to call create primary, so using the SRK creates a scratch space for normal users. This is a "first to set" model, in where the first person to set the key in the LUKS header wins. Thus, setup should be done in a known good state. If an SRK, which is a primary key at a special persistent address, is found, it will use whatever is there. If not, it creates an SRK. The SRK follows the convetions used through the tpm2-software organization code on GitHub [2], however, a split has occured between Windows and Linux with respect to SRK templates. The Linux SRK is generated with the unique field size set to 0, in Windows, it properly sets the size to key size in bytes and the unique data to all 0's of that size. Note the proper templates for SRKs is covered in spec [3]. However, the most important thing, is that both SRKs are passwordless, and thus they should be interchangable. If Windows is the first to make the SRK, systemd will gladly accept it and vice-versa. 1. Without the bindKey being utilized, an attacker was able to intercept this and fake a key, thus being able to decrypt and encrypt traffic as needed. Introduction of the bindKey strengthened this, but allows for the attacker to brute force AES128CFB using pin guesses. Introduction of the salt increases the difficulty of this attack as well as DA attacks on the TPM objects itself. 2. https://github.com/tpm2-software 3. https://trustedcomputinggroup.org/wp-content/uploads/TCG-TPM-v2.0-Provisioning-Guidance-Published-v1r1.pdf Fixes: #20668 Fixes: #22637 Signed-off-by: William Roberts <william.c.roberts@intel.com>
This commit is contained in:
committed by
Lennart Poettering
parent
6b868766eb
commit
acbb504eaf
2
TODO
2
TODO
@@ -621,6 +621,8 @@ Features:
|
||||
|
||||
* pick up creds from EFI vars
|
||||
|
||||
* Add and pickup tpm2 metadata for creds structure.
|
||||
|
||||
* sd-boot: we probably should include all BootXY EFI variable defined boot
|
||||
entries in our menu, and then suppress ourselves. Benefit: instant
|
||||
compatibility with all other OSes which register things there, in particular
|
||||
|
||||
@@ -142,7 +142,8 @@ int enroll_tpm2(struct crypt_device *cd,
|
||||
_cleanup_(erase_and_freep) void *secret = NULL;
|
||||
_cleanup_(json_variant_unrefp) JsonVariant *v = NULL, *signature_json = NULL;
|
||||
_cleanup_(erase_and_freep) char *base64_encoded = NULL;
|
||||
size_t secret_size, blob_size, hash_size, pubkey_size = 0;
|
||||
_cleanup_(freep) void *srk_buf = NULL;
|
||||
size_t secret_size, blob_size, hash_size, pubkey_size = 0, srk_buf_size = 0;
|
||||
_cleanup_free_ void *blob = NULL, *hash = NULL, *pubkey = NULL;
|
||||
uint16_t pcr_bank, primary_alg;
|
||||
const char *node;
|
||||
@@ -214,7 +215,9 @@ int enroll_tpm2(struct crypt_device *cd,
|
||||
&blob, &blob_size,
|
||||
&hash, &hash_size,
|
||||
&pcr_bank,
|
||||
&primary_alg);
|
||||
&primary_alg,
|
||||
&srk_buf,
|
||||
&srk_buf_size);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
@@ -245,6 +248,7 @@ int enroll_tpm2(struct crypt_device *cd,
|
||||
primary_alg,
|
||||
blob, blob_size,
|
||||
hash, hash_size,
|
||||
srk_buf, srk_buf_size,
|
||||
&secret2, &secret2_size);
|
||||
if (r < 0)
|
||||
return r;
|
||||
@@ -283,6 +287,7 @@ int enroll_tpm2(struct crypt_device *cd,
|
||||
hash, hash_size,
|
||||
use_pin ? binary_salt : NULL,
|
||||
use_pin ? sizeof(binary_salt) : 0,
|
||||
srk_buf, srk_buf_size,
|
||||
flags,
|
||||
&v);
|
||||
if (r < 0)
|
||||
|
||||
@@ -42,8 +42,8 @@ _public_ int cryptsetup_token_open_pin(
|
||||
void *usrptr /* plugin defined parameter passed to crypt_activate_by_token*() API */) {
|
||||
|
||||
_cleanup_(erase_and_freep) char *base64_encoded = NULL, *pin_string = NULL;
|
||||
_cleanup_free_ void *blob = NULL, *pubkey = NULL, *policy_hash = NULL, *salt = NULL;
|
||||
size_t blob_size, policy_hash_size, decrypted_key_size, pubkey_size, salt_size = 0;
|
||||
_cleanup_free_ void *blob = NULL, *pubkey = NULL, *policy_hash = NULL, *salt = NULL, *srk_buf = NULL;
|
||||
size_t blob_size, policy_hash_size, decrypted_key_size, pubkey_size, salt_size = 0, srk_buf_size = 0;
|
||||
_cleanup_(erase_and_freep) void *decrypted_key = NULL;
|
||||
_cleanup_(json_variant_unrefp) JsonVariant *v = NULL;
|
||||
uint32_t hash_pcr_mask, pubkey_pcr_mask;
|
||||
@@ -92,6 +92,8 @@ _public_ int cryptsetup_token_open_pin(
|
||||
&policy_hash_size,
|
||||
&salt,
|
||||
&salt_size,
|
||||
&srk_buf,
|
||||
&srk_buf_size,
|
||||
&flags);
|
||||
if (r < 0)
|
||||
return log_debug_open_error(cd, r);
|
||||
@@ -114,6 +116,8 @@ _public_ int cryptsetup_token_open_pin(
|
||||
policy_hash_size,
|
||||
salt,
|
||||
salt_size,
|
||||
srk_buf,
|
||||
srk_buf_size,
|
||||
flags,
|
||||
&decrypted_key,
|
||||
&decrypted_key_size);
|
||||
@@ -172,9 +176,9 @@ _public_ void cryptsetup_token_dump(
|
||||
const char *json /* validated 'systemd-tpm2' token if cryptsetup_token_validate is defined */) {
|
||||
|
||||
_cleanup_free_ char *hash_pcrs_str = NULL, *pubkey_pcrs_str = NULL, *blob_str = NULL, *policy_hash_str = NULL, *pubkey_str = NULL;
|
||||
_cleanup_free_ void *blob = NULL, *pubkey = NULL, *policy_hash = NULL, *salt = NULL;
|
||||
_cleanup_free_ void *blob = NULL, *pubkey = NULL, *policy_hash = NULL, *salt = NULL, *srk_buf = NULL;
|
||||
_cleanup_(json_variant_unrefp) JsonVariant *v = NULL;
|
||||
size_t blob_size, policy_hash_size, pubkey_size, salt_size = 0;
|
||||
size_t blob_size, policy_hash_size, pubkey_size, salt_size = 0, srk_buf_size = 0;
|
||||
uint32_t hash_pcr_mask, pubkey_pcr_mask;
|
||||
uint16_t pcr_bank, primary_alg;
|
||||
TPM2Flags flags = 0;
|
||||
@@ -201,6 +205,8 @@ _public_ void cryptsetup_token_dump(
|
||||
&policy_hash_size,
|
||||
&salt,
|
||||
&salt_size,
|
||||
&srk_buf,
|
||||
&srk_buf_size,
|
||||
&flags);
|
||||
if (r < 0)
|
||||
return (void) crypt_log_debug_errno(cd, r, "Failed to parse " TOKEN_NAME " JSON fields: %m");
|
||||
@@ -234,6 +240,7 @@ _public_ void cryptsetup_token_dump(
|
||||
crypt_log(cd, "\ttpm2-policy-hash:" CRYPT_DUMP_LINE_SEP "%s\n", policy_hash_str);
|
||||
crypt_log(cd, "\ttpm2-pin: %s\n", true_false(flags & TPM2_FLAGS_USE_PIN));
|
||||
crypt_log(cd, "\ttpm2-salt: %s\n", true_false(salt));
|
||||
crypt_log(cd, "\ttpm2-srk: %s\n", true_false(srk_buf));
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -29,6 +29,8 @@ int acquire_luks2_key(
|
||||
size_t policy_hash_size,
|
||||
const void *salt,
|
||||
size_t salt_size,
|
||||
const void *srk_buf,
|
||||
size_t srk_buf_size,
|
||||
TPM2Flags flags,
|
||||
void **ret_decrypted_key,
|
||||
size_t *ret_decrypted_key_size) {
|
||||
@@ -89,5 +91,6 @@ int acquire_luks2_key(
|
||||
primary_alg,
|
||||
key_data, key_data_size,
|
||||
policy_hash, policy_hash_size,
|
||||
srk_buf, srk_buf_size,
|
||||
ret_decrypted_key, ret_decrypted_key_size);
|
||||
}
|
||||
|
||||
@@ -22,6 +22,8 @@ int acquire_luks2_key(
|
||||
size_t policy_hash_size,
|
||||
const void *salt,
|
||||
size_t salt_size,
|
||||
const void *srk_buf,
|
||||
size_t srk_buf_size,
|
||||
TPM2Flags flags,
|
||||
void **ret_decrypted_key,
|
||||
size_t *ret_decrypted_key_size);
|
||||
|
||||
@@ -72,6 +72,8 @@ int acquire_tpm2_key(
|
||||
size_t policy_hash_size,
|
||||
const void *salt,
|
||||
size_t salt_size,
|
||||
const void *srk_buf,
|
||||
size_t srk_buf_size,
|
||||
TPM2Flags flags,
|
||||
usec_t until,
|
||||
bool headless,
|
||||
@@ -141,6 +143,8 @@ int acquire_tpm2_key(
|
||||
blob_size,
|
||||
policy_hash,
|
||||
policy_hash_size,
|
||||
srk_buf,
|
||||
srk_buf_size,
|
||||
ret_decrypted_key,
|
||||
ret_decrypted_key_size);
|
||||
|
||||
@@ -181,6 +185,8 @@ int acquire_tpm2_key(
|
||||
blob_size,
|
||||
policy_hash,
|
||||
policy_hash_size,
|
||||
srk_buf,
|
||||
srk_buf_size,
|
||||
ret_decrypted_key,
|
||||
ret_decrypted_key_size);
|
||||
/* We get this error in case there is an authentication policy mismatch. This should
|
||||
@@ -210,6 +216,8 @@ int find_tpm2_auto_data(
|
||||
size_t *ret_policy_hash_size,
|
||||
void **ret_salt,
|
||||
size_t *ret_salt_size,
|
||||
void **ret_srk_buf,
|
||||
size_t *ret_srk_buf_size,
|
||||
TPM2Flags *ret_flags,
|
||||
int *ret_keyslot,
|
||||
int *ret_token) {
|
||||
@@ -219,9 +227,9 @@ int find_tpm2_auto_data(
|
||||
assert(cd);
|
||||
|
||||
for (token = start_token; token < sym_crypt_token_max(CRYPT_LUKS2); token++) {
|
||||
_cleanup_free_ void *blob = NULL, *policy_hash = NULL, *pubkey = NULL, *salt = NULL;
|
||||
_cleanup_free_ void *blob = NULL, *policy_hash = NULL, *pubkey = NULL, *salt = NULL, *srk_buf = NULL;
|
||||
_cleanup_(json_variant_unrefp) JsonVariant *v = NULL;
|
||||
size_t blob_size, policy_hash_size, pubkey_size, salt_size = 0;
|
||||
size_t blob_size, policy_hash_size, pubkey_size, salt_size = 0, srk_buf_size = 0;
|
||||
uint32_t hash_pcr_mask, pubkey_pcr_mask;
|
||||
uint16_t pcr_bank, primary_alg;
|
||||
TPM2Flags flags;
|
||||
@@ -244,6 +252,7 @@ int find_tpm2_auto_data(
|
||||
&blob, &blob_size,
|
||||
&policy_hash, &policy_hash_size,
|
||||
&salt, &salt_size,
|
||||
&srk_buf, &srk_buf_size,
|
||||
&flags);
|
||||
if (r == -EUCLEAN) /* Gracefully handle issues in JSON fields not owned by us */
|
||||
continue;
|
||||
@@ -270,6 +279,8 @@ int find_tpm2_auto_data(
|
||||
*ret_salt_size = salt_size;
|
||||
*ret_keyslot = keyslot;
|
||||
*ret_token = token;
|
||||
*ret_srk_buf = TAKE_PTR(srk_buf);
|
||||
*ret_srk_buf_size = srk_buf_size;
|
||||
*ret_flags = flags;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -30,6 +30,8 @@ int acquire_tpm2_key(
|
||||
size_t policy_hash_size,
|
||||
const void *salt,
|
||||
size_t salt_size,
|
||||
const void *srk_buf,
|
||||
size_t salt_srk_buf_size,
|
||||
TPM2Flags flags,
|
||||
usec_t until,
|
||||
bool headless,
|
||||
@@ -53,6 +55,8 @@ int find_tpm2_auto_data(
|
||||
size_t *ret_policy_hash_size,
|
||||
void **ret_salt,
|
||||
size_t *ret_salt_size,
|
||||
void **ret_srk_buf,
|
||||
size_t *ret_srk_size,
|
||||
TPM2Flags *ret_flags,
|
||||
int *ret_keyslot,
|
||||
int *ret_token);
|
||||
|
||||
@@ -1659,6 +1659,7 @@ static int attach_luks_or_plain_or_bitlk_by_tpm2(
|
||||
key_data, key_data_size,
|
||||
/* policy_hash= */ NULL, /* policy_hash_size= */ 0, /* we don't know the policy hash */
|
||||
/* salt= */ NULL, /* salt_size= */ 0,
|
||||
/* srk_buf= */ NULL, /* srk_buf_size= */ 0,
|
||||
arg_tpm2_pin ? TPM2_FLAGS_USE_PIN : 0,
|
||||
until,
|
||||
arg_headless,
|
||||
@@ -1704,8 +1705,8 @@ static int attach_luks_or_plain_or_bitlk_by_tpm2(
|
||||
* works. */
|
||||
|
||||
for (;;) {
|
||||
_cleanup_free_ void *pubkey = NULL, *salt = NULL;
|
||||
size_t pubkey_size = 0, salt_size = 0;
|
||||
_cleanup_free_ void *pubkey = NULL, *salt = NULL, *srk_buf = NULL;
|
||||
size_t pubkey_size = 0, salt_size = 0, srk_buf_size = 0;
|
||||
uint32_t hash_pcr_mask, pubkey_pcr_mask;
|
||||
uint16_t pcr_bank, primary_alg;
|
||||
TPM2Flags tpm2_flags;
|
||||
@@ -1722,6 +1723,7 @@ static int attach_luks_or_plain_or_bitlk_by_tpm2(
|
||||
&blob, &blob_size,
|
||||
&policy_hash, &policy_hash_size,
|
||||
&salt, &salt_size,
|
||||
&srk_buf, &srk_buf_size,
|
||||
&tpm2_flags,
|
||||
&keyslot,
|
||||
&token);
|
||||
@@ -1752,6 +1754,7 @@ static int attach_luks_or_plain_or_bitlk_by_tpm2(
|
||||
blob, blob_size,
|
||||
policy_hash, policy_hash_size,
|
||||
salt, salt_size,
|
||||
srk_buf, srk_buf_size,
|
||||
tpm2_flags,
|
||||
until,
|
||||
arg_headless,
|
||||
|
||||
@@ -3389,8 +3389,8 @@ static int partition_encrypt(Context *context, Partition *p, const char *node) {
|
||||
_cleanup_(json_variant_unrefp) JsonVariant *v = NULL;
|
||||
_cleanup_(erase_and_freep) void *secret = NULL;
|
||||
_cleanup_free_ void *pubkey = NULL;
|
||||
_cleanup_free_ void *blob = NULL, *hash = NULL;
|
||||
size_t secret_size, blob_size, hash_size, pubkey_size = 0;
|
||||
_cleanup_free_ void *blob = NULL, *hash = NULL, *srk_buf = NULL;
|
||||
size_t secret_size, blob_size, hash_size, pubkey_size = 0, srk_buf_size = 0;
|
||||
ssize_t base64_encoded_size;
|
||||
uint16_t pcr_bank, primary_alg;
|
||||
int keyslot;
|
||||
@@ -3415,7 +3415,9 @@ static int partition_encrypt(Context *context, Partition *p, const char *node) {
|
||||
&blob, &blob_size,
|
||||
&hash, &hash_size,
|
||||
&pcr_bank,
|
||||
&primary_alg);
|
||||
&primary_alg,
|
||||
&srk_buf,
|
||||
&srk_buf_size);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to seal to TPM2: %m");
|
||||
|
||||
@@ -3447,6 +3449,7 @@ static int partition_encrypt(Context *context, Partition *p, const char *node) {
|
||||
blob, blob_size,
|
||||
hash, hash_size,
|
||||
NULL, 0, /* no salt because tpm2_seal has no pin */
|
||||
srk_buf, srk_buf_size,
|
||||
0,
|
||||
&v);
|
||||
if (r < 0)
|
||||
|
||||
@@ -703,7 +703,9 @@ int encrypt_credential_and_warn(
|
||||
&tpm2_blob, &tpm2_blob_size,
|
||||
&tpm2_policy_hash, &tpm2_policy_hash_size,
|
||||
&tpm2_pcr_bank,
|
||||
&tpm2_primary_alg);
|
||||
&tpm2_primary_alg,
|
||||
/* ret_srk_buf= */ NULL,
|
||||
/* ret_srk_buf_size= */ 0);
|
||||
if (r < 0) {
|
||||
if (sd_id128_equal(with_key, _CRED_AUTO_INITRD))
|
||||
log_warning("TPM2 present and used, but we didn't manage to talk to it. Credential will be refused if SecureBoot is enabled.");
|
||||
@@ -1033,6 +1035,10 @@ int decrypt_credential_and_warn(
|
||||
le32toh(z->size));
|
||||
}
|
||||
|
||||
/*
|
||||
* TODO: Add the SRK data to the credential structure so it can be plumbed
|
||||
* through and used to verify the TPM session.
|
||||
*/
|
||||
r = tpm2_unseal(tpm2_device,
|
||||
le64toh(t->pcr_mask),
|
||||
le16toh(t->pcr_bank),
|
||||
@@ -1046,6 +1052,8 @@ int decrypt_credential_and_warn(
|
||||
le32toh(t->blob_size),
|
||||
t->policy_hash_and_blob + le32toh(t->blob_size),
|
||||
le32toh(t->policy_hash_size),
|
||||
/* srk_buf= */ NULL,
|
||||
/* srk_buf_size= */ 0,
|
||||
&tpm2_key,
|
||||
&tpm2_key_size);
|
||||
if (r < 0)
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -13,6 +13,12 @@ typedef enum TPM2Flags {
|
||||
} TPM2Flags;
|
||||
|
||||
|
||||
typedef enum Tpm2SRKTemplateFlags {
|
||||
TPM2_SRK_TEMPLATE_ECC = 1 << 0,
|
||||
TPM2_SRK_TEMPLATE_NEW_STYLE = 1 << 1,
|
||||
_TPM2_SRK_TEMPLATE_MAX = TPM2_SRK_TEMPLATE_NEW_STYLE|TPM2_SRK_TEMPLATE_ECC,
|
||||
} Tpm2SRKTemplateFlags;
|
||||
|
||||
/* As per https://trustedcomputinggroup.org/wp-content/uploads/TCG_PCClient_PFP_r1p05_v23_pub.pdf a
|
||||
* TPM2 on a Client PC must have at least 24 PCRs. This hardcodes our expectation of 24. */
|
||||
#define TPM2_PCRS_MAX 24U
|
||||
@@ -65,8 +71,8 @@ extern TSS2_RC (*sym_Tss2_MU_TPM2B_PUBLIC_Unmarshal)(uint8_t const buffer[], siz
|
||||
|
||||
int dlopen_tpm2(void);
|
||||
|
||||
int tpm2_seal(const char *device, uint32_t hash_pcr_mask, const void *pubkey, size_t pubkey_size, uint32_t pubkey_pcr_mask, const char *pin, void **ret_secret, size_t *ret_secret_size, void **ret_blob, size_t *ret_blob_size, void **ret_pcr_hash, size_t *ret_pcr_hash_size, uint16_t *ret_pcr_bank, uint16_t *ret_primary_alg);
|
||||
int tpm2_unseal(const char *device, 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, void **ret_secret, size_t *ret_secret_size);
|
||||
int tpm2_seal(const char *device, uint32_t hash_pcr_mask, const void *pubkey, size_t pubkey_size, uint32_t pubkey_pcr_mask, const char *pin, void **ret_secret, size_t *ret_secret_size, void **ret_blob, size_t *ret_blob_size, void **ret_pcr_hash, size_t *ret_pcr_hash_size, uint16_t *ret_pcr_bank, uint16_t *ret_primary_alg, void **ret_srk_buf, size_t *ret_srk_buf_size);
|
||||
int tpm2_unseal(const char *device, 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);
|
||||
|
||||
typedef struct {
|
||||
unsigned n_ref;
|
||||
@@ -85,6 +91,7 @@ DEFINE_TRIVIAL_CLEANUP_FUNC(Tpm2Context*, tpm2_context_unref);
|
||||
typedef struct {
|
||||
Tpm2Context *tpm2_context;
|
||||
ESYS_TR esys_handle;
|
||||
bool keep;
|
||||
} Tpm2Handle;
|
||||
|
||||
#define _tpm2_handle(c, h) { .tpm2_context = (c), .esys_handle = (h), }
|
||||
@@ -124,6 +131,8 @@ char *tpm2_tpml_pcr_selection_to_string(const TPML_PCR_SELECTION *l);
|
||||
size_t tpm2_tpml_pcr_selection_weight(const TPML_PCR_SELECTION *l);
|
||||
#define tpm2_tpml_pcr_selection_is_empty(l) (tpm2_tpml_pcr_selection_weight(l) == 0)
|
||||
|
||||
const TPM2B_PUBLIC *tpm2_get_primary_template(Tpm2SRKTemplateFlags flags);
|
||||
|
||||
#else /* HAVE_TPM2 */
|
||||
typedef struct {} Tpm2Context;
|
||||
typedef struct {} Tpm2Handle;
|
||||
@@ -135,8 +144,8 @@ int tpm2_find_device_auto(int log_level, char **ret);
|
||||
int tpm2_make_pcr_json_array(uint32_t pcr_mask, JsonVariant **ret);
|
||||
int tpm2_parse_pcr_json_array(JsonVariant *v, uint32_t *ret);
|
||||
|
||||
int tpm2_make_luks2_json(int keyslot, uint32_t hash_pcr_mask, uint16_t pcr_bank, const void *pubkey, size_t pubkey_size, uint32_t pubkey_pcr_mask, uint16_t primary_alg, const void *blob, size_t blob_size, const void *policy_hash, size_t policy_hash_size, const void *salt, size_t salt_size, TPM2Flags flags, JsonVariant **ret);
|
||||
int tpm2_parse_luks2_json(JsonVariant *v, int *ret_keyslot, uint32_t *ret_hash_pcr_mask, uint16_t *ret_pcr_bank, void **ret_pubkey, size_t *ret_pubkey_size, uint32_t *ret_pubkey_pcr_mask, uint16_t *ret_primary_alg, void **ret_blob, size_t *ret_blob_size, void **ret_policy_hash, size_t *ret_policy_hash_size, void **ret_salt, size_t *ret_salt_size, TPM2Flags *ret_flags);
|
||||
int tpm2_make_luks2_json(int keyslot, uint32_t hash_pcr_mask, uint16_t pcr_bank, const void *pubkey, size_t pubkey_size, uint32_t pubkey_pcr_mask, uint16_t primary_alg, const void *blob, size_t blob_size, const void *policy_hash, size_t policy_hash_size, const void *salt, size_t salt_size, const void *srk_buf, size_t srk_buf_size, TPM2Flags flags, JsonVariant **ret);
|
||||
int tpm2_parse_luks2_json(JsonVariant *v, int *ret_keyslot, uint32_t *ret_hash_pcr_mask, uint16_t *ret_pcr_bank, void **ret_pubkey, size_t *ret_pubkey_size, uint32_t *ret_pubkey_pcr_mask, uint16_t *ret_primary_alg, void **ret_blob, size_t *ret_blob_size, void **ret_policy_hash, size_t *ret_policy_hash_size, void **ret_salt, size_t *ret_salt_size, void **ret_srk_buf, size_t *ret_srk_buf_size, TPM2Flags *ret_flags);
|
||||
|
||||
/* Default to PCR 7 only */
|
||||
#define TPM2_PCR_MASK_DEFAULT (UINT32_C(1) << 7)
|
||||
|
||||
@@ -409,6 +409,96 @@ TEST(tpml_pcr_selection_add_sub) {
|
||||
expected2, expected2_count);
|
||||
}
|
||||
|
||||
/* this test includes TPM2 specific data structures */
|
||||
TEST(tpm2_get_primary_template) {
|
||||
|
||||
/*
|
||||
* Verify that if someone changes the template code, they know they're breaking things.
|
||||
* Templates MUST be changed in a backwards compatible way.
|
||||
*
|
||||
*/
|
||||
static const TPM2B_PUBLIC templ[] = {
|
||||
/* index 0 RSA old */
|
||||
[0] = {
|
||||
.publicArea = {
|
||||
.type = TPM2_ALG_RSA,
|
||||
.nameAlg = TPM2_ALG_SHA256,
|
||||
.objectAttributes = TPMA_OBJECT_RESTRICTED|TPMA_OBJECT_DECRYPT|TPMA_OBJECT_FIXEDTPM|TPMA_OBJECT_FIXEDPARENT|TPMA_OBJECT_SENSITIVEDATAORIGIN|TPMA_OBJECT_USERWITHAUTH,
|
||||
.parameters.rsaDetail = {
|
||||
.symmetric = {
|
||||
.algorithm = TPM2_ALG_AES,
|
||||
.keyBits.aes = 128,
|
||||
.mode.aes = TPM2_ALG_CFB,
|
||||
},
|
||||
.scheme.scheme = TPM2_ALG_NULL,
|
||||
.keyBits = 2048,
|
||||
},
|
||||
},
|
||||
},
|
||||
/* Index 1 ECC old */
|
||||
[TPM2_SRK_TEMPLATE_ECC] = {
|
||||
.publicArea = {
|
||||
.type = TPM2_ALG_ECC,
|
||||
.nameAlg = TPM2_ALG_SHA256,
|
||||
.objectAttributes = TPMA_OBJECT_RESTRICTED|TPMA_OBJECT_DECRYPT|TPMA_OBJECT_FIXEDTPM|TPMA_OBJECT_FIXEDPARENT|TPMA_OBJECT_SENSITIVEDATAORIGIN|TPMA_OBJECT_USERWITHAUTH,
|
||||
.parameters.eccDetail = {
|
||||
.symmetric = {
|
||||
.algorithm = TPM2_ALG_AES,
|
||||
.keyBits.aes = 128,
|
||||
.mode.aes = TPM2_ALG_CFB,
|
||||
},
|
||||
.scheme.scheme = TPM2_ALG_NULL,
|
||||
.curveID = TPM2_ECC_NIST_P256,
|
||||
.kdf.scheme = TPM2_ALG_NULL,
|
||||
},
|
||||
},
|
||||
},
|
||||
/* index 2 RSA SRK */
|
||||
[TPM2_SRK_TEMPLATE_NEW_STYLE] = {
|
||||
.publicArea = {
|
||||
.type = TPM2_ALG_RSA,
|
||||
.nameAlg = TPM2_ALG_SHA256,
|
||||
.objectAttributes = TPMA_OBJECT_FIXEDTPM|TPMA_OBJECT_FIXEDPARENT|TPMA_OBJECT_SENSITIVEDATAORIGIN|TPMA_OBJECT_RESTRICTED|TPMA_OBJECT_DECRYPT|TPMA_OBJECT_USERWITHAUTH|TPMA_OBJECT_NODA,
|
||||
.parameters.rsaDetail = {
|
||||
.symmetric = {
|
||||
.algorithm = TPM2_ALG_AES,
|
||||
.keyBits.aes = 128,
|
||||
.mode.aes = TPM2_ALG_CFB,
|
||||
},
|
||||
.scheme.scheme = TPM2_ALG_NULL,
|
||||
.keyBits = 2048,
|
||||
},
|
||||
},
|
||||
},
|
||||
/* Index 3 ECC SRK */
|
||||
[TPM2_SRK_TEMPLATE_NEW_STYLE | TPM2_SRK_TEMPLATE_ECC] = {
|
||||
.publicArea = {
|
||||
.type = TPM2_ALG_ECC,
|
||||
.nameAlg = TPM2_ALG_SHA256,
|
||||
.objectAttributes = TPMA_OBJECT_FIXEDTPM|TPMA_OBJECT_FIXEDPARENT|TPMA_OBJECT_SENSITIVEDATAORIGIN|TPMA_OBJECT_RESTRICTED|TPMA_OBJECT_DECRYPT|TPMA_OBJECT_USERWITHAUTH|TPMA_OBJECT_NODA,
|
||||
.parameters.eccDetail = {
|
||||
.symmetric = {
|
||||
.algorithm = TPM2_ALG_AES,
|
||||
.keyBits.aes = 128,
|
||||
.mode.aes = TPM2_ALG_CFB,
|
||||
},
|
||||
.scheme.scheme = TPM2_ALG_NULL,
|
||||
.curveID = TPM2_ECC_NIST_P256,
|
||||
.kdf.scheme = TPM2_ALG_NULL,
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
assert_cc(ELEMENTSOF(templ) == _TPM2_SRK_TEMPLATE_MAX + 1);
|
||||
|
||||
for (size_t i = 0; i < ELEMENTSOF(templ); i++) {
|
||||
/* the index counter lines up with the flags and the expected template received */
|
||||
const TPM2B_PUBLIC *got = tpm2_get_primary_template((Tpm2SRKTemplateFlags)i);
|
||||
assert_se(memcmp(&templ[i], got, sizeof(*got)) == 0);
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* HAVE_TPM2 */
|
||||
|
||||
DEFINE_TEST_MAIN(LOG_DEBUG);
|
||||
|
||||
Reference in New Issue
Block a user