1tpm2_import(1)              General Commands Manual             tpm2_import(1)
2
3
4

NAME

6       tpm2_import(1)  - Imports an external key into the tpm as a TPM managed
7       key object.
8

SYNOPSIS

10       tpm2_import [OPTIONS]
11

DESCRIPTION

13       tpm2_import(1) - Imports an external generated key as TPM  managed  key
14       object.  It requires that the parent key object be a RSA key.  Can also
15       import a TPM managed key object created by the tpm2_duplicate tool.
16

OPTIONS

18       These options control the key importation process:
19
20-G, --key-algorithm=ALGORITHM:
21         The algorithm used by the key to be imported.  Supports:
22
23aes - AES 128, 192 or 256 key.
24
25rsa - RSA 1024 or 2048 key.
26
27ecc - ECC NIST P192, P224, P256, P384 or P521  public  and  private
28           key.
29
30hmac - HMAC key.
31
32-g, --hash-algorithm=ALGORITHM:
33
34         The hash algorithm for generating the objects name.  This is optional
35         and defaults to sha256 when not specified.  Algorithms should  follow
36         the  “formatting standards”, see section “Algorithm Specifiers”.  Al‐
37         so, see section “Supported Hash Algorithms” for a list  of  supported
38         hash algorithms.
39
40-i, --input=FILE:
41
42         Specifies the filename of the key to be imported.  For AES keys, this
43         file is the raw key bytes.  For assymetric keys in PEM or DER format.
44         A typical file is generated with openssl genrsa.
45
46-C, --parent-context=OBJECT:
47
48         The parent key object.
49
50-U, --parent-public=FILE:
51
52         Optional.  Specifies the parent key public data file input.  This can
53         be read with tpm2_readpublic(1) tool.  If not specified, the tool in‐
54         vokes a tpm2_readpublic on the parent object.
55
56-k, --encryption-key=FILE:
57
58         Optional.   Specifies the file containing the symmetric algorithm key
59         that was used for the inner wrapper.  If the file  is  specified  the
60         tool assumes the algorithm is AES 128 in CFB mode otherwise none.
61
62-r, --private=FILE:
63
64         Specifies  the  file path required to save the encrypted private por‐
65         tion of the object imported as key.
66
67         When importing a duplicated object this  option  specifies  the  file
68         containing  the private portion of the object to be imported.  # Pro‐
69         tection Details
70
71       Objects that can move outside of TPM need to  be  protected  (confiden‐
72       tiality  and  integrity).  For instance, transient objects require that
73       TPM protected data (key or seal material) be stored outside of the TPM.
74       This  is seen in tools like tpm2_create(1), where the -r option outputs
75       this protected data.  This blob contains the sensitive portions of  the
76       object.  The sensitive portions of the object are protected by the par‐
77       ent object, using the parent’s symmetric encryption details to  encrypt
78       the sensitive data and HMAC it.
79
80       In-depth details can be found in sections 23 of:
81
82https://trustedcomputinggroup.org/wp-content/up
83         loads/TPM-Rev-2.0-Part-1-Architecture-01.38.pdf
84
85       Notably Figure 20, is relevant, even though it’s specifically referring
86       to duplication blobs, the process is identical.
87
88       If  the  output  is from tpm2_duplicate(1), the output will be slightly
89       different, as described fully in section 23.
90
91-u, --public=FILE:
92
93         Specifies the file path required to save the public  portion  of  the
94         object imported as key
95
96         When  importing  a  duplicated  object this option specifies the file
97         containing the public portion of the object to be imported.
98
99-a, --attributes=ATTRIBUTES:
100
101         The object attributes, optional.
102
103-P, --parent-auth=AUTH:
104
105         The authorization value for using the parent key specified with -C.
106
107-p, --key-auth=AUTH:
108
109         The authorization value for the imported key, optional.
110
111-L, --policy=POLICY_FILE:
112
113         The policy file.
114
115-s, --seed=FILE:
116
117         Specifies the file containing the encrypted seed  of  the  duplicated
118         object.
119
120--passin=OSSL_PEM_FILE_PASSWORD
121
122         An  optional password for an Open SSL (OSSL) provided input file.  It
123         mirrors the -passin option of OSSL and is known to support the  pass,
124         file,  env,  fd  and  plain password formats of openssl.  (see man(1)
125         openssl) for more.
126
127--cphash=FILE
128
129         File path to record the hash of the command parameters.  This is com‐
130         monly termed as cpHash.  NOTE: When this option is selected, The tool
131         will not actually execute the command, it simply returns a cpHash.
132
133   References

