tpm2_startauthsession(1)

๐Ÿ’– tpm2_startauthsession(1) ๐Ÿ’–

straight outta the General Commands Manual bestie, this is the whole thing, nothing skipped, we're doing this ๐Ÿซถ


๐ŸŒธ NAME ๐ŸŒธ

tpm2_startauthsession(1) โ€” start a session with the TPM. that's it, that's the vibe. โœจ


๐Ÿฆ‹ SYNOPSIS ๐Ÿฆ‹

tpm2_startauthsession [OPTIONS]

๐ŸŽ€ DESCRIPTION ๐ŸŽ€

Okay so tpm2_startauthsession(1) starts a session with the TPM. The default, no cap, is to start a trial session โ€” unless you pass the -a option. Then it saves the policy session data into a file. And that file? Iconic. You can use it in subsequent tools that take a policy file for authorization or policy events. ๐Ÿ—‚๏ธ

real talk warning โš ๏ธ this will not work with resource managers (RMs) outside of tpm2-abrmd, because most RMs will flush session handles when a client disconnects from the IPC channel. That's just how they are. ๐Ÿ˜ญ However โ€” when using an RM without the session gapping feature, you can use the command TCTI to keep the connection open. loophole found ๐Ÿ’…

Step one: create a socket listener that uses tpm2_send:

mknod "$HOME/backpipe" p
while [ 1 ]; do tpm2_send 0<"$HOME/backpipe" | nc -lU "$HOME/sock" 1>"$HOME/backpipe"; done;

Step two: use the command TCTI and netcat (nc) to send data to the socket:

tpm2_startauthsession --tcti="cmd:nc -q 0 -U $HOME/sock" <options>

When you're finishing up, make sure to kill the listener ๐Ÿ”ช. And for commands executed with the command tcti against the listener, you'll need to manage transient handles โ€” the simplest way is to add a flush after each command: tpm2_flushcontext --tcti="cmd:nc -q 0 -U $HOME/sock" -t

๐ŸŒˆ Note: this example uses UNIX sockets, since the socket is controlled with Linux access controls. Using a port is not recommended โ€” it's either open to any user on the system (localhost) or bound to a network card and exposed to the network. bestie don't do it ๐Ÿ™ˆ

This will work with direct TPM access, but heads up: internally this calls a ContextSave and a ContextLoad on the session handle, so the session cannot be saved/loaded again. one and done, no reruns ๐ŸŽฌ


โœจ OPTIONS โœจ

  • --policy-session โ€” start a policy session of type TPM_SE_POLICY. Default without this option is TPM_SE_TRIAL. ๐Ÿ’ซ
๐Ÿง  NOTE: a trial session is used when building a policy, and a policy session is used when authenticating with a policy. iykyk
  • --audit-session โ€” start an HMAC session to be used as an audit session. Default without this option is TPM2_SE_TRIAL.
  • --hmac-session โ€” start an HMAC session of type TPM_SE_HMAC. Default without this option is TPM2_SE_TRIAL.
  • -g, --hash-algorithm=ALGORITHM โ€” the hash algorithm used in computation of the policy digest. ๐Ÿงฎ
  • -G, --key-algorithm=ALGORITHM โ€” the symmetric algorithm used in parameter encryption/decryption. ๐Ÿ”
  • -c, --key-context=OBJECT โ€” set the tpmkey and bind objects to be the same. Session parameter encryption is turned on. Session parameter decryption is turned on. Parameter encryption/decryption symmetric-key set to AES-CFB. ๐Ÿ’…
  • -S, --session=FILE โ€” the name of the policy session file, required. (yes queen, it's mandatory ๐Ÿซถ)
  • --bind-context=FILE โ€” set the bind object. Session parameter encryption is off โ€” use tpm2_sessionconfig to turn on. Session parameter decryption is off โ€” use tpm2_sessionconfig to turn on. Parameter encryption/decryption symmetric-key set to AES-CFB.
  • --bind-auth=AUTH โ€” set the authorization value for the bind object. ๐Ÿ”‘
  • --tpmkey-context=FILE โ€” set the tpmkey object. Session parameter encryption is off โ€” use tpm2_sessionconfig to turn on. Session parameter decryption is off โ€” use tpm2_sessionconfig to turn on. Parameter encryption/decryption symmetric-key set to AES-CFB.
  • -n, --name=FILE โ€” a name file, as output from a tool like tpm2_readpublic(1)'s -n option. The name file can be used to verify a persistent handle input for the --tpmkey-context, -c, and --key-context options. Verification that the object referenced by a persistent handle, e.g. 0x81000000, is the key expected prevents attackers from performing a man-in-the-middle attack on session traffic. ๐Ÿ›ก๏ธ literal bodyguard behavior tbh

๐Ÿ“š References

๐Ÿงธ Context Object Format

The type of a context object โ€” whether it's a handle or a 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. ๐Ÿ“
  • 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_. ๐Ÿ”ข

๐Ÿ”‘ 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". ๐Ÿซฅ

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)). ๐Ÿ”’

๐Ÿ”ค 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.

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. ๐Ÿ’€ (chaos passwords, we love her)

Example

hex:1122334455667788

๐Ÿ“„ File

A file based password, specified be 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 your secrets bestie

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. โž•

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".

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. โœ…


๐Ÿ› ๏ธ COMMON OPTIONS ๐Ÿ› ๏ธ

This collection of options are common to many programs and provide information that many users may expect. ๐ŸŽ

  • -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.

  • -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. ๐Ÿ—ฃ๏ธ
  • -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. ๐Ÿ”“
  • -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. ๐Ÿšฟ

TCTI Configuration ๐Ÿ’–

TCTI means โ€œTransmission Interfaceโ€ โ€” itโ€™s literally the communication mechanism with the TPM, bestie. TCTIs can be changed for communication with TPMs across different mediums. Slay.

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. No cap.

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 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โ€.

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. iykyk ๐Ÿ’…

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. obsessed with a predictable default ngl ๐Ÿฆ‹

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. custom TCTI main character energy โœจ

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. (yes bestie, that trailing bit is exactly what the page says ๐Ÿ’€)

EXAMPLES โœจ

Parameter encryption. ๐Ÿ”

Command parameters and responses are not encrypted if no hmac session is used for commands. A session where the parameter, in this case the password, is encrypted can be created as follows:

tpm2_createprimary -c prim.ctx
tpm2_startauthsession -S enc_session.ctx --hmac-session --key-context prim.ctx
tpm2_create -C prim.ctx -c key.ctx -S enc_session.ctx -p password

Even without using a key for the session, a session can be used for parameter encryption:

tpm2_startauthsession -S enc_session.ctx --hmac-session
tpm2_sessionconfig enc_session.ctx --enable-decrypt
tpm2_create -C prim.ctx -c key.ctx -S enc_session.ctx -p password

If the response has to be encrypted, the โ€“enable-encrypt parameter can be used:

tpm2_startauthsession -S enc_session.ctx --hmac-session
tpm2_sessionconfig enc_session.ctx --enable-encrypt
tpm2_getrandom -S enc_session.ctx -o rand

Start a trial session and save the session data to a file ๐ŸŽ€

tpm2_startauthsession -S mysession.ctx

Start a policy session and save the session data to a file ๐Ÿฆ‹

tpm2_startauthsession --policy-session -S mysession.ctx

Start an encrypted and bound policy session and save the session data to a file ๐Ÿ‘‘

tpm2_createprimary -c primary.ctx
tpm2_startauthsession --policy-session -c primary.ctx -S mysession.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.

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, bestie ๐Ÿซถ โ€” final footer shoutout: source/version tpm2-tools, page tpm2_startauthsession(1); the date isnโ€™t in this copy so Iโ€™m not inventing one, periodt ๐Ÿ’…โœจ

๐Ÿ“ฆ where this page comes from