tpm2_nvwritelock(1)

๐Ÿ’… tpm2_nvwritelock(1) ๐Ÿ’…

Okay bestie, welcome to the General Commands Manual entry for tpm2_nvwritelock(1) โ€” she locks NV indexes and she is very serious about it. ๐ŸŽ€


๐ŸŒธ NAME ๐ŸŒธ

tpm2_nvwritelock(1) โ€” lock the Non-Volatile (NV) index for further writes. No cap, thatโ€™s the whole job. ๐Ÿ’–


โœจ SYNOPSIS โœจ

tpm2_nvwritelock [OPTIONS] [ARGUMENT]

๐Ÿฆ‹ DESCRIPTION ๐Ÿฆ‹

So tpm2_nvwritelock(1) locks the Non-Volatile (NV) index for further writes. The lock on the NV index is unlocked when the TPM is restarted, and the NV index becomes writable again. Slay, temporary lock behavior. ๐Ÿซถ

The index can be specified as a raw handle or an offset value to the nv handle range TPM2_HR_NV_INDEX. iykyk ๐Ÿ’ซ


๐Ÿ‘‘ OPTIONS ๐Ÿ‘‘

  • -C, --hierarchy=OBJECT โ€” specifies the hierarchy used to authorize. Supported options are:
    • o for TPM_RH_OWNER
    • p for TPM_RH_PLATFORM
    • <num> where a hierarchy handle or nv-index may be used.

When -C isnโ€™t explicitly passed, the index handle will be used to authorize against the index. The index auth value is set via the -p option to tpm2_nvdefine(1). bestie, that -p belongs to the other tool, donโ€™t get it twisted. ๐Ÿ’…

  • -P, --auth=AUTH โ€” specifies the authorization value for the hierarchy.
  • --global โ€” lock all NV indices with attribute TPMA_NV_GLOBALLOCK. This option does not require an NV index or offset as an argument. global means global, periodt. ๐ŸŒ
  • --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 unless rphash is also required. very โ€œjust calculating, not dispatchingโ€ energy. ๐Ÿงฎ
  • --rphash=FILE โ€” file path to record the hash of the response parameters. This is commonly termed as rpHash.
  • -S, --session=FILE โ€” the session created using tpm2_startauthsession. This can be used to specify an auxiliary session for auditing and or encryption/decryption of the parameters. audit girlies rise. ๐Ÿช„
  • -n, --name=FILE โ€” the name of the NV index that must be provided when only calculating the cpHash without actually dispatching the command to the TPM.
  • ARGUMENT โ€” the command line argument specifies the NV index or offset number.

๐Ÿงš References ๐Ÿงš

Context Object Format

The type of a context object, whether it is a handle or 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. file path behavior, iconic.
  • 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, โ€œargument argumentโ€ is in the original and we respect the lore. ๐ŸŒˆ

๐Ÿ” 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โ€. empty password default is real, bestie. ๐Ÿ˜ญ

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 this case, an HMAC session should be used (see tpm2_startauthsession(1)). HMAC session for object passwords, got it. ๐Ÿ”ฅ

๐Ÿ”‘ 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 its absence (raw string without prefix) is not interpreted, and is directly used for authorization. raw string stays raw. ๐Ÿ“

Examples

foobar
str:foobar

๐Ÿงช Hex-string ๐Ÿงช

A hex-string password, specified by prefix hex: is converted from a hexidecimal form into a byte array form, thus allowing passwords with non-printable and/or terminal un-friendly characters. chaotic bytes welcome. ๐Ÿ’€

Example

hex:1122334455667788

๐Ÿ“ File ๐Ÿ“

A file based password, specified by 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. protect the password, protect the peace. ๐Ÿซถ

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. session keyword first, then the file, then optional auth value with a plus. cute. ๐Ÿ’…

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 in the section โ€œPCR bank specifiersโ€. yes, โ€œin inโ€ โ€” we keep the typo lore alive. ๐Ÿงš

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. PCR policy satisfied, main character energy. ๐ŸŒŸ


๐ŸŒˆ COMMON OPTIONS ๐ŸŒˆ