Context Object Format

135       The type of a context object, whether it is a handle or file  name,  is
136       determined according to the following logic in-order:
137
138       • If the argument is a file path, then the file is loaded as a restored
139         TPM transient object.
140
141       • If the argument is a prefix match on one of:
142
143         • owner: the owner hierarchy
144
145         • platform: the platform hierarchy
146
147         • endorsement: the endorsement hierarchy
148
149         • lockout: the lockout control persistent object
150
151       • If the argument argument can be loaded as a number it will  be  treat
152         as a handle, e.g. 0x81010013 and used directly._OBJECT_.
153

Authorization Formatting

155       Authorization  for  use  of an object in TPM2.0 can come in 3 different
156       forms: 1.  Password 2.  HMAC 3.  Sessions
157
158       NOTE: “Authorizations default to the EMPTY  PASSWORD  when  not  speci‐
159       fied”.
160
161   Passwords
162       Passwords  are  interpreted  in  the following forms below using prefix
163       identifiers.
164
165       Note: By default passwords are assumed to be in the  string  form  when
166       they do not have a prefix.
167
168   String
169       A  string  password,  specified  by  prefix “str:” or it’s absence (raw
170       string without prefix) is not interpreted, and is directly used for au‐
171       thorization.
172
173   Examples
174              foobar
175              str:foobar
176
177   Hex-string
178       A  hex-string  password, specified by prefix “hex:” is converted from a
179       hexidecimal form into a byte array form, thus allowing  passwords  with
180       non-printable and/or terminal un-friendly characters.
181
182   Example
183              hex:0x1122334455667788
184
185   File
186       A  file  based password, specified be prefix “file:” should be the path
187       of a file containing the password to be read by the tool or  a  “-”  to
188       use  stdin.   Storing  passwords in files prevents information leakage,
189       passwords passed as options can be read from the process list or common
190       shell history features.
191
192   Examples
193              # to use stdin and be prompted
194              file:-
195
196              # to use a file from a path
197              file:path/to/password/file
198
199              # to echo a password via stdin:
200              echo foobar | tpm2_tool -p file:-
201
202              # to use a bash here-string via stdin:
203
204              tpm2_tool -p file:- <<< foobar
205
206   Sessions
207       When  using  a policy session to authorize the use of an object, prefix
208       the option argument with the session keyword.  Then indicate a path  to
209       a session file that was created with tpm2_startauthsession(1).  Option‐
210       ally, if the session requires an auth value to be sent with the session
211       handle  (eg policy password), then append a + and a string as described
212       in the Passwords section.
213
214   Examples
215       To use a session context file called session.ctx.
216
217              session:session.ctx
218
219       To use a session context file called session.ctx AND send the authvalue
220       mypassword.
221
222              session:session.ctx+mypassword
223
224       To use a session context file called session.ctx AND send the HEX auth‐
225       value 0x11223344.
226
227              session:session.ctx+hex:11223344
228
229   PCR Authorizations
230       You can satisfy a PCR policy using the “pcr:” prefix and the PCR  mini‐
231       language.       The     PCR     minilanguage     is     as     follows:
232       <pcr-spec>=<raw-pcr-file>
233
234       The PCR spec is documented in in the section “PCR bank specifiers”.
235
236       The raw-pcr-file is an optional argument that contains  the  output  of
237       the raw PCR contents as returned by tpm2_pcrread(1).
238
239       PCR bank specifiers (pcr.md)
240
241   Examples
242       To satisfy a PCR policy of sha256 on banks 0, 1, 2 and 3 use a specifi‐
243       er of:
244
245              pcr:sha256:0,1,2,3
246
247       specifying AUTH.
248

Algorithm Specifiers

