tpm2_nvwrite(1)

🌸 NAME 🌸

tpm2_nvwrite(1) β€” bestie, this is the tool that writes data to a Non-Volatile (NV) index. That's it. That's the whole vibe. πŸ’…

(also hi, this is the tpm2_nvwrite manpage, general commands manual, welcome to the group chat 🫢)


✨ SYNOPSIS ✨

tpm2_nvwrite [OPTIONS] [ARGUMENT]

πŸ’– DESCRIPTION πŸ’–

Okay so tpm2_nvwrite(1) takes the data you point it at (that's your FILE) and writes it into a Non-Volatile (NV) index. Slay. πŸ”₯

If FILE isn't specified, it lowkey just defaults to stdin β€” no cap, it'll just wait there for you to feed it.

The index itself goes in as an argument, and it can be either a raw handle or an offset value into the nv handle range "TPM2_HR_NV_INDEX". Either way works, pick your fighter. πŸ’œ


πŸŽ€ OPTIONS πŸŽ€

  • ARGUMENT=NUMBER β€” the NV index you're writing to, given either as an offset from the start of the NV index range or as a straight-up absolute index value. Like, tpm2_nvwrite 1 is literally the same thing as tpm2_nvwrite 0x01000001. Same energy, different spelling. ✨
  • -i, --input=FILE β€” this one's mandatory, bestie, you genuinely cannot skip it. It's the input file holding the data you wanna write to NV. You can also feed it from stdin using the -i- option. πŸ“
  • -C, --hierarchy=OBJECT β€” tells the tool which hierarchy gets to authorize this whole situation. The supported options are:
    • o for TPM_RH_OWNER
    • p for TPM_RH_PLATFORM
    • <num> where a hierarchy handle or nv-index may be used.

And when you don't explicitly pass -C, the index handle itself is used to authorize against the index. The index auth value is the one you set via the -p option back when you ran tpm2_nvdefine(1). iykyk 🧚

  • -P, --auth=AUTH β€” the authorization value for the hierarchy. That's the vibe check for whoever's asking. πŸ‘‘
  • --offset=NATURAL_NUMBER β€” the offset within the NV index where you start writing. Not the same as the index number, don't mix them up bestie 😭
  • --cphash=FILE β€” file path where you want the hash of the command parameters recorded. People commonly call this the cpHash. ⚠️ NOTE: when this option is selected, the tool does not actually execute the command β€” it simply returns a cpHash, unless rphash is also required. So like, no writing happens, it's just the hash. Don't be surprised. πŸ’€
  • --rphash=FILE β€” file path to record the hash of the response parameters. This one's commonly termed the rpHash. Twin of the one above. πŸ¦‹
  • -S, --session=FILE β€” the session you created with tpm2_startauthsession. Use this to specify an auxiliary session for auditing and/or encryption/decryption of the parameters. Fancy. 🌸
  • -n, --name=FILE β€” the name of the NV index, which you must provide when you're only calculating the cpHash without actually dispatching the command to the TPM. Like, required required. πŸ™ˆ

πŸ“š REFERENCES πŸ“š

Context Object Format

The type of a context object β€” whether it's a handle or a file name β€” gets figured out using this logic, in order:

  • If the argument is a file path, then the file gets 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'll be treated as a handle, e.g. 0x81010013, and used directly. That's the OBJECT part, periodt. πŸ”₯

Authorization Formatting

Using an object in TPM2.0 can be authorized in 3 different forms:

  1. Password
  2. HMAC
  3. Sessions
⚠️ NOTE: "Authorizations default to the EMPTY PASSWORD when not specified". So if you say nothing, that's what you get. 😭

For authentication with auth values, the tool commands implicitly generate an HMAC session. Which means passwords are not transmitted unencrypted β€” good, we love that for us. πŸ’œ

But heads up: this does not apply to passwords defined for objects. In that case, you should use an HMAC session (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 by the prefix "str:" or by its absence (raw string, no prefix) β€” is not interpreted, and gets used directly for authorization. Simple. Clean. ✨

Examples:

foobar
str:foobar

Hex-string

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

Example:

hex:1122334455667788

File

A file based password, specified by 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. So like, do that. Protect yourself. πŸŽ€

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 the path of 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. Here's the minilanguage:

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

The PCR spec is documented in 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

(okay so this heading exists in the original and then there's genuinely nothing under it β€” not me, that's just how it is πŸ’€)

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. The reliable squad. 🫢

  • -h, --help=[man|no-man] β€” display 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 the "man" option argument is specified β€” but 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, the manpages need to be installed or on MANPATH, see man(1) for more details. πŸ“–
  • -v, --version β€” display version information for this tool, the supported tctis, and exit. Bye bestie πŸ‘‹
  • -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. Maximum transparency. πŸ”
  • -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. Use this to avoid problems when unsalted sessions are used in OpenSSL FIPS mode. But: 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, the transient parent object will be flushed too. Autoflush can also be activated if the environment variable TPM2TOOLS_AUTOFLUSH is set to yes or true. (the original says "is is set", we're keeping the spirit of the typo 😭) πŸ’œ

🌈 TCTI CONFIGURATION 🌈

The TCTI, aka "Transmission Interface", is the communication mechanism with the TPM. TCTIs can be changed for communication with TPMs across different mediums. Basically it's how the tool talks to the 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. 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 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". Like, exact exact. πŸ’€

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. πŸ”₯

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 tell you 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. So this could be a path to the shared library, or a library name as understood by dlopen(3) semantics. Build your own, bestie, go off. 🌸

πŸ’… TCTI OPTIONS πŸ’…

okay so this little collection of options is how you configure all the various known TCTI modules that exist out here, and honestly there's a lot of them, so let's go 🫢

  • device β€” for the device TCTI, you can pick which TPM character device file the device TCTI uses. the default is /dev/tpm0, no cap.

example: -T device:/dev/tpm0 or export TPM2TOOLS_TCTI=β€œdevice:/dev/tpm0”

  • mssim β€” for the mssim TCTI, you can specify the domain name or IP address and the port number the simulator uses. 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 literally just a series of simple key value pairs separated by a , character. each key and value string are separated by a = character. it's giving very straightforward, we love to see 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. no other vibes allowed πŸ™ˆ

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 🌸

πŸŽ€ Write the file nv.data to index 0x01000001 πŸŽ€

okay bestie, here's the whole little ritual, in order, exactly as it goes:

              tpm2_nvdefine -Q   1 -C o -s 32 -a "ownerread|policywrite|ownerwrite"

              echo "please123abc" > nv.test_w

              tpm2_nvwrite -Q   1 -C o -i nv.test_w

like, define the space, write your little secret into a file, then yeet it into the NV index. iconic behavior, honestly πŸ’…


⭐ Returns ⭐

tools can return any of the following codes, and yes you should actually check them:

  • 0 β€” Success. slay πŸŽ‰
  • 1 β€” General non-specific error. the vague ominous one 😭
  • 2 β€” Options handling error. you probably typo'd a flag, no shade
  • 3 β€” Authentication error. wrong password energy πŸ’€
  • 4 β€” TCTI related error. the connection said nope
  • 5 β€” Non supported scheme. applicable to tpm2_testparams.

πŸ¦‹ BUGS πŸ¦‹

Github Issues β€” that's where the bugs live, go report them 🫢


🧚 HELP 🧚

See the Mailing List β€” the people there are genuinely so helpful, fr fr.


πŸ‘‘ License πŸ‘‘

this work is licensed under the Creative Commons Attribution 4.0 International License (CC BY 4.0). go make things, just give credit, that's the whole vibe ⭐


okay that's the whole page, bestie, you're officially a tpm2_nvwrite girlie now πŸ’– this was tpm2-tools, and the page was tpm2_nvwrite(1) β€” mwah, go write some NV indices, you've got this πŸŽ€βœ¨

πŸ“¦ where this page comes from