tpm2: add tpm2_get_legacy_template() and tpm2_get_srk_template()
Add functions to get either the 'legacy' or standard SRK template, for RSA or ECC. The 'legacy' templates are those used with earlier code, where a transient key was created to use for tpm sealing; the standard SRK is the persistent shared key as defined in TCG guidance docs. This also replaces tpm2_get_primary_template() with the new functions; that function's use of flags is confusing and unnecessary.
This commit is contained in:
@@ -458,96 +458,6 @@ 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);
|
||||
}
|
||||
}
|
||||
|
||||
static bool digest_check(const TPM2B_DIGEST *digest, const char *expect) {
|
||||
_cleanup_free_ char *h = NULL;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user