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.
    • pem will output an OpenSSL compatible PEM encoded public key.
    • der will output an OpenSSL compatible DER encoded public key.
    • tpmt will output a binary blob of the TPMT_PUBLIC struct referenced by TPM 2.0 specs.

so yeah. public key format. 🎨

  • -o, --output=FILE β€” the output file path, recording the serialized ESYS_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 hierarchy
    • platform: the platform hierarchy
    • endorsement: the endorsement hierarchy
    • lockout: 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 the man option argument β€” except if you explicitly request man, the tool will provide errors from man on stderr. if you specify the no-man option, or the manpager fails, the short options get output to stdout.
to successfully use the manpages feature, the manpages need to be installed or on MANPATH. see man(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 variable TPM2TOOLS_ENABLE_ERRATA is 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 variable TPM2TOOLS_AUTOFLUSH is set to yes or true. 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:

  1. the command line option -T or --tcti
  2. 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 that tabrmd and abrmd as 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 of none.

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 are 127.0.0.1 and 2321.

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 abrmd supports two keys:
      1. bus_name : the name of the tabrmd service on the bus (a string).
      2. bus_type : the type of the dbus instance (a string) limited to session and system.

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: abrmd and tabrmd are 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 to tpm2_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