The script of tpm2_policyauthorize failed
by Zhao, Shirley
Hi, all,
I ran the script of tpm2_policyauthorize and met error.
The steps is following the page https://github.com/tpm2-software/tpm2-tools/blob/master/man/tpm2_policyau....
Not sure whether it is the script error or any bug in source code.
The log is as below, please help check.
$ openssl genrsa -out signing_key_private.pem 2048
Generating RSA private key, 2048 bit long modulus (2 primes)
........................+++++
....................................................................................................................................................................................................................................+++++
e is 65537 (0x010001)
$ openssl rsa -in signing_key_private.pem -out signing_key_public.pem -pubout
writing RSA key
$ tpm2_startup --clear --tcti=mssim
$ tpm2_loadexternal -G rsa -C o -u signing_key_public.pem -c signing_key.ctx -n signing_key.name --tcti=mssim
name: 000be282af94009998a545488daf129bac7379048a44361b9e77df40a03bc4ab8a4e
$ tpm2_pcrread -opcr0.sha256 sha256:0 --tcti=mssim
sha256:
0 : 0x0000000000000000000000000000000000000000000000000000000000000000
$ tpm2_startauthsession -S session.ctx --tcti=mssim
$ tpm2_policypcr -S session.ctx -l sha256:0 -f pcr0.sha256 -L pcr.policy --tcti=mssim
093ceb41181d47808862d7946268ee6a17a10e3d1b79b32351bc56e4beaceff0
$ tpm2_flushcontext session.ctx --tcti=mssim
$ openssl dgst -sha256 -sign signing_key_private.pem -out pcr.signature pcr.policy
$ tpm2_startauthsession -S session.ctx --tcti=mssim
$ tpm2_policyauthorize -S session.ctx -L authorized.policy -i pcr.policy -n signing_key.name --tcti=mssim
1307183d719d482ddb2465b67e31ee1728313157d4be0f15a6fe0ded4540758d
$ tpm2_flushcontext session.ctx --tcti=mssim
$ tpm2_nvdefine 0x1500017 -C o -s 32 -L authorized.policy -a "policyread|policywrite" --tcti=mssim
nv-index: 0x1500017
$ tpm2_verifysignature -c signing_key.ctx -g sha256 -m pcr.policy -s pcr.signature -t verification.tkt -f rsassa --tcti=mssim
$ tpm2_startauthsession --policy-session -S session.ctx --tcti=mssim
$ tpm2_policyauthorize -S session.ctx -L authorized.policy -i pcr.policy -n signing_key.name -t verification.tkt --tcti=mssim
WARNING:esys:src/tss2-esys/api/Esys_PolicyAuthorize.c:306:Esys_PolicyAuthorize_Finish() Received TPM Error
ERROR:esys:src/tss2-esys/api/Esys_PolicyAuthorize.c:108:Esys_PolicyAuthorize() Esys Finish ErrorCode (0x000001c4)
ERROR: Esys_PolicyAuthorize(0x1C4) - tpm:parameter(1):value is out of range or is not correct for the context
ERROR: Could not build tpm authorized policy
ERROR: Unable to run tpm2_policyauthorize
$ echo "nvpolicyauthorizetest" > nv.test_w
$ tpm2_nvwrite 0x1500017 -P"session:session.ctx" -i nv.test_w --tcti=mssim
WARNING:esys:src/tss2-esys/api/Esys_NV_Write.c:310:Esys_NV_Write_Finish() Received TPM Error
ERROR:esys:src/tss2-esys/api/Esys_NV_Write.c:110:Esys_NV_Write() Esys Finish ErrorCode (0x0000099d)
ERROR: Failed to write NV area at index 0x1500017
ERROR: Tss2_Sys_NV_Write(0x99D) - tpm:session(1):a policy check failed
ERROR: Unable to run tpm2_nvwrite
Thanks.
* Shirley
9 months, 3 weeks
Are there any help documents/sites on writing an ESAPI program.
by Steven Clark
I need to perform a command that doesn't have a tools executable yet
(TPM2_ECDH_ZGen) and on a persistent object handle that won't be compatible
with the on-disk key-databases of FAPI or PKCS#11. So that means I need to
write my own code in C, and that code needs to use the ESAPI.
I've had a lot of lead time to see this coming so I've done a few little
experiments. They have not improved my confidence in my understanding of
the API. For example I'm still not sure which structures I'm supposed to
access directly and which ones are supposed to be manipulated using
functions.
The Specs are either long and theoretical or dry and terse. And both the
tests for TSS and the source files for Tools make use of internal
abstraction layers. I'm having trouble getting a whole-process
picture. Are there any resources out there to help me get my sea-legs on
ESAPI code?
10 months
Can an ECC key both sign and perform ECDH key agreement?
by Steven Clark
For my project I need to create an ECC shared secret. I'm going to need to
get up to speed to writing an ESAPI executable from scratch to do this. In
the meantime I'm studying up on the specs again to see if they make me any
more confident, and if I find any theoretical gotchas.
Here's a potential:
Spec v1.59 part 1 appendix C.7.3 on TPM2_ECDH_ZGen says "To prevent
inadvertent compromise of a signing key, sign and restricted are required
to be CLEAR in the referenced key.
Spec v1.59 part 3 section 14.5.1 only says that restricted needs to be
CLEAR and decrypt SET. Along with something about the scheme needing to be
TPM_ALG_ECDH or TPM_ALG_NULL, which I don't know is relevant yet.
To register this key with other parts of the system I may need to produce a
CSR from it, which presumably means I need to be able to sign with the key,
even though it's primary use is key agreement.
Is this going to be possible? Does the first reference preclude a key that
is both a signing and encryption key? or only a key that can perform both
attestation and key agreement?
10 months
PCR pre-calculation
by Michael Walz
Hi there,
I do not know if this is the right place for this question, so please
point me in the right direction when I am wrong here.
We are trying to use the TPM2.0 in embedded devices. My job is to write
a verification suite to test if our scripts and tools are working
correctly. One point here is that I want to check if the resulting PCRs
are as expected.
Microsoft provides a "TPM PCR Calculator" for this purpose. I would need
something similar for linux command line and I googled a lot, but I did
not find something useful. I tried openssl and commands like
echo -n '86454b08919afa1c912af74dc704b87bc08afe99' | xxd -r -p | openssl
dgst -sha1 -mac hmac -macopt hexkey:0000000000000000000000000000000000000000
I tested several options and variations, but the results never match the
PCR register I get with tpm2_pcrextend.
Is there some way to get a pre-calculation for the PCRs?
Thanks in advance!!
Michael
10 months
Usage of openssl command line API as library function along with tpm-tss engine
by muthu.smk@gmail.com
Hi ,
I would like to know how to use the below mentioned command line openssl APIs as library call inside a "c" program.
I could see a "helper crypto functions as ESYS API . from this block diagram https://github.com/tpm2-software/tpm2-tss/blob/master/doc/TSS_block_diagr...
I dont want to use TPM ESYS/other TPM API to perform encryption/decryption of keys generated by TPM . Instead need to use openssl s/w library with the input of tpm generated key and generated a "encrypted file" and "decrypt" it back.
Ex: I would like encrypt the private key(priv_key) and random number (input_random_key) as input to below openssl api and generate a encrypted output file and vice versa for decryption.
Encryption:
#openssl enc -aes-256-cbc -salt -in priv_key -out output_key -k input_random_key
"priv_key" is the output key that has been created using tpm2tss-rsa-genkey() API - using TPM
"input_random_key" is the output key generated using Esys_GetRandom() API - using TPM
"output_key" will be encryption file generated as output of this openssl command line API - using pure S/W openssl which understanding tpm generated keys and works via tpm2-tss/tpm2-tss-engine.
Vice versa of below decryption , need to use below command line API as library function and achieve the expectation.
Decryption:
#openssl enc -aes-256-cbc -d -in output_key -out decrypted_output_key -k input_random_rum
Now the output_key should have the content of "priv_key" which has been used as input to above openssl API during encryption.
Thanks,
10 months
One question about Marshal/Unmarshal
by Zhao, Shirley
Hi, all,
The size of the send command in TPM2.0 is not the size calculated directly by sizeof(structure).
For example, when loading and external public key into TPM using tpm2_loadexternal, it needs to fill the structure TPM2_PUBLIC.
typedef struct {
UINT16 size;
TPMT_PUBLIC publicArea;
} TPM2B_PUBLIC;
But the size in the structure above is not sizeof(publicArea).
For example, if pub.publicArea.parameters.rsaDetail.scheme.scheme is TPM_ALG_NULL.
Then pub.publicArea.parameters.rsaDetail.scheme.details.anySig.hashAlg will not be calculated in the send command.
But in the marshal function of Tss2_MU_##type##_Marshal in base-type.c, it just copy from the src structure like below.
memcpy (&buffer [local_offset], &src, sizeof (src));
So there must be a rule to calculate the send command size according to each parameter requirement.
Where can I find these rules?
Thanks.
* Shirley
10 months, 1 week
One question in the code of tpm2-tools/tools/tpm2_loadexternal.c
by Zhao, Shirley
Hi, all,
In the following condition in tools/tpm2_loadexternal.c, if both policy and auth are empty, then it will also set TPMA_OBJECT_USERWITHAUTH.
Seems it is not correct.
pub.publicArea.objectAttributes = BASE_DEFAULT_ATTRS;
if (!(ctx.policy && !ctx.auth)) {
pub.publicArea.objectAttributes |= TPMA_OBJECT_USERWITHAUTH;
}
And no description about this scenario in spec, part2, section 8.3.1.
6
userWithAuth
SET (1): Approval of USER role actions with this object may be with an HMAC session or with a password using the authValue of the object or a policy session.
CLEAR (0): Approval of USER role actions with this object may only be done with a policy session.
Can you help to give more information?
Thanks.
* Shirley
10 months, 1 week
using Esys_Create() API creating a key with AES encryption
by muthu.smk@gmail.com
Hi @williams
As suggested by you creating this request in the emailing list
I just want to create a "AES key" using TPM , i could find the below sample of RSA key generation using tpm2tss_rsa_genkey() API . Could you help me on sharing the API or sample code block that helps me to generate "AES based key" using TPM ?
rsa = RSA_new();
if (!rsa) {
ERR("out of memory\n");
BN_free(e);
return NULL;
}
if (!tpm2tss_rsa_genkey(rsa, opt.keysize, e, opt.password, opt.parent)) {
BN_free(e);
RSA_free(rsa);
ERR("Error: Generating key failed\n");
return NULL;
}
You have suggested to use - Esys_Create, with the public template filled in for an AES key.
I have found the sample of the same in https://github.com/tpm2-software/tpm2-tss/blob/master/test/integration/es...
And the below code block/structure that enable "AES" based key generation was shared below. Can you please confirm whether am i going in correct direction to achieve my requirement . It would be great if you have any sample code to be shared with me on this front.
...
..
TPM2B_PUBLIC inPublic2 = {
..
..
.parameters.rsaDetail = {
.symmetric = {
.algorithm = TPM2_ALG_AES,
.keyBits.aes = 128,
.mode.aes = TPM2_ALG_CFB},
.scheme = {
.scheme = TPM2_ALG_NULL
},
.keyBits = 2048,
.exponent = 0,
},
...
...
}
/* Esys_Create API , which will take above struct inputs filled by user as
r = Esys_Create(esys_context,
primaryHandle,
ESYS_TR_PASSWORD, ESYS_TR_NONE, ESYS_TR_NONE,
&inSensitive2,
&inPublic2, /* in this struct we are filling that we required AES based input key gen */
&outsideInfo2,
&creationPCR2,
&outPrivate2,
&outPublic2,
&creationData2, &creationHash2, &creationTicket2);
&creationTicket);
10 months, 1 week