@@ -352,6 +352,33 @@ mount_by_uuid() {
352
352
esac
353
353
}
354
354
355
+ # An EKpub is a TPM2B_PUBLIC format payload. For an RSA public key the
356
+ # TPM2B_PUBLIC for an EK public key can vary in two ways:
357
+ #
358
+ # - the exponent, if it is the default 65537, can be written either as
359
+ # the all-zero exponent (which indicates that the exponent is the
360
+ # default exponent), or as 0x00010001 (65537)
361
+ #
362
+ # - the RSA scheme, which for a restricted decrypt-only key (as all EKs
363
+ # are) must be OEAP, and this can be written as the null algorithm ID
364
+ # or as the actual algorithm ID
365
+ #
366
+ # Since we want to identify enrolled hosts by the hash of their EKpubs
367
+ # (which we call "EKhash"), we may need to normalize the enrollee's
368
+ # EKpub TPM2B_PUBLIC payload. The swTPM will use the all-zero exponent,
369
+ # and the null alg ID for the RSA scheme, while at least one dTPM writes
370
+ # the actual exponent (65537) but thankfully also uses the null alg ID
371
+ # for the RSA scheme.
372
+ #
373
+ # This function normalizes an EKpub so that we may reliably use its hash
374
+ # to identify the enrollee.
375
+ normalize_ekpub {
376
+ # We'd like to use tpm2 loadexternal then tpm2 readpublic, but
377
+ # the swtpm will remember the exponent field and then use the
378
+ # same value on output. So we have to use dd.
379
+ dd if=/dev/zero of=" $1 " seek=54 bs=1 count=4 conv=notrunc
380
+ }
381
+
355
382
# Convert a bare RSA public key (2048 bits) in PEM format to TPM2B_PUBLIC
356
383
# format.
357
384
#
@@ -372,7 +399,7 @@ pem2tpm2bpublic() {
372
399
fi
373
400
374
401
# This is the policy on the EKs produced by swtpm. It may be different
375
- # on other TPMs.
402
+ # on other TPMs. (It's not. The TCG requires this policyDigest for EKs.)
376
403
ekpolicy=${3:- 837197674484b3f81a90cc8d46a5d724fd52d76e06520b64f2a1da1b331469aa}
377
404
378
405
attrs=' fixedtpm|fixedparent|sensitivedataorigin|adminwithpolicy|restricted|decrypt'
@@ -395,6 +422,7 @@ pem2tpm2bpublic() {
395
422
&& tpm2 readpublic \
396
423
--output=" $2 " \
397
424
--object-context=" ${1} .ctx" ; then
425
+ normalize_ekpub " $2 "
398
426
rm " ${pemfile} .policy"
399
427
return 0
400
428
fi
0 commit comments