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 1is literally the same thing astpm2_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 fromstdinusing the-i-option. π-C,--hierarchy=OBJECTβ tells the tool which hierarchy gets to authorize this whole situation. The supported options are:oforTPM_RH_OWNERpforTPM_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 withtpm2_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 hierarchyplatform: the platform hierarchyendorsement: the endorsement hierarchylockout: 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:
- Password
- HMAC
- 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 onMANPATH, seeman(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 variableTPM2TOOLS_ENABLE_ERRATAis 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 variableTPM2TOOLS_AUTOFLUSHis set toyesortrue. (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:
- The command line option
-Tor--tcti - 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 thattabrmdandabrmdas 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 are127.0.0.1and2321π
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:
bus_name: the name of the tabrmd service on the bus (a string).bus_type: the type of the dbus instance (a string) limited tosessionandsystem. 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:abrmdandtabrmdare 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 shade3β Authentication error. wrong password energy π4β TCTI related error. the connection said nope5β Non supported scheme. applicable totpm2_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
- arch rolling: tpm2-tools 5.8-1 Β· BSD-3-Clause
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms