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 typeTPM_SE_POLICY. Default without this option isTPM_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 isTPM2_SE_TRIAL.--hmac-sessionโ start an HMAC session of typeTPM_SE_HMAC. Default without this option isTPM2_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 toAES-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 โ usetpm2_sessionconfigto turn on. Session parameter decryption is off โ usetpm2_sessionconfigto turn on. Parameter encryption/decryption symmetric-key set toAES-CFB.--bind-auth=AUTHโ set the authorization value for the bind object. ๐--tpmkey-context=FILEโ set the tpmkey object. Session parameter encryption is off โ usetpm2_sessionconfigto turn on. Session parameter decryption is off โ usetpm2_sessionconfigto turn on. Parameter encryption/decryption symmetric-key set toAES-CFB.-n,--name=FILEโ a name file, as output from a tool liketpm2_readpublic(1)'s-noption. The name file can be used to verify a persistent handle input for the--tpmkey-context,-c, and--key-contextoptions. 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 hierarchyplatform:the platform hierarchyendorsement:the endorsement hierarchylockout:the lockout control persistent object
- If the argument argument can be loaded as a number it will be treat as a handle, e.g.
0x81010013and used directly._OBJECT_. ๐ข
๐ Authorization Formatting
Authorization for use of an object in TPM2.0 can come in 3 different forms:
- Password
- HMAC
- 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 environmentTPM2TOOLS_ENABLE_ERRATAis 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 variableTPM2TOOLS_AUTOFLUSHis is set toyesortrue. 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:
- The command line option
-Tor--tcti - 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, calledtabrmd. 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 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 thedeviceTCTI, the TPM character device file for use by the device TCTI can be specified. The default is/dev/tpm0. Example:-T device:/dev/tpm0orexport TPM2TOOLS_TCTI=โdevice:/dev/tpm0โmssimโ for themssimTCTI, the domain name or IP address and port number used by the simulator can be specified. The default are127.0.0.1and2321. Example:-T mssim:host=localhost,port=2321orexport TPM2TOOLS_TCTI=โmssim:host=localhost,port=2321โabrmdโ for theabrmdTCTI, 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:
bus_nameโ the name of thetabrmdservice on the bus (a string).bus_typeโ the type of the dbus instance (a string) limited tosessionandsystem.
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. (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 totpm2_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
- 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