tpm2_loadexternal(1)
π NAME π
bestie, this is the General Commands Manual page for tpm2_loadexternal(1) β and its whole main character energy is: Load an external object into the TPM. πΈ
β‘ SYNOPSIS β‘
tpm2_loadexternal [OPTIONS]
β¨ DESCRIPTION β¨
okay so tpm2_loadexternal(1) loads an external object into the TPM, literally forgoing TPM protections β i.e. the key material is not protected by the parent objectβs seed. π«Ά It can also be used to load TSS2 Private Keys in pem format. The command allows loading of just the public portion of an object, or both the public and private portions of an object. For TSS2 Private Keys, only the public portion of the key is loaded.
The tool outputs the name of the loaded object in a YAML dictionary format with the key name, where the value for that key is the name of the object in hex format, for example:
name: 000bac25cb8743111c8e1f52f2ee7279d05d3902a18dd1af694db5d1afa7adf1c8b3
It also saves a context file for future interactions with the object. periodt. π
π OPTIONS π
-C,--hierarchy=OBJECTβ the hierarchy to use for the ticket, optional. Defaults ton, null. Supported options are:ofor the owner hierarchy.pfor the platform hierarchy.efor the endorsement hierarchy.nfor the null hierarchy.
-G,--key-algorithm=ALGORITHMβ the algorithm used by the key to be imported. Supports:aesβ AES 128,192 or 256 key.rsaβ RSA 1024 or 2048 key.eccβ ECC NIST P192, P224, P256, P384 or P521 public and private key.
-u,--public=FILEβ the public portion of the object; this can be one of the following file formats:TSSβ the TSS/TPM format. For example from option-uof commandtpm2_create(1).RSAβ OSSL PEM formats. For examplepublic.pemfrom the commandopenssl rsa -in private.pem -out public.pem -puboutECCβ OSSL PEM formats. For examplepublic.pemfrom the commandopenssl ec -in private.ecc.pem -out public.ecc.pem -pubout
-r,--private=FILEβ the sensitive portion of the object, optional. If one wishes to use the private portion of a key, this must be specified. Like option-u, this command takes files in the following format:RSAβ OSSL PEM formats. For exampleprivate.pemfrom the commandopenssl genrsa -out private.pem 2048Since an RSA public key can be derived from the private PEM file, thereβs no need to specify-ufor the public portion.TSS2 PrivateKeyPEM formats.
Note: The private portion does not respect TSS formats as itβs impossible to get aTPM2B_SENSITIVEoutput from a previous command. They are always protected by the TPM asTPM2B_PRIVATEblobs.
-p,--auth=AUTHβ the authorization value for the key, optional.-L,--policy=FILE or HEX_STRINGβ the input policy file or hex string, optional. A file or hex string containing the hash of a policy derived fromtpm2_createpolicyor another policy digest generating source.-g,--hash-algorithm=ALGORITHMβ the hash algorithm for generating the objectβs name. This is optional and defaults tosha256when not specified. However, load external supports having a null name algorithm. In this case, no cryptographic binding checks between the public and private portions are performed.-a,--attributes=ATTRIBUTESβ the object attributes, optional. The default for created objects is:TPMA_OBJECT_SIGN_ENCRYPT|TPMA_OBJECT_DECRYPT. Optionally, if-pis specified or no-por-Lis specified thenTPMA_OBJECT_USERWITHAUTHis added to the default attribute set.
Note: If specifying attributes, the TPM will reject certain attributes like TPMA_OBJECT_FIXEDTPM, as those guarantees cannot be made.
-c,--key-context=FILEβ the file name to save the object context, required.-n,--name=FILEβ an optional file to save the object name, which is in a binary hash format. The size of the hash is based on the name algorithm or the-goption.--passin=OSSL_PEM_FILE_PASSWORDβ an optional password for an Open SSL (OSSL) provided input file. It mirrors the-passinoption of OSSL and is known to support thepass,file,env,fdand plain password formats of openssl. (seeman(1) openssl) for more.-e,--rsa_exponent_zeroβ set the exponent of a public RSA key to zero, to enable compatibility in the computation of the key name if the TPM key is generated with exponent zero.
π 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.
- 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 itβs 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 β¨
Okay bestie, options that take algorithms support βnice-namesβ π β and 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. Periodt.
π§Έ 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, iykyk.
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, no stress π.
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. The one here is ecdaa. For example, ecdaa4-sha256. If no count is specified, it defaults to 4.
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 its attributes. Generally, any valid Symmetric specifier from the Type Specifiers list should work. If not specified, an asymmetric objectβs 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 page also has this stray little crumb right after that example: cryptographic algorithms ALGORITHM. β keeping it because every detail matters π«‘.
π·οΈ Object Attributes
Object Attributes are used to control various properties of created objects. When specified as an option, either the raw bitfield mask or βnice-namesβ may be used. The values can be found in Table 31 Part 2 of the TPM2.0 specification, which can be found here:
https://trustedcomputinggroup.org/wp-content/uploads/TPM-Rev-2.0-Part-2-Structures-01.38.pdf
Nice names are calculated by taking the name field of Table 31 and removing the prefix TPMA_OBJECT_ and lowercasing the result. Thus, TPMA_OBJECT_FIXEDTPM becomes fixedtpm. Nice names can be joined using the bitwise or | symbol.
For instance, to set the fields TPMA_OBJECT_FIXEDTPM, TPMA_OBJECT_NODA, and TPMA_OBJECT_SIGN_ENCRYPT, the argument would be:
fixedtpm|noda|sign
β¦specifying the object attributes ATTRIBUTES β¨.
π COMMON OPTIONS
This collection of options are common to many programs and provide information that many users may expect. Group-chat classics, honestly.
-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 onMANPATH. Seeman(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 set toyesortrue. And yes, the bullet also trails withinformation many users may expect.β manpage confetti, preserved π.
π 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.
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 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 <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 π₯. 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. Very main character energy for a shared library, honestly.
ποΈ 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 thedeviceTCTI can be specified. The default is/dev/tpm0.
Example: -T device:/dev/tpm0 or export 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=2321 or export 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
abrmdsupports 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.
- TCTI
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 thatβs the tea on the various known TCTI modules π«Ά.
π NOTES
- If the hierarchy is
nullor the name hashing algorithm isnull, tickets produced using the object will beNULL. - If the private portion of an object is specified, the hierarchy must be
nullor the TPM will reject loading it.
β¨ EXAMPLES β¨
These are the actual little recipes, bestie β copy them, run them, watch your context files appear like magic πͺ
πΈ Load a TPM generated public key into the owner hierarchy
tpm2_createprimary -c primary.ctx
tpm2_create -C primary.ctx -u pub.dat -r priv.dat
tpm2_loadexternal -C o -u pub.dat -c pub.ctx
and it hands you back the name, no cap:
name: 000b9be4d7c6193a57e1bfc86a42a6b03856a91d2f9e77c6cbdb796a783d52d4b3b9
π¦ Load an RSA public key into the owner hierarchy
openssl genrsa -out private.pem 2048
openssl rsa -in private.pem -out public.pem -outform PEM -pubout
tpm2_loadexternal -C o -Grsa -u public.pem -c key.ctx
output era π
name: 000b7b91d304d16995d42792b57d0fb25df7abe5fdd8afe9950730e00dc5b934ddbc
π Load an RSA key-pair into the null hierarchy
openssl genrsa -out private.pem 2048
tpm2_loadexternal -C n -Grsa -r private.pem -c key.ctx
name: 000b635ea220b6c62ec1d02343859dd203c8ac5dad82ebc5b124e407d2502f88691f
π Load an AES key into the null hierarchy
dd if=/dev/urandom of=sym.key bs=1 count=16
tpm2_loadexternal -C n -Gaes -r sym.key -c key.ctx
name: 000bfc4d8dd7e4f921bcc9dca4b04f49564243cd9def129a3740002bfd4b9e966d34
π§ Load TSS2 Private Key into the null hierarchy
tpm2_loadexternal -r tss_privkey.pem -c tss_privkey.ctx
name: 000bc5a216702aca9ba226af1214c50dc4dc33ce6269677aa581ea6d9eec7f27000d
π Returns
Tools can return any of the following codes, so likeβ¦ vibe check your exit status, okay? π
0β Success. slay, it worked π1β General non-specific error. the vague one π2β Options handling error. you typed a flag wrong bestie3β Authentication error. wrong password energy π4β TCTI related error. the TPM talking thing got confused5β Non supported scheme. Applicable totpm2_testparams.
π BUGS
Github Issues β that's literally where the bugs live, go yell there (nicely pls) π«Ά
π HELP
See the Mailing List β real ones ask questions in public, iykyk π
β License
This work is licensed under the Creative Commons Attribution 4.0 International License (CC BY 4.0). iconic of them honestly π
and that's the whole page bestie π source is tpm2-tools, and this gorgeous thing is tpm2_loadexternal(1) β go externalize those keys, you absolute main character πβ¨
π¦ 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