[tpm2] import bytes as AES key into TPM using pytss
Gadacz, Henry <henry.gadacz at sit.fraunhofer.de> Thu, 22 Sep 2022 08:51:21 +0000
| Newsgroups | dev.linux.lists.tpm2 |
|---|---|
| Message-ID | <FR0P281MB17067E121B8219E749B38197D14E9@FR0P281MB1706.DEUP281.PROD.OUTLOOK.COM> |
Hello everyone, I have a secret bytestring which I want to import as an AES key into the TPM using tpm2-pytss. For the example lets use some random generated bytes as the secret: secret = bytes(esapi.get_random(16)) To put it into an TPM2B_PRIVATE object that I can use in esapi.import_() I put the secret into a TPM2B_SENSITIVE object: sensitive = TPM2B_SENSITIVE(sensitiveArea=TPMT_SENSITIVE(sensitiveType=TPM2_ALG_AES, authValue=TPM2B_AUTH(bytes()), seedValue=TPM2B_DIGEST(bytes()), sensitive=TPMU_SENSITIVE_COMPOSITE( sym=TPM2B_SYM_KEY(buffer=secret)))) sensitive.size = asizeof.asizeof(sensitive) The creation of TPM2B_PRIVATE requires bytes or list or tuple (not TPM2B_SENSITIVE) so I want to marshal the TPM2B_SENSITIVE into bytes. key = TPM2B_PRIVATE(buffer=sensitive.marshal()) Unfortunately the marshaling fails with the exception: "TSS2_Exception: mu:A parameter has a bad value" Does anybody has the experience or knowledge to help me which value is bad or missing or to tell me what else is my mistake? Best Regards, Henry
attachment.htm
(text/html, 4.6 KB)
<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40"><head><META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=us-ascii"><meta name=Generator content="Microsoft Word 15 (filtered medium)"><style><!--
/* Font Definitions */
@font-face
{font-family:"Cambria Math";
panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0cm;
font-size:11.0pt;
font-family:"Calibri",sans-serif;}
.MsoChpDefault
{mso-style-type:export-only;}
@page WordSection1
{size:612.0pt 792.0pt;
margin:70.85pt 70.85pt 2.0cm 70.85pt;}
div.WordSection1
{page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]--></head><body lang=EN-US link="#0563C1" vlink="#954F72" style='word-wrap:break-word'><div class=WordSection1><p class=MsoNormal><span lang=DE>Hello everyone,<o:p></o:p></span></p><p class=MsoNormal><span lang=DE><o:p> </o:p></span></p><p class=MsoNormal>I have a secret bytestring which I want to import as an AES key into the TPM using tpm2-pytss. <o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>For the example lets use some random generated bytes as the secret:<o:p></o:p></p><p class=MsoNormal>secret = bytes(esapi.get_random(16)) <o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>To put it into an TPM2B_PRIVATE object that I can use in esapi.import_() I put the secret into a TPM2B_SENSITIVE object:<o:p></o:p></p><p class=MsoNormal>sensitive = TPM2B_SENSITIVE(sensitiveArea=TPMT_SENSITIVE(sensitiveType=TPM2_ALG_AES,<o:p></o:p></p><p class=MsoNormal> authValue=TPM2B_AUTH(bytes()),<o:p></o:p></p><p class=MsoNormal> seedValue=TPM2B_DIGEST(bytes()),<o:p></o:p></p><p class=MsoNormal> sensitive=TPMU_SENSITIVE_COMPOSITE(<o:p></o:p></p><p class=MsoNormal> sym=TPM2B_SYM_KEY(buffer=secret))))<o:p></o:p></p><p class=MsoNormal>sensitive.size = asizeof.asizeof(sensitive)<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>The creation of TPM2B_PRIVATE requires bytes or list or tuple (not TPM2B_SENSITIVE) so I want to marshal the TPM2B_SENSITIVE into bytes.<o:p></o:p></p><p class=MsoNormal>key = TPM2B_PRIVATE(buffer=sensitive.marshal())<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>Unfortunately the marshaling fails with the exception: “TSS2_Exception: mu:A parameter has a bad value”<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>Does anybody has the experience or knowledge to help me which value is bad or missing or to tell me what else is my mistake?<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal><span lang=DE>Best Regards,<o:p></o:p></span></p><p class=MsoNormal><span lang=DE>Henry<o:p></o:p></span></p><p class=MsoNormal><o:p> </o:p></p></div></body></html>
smime.p7s
(application/pkcs7-signature, 7.7 KB) - not displayed