tpm2_setprimarypolicy(1)
๐ NAME ๐
tpm2_setprimarypolicy(1) โ straight out of the General Commands Manual โ is the girl that sets the authorization policy for the lockout hierarchy (lockoutPolicy), the platform hierarchy (platformPolicy), the storage hierarchy (ownerPolicy), and the endorsement hierarchy (endorsementPolicy). Slay.
โจ SYNOPSIS โจ
tpm2_setprimarypolicy [OPTIONS]
๐ธ DESCRIPTION ๐ธ
okay so tpm2_setprimarypolicy(1) sets the authorization policy for the lockout hierarchy (lockoutPolicy), the platform hierarchy (platformPolicy), the storage hierarchy (ownerPolicy), and the endorsement hierarchy (endorsementPolicy). That's the whole vibe: policy goes in, hierarchy gets its auth policy set. ๐
๐ OPTIONS ๐
These options control creating the policy authorization session โ yes, this is the whole "who gets to authorize what" part:
-C,--hierarchy=OBJECTโ tells the tool which hierarchy's authorization policy you're setting up. You can pass it aso|p|e|l.-P,--auth=AUTHโ the authorization value for that hierarchy.-L,--policy=FILEโ the file path of the authorization policy data.-g,--hash-algorithm=ALGORITHMโ the hash algorithm used when computing the policy digest.--cphash=FILEโ file path where the hash of the command parameters gets recorded. This is commonly calledcpHash. NOTE: when this option is selected, the tool will not actually execute the command โ it simply returns acpHash. That's not a drill, bestie. ๐
๐ References ๐
๐งฉ Context Object Format ๐งฉ
The type of a context object โ handle or file name โ is figured out with this in-order logic:
- 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.
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.
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.
๐งฎ Algorithm Specifiers ๐งฎ
Options that take algorithms support โnice-namesโ.
There are two major algorithm specification string classes, simple and complex. Only certain algorithms will be accepted by the TPM, based on usage and conditions.
๐ Simple specifiers ๐
These are strings with no additional specification data. When creating objects, non-specified portions of an object are assumed to defaults. You can find the list of known โSimple Specifiersโ below.
Asymmetric
rsaecc
Symmetric
aescamelliasm4
Hashing Algorithms
sha1sha256sha384sha512sm3_256sha3_256sha3_384sha3_512
Keyed Hash
hmacxor
Signing Schemes
rsassarsapssecdsaecdaaecschnorrsm2
Asymmetric Encryption Schemes
oaeprsaesecdh
Modes
ctrofbcbccfbecb
Misc
null
๐ Complex Specifiers ๐
Objects, when specified for creation by the TPM, have numerous algorithms to populate in the public data. Things like type, scheme and asymmetric details, key size, etc. Below is the general format for specifying this data: <type>:<scheme>:<symmetric-details>
Type Specifiers
This portion of the complex algorithm specifier is required. The remaining scheme and symmetric details will default based on the type specified and the type of the object being created.
aesโ Default AES:aes128aes128<mode>โ 128 bit AES with optional mode (ctr|ofb|cbc|cfb|ecb). If mode is not specified, defaults tonull.aes192<mode>โ Same asaes128<mode>, except for a 192 bit key size.aes256<mode>โ Same asaes128<mode>, except for a 256 bit key size.sm4โ Default SM4:sm4128sm4128orsm4_128 <mode>โ 128 bit SM4 with optional mode (ctr|ofb|cbc|cfb|ecb). If mode is not specified, defaults tonull.eccโ Elliptical Curve, defaults toecc256.ecc192orecc_nist_p192โ 192 bit ECC NIST curveecc224orecc_nist_p224โ 224 bit ECC NIST curveecc256orecc_nist_p256โ 256 bit ECC NIST curveecc384orecc_nist_p384โ 384 bit ECC NIST curveecc521orecc_nist_p521โ 521 bit ECC NIST curveecc_sm2orecc_sm2_p256โ 256 bit SM2 curversaโ Default RSA:rsa2048rsa1024โ RSA with 1024 bit keysize.rsa2048โ RSA with 2048 bit keysize.rsa3072โ RSA with 3072 bit keysize.rsa4096โ RSA with 4096 bit keysize.
Scheme Specifiers
Next, is an optional field, it can be skipped.
Schemes are usually Signing Schemes or Asymmetric Encryption Schemes. Most signing schemes take a hash algorithm directly following the signing scheme. If the hash algorithm is missing, it defaults to sha256. Some take no arguments, and some take multiple arguments.
Hash Optional Scheme Specifiers
These scheme specifiers are followed by a dash and a valid hash algorithm, For example: oaep-sha256.
oaepecdhrsassarsapssecdsaecschnorrsm2
Multiple Option Scheme Specifiers
This scheme specifier is followed by a count (max size UINT16) then followed by a dash(-) and a valid hash algorithm.
ecdaaโ For example,ecdaa4-sha256. If no count is specified, it defaults to4.
No Option Scheme Specifiers
This scheme specifier takes NO arguments.
rsaes
Symmetric Details Specifiers
This field is optional, and defaults based on the type of object being created and itโs attributes. Generally, any valid Symmetric specifier from the Type Specifiers list should work. If not specified, an asymmetric objects symmetric details defaults to aes128cfb.
โจ Examples โจ
Create an rsa2048 key with an rsaes asymmetric encryption scheme
tpm2_create -C parent.ctx -G rsa2048:rsaes -u key.pub -r key.priv
Create an ecc256 key with an ecdaa signing scheme with a count of 4 and sha384 hash
/tpm2_create -C parent.ctx -G ecc256:ecdaa4-sha384 -u key.pub -r key.priv
and the original page also has cryptographic algorithms ALGORITHM. hanging out at the end of that line, so here that is, preserved exactly: cryptographic algorithms ALGORITHM.
๐ COMMON OPTIONS ๐
okay so this little collection is the stuff basically every tool in the family speaks โ the vibes everybody expects โจ
-h,--help=[man|no-man]โ shows you the tool's manpage. by default it tries to summon the manpager, and if that flops it just prints a short tool summary instead. same energy if you pass themanoption argument โ BUT if you explicitly ask forman, the tool will actually hand you man's errors on stderr, no filter ๐ญ. if you sayno-man, or the manpager just gives up, the short options go to stdout.
fr fr to use the manpage feature you need the manpages actually installed or sitting onMANPATHโ peepman(1)for the deets ๐ซถ
-v,--versionโ prints version info for this tool plus the tctis it supports, then dips ๐-V,--verboseโ turns up the volume on what the tool prints to the console while it runs. with this one on, you also get the file and line number printed ๐-Q,--quietโ silences normal tool output to stdout. shhh ๐คซ-Z,--enable-errataโ enables applying errata fixups. useful when an errata fixup needs to be applied to commands sent to the TPM. setting the environmentTPM2TOOLS_ENABLE_ERRATAdoes the exact same thing, lowkey twins ๐-z,--pwd-sessionโ uses a password session instead of a HMAC session for authentication. a clear text password gets passed to the TPM to authorize the action. this one's your go-to for dodging problems when unsalted sessions are used in OpenSSL FIPS mode. but โ if auth values are in play, a salted session should be used for authentication, no cap โ ๏ธ-R,--autoflushโ enables autoflush for transient objects created by the command. if a parent object is loaded from a context file, the transient parent object gets flushed too. autoflush also activates if the environment variableTPM2TOOLS_AUTOFLUSHis set toyesortrue๐ง (and yes, the original manpage really does trail off with "information many users may expect." right here โ we stan a copy-paste moment ๐)
๐ TCTI Configuration ๐
the TCTI, aka the "Transmission Interface", is literally the communication mechanism with the TPM. you can switch TCTIs up so you're chatting with TPMs across all different mediums ๐ซ
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. always. 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 simulatordeviceโ used when talking directly to a TPM device filenoneโ 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 out when you try to use them without a TCTI connection. it does not support ANY options and it MUST BE presented as the exact text ofnone๐จ
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> means the default gets 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 which TCTI will be picked 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 ๐ซ
โญ TCTI OPTIONS โญ
this collection configures the various known TCTI modules available:
deviceโ for the device TCTI, you can specify the TPM character device file for the device TCTI to use. the default is/dev/tpm0๐ง
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 used by the simulator. 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 a series of simple key value pairs separated by a,character. each key and value string is separated by a=character ๐
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
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 ๐ซถ (and yes, the original trails off with "the various known TCTI modules." right here โ iconic behavior honestly ๐)
โจ EXAMPLES โจ
Set a blank authorization policy for endorsement hierarchy
tpm2_setprimarypolicy -C e
๐ Returns ๐
tools can return any of the following codes:
0โ success ๐1โ general non-specific error2โ options handling error3โ authentication error4โ TCTI related error5โ 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) ๐
and that's the whole page bestie, you ate that ๐ซถ๐ it's from the tpm2-tools source, page tpm2_setprimarypolicy(1) โ go forth and set those primary policies, no cap โจ๐๐ฆ
๐ฆ 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