tpm2_load(1)

πŸ’… tpm2_load(1) πŸ’…

okay bestie, listen up β€” this whole page comes straight out of the General Commands Manual, and it's giving "load stuff into your TPM" energy. let's get into it 🫢


🌸 NAME 🌸

tpm2_load(1) β€” Load an object into the TPM. πŸ’–

✨ SYNOPSIS ✨

tpm2_load [OPTIONS]

πŸ¦‹ DESCRIPTION πŸ¦‹

okay so tpm2_load(1) has two whole jobs and honestly it slays both: it loads both the private and the public portions of an object into the TPM, or it loads the object in the TSS2-Private-Key PEM format. you can do this by specifying the private as well as the public section, or via a pem file using the -r option. no cap. ✨

the tool outputs the name of the loaded object in a YAML dictionary format, with the key name β€” and the value for that key is the name of the object in hex format, for example:

name: 000bac25cb8743111c8e1f52f2ee7279d05d3902a18dd1af694db5d1afa7adf1c8b3

it also saves a context file for future interactions with the object. πŸŽ€

⚠️ NOTE: Both private and public portions of the tpm key must be specified. The exception to this is if a TSS2-Private-Key formatted PEM object is to be loaded which does not need the public specified.

πŸŽ€ OPTIONS πŸŽ€

  • -C, --parent-context=OBJECT β€” The parent object. πŸ‘‘
  • -P, --auth=AUTH β€” The authorization value of the parent object specified by -C. πŸ”‘
  • -u, --public=FILE β€” A file containing the public portion of the object. 🌈
  • -r, --private=FILE β€” A file containing the sensitive portion of the object. πŸ™ˆ
  • -n, --name=FILE β€” An optional file to save the name structure of the object. ⭐
  • -c, --key-context=FILE β€” The file name of the saved object context, required. πŸ’€
  • --cphash=FILE β€” File path to record the hash of the command parameters. This is commonly termed as cpHash. NOTE: When this option is selected, the tool will not actually execute the command, it simply returns a cpHash. 🧚

πŸ“š References πŸ“š

🧸 Context Object Format

the type of a context object β€” whether it's a handle or a file name β€” is determined 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_. πŸ”’

πŸ” Authorization Formatting

authorization for use of an object in TPM2.0 can come in 3 different forms:

  1. Password
  2. HMAC
  3. Sessions
πŸ’¬ NOTE: "Authorizations default to the EMPTY PASSWORD when not specified".

for authentication with auth values, the tool commands implicitly generate an HMAC session. thus passwords are not transmitted unencrypted. this does not apply to passwords defined for objects β€” in that case, an HMAC session should be used (see tpm2_startauthsession(1)). 🫢

πŸ”‘ Passwords

passwords are interpreted in the following forms below using prefix identifiers.

Note: by default passwords are assumed to be in the string form when they do not have a prefix.

πŸ“ String

a string password, specified by prefix str: or it's absence (raw string without prefix), is not interpreted, and is directly used for authorization. ✨

🌸 Examples

foobar
str:foobar

🌈 Hex-string

a hex-string password, specified by prefix hex:, is converted from a hexadecimal form into a byte array form β€” thus allowing passwords with non-printable and/or terminal un-friendly characters. iconic. πŸ’…

⭐ Example

hex:1122334455667788

πŸ—‚οΈ File

a file based password, specified be prefix file:, should be the path of a file containing the password to be read by the tool β€” or a - to use stdin. storing passwords in files prevents information leakage; passwords passed as options can be read from the process list or common shell history features. πŸ”₯

πŸŽ€ Examples

# to use stdin and be prompted
file:-

# to use a file from a path
file:path/to/password/file

# to echo a password via stdin:
echo foobar | tpm2_tool -p file:-

# to use a bash here-string via stdin:

tpm2_tool -p file:- <<< foobar

🧚 Sessions

when using a policy session to authorize the use of an object, prefix the option argument with the session keyword. then indicate a path to a session file that was created with tpm2_startauthsession(1). optionally, if the session requires an auth value to be sent with the session handle (eg policy password), then append a + and a string as described in the Passwords section. πŸ’œ

πŸ’– Examples

to use a session context file called session.ctx.

session:session.ctx

to use a session context file called session.ctx AND send the authvalue mypassword.

session:session.ctx+mypassword

to use a session context file called session.ctx AND send the HEX authvalue 0x11223344.

session:session.ctx+hex:11223344

🧬 PCR Authorizations

you can satisfy a PCR policy using the pcr: prefix and the PCR minilanguage. the PCR minilanguage is as follows:

<pcr-spec>=<raw-pcr-file>

the PCR spec is documented in the section "PCR bank specifiers".

the raw-pcr-file is an optional argument that contains the output of the raw PCR contents as returned by tpm2_pcrread(1).

πŸ§ͺ PCR bank specifiers

✨ Examples

to satisfy a PCR policy of sha256 on banks 0, 1, 2 and 3 use a specifier of:

pcr:sha256:0,1,2,3

specifying AUTH.


πŸ› οΈ COMMON OPTIONS πŸ› οΈ

this collection of options are common to many programs and provide information that many users may expect. πŸ‘‘

  • -h, --help=[man|no-man] β€” Display the tools manpage. By default, it attempts to invoke the manpager for the tool, however, on failure 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 if 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. 🌟
  • -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. πŸ”
  • -Q, --quiet β€” Silence normal tool output to stdout. 🀫
  • -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 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. 🌐

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. πŸ’…

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. πŸ¦‹


βš™οΈ 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 default 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 πŸŽ€

🌸 Setup

okay bestie, so before you can load literally anything, you need something to load it under. like, the TPM doesn't just accept random objects, it wants a parent, y'know? so step one is making the primary object πŸ’…

tpm2_createprimary -c primary.ctx

Step 2, queen: create an object under the primary object πŸ¦‹

tpm2_create -C primary.ctx -u key.pub -r key.priv

this is the part where you get the private and public portions of the TPM object β€” the two halves of the whole thing, fr fr. and with those object portions in your hands, you can now load that object into the TPM for whatever you need it for next. slay.

✨ Loading an Object into the TPM

the final step, the main character moment 🫢 β€” you take the public and private portions of the object and load them into the TPM:

tpm2_load  -C primary.ctx -u key.pub -r key.priv -c key.ctx
name: 000bac25cb8743111c8e1f52f2ee7279d05d3902a18dd1af694db5d1afa7adf1c8b3

that name: line is your receipt, and it is iconic. keep it πŸ’–


πŸ’€ Returns

tools can return any of the following codes, no cap:

  • 0 β€” success. we love to see it πŸ‘‘
  • 1 β€” general non-specific error. just... a vibe, unfortunately 😭
  • 2 β€” options handling error. something about your flags was giving wrong 🚩
  • 3 β€” authentication error. wrong password energy, and it hurts πŸ™ˆ
  • 4 β€” TCTI related error. the transport layer said no ma'am 🌸
  • 5 β€” non supported scheme. applicable to tpm2_testparams.

πŸ¦‹ BUGS

Github Issues β€” that's where the bugs live, bestie πŸ›

🌈 HELP

See the Mailing List β€” the group chat for when you're stuck πŸ’œ

⭐ License

This work is licensed under the Creative Commons Attribution 4.0 International License (CC BY 4.0). very generous of them, honestly πŸŽ€


and that's the whole page, bestie!! πŸ’– she's a tpm2-tools production, page tpm2_load(1), and she ate. now go load some objects β€” you got this, iykyk ✨🫢

πŸ“¦ where this page comes from