Skip to content

Commit 969676d

Browse files
committed
Normalize EKpubs (fix osresearch#170)
1 parent fd0aef4 commit 969676d

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

Diff for: functions.sh

+29-1
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,33 @@ mount_by_uuid() {
352352
esac
353353
}
354354

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+
355382
# Convert a bare RSA public key (2048 bits) in PEM format to TPM2B_PUBLIC
356383
# format.
357384
#
@@ -372,7 +399,7 @@ pem2tpm2bpublic() {
372399
fi
373400

374401
# 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.)
376403
ekpolicy=${3:-837197674484b3f81a90cc8d46a5d724fd52d76e06520b64f2a1da1b331469aa}
377404

378405
attrs='fixedtpm|fixedparent|sensitivedataorigin|adminwithpolicy|restricted|decrypt'
@@ -395,6 +422,7 @@ pem2tpm2bpublic() {
395422
&& tpm2 readpublic \
396423
--output="$2" \
397424
--object-context="${1}.ctx"; then
425+
normalize_ekpub "$2"
398426
rm "${pemfile}.policy"
399427
return 0
400428
fi

Diff for: sbin/attest-enroll

+2-1
Original file line numberDiff line numberDiff line change
@@ -713,7 +713,8 @@ text/plain)
713713

714714
application/octet-stream)
715715
EKCERT=
716-
cp "$tmp/ekpub" "$tmp/ek.pub";;
716+
cp "$tmp/ekpub" "$tmp/ek.pub"
717+
normalize_ekpub "$tmp/ek.pub";;
717718

718719
*) die "Given EKpub is not in a supported format: $(file -b --mime-type "$tmp/ekpub")";;
719720
esac

0 commit comments

Comments
 (0)