tpm2_tr_encode(1)
π tpm2_tr_encode(1) β ok bestie, let's talk ESYS_TR
so this is a page straight out of the General Commands Manual for tpm2-tools, and it's about tpm2_tr_encode(1). buckle up, it's actually not that deep i promise π
β¨ NAME β¨
tpm2_tr_encode(1) β takes a persistent handle plus a TPM2B_NAME and encodes the whole thing into a serialized ESYS_TR as the output. that's the whole vibe. π¦
β¨ SYNOPSIS β¨
tpm2_tr_encode [OPTIONS]
β¨ DESCRIPTION β¨
okay so tpm2_tr_encode(1) encodes a persistent TPM2 handle together with a populated TPM2B_PUBLIC as a serialized ESYS_TR. literally what it says on the tin. π«Ά
why would you even want this? because it's so useful for moving a public and handle from one environment where there's no TPM available over to another environment that does have a TPM, and then actually making use of it through the ESAPI API or through tpm2-tools(1). main character energy: the object travels, the TPM stays home. βοΈ
β¨ OPTIONS β¨
-c,--object-context=OBJECTβ the persistent handle. that's it, that's the description. π―-f,--formatβ format selection for the public key output file. the options are:tss(this one is the default) will output a binary blob according to the TPM 2.0 Specification.pemwill output an OpenSSL compatible PEM encoded public key.derwill output an OpenSSL compatible DER encoded public key.tpmtwill output a binary blob of theTPMT_PUBLICstruct referenced by TPM 2.0 specs.
so yeah. public key format. π¨
-o,--output=FILEβ the output file path, recording the serializedESYS_TR. give it a home. π‘
πΈ References
π Context Object Format
the type of a context object β whether it's a handle or a file name β gets figured out according to this logic, in order:
- if the argument is a file path, then the file is loaded as a restored TPM transient object.
- if the argument is a prefix match on one of:
owner: the owner hierarchyplatform: the platform hierarchyendorsement: the endorsement hierarchylockout: the lockout control persistent object
- if the argument can be loaded as a number it will be treated as a handle, e.g.
0x81010013, and used directly._OBJECT_.
no cap, that's the whole decision tree. π³
β¨ COMMON OPTIONS β¨
this collection of options is common to many programs and provides info that many users may expect. the classics. the staples. π§
-h,--help=[man|no-man]β displays the tool's manpage. by default it attempts to invoke the manpager for the tool, but on failure it'll output a short tool summary. same behavior if you pass themanoption argument β except if you explicitly requestman, the tool will provide errors from man on stderr. if you specify theno-manoption, or the manpager fails, the short options get output to stdout.
to successfully use the manpages feature, the manpages need to be installed or onMANPATH. seeman(1)for more details. π
-v,--versionβ display version information for this tool and supported tctis, then exit. bye π-V,--verboseβ increase the information the tool prints to the console during execution. when you use this option, the file and line number are printed. so nosy, love that. π-Q,--quietβ silence normal tool output to stdout. shhh. π€«-Z,--enable-errataβ enable the application of errata fixups. useful if an errata fixup needs to be applied to commands sent to the TPM. defining the environment variableTPM2TOOLS_ENABLE_ERRATAis equivalent. π§-z,--pwd-sessionβ use a password session instead of a HMAC session for authentication. a clear text password is passed to the TPM to authorize the action. this option can be used to avoid problems when unsalted sessions are used in OpenSSL FIPS mode. if auth values are used, a salted session should be used for authentication. β οΈ-R,--autoflushβ enable autoflush for transient objects created by the command. if a parent object is loaded from a context file, also the transient parent object will be flushed. autoflush can also be activated if the environment variableTPM2TOOLS_AUTOFLUSHis set toyesortrue. yes that sentence really does say "is is" in the original, we don't gatekeep typos here. information many users may expect. π«
β¨ TCTI Configuration β¨
the TCTI, or "Transmission Interface", is the communication mechanism with the TPM. TCTIs can be changed for communication with TPMs across different mediums. it's giving adaptability. π
to control the TCTI, the tools respect:
- the command line option
-Tor--tcti - the environment variable:
TPM2TOOLS_TCTI.
Note: the command line option always overrides the environment variable. always. periodt. π
the current known TCTIs are:
tabrmdβ the resource manager, called tabrmd. note thattabrmdandabrmdas a tcti name are synonymous.mssimβ typically used for communicating to the TPM software simulator.deviceβ used when talking directly to a TPM device file.noneβ do not initialize a connection with the TPM. some tools allow for off-tpm options and thus support not using a TCTI. tools that do not support it will error when attempted to be used without a TCTI connection. does not support ANY options and MUST BE presented as the exact text ofnone.
the arguments to either the command line option or the environment variable are in the form:
<tcti-name>:<tcti-option-config>
specifying an empty string for either the <tcti-name> or <tcti-option-config> results in the default being used for that portion respectively. β¨
π¦ TCTI Defaults
when a TCTI is not specified, the default TCTI is searched for using dlopen(3) semantics. the tools will search for tabrmd, device and mssim TCTIs IN THAT ORDER and USE THE FIRST ONE FOUND. you can query what TCTI will be chosen as the default by using the -v option to print the version information. the default-tcti key-value pair will indicate which of the aforementioned TCTIs is the default. iykyk. π
π Custom TCTIs
any TCTI that implements the dynamic TCTI interface can be loaded. the tools internally use dlopen(3), and the raw tcti-name value is used for the lookup. thus, this could be a path to the shared library, or a library name as understood by dlopen(3) semantics. bring your own, we love a plug-in moment. π
β¨ TCTI OPTIONS β¨
this collection of options is used to configure the various known TCTI modules available:
device: for the device TCTI, the TPM character device file for use by the device TCTI can be specified. the default is/dev/tpm0.
Example: -T device:/dev/tpm0 or export TPM2TOOLS_TCTI="device:/dev/tpm0"
mssim: for the mssim TCTI, the domain name or IP address and port number used by the simulator can be specified. the defaults are127.0.0.1and2321.
Example: -T mssim:host=localhost,port=2321 or export TPM2TOOLS_TCTI="mssim:host=localhost,port=2321"
abrmd: for the abrmd TCTI, the configuration string format is a series of simple key value pairs separated by a,character. each key and value string are separated by a=character.- the TCTI
abrmdsupports two keys:bus_name: the name of the tabrmd service on the bus (a string).bus_type: the type of the dbus instance (a string) limited tosessionandsystem.
- the TCTI
specify the tabrmd tcti name and a config string of bus_name=com.example.FooBar:
\--tcti=tabrmd:bus_name=com.example.FooBar
specify the default (abrmd) tcti and a config string of bus_type=session:
\--tcti:bus_type=session
NOTE:abrmdandtabrmdare synonymous. the various known TCTI modules. π
β¨ EXAMPLES β¨
π Serialize a public and handle as an ESYS_TR
tpm2_createprimary -c primary.ctx
tpm2_evictcontrol -c primary.ctx -o primary.tr 0x81000002
tpm2_readpublic -c primary.tr -o primary.pub
tpm2_tr_encode -c 0x81000002 -u primary.pub -o primary2.tr
look at that pipeline. it ate. π₯
β¨ Returns β¨
tools can return any of the following codes:
0β Success.1β General non-specific error.2β Options handling error.3β Authentication error.4β TCTI related error.5β Non supported scheme. applicable totpm2_testparams.
β¨ BUGS β¨
Github Issues. π
β¨ HELP β¨
See the Mailing List. π¬
β¨ License β¨
this work is licensed under the Creative Commons Attribution 4.0 International License (CC BY 4.0). π«Ά
and that's the whole page bestie, no notes. this little beauty comes to you from tpm2-tools, and it's the tpm2_tr_encode(1) page β go encode something iconic. πβ¨π
π¦ where this page comes from
- arch rolling: tpm2-tools 5.8-1 Β· BSD-3-Clause
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms