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 or HEX_STRING:
112
113         The policy file or policy hex string used for  authorization  to  the
114         object.
115
116-s, --seed=FILE:
117
118         Specifies  the  file  containing the encrypted seed of the duplicated
119         object.
120
121         In order to perform an “unencrypted import” a seed file with the con‐
122         tent  0x0000  needs  to  be  provided (e.g. printf “0000” | xxd -r -p
123         >seed.file).
124
125--passin=OSSL_PEM_FILE_PASSWORD
126
127         An optional password for an Open SSL (OSSL) provided input file.   It
128         mirrors  the -passin option of OSSL and is known to support the pass,
129         file, env, fd and plain password formats  of  openssl.   (see  man(1)
130         openssl) for more.
131
132--cphash=FILE
133
134         File path to record the hash of the command parameters.  This is com‐
135         monly termed as cpHash.  NOTE: When this option is selected, The tool
136         will not actually execute the command, it simply returns a cpHash.
137
138   References

Context Object Format

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

Authorization Formatting

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

Algorithm Specifiers

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

Object Attributes

433       Object Attributes are used to control various properties of created ob‐
434       jects.  When specified as an option, either the raw  bitfield  mask  or
435       “nice-names”  may  be used.  The values can be found in Table 31 Part 2
436       of the TPM2.0 specification, which can be found here:
437
438       <https://trustedcomputinggroup.org/wp-content/uploads/TPM-
439       Rev-2.0-Part-2-Structures-01.38.pdf>
440
441       Nice  names are calculated by taking the name field of table 31 and re‐
442       moving the prefix TPMA_OBJECT_ and lowercasing the result.   Thus,  TP‐
443       MA_OBJECT_FIXEDTPM  becomes  fixedtpm.   Nice names can be joined using
444       the bitwise or “|” symbol.
445
446       For instance, to set The fields TPMA_OBJECT_FIXEDTPM, TPMA_OBJECT_NODA,
447       and TPMA_OBJECT_SIGN_ENCRYPT, the argument would be:
448
449       fixedtpm|noda|sign specifying the object attributes ATTRIBUTES.
450

COMMON OPTIONS

452       This  collection of options are common to many programs and provide in‐
453       formation that many users may expect.
454
455-h, --help=[man|no-man]: Display the tools manpage.  By  default,  it
456         attempts  to  invoke  the  manpager for the tool, however, on failure
457         will output a short tool summary.  This is the same behavior  if  the
458         “man”  option argument is specified, however if explicit “man” is re‐
459         quested, the tool will provide errors from man  on  stderr.   If  the
460         “no-man”  option  if  specified, or the manpager fails, the short op‐
461         tions will be output to stdout.
462
463         To successfully use the manpages feature requires the manpages to  be
464         installed or on MANPATH, See man(1) for more details.
465
466-v,  --version:  Display version information for this tool, supported
467         tctis and exit.
468
469-V, --verbose: Increase the information that the tool prints  to  the
470         console  during  its  execution.  When using this option the file and
471         line number are printed.
472
473-Q, --quiet: Silence normal tool output to stdout.
474
475-Z, --enable-errata: Enable the application of errata fixups.  Useful
476         if  an  errata fixup needs to be applied to commands sent to the TPM.
477         Defining the environment TPM2TOOLS_ENABLE_ERRATA is equivalent.   in‐
478         formation many users may expect.
479

TCTI Configuration

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

TCTI OPTIONS

535       This collection of options are used to configure the various known TCTI
536       modules available:
537
538device: For the device TCTI, the TPM character device file for use by
539         the device TCTI can be specified.  The default is /dev/tpm0.
540
541         Example:   -T   device:/dev/tpm0   or   export    TPM2TOOLS_TCTI=“de‐
542         vice:/dev/tpm0”
543
544mssim:  For  the  mssim  TCTI, the domain name or IP address and port
545         number used by the simulator  can  be  specified.   The  default  are
546         127.0.0.1 and 2321.
547
548         Example:  -T  mssim:host=localhost,port=2321  or export TPM2TOOLS_TC‐
549         TI=“mssim:host=localhost,port=2321”
550
551abrmd: For the abrmd TCTI, the configuration string format is  a  se‐
552         ries  of  simple  key value pairs separated by a `,' character.  Each
553         key and value string are separated by a `=' character.
554
555         • TCTI abrmd supports two keys:
556
557           1. `bus_name' : The name of  the  tabrmd  service  on  the  bus  (a
558              string).
559
560           2. `bus_type' : The type of the dbus instance (a string) limited to
561              `session' and `system'.
562
563         Specify the tabrmd tcti name and a config string of  bus_name=com.ex‐
564         ample.FooBar:
565
566                \--tcti=tabrmd:bus_name=com.example.FooBar
567
568         Specify the default (abrmd) tcti and a config string of bus_type=ses‐
569         sion:
570
571                \--tcti:bus_type=session
572
573         NOTE: abrmd and tabrmd are synonymous.  the various known  TCTI  mod‐
574         ules.
575

EXAMPLES

577   To import a key, one needs to have a parent key
578              tpm2_createprimary -Grsa2048:aes128cfb -C o -c parent.ctx
579
580       Create your key and and import it.  If you already have a key, just use
581       that and skip creating it.
582
583   Import an AES 128 key
584              dd if=/dev/urandom of=sym.key bs=1 count=16
585
586              tpm2_import -C parent.ctx -G aes -i sym.key -u key.pub -r key.priv
587
588   Import an RSA key
589              openssl genrsa -out private.pem 2048
590
591              tpm2_import -C parent.ctx -G rsa -i private.pem -u key.pub -r key.priv
592
593   Import an ECC key
594              openssl ecparam -name prime256v1 -genkey -noout -out private.ecc.pem
595
596              tpm2_import -C parent.ctx -G ecc -i private.ecc.pem -u key.pub -r key.priv
597
598   Import a duplicated key
599              tpm2_import -C parent.ctx -i key.dup -u key.pub -r key.priv -L policy.dat
600

LIMITATIONS

602       • The TPM requires that the name algorithm of the child be smaller than
603         the parent.
604

Returns

606       Tools can return any of the following codes:
607
608       • 0 - Success.
609
610       • 1 - General non-specific error.
611
612       • 2 - Options handling error.
613
614       • 3 - Authentication error.
615
616       • 4 - TCTI related error.
617
618       • 5 - Non supported scheme.  Applicable to tpm2_testparams.
619

BUGS

621       Github Issues (https://github.com/tpm2-software/tpm2-tools/issues)
622

HELP

624       See the Mailing List (https://lists.linuxfoundation.org/mailman/listin
625       fo/tpm2)
626
627
628
629tpm2-tools                                                      tpm2_import(1)
Impressum