1tpm2_sign(1) General Commands Manual tpm2_sign(1)
2
3
4
6 tpm2_sign(1) - Sign a hash or message using the TPM.
7
9 tpm2_sign [OPTIONS] [ARGUMENT]
10
12 tpm2_sign(1) - Generates signature of specified message or message-di‐
13 gest using the specified symmetric or asymmetric signing key.
14
15 When signing a message, tpm2_sign utility first calculates the digest
16 of the message similar to the tpm2_hash command. It also generates a
17 validation ticket under TPM2_RH_NULL or TPM2_RH_OWNER hierarchies re‐
18 spectively for unrestricted or the restricted signing keys.
19
20 While signing messages is a provision in this tool it is recommended to
21 use the tpm2_hash tool first and pass the digest and validation ticket.
22
23 NOTE: If the signing key is a restricted signing key, then validation
24 and digest must be provided via the -t input. The ticket indicates
25 that the TPM performed the hash of the message.
26
28 • -c, --key-context=OBJECT:
29
30 Context object pointing to the the key used for signing. Either a
31 file or a handle number. See section “Context Object Format”.
32
33 • -p, --auth_AUTH_:
34
35 Optional authorization value to use the key specified by -c. Autho‐
36 rization values should follow the “authorization formatting stan‐
37 dards”, see section “Authorization Formatting”.
38
39 • -g, --hash-algorithm=ALGORITHM:
40
41 The hash algorithm used to digest the message. Algorithms should
42 follow the “formatting standards”, see section “Algorithm Speci‐
43 fiers”. Also, see section “Supported Hash Algorithms” for a list of
44 supported hash algorithms.
45
46 • -s, --scheme=ALGORITHM:
47
48 The signing scheme used to sign the message. Optional.
49
50 Signing schemes should follow the “formatting standards”, see section
51 “Algorithm Specifiers”.
52
53 If specified, the signature scheme must match the key type. If left
54 unspecified, a default signature scheme for the key type will be
55 used.
56
57 • -d, --digest:
58
59 Indicate that FILE is a file containing the digest of the message.
60 When this option and -t is specified, a warning is generated and the
61 validation ticket (-t) is ignored. You cannot use this option to
62 sign a digest against a restricted signing key.
63
64 • -t, --ticket=FILE:
65
66 The ticket file, containing the validation structure, optional.
67
68 • -o, --signature=FILE:
69
70 The signature file, records the signature structure.
71
72 • -f, --format=FORMAT:
73
74 Format selection for the signature output file. See section “Signa‐
75 ture Format Specifiers”.
76
77 • --cphash=FILE
78
79 File path to record the hash of the command parameters. This is com‐
80 monly termed as cpHash. NOTE: When this option is selected, The tool
81 will not actually execute the command, it simply returns a cpHash.
82
83 • --commit-index=NATURALNUMBER
84
85 The commit counter value to determine the key index to use in an EC‐
86 DAA signing scheme. The default counter value is 0.
87
88 • ARGUMENT the command line argument specifies the file data for sign.
89
90 References
92 The type of a context object, whether it is a handle or file name, is
93 determined according to the following logic in-order:
94
95 • If the argument is a file path, then the file is loaded as a restored
96 TPM transient object.
97
98 • If the argument is a prefix match on one of:
99
100 • owner: the owner hierarchy
101
102 • platform: the platform hierarchy
103
104 • endorsement: the endorsement hierarchy
105
106 • lockout: the lockout control persistent object
107
108 • If the argument argument can be loaded as a number it will be treat
109 as a handle, e.g. 0x81010013 and used directly._OBJECT_.
110
112 Authorization for use of an object in TPM2.0 can come in 3 different
113 forms: 1. Password 2. HMAC 3. Sessions
114
115 NOTE: “Authorizations default to the EMPTY PASSWORD when not speci‐
116 fied”.
117
118 Passwords
119 Passwords are interpreted in the following forms below using prefix
120 identifiers.
121
122 Note: By default passwords are assumed to be in the string form when
123 they do not have a prefix.
124
125 String
126 A string password, specified by prefix “str:” or it’s absence (raw
127 string without prefix) is not interpreted, and is directly used for au‐
128 thorization.
129
130 Examples
131 foobar
132 str:foobar
133
134 Hex-string
135 A hex-string password, specified by prefix “hex:” is converted from a
136 hexidecimal form into a byte array form, thus allowing passwords with
137 non-printable and/or terminal un-friendly characters.
138
139 Example
140 hex:1122334455667788
141
142 File
143 A file based password, specified be prefix “file:” should be the path
144 of a file containing the password to be read by the tool or a “-” to
145 use stdin. Storing passwords in files prevents information leakage,
146 passwords passed as options can be read from the process list or common
147 shell history features.
148
149 Examples
150 # to use stdin and be prompted
151 file:-
152
153 # to use a file from a path
154 file:path/to/password/file
155
156 # to echo a password via stdin:
157 echo foobar | tpm2_tool -p file:-
158
159 # to use a bash here-string via stdin:
160
161 tpm2_tool -p file:- <<< foobar
162
163 Sessions
164 When using a policy session to authorize the use of an object, prefix
165 the option argument with the session keyword. Then indicate a path to
166 a session file that was created with tpm2_startauthsession(1). Option‐
167 ally, if the session requires an auth value to be sent with the session
168 handle (eg policy password), then append a + and a string as described
169 in the Passwords section.
170
171 Examples
172 To use a session context file called session.ctx.
173
174 session:session.ctx
175
176 To use a session context file called session.ctx AND send the authvalue
177 mypassword.
178
179 session:session.ctx+mypassword
180
181 To use a session context file called session.ctx AND send the HEX auth‐
182 value 0x11223344.
183
184 session:session.ctx+hex:11223344
185
186 PCR Authorizations
187 You can satisfy a PCR policy using the “pcr:” prefix and the PCR mini‐
188 language. The PCR minilanguage is as follows:
189 <pcr-spec>=<raw-pcr-file>
190
191 The PCR spec is documented in in the section “PCR bank specifiers”.
192
193 The raw-pcr-file is an optional argument that contains the output of
194 the raw PCR contents as returned by tpm2_pcrread(1).
195
196 PCR bank specifiers (pcr.md)
197
198 Examples
199 To satisfy a PCR policy of sha256 on banks 0, 1, 2 and 3 use a specifi‐
200 er of:
201
202 pcr:sha256:0,1,2,3
203
204 specifying AUTH.
205
207 Options that take algorithms support “nice-names”.
208
209 There are two major algorithm specification string classes, simple and
210 complex. Only certain algorithms will be accepted by the TPM, based on
211 usage and conditions.
212
213 Simple specifiers
214 These are strings with no additional specification data. When creating
215 objects, non-specified portions of an object are assumed to defaults.
216 You can find the list of known “Simple Specifiers” below.
217
218 Asymmetric
219 • rsa
220
221 • ecc
222
223 Symmetric
224 • aes
225
226 • camellia
227
228 • sm4
229
230 Hashing Algorithms
231 • sha1
232
233 • sha256
234
235 • sha384
236
237 • sha512
238
239 • sm3_256
240
241 • sha3_256
242
243 • sha3_384
244
245 • sha3_512
246
247 Keyed Hash
248 • hmac
249
250 • xor
251
252 Signing Schemes
253 • rsassa
254
255 • rsapss
256
257 • ecdsa
258
259 • ecdaa
260
261 • ecschnorr
262
263 • sm2
264
265 Asymmetric Encryption Schemes
266 • oaep
267
268 • rsaes
269
270 • ecdh
271
272 Modes
273 • ctr
274
275 • ofb
276
277 • cbc
278
279 • cfb
280
281 • ecb
282
283 Misc
284 • null
285
286 Complex Specifiers
287 Objects, when specified for creation by the TPM, have numerous algo‐
288 rithms to populate in the public data. Things like type, scheme and
289 asymmetric details, key size, etc. Below is the general format for
290 specifying this data: <type>:<scheme>:<symmetric-details>
291
292 Type Specifiers
293 This portion of the complex algorithm specifier is required. The re‐
294 maining scheme and symmetric details will default based on the type
295 specified and the type of the object being created.
296
297 • aes - Default AES: aes128
298
299 • aes128<mode> - 128 bit AES with optional mode (ctr|ofb|cbc|cfb|ecb).
300 If mode is not specified, defaults to null.
301
302 • aes192<mode> - Same as aes128<mode>, except for a 192 bit key size.
303
304 • aes256<mode> - Same as aes128<mode>, except for a 256 bit key size.
305
306 • sm4 - Default SM4: sm4128
307
308 • sm4128 or sm4_128 <mode> - 128 bit SM4 with optional mode
309 (ctr|ofb|cbc|cfb|ecb). If mode is not specified, defaults to null.
310
311 • ecc - Elliptical Curve, defaults to ecc256.
312
313 • ecc192 or ecc_nist_p192 - 192 bit ECC NIST curve
314
315 • ecc224 or ecc_nist_p224 - 224 bit ECC NIST curve
316
317 • ecc256 or ecc_nist_p256 - 256 bit ECC NIST curve
318
319 • ecc384 or ecc_nist_p384 - 384 bit ECC NIST curve
320
321 • ecc521 or ecc_nist_p521 - 521 bit ECC NIST curve
322
323 • ecc_sm2 or ecc_sm2_p256 - 256 bit SM2 curve
324
325 • rsa - Default RSA: rsa2048
326
327 • rsa1024 - RSA with 1024 bit keysize.
328
329 • rsa2048 - RSA with 2048 bit keysize.
330
331 • rsa3072 - RSA with 3072 bit keysize.
332
333 • rsa4096 - RSA with 4096 bit keysize.
334
335 Scheme Specifiers
336 Next, is an optional field, it can be skipped.
337
338 Schemes are usually Signing Schemes or Asymmetric Encryption Schemes.
339 Most signing schemes take a hash algorithm directly following the sign‐
340 ing scheme. If the hash algorithm is missing, it defaults to sha256.
341 Some take no arguments, and some take multiple arguments.
342
343 Hash Optional Scheme Specifiers
344 These scheme specifiers are followed by a dash and a valid hash algo‐
345 rithm, For example: oaep-sha256.
346
347 • oaep
348
349 • ecdh
350
351 • rsassa
352
353 • rsapss
354
355 • ecdsa
356
357 • ecschnorr
358
359 • sm2
360
361 Multiple Option Scheme Specifiers
362 This scheme specifier is followed by a count (max size UINT16) then
363 followed by a dash(-) and a valid hash algorithm. * ecdaa For example,
364 ecdaa4-sha256. If no count is specified, it defaults to 4.
365
366 No Option Scheme Specifiers
367 This scheme specifier takes NO arguments. * rsaes
368
369 Symmetric Details Specifiers
370 This field is optional, and defaults based on the type of object being
371 created and it’s attributes. Generally, any valid Symmetric specifier
372 from the Type Specifiers list should work. If not specified, an asym‐
373 metric objects symmetric details defaults to aes128cfb.
374
375 Examples
376 Create an rsa2048 key with an rsaes asymmetric encryption scheme
377 tpm2_create -C parent.ctx -G rsa2048:rsaes -u key.pub -r key.priv
378
379 Create an ecc256 key with an ecdaa signing scheme with a count of 4 and
380 sha384 hash
381 /tpm2_create -C parent.ctx -G ecc256:ecdaa4-sha384 -u key.pub -r
382 key.priv cryptographic algorithms ALGORITHM.
383
385 This collection of options are common to many programs and provide in‐
386 formation that many users may expect.
387
388 • -h, --help=[man|no-man]: Display the tools manpage. By default, it
389 attempts to invoke the manpager for the tool, however, on failure
390 will output a short tool summary. This is the same behavior if the
391 “man” option argument is specified, however if explicit “man” is re‐
392 quested, the tool will provide errors from man on stderr. If the
393 “no-man” option if specified, or the manpager fails, the short op‐
394 tions will be output to stdout.
395
396 To successfully use the manpages feature requires the manpages to be
397 installed or on MANPATH, See man(1) for more details.
398
399 • -v, --version: Display version information for this tool, supported
400 tctis and exit.
401
402 • -V, --verbose: Increase the information that the tool prints to the
403 console during its execution. When using this option the file and
404 line number are printed.
405
406 • -Q, --quiet: Silence normal tool output to stdout.
407
408 • -Z, --enable-errata: Enable the application of errata fixups. Useful
409 if an errata fixup needs to be applied to commands sent to the TPM.
410 Defining the environment TPM2TOOLS_ENABLE_ERRATA is equivalent. in‐
411 formation many users may expect.
412
414 The TCTI or “Transmission Interface” is the communication mechanism
415 with the TPM. TCTIs can be changed for communication with TPMs across
416 different mediums.
417
418 To control the TCTI, the tools respect:
419
420 1. The command line option -T or --tcti
421
422 2. The environment variable: TPM2TOOLS_TCTI.
423
424 Note: The command line option always overrides the environment vari‐
425 able.
426
427 The current known TCTIs are:
428
429 • tabrmd - The resource manager, called tabrmd
430 (https://github.com/tpm2-software/tpm2-abrmd). Note that tabrmd and
431 abrmd as a tcti name are synonymous.
432
433 • mssim - Typically used for communicating to the TPM software simula‐
434 tor.
435
436 • device - Used when talking directly to a TPM device file.
437
438 • none - Do not initalize a connection with the TPM. Some tools allow
439 for off-tpm options and thus support not using a TCTI. Tools that do
440 not support it will error when attempted to be used without a TCTI
441 connection. Does not support ANY options and MUST BE presented as
442 the exact text of “none”.
443
444 The arguments to either the command line option or the environment
445 variable are in the form:
446
447 <tcti-name>:<tcti-option-config>
448
449 Specifying an empty string for either the <tcti-name> or <tcti-op‐
450 tion-config> results in the default being used for that portion respec‐
451 tively.
452
453 TCTI Defaults
454 When a TCTI is not specified, the default TCTI is searched for using
455 dlopen(3) semantics. The tools will search for tabrmd, device and
456 mssim TCTIs IN THAT ORDER and USE THE FIRST ONE FOUND. You can query
457 what TCTI will be chosen as the default by using the -v option to print
458 the version information. The “default-tcti” key-value pair will indi‐
459 cate which of the aforementioned TCTIs is the default.
460
461 Custom TCTIs
462 Any TCTI that implements the dynamic TCTI interface can be loaded. The
463 tools internally use dlopen(3), and the raw tcti-name value is used for
464 the lookup. Thus, this could be a path to the shared library, or a li‐
465 brary name as understood by dlopen(3) semantics.
466
468 This collection of options are used to configure the various known TCTI
469 modules available:
470
471 • device: For the device TCTI, the TPM character device file for use by
472 the device TCTI can be specified. The default is /dev/tpm0.
473
474 Example: -T device:/dev/tpm0 or export TPM2TOOLS_TCTI=“de‐
475 vice:/dev/tpm0”
476
477 • mssim: For the mssim TCTI, the domain name or IP address and port
478 number used by the simulator can be specified. The default are
479 127.0.0.1 and 2321.
480
481 Example: -T mssim:host=localhost,port=2321 or export TPM2TOOLS_TC‐
482 TI=“mssim:host=localhost,port=2321”
483
484 • abrmd: For the abrmd TCTI, the configuration string format is a se‐
485 ries of simple key value pairs separated by a `,' character. Each
486 key and value string are separated by a `=' character.
487
488 • TCTI abrmd supports two keys:
489
490 1. `bus_name' : The name of the tabrmd service on the bus (a
491 string).
492
493 2. `bus_type' : The type of the dbus instance (a string) limited to
494 `session' and `system'.
495
496 Specify the tabrmd tcti name and a config string of bus_name=com.ex‐
497 ample.FooBar:
498
499 \--tcti=tabrmd:bus_name=com.example.FooBar
500
501 Specify the default (abrmd) tcti and a config string of bus_type=ses‐
502 sion:
503
504 \--tcti:bus_type=session
505
506 NOTE: abrmd and tabrmd are synonymous. the various known TCTI mod‐
507 ules.
508
510 Format selection for the signature output file. tss (the default) will
511 output a binary blob according to the TPM 2.0 specification and any po‐
512 tential compiler padding. The option plain will output the plain sig‐
513 nature data as defined by the used cryptographic algorithm.
514
516 Sign and verify with the TPM using the endorsement hierarchy
517 tpm2_createprimary -C e -c primary.ctx
518
519 tpm2_create -G rsa -u rsa.pub -r rsa.priv -C primary.ctx
520
521 tpm2_load -C primary.ctx -u rsa.pub -r rsa.priv -c rsa.ctx
522
523 echo "my message" > message.dat
524
525 tpm2_sign -c rsa.ctx -g sha256 -o sig.rssa message.dat
526
527 tpm2_verifysignature -c rsa.ctx -g sha256 -s sig.rssa -m message.dat
528
529 Sign with the TPM and verify with OSSL
530 openssl ecparam -name prime256v1 -genkey -noout -out private.ecc.pem
531
532 openssl ec -in private.ecc.pem -out public.ecc.pem -pubout
533
534 # Generate a hash to sign
535 echo "data to sign" > data.in.raw
536
537 sha256sum data.in.raw | awk '{ print "000000 " $1 }' | \
538 xxd -r -c 32 > data.in.digest
539
540 # Load the private key for signing
541 tpm2_loadexternal -Q -G ecc -r private.ecc.pem -c key.ctx
542
543 # Sign in the TPM and verify with OSSL
544 tpm2_sign -Q -c key.ctx -g sha256 -d -f plain -o data.out.signed data.in.digest
545
546 openssl dgst -verify public.ecc.pem -keyform pem -sha256 \
547 -signature data.out.signed data.in.raw
548
550 Tools can return any of the following codes:
551
552 • 0 - Success.
553
554 • 1 - General non-specific error.
555
556 • 2 - Options handling error.
557
558 • 3 - Authentication error.
559
560 • 4 - TCTI related error.
561
562 • 5 - Non supported scheme. Applicable to tpm2_testparams.
563
565 Github Issues (https://github.com/tpm2-software/tpm2-tools/issues)
566
568 See the Mailing List (https://lists.linuxfoundation.org/mailman/listin‐
569 fo/tpm2)
570
571
572
573tpm2-tools tpm2_sign(1)