250       Options that take algorithms support “nice-names”.
251
252       There are two major algorithm specification string classes, simple  and
253       complex.  Only certain algorithms will be accepted by the TPM, based on
254       usage and conditions.
255
256   Simple specifiers
257       These are strings with no additional specification data.  When creating
258       objects,  non-specified  portions of an object are assumed to defaults.
259       You can find the list of known “Simple Specifiers Below”.
260
261   Asymmetric
262       • rsa
263
264       • ecc
265
266   Symmetric
267       • aes
268
269       • camellia
270
271   Hashing Algorithms
272       • sha1
273
274       • sha256
275
276       • sha384
277
278       • sha512
279
280       • sm3_256
281
282       • sha3_256
283
284       • sha3_384
285
286       • sha3_512
287
288   Keyed Hash
289       • hmac
290
291       • xor
292
293   Signing Schemes
294       • rsassa
295
296       • rsapss
297
298       • ecdsa
299
300       • ecdaa
301
302       • ecschnorr
303
304   Asymmetric Encryption Schemes
305       • oaep
306
307       • rsaes
308
309       • ecdh
310
311   Modes
312       • ctr
313
314       • ofb
315
316       • cbc
317
318       • cfb
319
320       • ecb
321
322   Misc
323       • null
324
325   Complex Specifiers
326       Objects, when specified for creation by the TPM,  have  numerous  algo‐
327       rithms  to  populate  in the public data.  Things like type, scheme and
328       asymmetric details, key size, etc.  Below is  the  general  format  for
329       specifying this data: <type>:<scheme>:<symmetric-details>
330
331   Type Specifiers
332       This  portion  of the complex algorithm specifier is required.  The re‐
333       maining scheme and symmetric details will default  based  on  the  type
334       specified and the type of the object being created.
335
336       • aes - Default AES: aes128
337
338       • aes128<mode>  - 128 bit AES with optional mode (ctr|ofb|cbc|cfb|ecb).
339         If mode is not specified, defaults to null.
340
341       • aes192<mode> - Same as aes128<mode>, except for a 192 bit key size.
342
343       • aes256<mode> - Same as aes128<mode>, except for a 256 bit key size.
344
345       • ecc - Elliptical Curve, defaults to ecc256.
346
347       • ecc192 - 192 bit ECC
348
349       • ecc224 - 224 bit ECC
350
351       • ecc256 - 256 bit ECC
352
353       • ecc384 - 384 bit ECC
354
355       • ecc521 - 521 bit ECC
356
357       • rsa - Default RSA: rsa2048
358
359       • rsa1024 - RSA with 1024 bit keysize.
360
361       • rsa2048 - RSA with 2048 bit keysize.
362
363       • rsa4096 - RSA with 4096 bit keysize.
364
365   Scheme Specifiers
366       Next, is an optional field, it can be skipped.
367
368       Schemes are usually Signing Schemes or Asymmetric  Encryption  Schemes.
369       Most signing schemes take a hash algorithm directly following the sign‐
370       ing scheme.  If the hash algorithm is missing, it defaults  to  sha256.
371       Some take no arguments, and some take multiple arguments.
372
373   Hash Optional Scheme Specifiers
374       These  scheme  specifiers are followed by a dash and a valid hash algo‐
375       rithm, For example: oaep-sha256.
376
377       • oaep
378
379       • ecdh
380
381       • rsassa
382
383       • rsapss
384
385       • ecdsa
386
387       • ecschnorr
388
389   Multiple Option Scheme Specifiers
390       This scheme specifier is followed by a count  (max  size  UINT16)  then
391       followed by a dash(-) and a valid hash algorithm.  * ecdaa For example,
392       ecdaa4-sha256.  If no count is specified, it defaults to 4.
393
394   No Option Scheme Specifiers
395       This scheme specifier takes NO arguments.  * rsaes
396
397   Symmetric Details Specifiers
398       This field is optional, and defaults based on the type of object  being
399       created  and it’s attributes.  Generally, any valid Symmetric specifier
400       from the Type Specifiers list should work.  If not specified, an  asym‐
401       metric objects symmetric details defaults to aes128cfb.
402
403   Examples
404   Create an rsa2048 key with an rsaes asymmetric encryption scheme
405       tpm2_create -C parent.ctx -G rsa2048:rsaes -u key.pub -r key.priv
406
407   Create  an  ecc256  key  with an ecdaa signing scheme with a count of 4 and
408       sha384 hash
409       /tpm2_create  -C  parent.ctx  -G  ecc256:ecdaa4-sha384  -u  key.pub  -r
410       key.priv cryptographic algorithms ALGORITHM.
411

