tpm2_policynv(1)

πŸ’… tpm2_policynv(1) β€” the policy-nv girlies' manual ✨

okay so bestie, this is tpm2_policynv, and it lives in the General Commands Manual section. she's a tpm2-tools girlie and honestly she eats.


🌸 NAME 🌸

tpm2_policynv(1) β€” evaluates policy authorization by comparing a specified value against the contents in the specified NV Index. literally her whole personality. πŸŽ€


πŸ¦‹ SYNOPSIS πŸ¦‹

tpm2_policynv [OPTIONS] [ARGUMENT] [ARGUMENT]

two arguments, no cap. she's low maintenance like that.


✨ DESCRIPTION ✨

okay so tpm2_policynv(1) β€” here's the vibe: this command evaluates policy authorization by comparing the contents written to an NV index against the one you specified in the tool options. simple as.

the tool takes two arguments, and yes you need both:

  1. the NV index β€” specified as a raw handle, or as an offset value to the nv handle range β€œTPM2_HR_NV_INDEX”
  2. the comparison operator β€” for magnitude comparison and/or bit test operations

iykyk: in the spec, the NV index holding the data is called operandA, and the data you specify to compare is called operandB. main character vs. supporting character energy.

the comparison operator can be specified as follows 🫢:

  • β€œeq” if operandA = operandB
  • β€œneq” if operandA != operandB
  • β€œsgt” if signed operandA > signed operandB
  • β€œugt” if unsigned operandA > unsigned operandB
  • β€œslt” if signed operandA < signed operandB
  • β€œult” if unsigned operandA < unsigned operandB
  • β€œsge” if signed operandA >= signed operandB
  • β€œuge” if unsigned operandA >= unsigned operandB
  • β€œsle” if signed operandA <= unsigned operandB
  • β€œule” if unsigned operandA <= unsigned operandB
  • β€œbs” if all bits set in operandA are set in operandB
  • β€œbc” if all bits set in operandA are clear in operandB

twelve of them. she's thorough. periodt πŸ’…


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

  • -P, --auth=AUTH β€” specifies the authorization value for the hierarchy. πŸ”‘
  • -L, --policy=FILE β€” file to save the policy digest. she's saving receipts bestie.
  • -S, --session=FILE β€” the policy session file generated via the -S option to tpm2_startauthsession or saved off of a previous tool run.
  • --offset=NATURAL_NUMBER β€” the offset within the NV index to start comparing at. ⭐ heads up: the size of the data starting at offset and ending at size of NV index shall not exceed the size of the operand specified in the options. so don't be messy.
  • --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. no cap, it's just vibes and math at that point.
  • -i, --input=FILE β€” specifies the input file with data to compare to NV Index contents. in the standard specification, this is termed as operand or operandB more specifically. it can be specified as a file input or stdin if the option value is a β€œ-”. 😭 yes, just a dash. iconic.

πŸ“Ž References


🧚 COMMON OPTIONS 🧚

this collection of options are common to many programs and provide information that many users may expect. the group chat classics, fr fr.

  • -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 is 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. she's telling you exactly where it went down.
  • -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. πŸ’€ yeah, FIPS mode will humble you.
  • -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 original page says "is is" and honestly? we respect the typo era.) 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. basically the aux cord between you and 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. always always. no exceptions bestie.

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. the simulator girlies know.
  • device β€” used when talking directly to a TPM device file.
  • 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”. like, exact exact. don't try to be cute with it.

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. it's giving first-come-first-served.

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. build your own, slay.


⭐ 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 πŸ’–

test if NV index content value is equal to an input number. to do this we first create an NV index of size 1 byte and write a value. eg. 0xAA. next we attempt to create a policy that becomes valid if the equality comparison operation of the NV index content against the one specified in the tool options. let's gooo πŸ”₯

πŸŽ€ Define the test NV Index and write the value 0xAA to it πŸŽ€

nv_test_index=0x01500001
tpm2_nvdefine -C o -p nvpass $nv_test_index -a "authread|authwrite" -s 1
echo "aa" | xxd -r -p | tpm2_nvwrite -P nvpass -i- $nv_test_index

😭 Attempt defining policynv with wrong comparison value specified in options 😭

tpm2_startauthsession -S session.ctx --policy-session
### This should fail
echo "bb" | xxd -r -p | tpm2_policynv -S session.ctx -L policy.nv -i- 0x1500001 eq -P nvpass
tpm2_flushcontext session.ctx

✨ Attempt defining policynv with right comparison value specified in options ✨

tpm2_startauthsession -S session.ctx --policy-session
### This should pass
echo "aa" | xxd -r -p | tpm2_policynv -S session.ctx -L policy.nv -i- 0x1500001 eq -P nvpass
tpm2_flushcontext session.ctx

🫢 Returns 🫢

tools can return any of the following codes:

  • 0 β€” success. πŸŽ‰
  • 1 β€” general non-specific error.
  • 2 β€” options handling error.
  • 3 β€” authentication error. πŸ’€
  • 4 β€” TCTI related error.
  • 5 β€” non supported scheme. applicable to tpm2_testparams.

πŸ™ˆ Limitations πŸ™ˆ

it expects a session to be already established via tpm2_startauthsession(1) and requires one of the following:

  • direct device access
  • extended session support with tpm2-abrmd.

without it, most resource managers will not save session state between command invocations. so like... set your session up first, bestie. don't skip steps. 😭


πŸ’€ BUGS πŸ’€

Github Issues


🧚 HELP 🧚

See the Mailing List


πŸ“œ License πŸ“œ

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


okay that's the whole page πŸ’œ this was tpm2_policynv(1) from the lovely humans over at tpm2-tools β€” go forth, compare your operands, and slay βœ¨πŸ¦‹πŸŒΈ

πŸ“¦ where this page comes from