This collection of options are common to many programs and provide information that many users may expect. the classic group-chat essentials. ๐Ÿซถ

  • -h, --help=[man|no-man] โ€” display the toolโ€™s 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. manpages installed or on MANPATH, periodt. ๐Ÿ“–

  • -v, --version โ€” display version information for this tool, supported tctis and exit. version check, then bounce. โœจ
  • -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. file and line number, very โ€œshow your workโ€. ๐Ÿ”
  • -Q, --quiet โ€” silence normal tool output to stdout. shhh era. ๐Ÿคซ
  • -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. errata fixups, activated. ๐Ÿ› ๏ธ
  • -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. clear text password warning, bestie โ€” read it twice. ๐Ÿ˜ญ
  • -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. yes, the original page really ends that bullet like that. iconic. ๐Ÿ’€

๐Ÿฆ‹ 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. different mediums, same TPM communication energy. ๐ŸŒ

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. CLI wins, always. ๐Ÿ’…

The current known TCTIs are:

  • tabrmd โ€” the resource manager, called tabrmd. Note that tabrmd and abrmd as a tcti name are synonymous. same girl, different name.
  • mssim โ€” typically used for communicating to the TPM software simulator. simulator vibes.
  • device โ€” used when talking directly to a TPM device file. direct device file, no middleman.
  • none โ€” do not initalize 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. exact text none, no extra everything. ๐Ÿ’€

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. empty string means default for that part, got it. ๐Ÿซถ

๐ŸŒŸ 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. order matters: tabrmd, device, mssim. first one found wins. ๐Ÿ†

๐Ÿ’œ 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. shared library path or dlopen(3)-style library name, both valid. ๐Ÿงš

๐Ÿ”Œ TCTI OPTIONS ๐Ÿ”Œ

okay bestie so this little crew of options is all about configuring the various known TCTI modules that are available ๐Ÿ’… like, pick your transport, basically:

  • device โ€” for the device TCTI, you get to say which TPM character device file it should use. default is /dev/tpm0 (the classic, the icon, the main character).

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 port number that the simulator is using. the defaults are 127.0.0.1 and 2321 (localhost simulator vibes, we love her).

Example: -T mssim:host=localhost,port=2321 or export TPM2TOOLS_TCTI="mssim:host=localhost,port=2321"

  • abrmd โ€” for the abrmd TCTI, the config string format is a series of simple key value pairs separated by a , character. each key and value string gets separated by a = character. simple. clean. no notes.
    • 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. also yes, "the various known TCTI modules." is genuinely how the sentence ends, we're keeping it, it's iconic โœจ

๐ŸŒธ EXAMPLES ๐ŸŒธ

๐Ÿ”’ Lock an index

bestie watch this glow-up, we're gonna lock an NV index and then get denied and honestly that's the point:

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

echo "foobar" > nv.writelock

tpm2_nvwrite -C o -i nv.writelock 1

tpm2_nvwritelock -C o 1

# fails with "NV access locked"
tpm2_nvwrite -C o -i nv.writelock 1

so we define it, we write foobar into it, we lock it, and then the last write fails with "NV access locked" โ€” and that failing is literally the whole flex ๐Ÿ’… like yes queen, deny that access.

๐ŸŒ Global Lock

this one's the big one, the group-chat-wide lockdown, the globallock of it all:

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

tpm2_nvwritelock -C o --global

# this command fails with "NV access locked".
echo foo | tpm2_nvwrite -C o -i- 1

note that last line uses -i- โ€” that's reading from stdin, and it fails with "NV access locked". as it should. periodt ๐Ÿซถ


๐Ÿ“‹ Returns ๐Ÿ“‹

tools can return any of the following codes, and ngl you should memorise them, they're short:

  • 0 - Success. ๐ŸŽ‰ (the one we're manifesting)
  • 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

(like, genuinely โ€” that's the whole section. go file one, bestie, they're tracking it there ๐Ÿ‘‘)


๐Ÿ†˜ HELP ๐Ÿ†˜

See the Mailing List


๐Ÿ“œ License ๐Ÿ“œ

This work is licensed under the Creative Commons Attribution 4.0 International License (CC BY 4.0).


aaaand that's the whole page, you made it, I'm so proud ๐Ÿฅน๐Ÿ’– you now know more about tpm2_nvwritelock than like 99% of people, no cap. this was tpm2-tools โ€” tpm2_nvwritelock(1) โ€” go forth and lock those NV indices, you absolute icon ๐ŸŽ€๐Ÿฆ‹๐ŸŒŸ

๐Ÿ“ฆ where this page comes from