1tpm2_duplicate(1) General Commands Manual tpm2_duplicate(1)
2
3
4
6 tpm2_duplicate(1) - Duplicates a loaded object so that it may be used
7 in a different hierarchy.
8
10 tpm2_duplicate [OPTIONS]
11
13 tpm2_duplicate(1) - This tool duplicates a loaded object so that it may
14 be used in a different hierarchy. The new parent key for the duplicate
15 may be on the same or different TPM or TPM_RH_NULL.
16
18 These options control the key importation process:
19
20 • -G, --wrapper-algorithm=ALGORITHM:
21 The symmetric algorithm to be used for the inner wrapper. Supports:
22
23 • aes - AES 128 in CFB mode.
24
25 • null - none
26
27 • -i, --encryptionkey-in=FILE:
28
29 Specifies the filename of the symmetric key (128 bit data) to be used
30 for the inner wrapper. Valid only when specified symmetric algorithm
31 is not null
32
33 • -o, --encryptionkey-out=FILE:
34
35 Specifies the filename to store the symmetric key (128 bit data) that
36 was used for the inner wrapper. Valid only when specified symmetric
37 algorithm is not null and --input-key-file is not specified. The TPM
38 generates the key in this case.
39
40 • -C, --parent-context=OBJECT:
41
42 The parent key object.
43
44 • -U, --parent-public=FILE:
45
46 Specifies the file path to the public key of the parent object on the
47 destination TPM. This should be a TPM2B_PUBLIC formatted file.
48
49 • -k, --private-key=FILE:
50
51 Specifies the file path to the external private key be encrypted for
52 the remote TPM. This should be a PEM format private key.
53
54 • -r, --private=FILE:
55
56 Specifies the file path to save the private portion of the duplicated
57 object. # Protection Details
58
59 Objects that can move outside of TPM need to be protected (confiden‐
60 tiality and integrity). For instance, transient objects require that
61 TPM protected data (key or seal material) be stored outside of the TPM.
62 This is seen in tools like tpm2_create(1), where the -r option outputs
63 this protected data. This blob contains the sensitive portions of the
64 object. The sensitive portions of the object are protected by the par‐
65 ent object, using the parent’s symmetric encryption details to encrypt
66 the sensitive data and HMAC it.
67
68 In-depth details can be found in sections 23 of:
69
70 • https://trustedcomputinggroup.org/wp-content/up‐
71 loads/TPM-Rev-2.0-Part-1-Architecture-01.38.pdf
72
73 Notably Figure 20, is relevant, even though it’s specifically referring
74 to duplication blobs, the process is identical.
75
76 If the output is from tpm2_duplicate(1), the output will be slightly
77 different, as described fully in section 23.
78
79 • -u, --public=FILE:
80
81 Specifies the file path to save the public portion of the duplicated
82 object, if an external key is being duplicated.
83
84 • -s, --encrypted-seed=FILE:
85
86 The file to save the encrypted seed of the duplicated object.
87
88 • -p, --auth=AUTH:
89
90 The authorization value for the key, optional.
91
92 • -L, --policy=FILE:
93
94 The input policy file, optional.
95
96 • -c, --key-context=OBJECT:
97
98 The object to be duplicated.
99
100 • --cphash=FILE
101
102 File path to record the hash of the command parameters. This is com‐
103 monly termed as cpHash. NOTE: When this option is selected, The tool
104 will not actually execute the command, it simply returns a cpHash.
105
106 References
108 The type of a context object, whether it is a handle or file name, is
109 determined according to the following logic in-order:
110
111 • If the argument is a file path, then the file is loaded as a restored
112 TPM transient object.
113
114 • If the argument is a prefix match on one of:
115
116 • owner: the owner hierarchy
117
118 • platform: the platform hierarchy
119
120 • endorsement: the endorsement hierarchy
121
122 • lockout: the lockout control persistent object
123
124 • If the argument argument can be loaded as a number it will be treat
125 as a handle, e.g. 0x81010013 and used directly._OBJECT_.
126
128 Authorization for use of an object in TPM2.0 can come in 3 different
129 forms: 1. Password 2. HMAC 3. Sessions
130
131 NOTE: “Authorizations default to the EMPTY PASSWORD when not speci‐
132 fied”.
133
134 Passwords
135 Passwords are interpreted in the following forms below using prefix
136 identifiers.
137
138 Note: By default passwords are assumed to be in the string form when
139 they do not have a prefix.
140
141 String
142 A string password, specified by prefix “str:” or it’s absence (raw
143 string without prefix) is not interpreted, and is directly used for au‐
144 thorization.
145
146 Examples
147 foobar
148 str:foobar
149
150 Hex-string
151 A hex-string password, specified by prefix “hex:” is converted from a
152 hexidecimal form into a byte array form, thus allowing passwords with
153 non-printable and/or terminal un-friendly characters.
154
155 Example
156 hex:1122334455667788
157
158 File
159 A file based password, specified be prefix “file:” should be the path
160 of a file containing the password to be read by the tool or a “-” to
161 use stdin. Storing passwords in files prevents information leakage,
162 passwords passed as options can be read from the process list or common
163 shell history features.
164
165 Examples
166 # to use stdin and be prompted
167 file:-
168
169 # to use a file from a path
170 file:path/to/password/file
171
172 # to echo a password via stdin:
173 echo foobar | tpm2_tool -p file:-
174
175 # to use a bash here-string via stdin:
176
177 tpm2_tool -p file:- <<< foobar
178
179 Sessions
180 When using a policy session to authorize the use of an object, prefix
181 the option argument with the session keyword. Then indicate a path to
182 a session file that was created with tpm2_startauthsession(1). Option‐
183 ally, if the session requires an auth value to be sent with the session
184 handle (eg policy password), then append a + and a string as described
185 in the Passwords section.
186
187 Examples
188 To use a session context file called session.ctx.
189
190 session:session.ctx
191
192 To use a session context file called session.ctx AND send the authvalue
193 mypassword.
194
195 session:session.ctx+mypassword
196
197 To use a session context file called session.ctx AND send the HEX auth‐
198 value 0x11223344.
199
200 session:session.ctx+hex:11223344
201
202 PCR Authorizations
203 You can satisfy a PCR policy using the “pcr:” prefix and the PCR mini‐
204 language. The PCR minilanguage is as follows:
205 <pcr-spec>=<raw-pcr-file>
206
207 The PCR spec is documented in in the section “PCR bank specifiers”.
208
209 The raw-pcr-file is an optional argument that contains the output of
210 the raw PCR contents as returned by tpm2_pcrread(1).
211
212 PCR bank specifiers (pcr.md)
213
214 Examples
215 To satisfy a PCR policy of sha256 on banks 0, 1, 2 and 3 use a specifi‐
216 er of:
217
218 pcr:sha256:0,1,2,3
219
220 specifying AUTH.
221
223 Options that take algorithms support “nice-names”.
224
225 There are two major algorithm specification string classes, simple and
226 complex. Only certain algorithms will be accepted by the TPM, based on
227 usage and conditions.
228
229 Simple specifiers
230 These are strings with no additional specification data. When creating
231 objects, non-specified portions of an object are assumed to defaults.
232 You can find the list of known “Simple Specifiers” below.
233
234 Asymmetric
235 • rsa
236
237 • ecc
238
239 Symmetric
240 • aes
241
242 • camellia
243
244 • sm4
245
246 Hashing Algorithms
247 • sha1
248
249 • sha256
250
251 • sha384
252
253 • sha512
254
255 • sm3_256
256
257 • sha3_256
258
259 • sha3_384
260
261 • sha3_512
262
263 Keyed Hash
264 • hmac
265
266 • xor
267
268 Signing Schemes
269 • rsassa
270
271 • rsapss
272
273 • ecdsa
274
275 • ecdaa
276
277 • ecschnorr
278
279 • sm2
280
281 Asymmetric Encryption Schemes
282 • oaep
283
284 • rsaes
285
286 • ecdh
287
288 Modes
289 • ctr
290
291 • ofb
292
293 • cbc
294
295 • cfb
296
297 • ecb
298
299 Misc
300 • null
301
302 Complex Specifiers
303 Objects, when specified for creation by the TPM, have numerous algo‐
304 rithms to populate in the public data. Things like type, scheme and
305 asymmetric details, key size, etc. Below is the general format for
306 specifying this data: <type>:<scheme>:<symmetric-details>
307
308 Type Specifiers
309 This portion of the complex algorithm specifier is required. The re‐
310 maining scheme and symmetric details will default based on the type
311 specified and the type of the object being created.
312
313 • aes - Default AES: aes128
314
315 • aes128<mode> - 128 bit AES with optional mode (ctr|ofb|cbc|cfb|ecb).
316 If mode is not specified, defaults to null.
317
318 • aes192<mode> - Same as aes128<mode>, except for a 192 bit key size.
319
320 • aes256<mode> - Same as aes128<mode>, except for a 256 bit key size.
321
322 • sm4 - Default SM4: sm4128
323
324 • sm4128 or sm4_128 <mode> - 128 bit SM4 with optional mode
325 (ctr|ofb|cbc|cfb|ecb). If mode is not specified, defaults to null.
326
327 • ecc - Elliptical Curve, defaults to ecc256.
328
329 • ecc192 or ecc_nist_p192 - 192 bit ECC NIST curve
330
331 • ecc224 or ecc_nist_p224 - 224 bit ECC NIST curve
332
333 • ecc256 or ecc_nist_p256 - 256 bit ECC NIST curve
334
335 • ecc384 or ecc_nist_p384 - 384 bit ECC NIST curve
336
337 • ecc521 or ecc_nist_p521 - 521 bit ECC NIST curve
338
339 • ecc_sm2 or ecc_sm2_p256 - 256 bit SM2 curve
340
341 • rsa - Default RSA: rsa2048
342
343 • rsa1024 - RSA with 1024 bit keysize.
344
345 • rsa2048 - RSA with 2048 bit keysize.
346
347 • rsa3072 - RSA with 3072 bit keysize.
348
349 • rsa4096 - RSA with 4096 bit keysize.
350
351 Scheme Specifiers
352 Next, is an optional field, it can be skipped.
353
354 Schemes are usually Signing Schemes or Asymmetric Encryption Schemes.
355 Most signing schemes take a hash algorithm directly following the sign‐
356 ing scheme. If the hash algorithm is missing, it defaults to sha256.
357 Some take no arguments, and some take multiple arguments.
358
359 Hash Optional Scheme Specifiers
360 These scheme specifiers are followed by a dash and a valid hash algo‐
361 rithm, For example: oaep-sha256.
362
363 • oaep
364
365 • ecdh
366
367 • rsassa
368
369 • rsapss
370
371 • ecdsa
372
373 • ecschnorr
374
375 • sm2
376
377 Multiple Option Scheme Specifiers
378 This scheme specifier is followed by a count (max size UINT16) then
379 followed by a dash(-) and a valid hash algorithm. * ecdaa For example,
380 ecdaa4-sha256. If no count is specified, it defaults to 4.
381
382 No Option Scheme Specifiers
383 This scheme specifier takes NO arguments. * rsaes
384
385 Symmetric Details Specifiers
386 This field is optional, and defaults based on the type of object being
387 created and it’s attributes. Generally, any valid Symmetric specifier
388 from the Type Specifiers list should work. If not specified, an asym‐
389 metric objects symmetric details defaults to aes128cfb.
390
391 Examples
392 Create an rsa2048 key with an rsaes asymmetric encryption scheme
393 tpm2_create -C parent.ctx -G rsa2048:rsaes -u key.pub -r key.priv
394
395 Create an ecc256 key with an ecdaa signing scheme with a count of 4 and
396 sha384 hash
397 /tpm2_create -C parent.ctx -G ecc256:ecdaa4-sha384 -u key.pub -r
398 key.priv cryptographic algorithms ALGORITHM.
399
401 This collection of options are common to many programs and provide in‐
402 formation that many users may expect.
403
404 • -h, --help=[man|no-man]: Display the tools manpage. By default, it
405 attempts to invoke the manpager for the tool, however, on failure
406 will output a short tool summary. This is the same behavior if the
407 “man” option argument is specified, however if explicit “man” is re‐
408 quested, the tool will provide errors from man on stderr. If the
409 “no-man” option if specified, or the manpager fails, the short op‐
410 tions will be output to stdout.
411
412 To successfully use the manpages feature requires the manpages to be
413 installed or on MANPATH, See man(1) for more details.
414
415 • -v, --version: Display version information for this tool, supported
416 tctis and exit.
417
418 • -V, --verbose: Increase the information that the tool prints to the
419 console during its execution. When using this option the file and
420 line number are printed.
421
422 • -Q, --quiet: Silence normal tool output to stdout.
423
424 • -Z, --enable-errata: Enable the application of errata fixups. Useful
425 if an errata fixup needs to be applied to commands sent to the TPM.
426 Defining the environment TPM2TOOLS_ENABLE_ERRATA is equivalent. in‐
427 formation many users may expect.
428
430 The TCTI or “Transmission Interface” is the communication mechanism
431 with the TPM. TCTIs can be changed for communication with TPMs across
432 different mediums.
433
434 To control the TCTI, the tools respect:
435
436 1. The command line option -T or --tcti
437
438 2. The environment variable: TPM2TOOLS_TCTI.
439
440 Note: The command line option always overrides the environment vari‐
441 able.
442
443 The current known TCTIs are:
444
445 • tabrmd - The resource manager, called tabrmd
446 (https://github.com/tpm2-software/tpm2-abrmd). Note that tabrmd and
447 abrmd as a tcti name are synonymous.
448
449 • mssim - Typically used for communicating to the TPM software simula‐
450 tor.
451
452 • device - Used when talking directly to a TPM device file.
453
454 • none - Do not initalize a connection with the TPM. Some tools allow
455 for off-tpm options and thus support not using a TCTI. Tools that do
456 not support it will error when attempted to be used without a TCTI
457 connection. Does not support ANY options and MUST BE presented as
458 the exact text of “none”.
459
460 The arguments to either the command line option or the environment
461 variable are in the form:
462
463 <tcti-name>:<tcti-option-config>
464
465 Specifying an empty string for either the <tcti-name> or <tcti-op‐
466 tion-config> results in the default being used for that portion respec‐
467 tively.
468
469 TCTI Defaults
470 When a TCTI is not specified, the default TCTI is searched for using
471 dlopen(3) semantics. The tools will search for tabrmd, device and
472 mssim TCTIs IN THAT ORDER and USE THE FIRST ONE FOUND. You can query
473 what TCTI will be chosen as the default by using the -v option to print
474 the version information. The “default-tcti” key-value pair will indi‐
475 cate which of the aforementioned TCTIs is the default.
476
477 Custom TCTIs
478 Any TCTI that implements the dynamic TCTI interface can be loaded. The
479 tools internally use dlopen(3), and the raw tcti-name value is used for
480 the lookup. Thus, this could be a path to the shared library, or a li‐
481 brary name as understood by dlopen(3) semantics.
482
484 This collection of options are used to configure the various known TCTI
485 modules available:
486
487 • device: For the device TCTI, the TPM character device file for use by
488 the device TCTI can be specified. The default is /dev/tpm0.
489
490 Example: -T device:/dev/tpm0 or export TPM2TOOLS_TCTI=“de‐
491 vice:/dev/tpm0”
492
493 • mssim: For the mssim TCTI, the domain name or IP address and port
494 number used by the simulator can be specified. The default are
495 127.0.0.1 and 2321.
496
497 Example: -T mssim:host=localhost,port=2321 or export TPM2TOOLS_TC‐
498 TI=“mssim:host=localhost,port=2321”
499
500 • abrmd: For the abrmd TCTI, the configuration string format is a se‐
501 ries of simple key value pairs separated by a `,' character. Each
502 key and value string are separated by a `=' character.
503
504 • TCTI abrmd supports two keys:
505
506 1. `bus_name' : The name of the tabrmd service on the bus (a
507 string).
508
509 2. `bus_type' : The type of the dbus instance (a string) limited to
510 `session' and `system'.
511
512 Specify the tabrmd tcti name and a config string of bus_name=com.ex‐
513 ample.FooBar:
514
515 \--tcti=tabrmd:bus_name=com.example.FooBar
516
517 Specify the default (abrmd) tcti and a config string of bus_type=ses‐
518 sion:
519
520 \--tcti:bus_type=session
521
522 NOTE: abrmd and tabrmd are synonymous. the various known TCTI mod‐
523 ules.
524
526 Example-1: Duplicate a key created with a policy that allows for duplica‐
527 tion:
528 tpm2_startauthsession -S session.dat
529 tpm2_policycommandcode -S session.dat -L policy.dat TPM2_CC_Duplicate
530 tpm2_flushcontext session.dat
531
532 tpm2_createprimary -C o -g sha256 -G rsa -c primary.ctxt
533 tpm2_create -C primary.ctxt -g sha256 -G rsa -r key.prv -u key.pub -c key.ctxt \
534 -L policy.dat -a "sensitivedataorigin|userwithauth|decrypt|sign"
535
536 tpm2_createprimary -C o -g sha256 -G ecc -c new_parent.ctxt
537
538 tpm2_startauthsession \--policy-session -S session.dat
539 tpm2_policycommandcode -S session.dat -L policy.dat TPM2_CC_Duplicate
540 tpm2_duplicate -C new_parent.ctxt -c key.ctxt -G null -p "session:session.dat" \
541 -r duprv.bin -s seed.dat
542 tpm2_flushcontext session.dat
543
544 Example-2: As an end-to-end example, the following will transfer an RSA key
545 generated on TPM-A to TPM-B
546 On TPM-B
547 Create a parent object that will be used to wrap/transfer the key.
548
549 tpm2_createprimary -C o -g sha256 -G rsa -c primary.ctx
550
551 tpm2_create -C primary.ctx -g sha256 -G rsa \
552 -r new_parent.prv -u new_parent.pub \
553 -a "restricted|sensitivedataorigin|decrypt|userwithauth"
554
555 Copy new_parent.pub to TPM-A.
556
557 On TPM-A
558 Create root object and auth policy allows duplication only
559
560 tpm2_createprimary -C o -g sha256 -G rsa -c primary.ctx
561
562 tpm2_startauthsession -S session.dat
563
564 tpm2_policycommandcode -S session.dat -L dpolicy.dat TPM2_CC_Duplicate
565
566 tpm2_flushcontext session.dat
567
568 rm session.dat
569
570 Generate an RSA keypair on TPM-A that will be duplicated (note the
571 passphrase is `foo')
572
573 tpm2_create -C primary.ctx -g sha256 -G rsa -p foo -r key.prv \
574 -u key.pub -L dpolicy.dat -a "sensitivedataorigin|userwithauth|decrypt|sign"
575
576 tpm2_load -C primary.ctx -r key.prv -u key.pub -c key.ctx
577
578 tpm2_readpublic -c key.ctx -o dup.pub
579
580 Test sign and encryption locally (so we can compare later that the same
581 key was transferred).
582
583 echo "meet me at.." >file.txt
584 tpm2_rsaencrypt -c key.ctx -o data.encrypted file.txt
585 tpm2_sign -c key.ctx -g sha256 -f plain -p foo -o sign.raw file.txt
586
587 Compare the signature hash (we will use this later to confirm the key
588 was transferred to TPM-B):
589
590 sha256sum sign.raw
591
592 a1b4e3fbaa29e6e46d95cff498150b6b8e7d9fd21182622e8f5a3ddde257879e
593
594 Start an auth session and policy command to allow duplication
595
596 tpm2_startauthsession --policy-session -S session.dat
597
598 tpm2_policycommandcode -S session.dat -L dpolicy.dat TPM2_CC_Duplicate
599
600 Load the new_parent.pub file transferred from TPM-B
601
602 tpm2_loadexternal -C o -u new_parent.pub -c new_parent.ctx
603
604 Start the duplication
605
606 tpm2_duplicate -C new_parent.ctx -c key.ctx -G null \
607 -p "session:session.dat" -r dup.dpriv -s dup.seed
608
609 Copy the following files to TPM-B: * dup.pub * dup.dpriv * dup.seed *
610 (optionally data.encrypted just to test decryption)
611
612 On TPM-B
613 Start an auth,policy session
614
615 tpm2_startauthsession --policy-session -S session.dat
616
617 tpm2_policycommandcode -S session.dat -L dpolicy.dat TPM2_CC_Duplicate
618
619 Load the context we used to transfer
620
621 tpm2_flushcontext --transient-object
622
623 tpm2_load -C primary.ctx -u new_parent.pub -r new_parent.prv -c new_parent.ctx
624
625 Import the duplicated context against the parent we used
626
627 tpm2_import -C new_parent.ctx -u dup.pub -i dup.dpriv \
628 -r dup.prv -s dup.seed -L dpolicy.dat
629
630 Load the duplicated key context
631
632 tpm2_flushcontext --transient-object
633
634 tpm2_load -C new_parent.ctx -u dup.pub -r dup.prv -c dup.ctx
635
636 Test the imported key matches
637
638 • Sign
639
640 echo "meet me at.." >file.txt
641
642 tpm2_sign -c dup.ctx -g sha256 -o sig.rss -p foo file.txt
643
644 dd if=sig.rss of=sign.raw bs=1 skip=6 count=256
645
646 Compare the signature file hash:
647
648 $ sha256sum sign.raw
649
650 a1b4e3fbaa29e6e46d95cff498150b6b8e7d9fd21182622e8f5a3ddde257879e
651
652 • Decryption
653
654 tpm2_flushcontext --transient-object
655
656 tpm2_rsadecrypt -p foo -c dup.ctx -o data.ptext data.encrypted
657
658 # cat data.ptext
659 meet me at..
660
661 Example-3: Exporting an OpenSSL RSA key for a remote TPM
662 To securely send an OpenSSL generated RSA key to a remote TPM such that
663 only that remote TPM will be able to load it, and without exposing the
664 private key to the host operating system on the remote machine:
665
666 • On the destination TPM-B, create a primary context and read its pub‐
667 lic key, then send primary.pub to the source machine:
668
669 tpm2_createprimary -c primary.ctx
670 tpm2_readpublic -c primary.ctx -o primary.pub
671
672 • On the source machine create the RSA private key and wrap it for the
673 destination TPM’s public key. Similar to tpm2_makecredential, this
674 step should not require a TPM.
675
676 openssl genrsa -out rsa.pem
677 tpm2_duplicate -U primary.pub -G rsa -k rsa.pem -u rsa.pub -r rsa.dpriv -s rsa.seed
678
679 • Send the rsa.pub, rsa.dpriv and rsa.seed to the destination TPM-B and
680 import the files, which will decrypt them using the primary.ctx to
681 produce rsa.priv, which can then be loaded and used as a TPM key:
682
683 tpm2_import -C primary.ctx -G rsa -i rsa.dpriv -s rsa.seed -u rsa.pub -r rsa.priv
684 tpm2_load -C primary.ctx -c rsa.ctx -u rsa.pub -r rsa.priv
685
687 Tools can return any of the following codes:
688
689 • 0 - Success.
690
691 • 1 - General non-specific error.
692
693 • 2 - Options handling error.
694
695 • 3 - Authentication error.
696
697 • 4 - TCTI related error.
698
699 • 5 - Non supported scheme. Applicable to tpm2_testparams.
700
702 Github Issues (https://github.com/tpm2-software/tpm2-tools/issues)
703
705 See the Mailing List (https://lists.linuxfoundation.org/mailman/listin‐
706 fo/tpm2)
707
708
709
710tpm2-tools tpm2_duplicate(1)