Object Attributes

413       Object Attributes are used to control various properties of created ob‐
414       jects.  When specified as an option, either the raw  bitfield  mask  or
415       “nice-names”  may  be used.  The values can be found in Table 31 Part 2
416       of the TPM2.0 specification, which can be found here:
417
418       <https://trustedcomputinggroup.org/wp-content/uploads/TPM-
419       Rev-2.0-Part-2-Structures-01.38.pdf>
420
421       Nice  names are calculated by taking the name field of table 31 and re‐
422       moving the prefix TPMA_OBJECT_ and lowercasing the result.   Thus,  TP‐
423       MA_OBJECT_FIXEDTPM  becomes  fixedtpm.   Nice names can be joined using
424       the bitwise or “|” symbol.
425
426       For instance, to set The fields TPMA_OBJECT_FIXEDTPM, TPMA_OBJECT_NODA,
427       and TPMA_OBJECT_SIGN_ENCRYPT, the argument would be:
428
429       fixedtpm|noda|sign specifying the object attributes ATTRIBUTES.
430

COMMON OPTIONS

432       This  collection of options are common to many programs and provide in‐
433       formation that many users may expect.
434
435-h, --help=[man|no-man]: Display the tools manpage.  By  default,  it
436         attempts  to  invoke  the  manpager for the tool, however, on failure
437         will output a short tool summary.  This is the same behavior  if  the
438         “man”  option argument is specified, however if explicit “man” is re‐
439         quested, the tool will provide errors from man  on  stderr.   If  the
440         “no-man”  option  if  specified, or the manpager fails, the short op‐
441         tions will be output to stdout.
442
443         To successfully use the manpages feature requires the manpages to  be
444         installed or on MANPATH, See man(1) for more details.
445
446-v,  --version:  Display version information for this tool, supported
447         tctis and exit.
448
449-V, --verbose: Increase the information that the tool prints  to  the
450         console  during  its  execution.  When using this option the file and
451         line number are printed.
452
453-Q, --quiet: Silence normal tool output to stdout.
454
455-Z, --enable-errata: Enable the application of errata fixups.  Useful
456         if  an  errata fixup needs to be applied to commands sent to the TPM.
457         Defining the environment TPM2TOOLS_ENABLE_ERRATA is equivalent.   in‐
458         formation many users may expect.
459

TCTI Configuration

