tpm2_unseal(1)

πŸ’… tpm2_unseal β€” the tpm2_unseal(1) glow-up

okay so bestie, welcome to tpm2_unseal(1), a General Commands Manual moment, and honestly it's giving "reveal the secret" main character energy. let's get into it 🫢

✨ NAME ✨

tpm2_unseal(1) β€” Returns a data blob inside a loaded TPM object, and it hands you that blob in clear. yep. unsealed. out in the open. no cap. πŸ’–

✨ SYNOPSIS ✨

tpm2_unseal [OPTIONS]

✨ DESCRIPTION ✨

so tpm2_unseal(1) returns a data blob that's sitting inside a loaded TPM object, and it gives it to you in clear β€” like, fully unlocked, no scrambling, just the goods ✨

that data got sealed way back at object-creation time using the tpm2_create tool, so this is literally the un-sealing part of that whole glow-up.

one thing though, and this is important, so i'm saying it twice: an object that's meant for sealing data has to be of the type TPM_ALG_KEYEDHASH. that's the vibe check it must pass. periodt. πŸ‘‘


πŸ’… OPTIONS πŸ’…

  • -c, --object-context=OBJECT β€” the object context for the loaded object. like, which object are we unsealing from, bestie.
  • -p, --auth=AUTH β€” optional auth value to use for the key you named with -c.
  • -o, --output=FILE β€” output file name that'll contain the unsealed data. if you don't specify it, it defaults to STDOUT. (so it just spills out into your terminal, cute 🌸)
  • --cphash=FILE β€” file path to record the hash of the command parameters. everybody calls this the cpHash. ⚠️ NOTE: when you pick this option, the tool will not actually execute the command β€” it just returns a cpHash, unless rphash is also required. so it's a lil rehearsal, not the real performance πŸ’€
  • --rphash=FILE β€” file path to record the hash of the response parameters. this one's known as the rpHash.
  • -S, --session=FILE β€” the session created using tpm2_startauthsession. you can specify multiple of these β€” for example, one session for auditing and another one for encryption/decryption of the parameters. multitasking icon behavior fr fr 🌈

πŸŽ€ References πŸŽ€

Context Object Format

the type of a context object β€” like whether it's a handle or a file name β€” gets figured out with 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 these:
    • 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'll be treated as a handle, e.g. 0x81010013, and used directly. (the original text says "If the argument argument can be loaded as a number it will be treat as a handle, e.g. 0x81010013 and used directly._OBJECT_." β€” leaving that little _OBJECT_ there for the completionists, we don't gatekeep 🫢)

Authorization Formatting

authorization for using an object in TPM2.0 comes in 3 different forms:

  1. Password
  2. HMAC
  3. Sessions
NOTE: "Authorizations default to the EMPTY PASSWORD when not specified". yes, empty. like my plans on a friday night 😭

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

πŸ” Passwords

passwords get interpreted in the forms below, using prefix identifiers.

Note: by default, passwords are assumed to be in the string form when they don't have a prefix.

String

a string password β€” specified with the prefix str: or by its absence (raw string, no prefix) β€” is not interpreted, and is directly used for authorization.

Examples

foobar
str:foobar

Hex-string

a hex-string password, specified with the prefix hex:, gets converted from a hexadecimal form into a byte array form. this is the move that lets you have passwords with non-printable and/or terminal un-friendly characters πŸ’… iconic.

Example

hex:1122334455667788

File

a file-based password, specified with the 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, because passwords passed as options can be read from the process list or from common shell history features. lowkey a big deal πŸ”₯

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 you're using a policy session to authorize the use of an object, prefix the option argument with the session keyword. then point to 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 (e.g. policy password), then append a + and a string as described in the Passwords section. obsessed with the flexibility ngl.

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 goes like this:

<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

(bestie this heading is literally empty in the original, i'm not making stuff up to fill it in, that's not the vibe πŸ’€)

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 is common to many programs and provides information that many users may expect. like the shared friend group of options 🫢

  • -h, --help=[man|no-man] β€” display the tool's manpage. by default it tries to invoke the manpager for the tool, but on failure it'll 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 get output to stdout.

to successfully use the manpages feature you need the manpages 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 the tool prints to the console during its execution. when you use this option, the file and line number get printed. very "tell me everything" of 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 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. (the og page ends this bullet with a stray "information many users may expect." β€” so here it is, preserved like a lil fossil πŸŽ€)

πŸ”Œ 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 switchboard operator ☎️

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 discussion. πŸ‘‘

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 don't 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". literally exact. character for character. πŸ’€

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 the <tcti-option-config> results in the default being used for that portion respectively. ✨

TCTI Defaults

when a TCTI isn't specified, the default TCTI is searched for using dlopen(3) semantics. the tools search for tabrmd, device and mssim TCTIs IN THAT ORDER and USE THE FIRST ONE FOUND. loud and clear, bestie πŸ”₯

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. so 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 custom 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. very "just read the config" of it.
    • 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. (and yes, the original page ends that note with a dangling "the various known TCTI modules." β€” preserved, we don't throw away the crumbs πŸ“)

πŸŽ€ EXAMPLES πŸŽ€

okay this is the good part, the little script of it all ✨

tpm2_createprimary -c primary.ctx -Q

tpm2_pcrread -Q -o pcr.bin sha256:0,1,2,3

tpm2_createpolicy -Q --policy-pcr -l sha256:0,1,2,3 -f pcr.bin -L pcr.policy

echo 'secret' | tpm2_create -C primary.ctx -L pcr.policy -i-\
-u seal.pub -r seal.priv -c seal.ctx -Q

tpm2_unseal -c seal.ctx -p pcr:sha256:0,1,2,3

and that's where this part lands, bestie β€” the rest is queued up right behind it πŸ¦‹

✨ RETURNS ✨

okay so here's the vibe check on exit codes β€” tpm2_unseal and honestly every tool in this suite can hand you back any of these:

  • 0 β€” success πŸ’– literally the dream, everything worked, go celebrate
  • 1 β€” general non-specific error 😭 the vague one, something went wrong but it's not telling you what
  • 2 β€” options handling error πŸ™ˆ you typed a flag wrong bestie, check your args
  • 3 β€” authentication error πŸ”’ the password/auth didn't pass, no entry for you
  • 4 β€” TCTI related error πŸ’€ the connection to the TPM itself is the problem
  • 5 β€” Non supported scheme. Applicable to tpm2_testparams. πŸ‘‘

so yeah, if you get anything that isn't 0, peek at which number it is and it'll point you in the right direction. iykyk ✨


πŸ› BUGS πŸ›

Found a bug? Not me being dramatic but β€” Github Issues. that's the spot, that's where they live 🫢

πŸ†˜ HELP πŸ†˜

Need a human (or at least a helpful person)? See the Mailing List. the community's got you πŸ’œ

πŸ“œ License πŸ“œ

This work is licensed under the Creative Commons Attribution 4.0 International License (CC BY 4.0). slay, legally speaking πŸ’…


and that's the whole page bestie, you made it to the end πŸŽ€ the source is tpm2-tools, the page is tpm2_unseal(1), and the date is chilling up there in the header where dates go β€” go unseal something iconic βœ¨πŸ¦‹πŸ‘‘

πŸ“¦ where this page comes from