From: Jarkko Sakkinen <jarkko@kernel.org>
To: Stefan Berger <stefanb@linux.ibm.com>
Cc: linux-integrity@vger.kernel.org, peterhuewe@gmx.de,
linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org,
skhan@linuxfoundation.org
Subject: Re: [PATCH v2 1/3] selftests: tpm2: Probe for available PCR bank
Date: Sat, 27 Nov 2021 02:18:21 +0200 [thread overview]
Message-ID: <f5d6e6b189b46c53264bdb649e6a41589d8259bf.camel@kernel.org> (raw)
In-Reply-To: <1189a2ef-ae31-92f2-a7a7-d60064bdde44@linux.ibm.com>
On Wed, 2021-11-24 at 19:15 -0500, Stefan Berger wrote:
>
> On 11/24/21 18:54, Jarkko Sakkinen wrote:
> > On Wed, Nov 24, 2021 at 09:13:12AM -0500, Stefan Berger wrote:
> > > Probe for an available PCR bank to accommodate devices that do not have a
> > > SHA-1 PCR bank or whose SHA-1 bank is deactivated. Use the bank that can
> > > be used in the TPM2 commands. Assert on the probing function to not
> > > return None.
> > What is *the bank* that can be used?
>
> The bank can be either SHA-1 or SHA-256 at this point.
>
> >
> > In addition, I don't understand the last sentence.
>
>
> If the probing function returns None the test fails due to an
> assertIsNotNone().
You should have all this written down to the commit message.
/Jarkko
>
> stefan
>
> >
> > /Jarkko
> >
> >
> > > Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
> > > ---
> > > tools/testing/selftests/tpm2/tpm2_tests.py | 35 +++++++++++++++++-----
> > > 1 file changed, 27 insertions(+), 8 deletions(-)
> > >
> > > diff --git a/tools/testing/selftests/tpm2/tpm2_tests.py b/tools/testing/selftests/tpm2/tpm2_tests.py
> > > index 9d764306887b..6b88ff0e47b9 100644
> > > --- a/tools/testing/selftests/tpm2/tpm2_tests.py
> > > +++ b/tools/testing/selftests/tpm2/tpm2_tests.py
> > > @@ -27,7 +27,23 @@ class SmokeTest(unittest.TestCase):
> > > result = self.client.unseal(self.root_key, blob, auth, None)
> > > self.assertEqual(data, result)
> > >
> > > + def determine_bank_alg(self):
> > > + # Probe for available PCR bank
> > > + for bank_alg in [tpm2.TPM2_ALG_SHA1, tpm2.TPM2_ALG_SHA256]:
> > > + try:
> > > + handle = self.client.start_auth_session(tpm2.TPM2_SE_TRIAL)
> > > + self.client.policy_pcr(handle, [17], bank_alg=bank_alg)
> > > + return bank_alg
> > > + except tpm2.UnknownPCRBankError:
> > > + pass
> > > + finally:
> > > + self.client.flush_context(handle)
> > > + return None
> > > +
> > > def test_seal_with_policy(self):
> > > + bank_alg = self.determine_bank_alg()
> > > + self.assertIsNotNone(bank_alg)
> > > +
> > > handle = self.client.start_auth_session(tpm2.TPM2_SE_TRIAL)
> > >
> > > data = ('X' * 64).encode()
> > > @@ -35,7 +51,7 @@ class SmokeTest(unittest.TestCase):
> > > pcrs = [16]
> > >
> > > try:
> > > - self.client.policy_pcr(handle, pcrs)
> > > + self.client.policy_pcr(handle, pcrs, bank_alg=bank_alg)
> > > self.client.policy_password(handle)
> > >
> > > policy_dig = self.client.get_policy_digest(handle)
> > > @@ -47,7 +63,7 @@ class SmokeTest(unittest.TestCase):
> > > handle = self.client.start_auth_session(tpm2.TPM2_SE_POLICY)
> > >
> > > try:
> > > - self.client.policy_pcr(handle, pcrs)
> > > + self.client.policy_pcr(handle, pcrs, bank_alg=bank_alg)
> > > self.client.policy_password(handle)
> > >
> > > result = self.client.unseal(self.root_key, blob, auth, handle)
> > > @@ -72,6 +88,9 @@ class SmokeTest(unittest.TestCase):
> > > self.assertEqual(rc, tpm2.TPM2_RC_AUTH_FAIL)
> > >
> > > def test_unseal_with_wrong_policy(self):
> > > + bank_alg = self.determine_bank_alg()
> > > + self.assertIsNotNone(bank_alg)
> > > +
> > > handle = self.client.start_auth_session(tpm2.TPM2_SE_TRIAL)
> > >
> > > data = ('X' * 64).encode()
> > > @@ -79,7 +98,7 @@ class SmokeTest(unittest.TestCase):
> > > pcrs = [16]
> > >
> > > try:
> > > - self.client.policy_pcr(handle, pcrs)
> > > + self.client.policy_pcr(handle, pcrs, bank_alg=bank_alg)
> > > self.client.policy_password(handle)
> > >
> > > policy_dig = self.client.get_policy_digest(handle)
> > > @@ -91,13 +110,13 @@ class SmokeTest(unittest.TestCase):
> > > # Extend first a PCR that is not part of the policy and try to unseal.
> > > # This should succeed.
> > >
> > > - ds = tpm2.get_digest_size(tpm2.TPM2_ALG_SHA1)
> > > - self.client.extend_pcr(1, ('X' * ds).encode())
> > > + ds = tpm2.get_digest_size(bank_alg)
> > > + self.client.extend_pcr(1, ('X' * ds).encode(), bank_alg=bank_alg)
> > >
> > > handle = self.client.start_auth_session(tpm2.TPM2_SE_POLICY)
> > >
> > > try:
> > > - self.client.policy_pcr(handle, pcrs)
> > > + self.client.policy_pcr(handle, pcrs, bank_alg=bank_alg)
> > > self.client.policy_password(handle)
> > >
> > > result = self.client.unseal(self.root_key, blob, auth, handle)
> > > @@ -109,14 +128,14 @@ class SmokeTest(unittest.TestCase):
> > >
> > > # Then, extend a PCR that is part of the policy and try to unseal.
> > > # This should fail.
> > > - self.client.extend_pcr(16, ('X' * ds).encode())
> > > + self.client.extend_pcr(16, ('X' * ds).encode(), bank_alg=bank_alg)
> > >
> > > handle = self.client.start_auth_session(tpm2.TPM2_SE_POLICY)
> > >
> > > rc = 0
> > >
> > > try:
> > > - self.client.policy_pcr(handle, pcrs)
> > > + self.client.policy_pcr(handle, pcrs, bank_alg=bank_alg)
> > > self.client.policy_password(handle)
> > >
> > > result = self.client.unseal(self.root_key, blob, auth, handle)
> > > --
> > > 2.31.1
> > >
next prev parent reply other threads:[~2021-11-27 0:20 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-11-24 14:13 [PATCH v2 0/3] " Stefan Berger
2021-11-24 14:13 ` [PATCH v2 1/3] " Stefan Berger
2021-11-24 23:54 ` Jarkko Sakkinen
2021-11-25 0:15 ` Stefan Berger
2021-11-27 0:18 ` Jarkko Sakkinen [this message]
2021-11-24 14:13 ` [PATCH v2 2/3] selftests: tpm2: Reset the dictionary attack lock Stefan Berger
2021-11-24 14:13 ` [PATCH v2 3/3] selftests: tpm2: Add support for SHA-384 and SHA-512 Stefan Berger
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=f5d6e6b189b46c53264bdb649e6a41589d8259bf.camel@kernel.org \
--to=jarkko@kernel.org \
--cc=linux-integrity@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=peterhuewe@gmx.de \
--cc=skhan@linuxfoundation.org \
--cc=stefanb@linux.ibm.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®