461       The  TCTI  or  “Transmission  Interface” is the communication mechanism
462       with the TPM.  TCTIs can be changed for communication with TPMs  across
463       different mediums.
464
465       To control the TCTI, the tools respect:
466
467       1. The command line option -T or --tcti
468
469       2. The environment variable: TPM2TOOLS_TCTI.
470
471       Note:  The  command  line option always overrides the environment vari‐
472       able.
473
474       The current known TCTIs are:
475
476       • tabrmd     -     The     resource     manager,     called      tabrmd
477         (https://github.com/tpm2-software/tpm2-abrmd).   Note that tabrmd and
478         abrmd as a tcti name are synonymous.
479
480       • mssim - Typically used for communicating to the TPM software  simula‐
481         tor.
482
483       • device - Used when talking directly to a TPM device file.
484
485       • none  - Do not initalize a connection with the TPM.  Some tools allow
486         for off-tpm options and thus support not using a TCTI.  Tools that do
487         not  support  it  will error when attempted to be used without a TCTI
488         connection.  Does not support ANY options and MUST  BE  presented  as
489         the exact text of “none”.
490
491       The  arguments  to  either  the  command line option or the environment
492       variable are in the form:
493
494       <tcti-name>:<tcti-option-config>
495
496       Specifying an empty string for  either  the  <tcti-name>  or  <tcti-op‐
497       tion-config> results in the default being used for that portion respec‐
498       tively.
499
500   TCTI Defaults
501       When a TCTI is not specified, the default TCTI is  searched  for  using
502       dlopen(3)  semantics.   The  tools  will  search for tabrmd, device and
503       mssim TCTIs IN THAT ORDER and USE THE FIRST ONE FOUND.  You  can  query
504       what TCTI will be chosen as the default by using the -v option to print
505       the version information.  The “default-tcti” key-value pair will  indi‐
506       cate which of the aforementioned TCTIs is the default.
507
508   Custom TCTIs
509       Any TCTI that implements the dynamic TCTI interface can be loaded.  The
510       tools internally use dlopen(3), and the raw tcti-name value is used for
511       the lookup.  Thus, this could be a path to the shared library, or a li‐
512       brary name as understood by dlopen(3) semantics.
513

TCTI OPTIONS

515       This collection of options are used to configure the various known TCTI
516       modules available:
517
518device: For the device TCTI, the TPM character device file for use by
519         the device TCTI can be specified.  The default is /dev/tpm0.
520
521         Example:   -T   device:/dev/tpm0   or   export    TPM2TOOLS_TCTI=“de‐
522         vice:/dev/tpm0”
523
524mssim:  For  the  mssim  TCTI, the domain name or IP address and port
525         number used by the simulator  can  be  specified.   The  default  are
526         127.0.0.1 and 2321.
527
528         Example:  -T  mssim:host=localhost,port=2321  or export TPM2TOOLS_TC‐
529         TI=“mssim:host=localhost,port=2321”
530
531abrmd: For the abrmd TCTI, the configuration string format is  a  se‐
532         ries  of  simple  key value pairs separated by a `,' character.  Each
533         key and value string are separated by a `=' character.
534
535         • TCTI abrmd supports two keys:
536
537           1. `bus_name' : The name of  the  tabrmd  service  on  the  bus  (a
538              string).
539
540           2. `bus_type' : The type of the dbus instance (a string) limited to
541              `session' and `system'.
542
543         Specify the tabrmd tcti name and a config string of  bus_name=com.ex‐
544         ample.FooBar:
545
546                \--tcti=tabrmd:bus_name=com.example.FooBar
547
548         Specify the default (abrmd) tcti and a config string of bus_type=ses‐
549         sion:
550
551                \--tcti:bus_type=session
552
553         NOTE: abrmd and tabrmd are synonymous.  the various known  TCTI  mod‐
554         ules.
555

EXAMPLES

557   To import a key, one needs to have a parent key
558              tpm2_createprimary -Grsa2048:aes128cfb -C o -c parent.ctx
559
560       Create your key and and import it.  If you already have a key, just use
561       that and skip creating it.
562
563   Import an AES 128 key
564              dd if=/dev/urandom of=sym.key bs=1 count=16
565
566              tpm2_import -C parent.ctx -G aes -i sym.key -u key.pub -r key.priv
567
568   Import an RSA key
569              openssl genrsa -out private.pem 2048
570
571              tpm2_import -C parent.ctx -G rsa -i private.pem -u key.pub -r key.priv
572
573   Import an ECC key
574              openssl ecparam -name prime256v1 -genkey -noout -out private.ecc.pem
575
576              tpm2_import -C parent.ctx -G ecc -i private.ecc.pem -u key.pub -r key.priv
577
578   Import a duplicated key
579              tpm2_import -C parent.ctx -i key.dup -u key.pub -r key.priv -L policy.dat
580

LIMITATIONS

582       • The TPM requires that the name algorithm of the child be smaller than
583         the parent.
584

Returns

586       Tools can return any of the following codes:
587
588       • 0 - Success.
589
590       • 1 - General non-specific error.
591
592       • 2 - Options handling error.
593
594       • 3 - Authentication error.
595
596       • 4 - TCTI related error.
597
598       • 5 - Non supported scheme.  Applicable to tpm2_testparams.
599

BUGS

601       Github Issues (https://github.com/tpm2-software/tpm2-tools/issues)
602

HELP

604       See the Mailing List (https://lists.01.org/mailman/listinfo/tpm2)
605
606
607
608tpm2-tools                                                      tpm2_import(1)
Impressum