tpm2: Extend TPM2_GetInfo with info about the runtime profile

Also extend the man page to describe the new output.

swtpm_ioctl --info 0x20 --tcp :2322  | jq
{
  "ActiveProfile": {
    "Name": "null",
    "StateFormatLevel": 1,
    "Commands": "0x11f-0x122,0x124-0x12e,0x130-0x140,0x142-0x159,0x15b-0x15e,0x160-0x165,0x167-0x174,0x176-0x178,0x17a-0x193,0x197",
    "Algorithms": "rsa,rsa-min-size=1024,tdes,tdes-min-size=128,sha1,hmac,aes,aes-min-size=128,mgf1,keyedhash,xor,sha256,sha384,sha512,null,rsassa,rsaes,rsapss,oaep,ecdsa,ecdh,ecdaa,sm2,ecschnorr,ecmqv,kdf1-sp800-56a,kdf2,kdf1-sp800-108,ecc,ecc-min-size=192,ecc-nist,ecc-bn,symcipher,camellia,camellia-min-size=128,cmac,ctr,ofb,cbc,cfb,ecb",
    "Description": "The profile enables the commands and algorithms that were enabled in libtpms v0.9. This profile is automatically used when the state does not have a profile, for example when it was created by libtpms v0.9 or before."
  }
}

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
This commit is contained in:
Stefan Berger 2022-06-28 12:08:42 -04:00 committed by Stefan Berger
parent 03b022a717
commit 9ce8f1038c
4 changed files with 47 additions and 0 deletions

View File

@ -108,6 +108,7 @@ enum TPMLIB_InfoFlags {
TPMLIB_INFO_TPMFEATURES = 4,
TPMLIB_INFO_RUNTIME_ALGORITHMS = 8,
TPMLIB_INFO_RUNTIME_COMMANDS = 16,
TPMLIB_INFO_ACTIVE_PROFILE = 32,
};
char *TPMLIB_GetInfo(enum TPMLIB_InfoFlags flags);

View File

@ -108,6 +108,7 @@ enum TPMLIB_InfoFlags {
TPMLIB_INFO_TPMFEATURES = 4,
TPMLIB_INFO_RUNTIME_ALGORITHMS = 8,
TPMLIB_INFO_RUNTIME_COMMANDS = 16,
TPMLIB_INFO_ACTIVE_PROFILE = 32,
};
char *TPMLIB_GetInfo(enum TPMLIB_InfoFlags flags);

View File

@ -109,6 +109,34 @@ This JSON object enumerates all I<implemented> commands by their hexadecimal
numbers and shows which ones can be disabled, which ones are currently
enabled and which ones are disabled.
=item B<TPMLIB_INFO_ACTIVE_PROFILE> (since v0.10.0)
This JSON object shows the currently active profile.
{
"ActiveProfile": {
"Name": "null",
"StateFormatLevel": 1,
"Commands": "0x11f-0x122,0x124-0x12e,0x130-0x140,0x142-0x159," \
"0x15b-0x15e,0x160-0x165,0x167-0x174,0x176-0x178," \
"0x17a-0x193,0x197",
"Algorithms": "rsa,rsa-min-size=1024,tdes,tdes-min-size=128,sha1,hmac," \
"aes,aes-min-size=128,mgf1,keyedhash,xor,sha256,sha384," \
"sha512,null,rsassa,rsaes,rsapss,oaep,ecdsa,ecdh,ecdaa," \
"sm2,ecschnorr,ecmqv,kdf1-sp800-56a,kdf2,kdf1-sp800-108," \
"ecc,ecc-min-size=192,ecc-nist,ecc-bn,symcipher,camellia," \
"camellia-min-size=128,cmac,ctr,ofb,cbc,cfb,ecb",
"Description": "The profile enables the commands and algorithms that " \
"were enabled in libtpms v0.9. This profile is " \
"automatically used when the state does not have a " \
"profile, for example when it was created by " \
"libtpms v0.9 or before."
}
}
The above profile is the 'null' profile. If the null profile is used then
the state will again be readable by libtpms v0.9.
=back
=head1 RETURN VALUE

View File

@ -393,6 +393,7 @@ static char *TPM2_GetInfo(enum TPMLIB_InfoFlags flags)
"\"Enabled\":%s,"
"\"Disabled\":%s"
"}";
const char *tpmProfile_temp = "\"ActiveProfile\":%s";
char *fmt = NULL, *buffer;
bool printed = false;
char *tpmattrs = NULL;
@ -405,6 +406,8 @@ static char *TPM2_GetInfo(enum TPMLIB_InfoFlags flags)
enum RuntimeCommandType rct;
char *runtimeAlgorithms = NULL;
char *runtimeCommands = NULL;
char *profile = NULL;
const char *profileJSON;
size_t n;
if (!(buffer = strdup("{%s%s%s}")))
@ -500,6 +503,19 @@ static char *TPM2_GetInfo(enum TPMLIB_InfoFlags flags)
printed = true;
}
if ((flags & TPMLIB_INFO_ACTIVE_PROFILE) &&
(profileJSON = RuntimeProfileGetJSON(&g_RuntimeProfile))) {
fmt = buffer;
buffer = NULL;
if (asprintf(&profile, tpmProfile_temp, profileJSON) < 0)
goto error;
if (asprintf(&buffer, fmt, printed ? "," : "",
profile, "%s%s%s") < 0)
goto error;
free(fmt);
printed = true;
}
/* nothing else to add */
fmt = buffer;
buffer = NULL;
@ -510,6 +526,7 @@ exit:
free(fmt);
free(tpmattrs);
free(tpmfeatures);
free(profile);
for (rat = RUNTIME_ALGO_IMPLEMENTED; rat < RUNTIME_ALGO_NUM; rat++)
free(runtimeAlgos[rat]);
for (rct = RUNTIME_CMD_IMPLEMENTED; rct < RUNTIME_CMD_NUM; rct++)