tpm2_readpublic(1)

πŸ’… tpm2_readpublic(1) β€” like, the whole manual page, but make it make sense 🫢

okay so real talk: this is tpm2_readpublic from the General Commands Manual, one of the tpm2-tools girlies, and she's here to spill the tea on reading the public area of a loaded object. no cap, that's the whole vibe. let's get into it ✨


🌸 NAME 🌸

tpm2_readpublic(1) β€” Read the public area of a loaded object. that's it, that's the girl. πŸ’–


πŸ¦‹ SYNOPSIS πŸ¦‹

tpm2_readpublic [OPTIONS]

πŸ’œ DESCRIPTION πŸ’œ

tpm2_readpublic(1) β€” literally just reads the public area of a loaded object. iconic behavior, honestly. πŸ‘‘


✨ OPTIONS ✨

  • -c, --object-context=OBJECT β€” the context object for the object you wanna read. like, which one, bestie? πŸŽ€
  • -n, --name=FILE β€” an optional file to save the name structure of the object into. optional but like, why wouldn't you πŸ’…
  • -f, --format β€” format selection for the public key output file. here's the menu:
    • tss (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.

tl;dr: public key format. pick your fighter πŸ”₯

  • -o, --output=FILE β€” the output file path, recording the public portion of the object. yes, it writes the public bit to a file. groundbreaking, i know πŸ¦‹
  • -t, --serialized-handle=HANDLE β€” if the object you're reading is a persistent object specified by a raw handle, you can optionally save the serialized handle for use later. ⚠️ but hear me: this routine does NOT verify the name of the object being read. callers should ensure that the contents of name match the expected object's name. so like, do your own vibe check, fr fr πŸ™ˆ
  • -q, --qualified-name=FILE β€” saves the qualified name of the object to FILE. the qualified name of the object is the name algorithm hash of the parent's qualified name and the object's name. so basically the qualified name of the object serves as proof of the object's parents. genealogy but for TPM objects πŸ’€

πŸ”— References πŸ”—

🧚 Context Object Format 🧚

the type of a context object β€” whether it's a handle or a file name β€” gets figured out according to the following 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 argument can be loaded as a number it will be treat as a handle, e.g. 0x81010013 and used directly._OBJECT_. (yes that's how it's written, i don't make the rules 🫠)

🌈 COMMON OPTIONS 🌈

this collection of options are common to many programs and provide information that many users may expect. the shared bestie starter pack, basically πŸ’–

  • -h, --help=[man|no-man] β€” display the tool's manpage. by default, it attempts to invoke the manpager for the tool, however on failure it will output a short tool summary. this is the same behavior if the "man" option argument is specified, however if explicit "man" is requested, the tool will provide errors from man on stderr. if the "no-man" option is specified, or the manpager fails, the short options will be output to stdout.

to successfully use the manpages feature requires the manpages to be installed or on MANPATH, see man(1) for more details. πŸ“–

  • -v, --version β€” display version information for this tool, supported tctis and exit. cute AND informative ✨
  • -V, --verbose β€” increase the information that the tool prints to the console during its execution. when using this option the file and line number are printed. she's chatty and i respect it πŸ—£οΈ
  • -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 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 is set to yes or true. 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... networking but make it TPM πŸ’…

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. no exceptions. 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. πŸ”


🧁 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 TCTI, i guess 🫢


πŸ’€ TCTI OPTIONS πŸ’€

this collection of options are 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.
    • 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 (that's literally how the page transitions, i'm not fixing it, i'm just reporting it 😭)

πŸ“ EXAMPLES πŸ“

🌟 Create a primary object and read the public structure in an openssl compliant format 🌟

tpm2_createprimary -c primary.ctx
tpm2_readpublic -c primary.ctx -o output.dat -f pem

🌟 Serialize an existing persistent object handle to disk for later use 🌟

this work-flow is primarily intended for existing persistent TPM objects. ⚠️ this work-flow does not verify that the name of the serialized object matches the expected, and thus the serialized handle could be pointing to an attacker controlled object if no verification is done. if you are creating an object from scratch, save the serialized handle when making the object persistent. like, protect yourself bestie πŸ’–

we assume that an object has already been persisted, for example via:

# We assume that an object has already been persisted, for example
tpm2_createprimary -c primary.ctx

# context files have all the information for the TPM to verify the object
tpm2_evictcontrol -c primary.ctx
persistent-handle: 0x81000001
action: persisted

next, use the persistent handle to get a serialized handle:

# The persistent handle output could be at an attacker controlled object,
# best practice is to use the option "-o: for tpm2_evictcontrol to get a
# serialized handle instead.

tpm2_readpublic -c 0x81000001 -o output.dat -f pem -t primary.handle

# use this verified handle in an encrypted session with the tpm
tpm2_startauthsession --policy-session -S session.ctx -c primary.handle

for new objects, its best to use all serialized handles. 🫑


⭐ 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. (go off, file them πŸ’…)


πŸ†˜ 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 skips, no summaries, every flag accounted for 🫢

okay bye ily! this page came to you from the tpm2-tools girlies (that's the source/version, mwah πŸ’‹) β€” enjoy your public area reading era, you're gonna slay it βœ¨πŸ’…πŸŽ€

πŸ“¦ where this page comes from