From patchwork Thu Nov 25 00:38:25 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Berger X-Patchwork-Id: 12638263 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5600AC433EF for ; Thu, 25 Nov 2021 00:40:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344157AbhKYAno (ORCPT ); Wed, 24 Nov 2021 19:43:44 -0500 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:53180 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344852AbhKYAln (ORCPT ); Wed, 24 Nov 2021 19:41:43 -0500 Received: from pps.filterd (m0098394.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 1AONr0TK019350; Thu, 25 Nov 2021 00:38:31 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=7uULuc7RJ/sDND/XJhW4SmszDs2r+mbLmuNrja6S5MI=; b=o/ym8Vl+G7SO7f1/ckC9sEv5ADs1sQ9GOWEBvXfncv9U2hDLJlVB0nnnRUYalb7HRbUv k9l4Fg9m+HRmrL/qkplgci34GVM//MRLs69CAvUTROaVVKVg5LLli/tFhlZLB6mNSAnG g6yc2rqeb+CDMSLzyseo90pu0qTYfJDOKv1z4AwQk7DS41PE/Llv5I7xQdM68lC6NPQB mYKN4oNWyU1ADkcVgApEkSm/cVqJTucna0El8oMB67QDbxxdzHqh3SHnNeQ0FJGMPRFc dvzYXNqTGGLD2EfbCPD+bKO53Rq9PaRK7xnEwHXv6zXnQZ/94QrTPpbzxLtdPIdg+Q8/ Ew== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com with ESMTP id 3chyevrn8c-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 25 Nov 2021 00:38:31 +0000 Received: from m0098394.ppops.net (m0098394.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.43/8.16.0.43) with SMTP id 1AP0XX4J003717; Thu, 25 Nov 2021 00:38:31 GMT Received: from ppma02dal.us.ibm.com (a.bd.3ea9.ip4.static.sl-reverse.com [169.62.189.10]) by mx0a-001b2d01.pphosted.com with ESMTP id 3chyevrn7v-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 25 Nov 2021 00:38:31 +0000 Received: from pps.filterd (ppma02dal.us.ibm.com [127.0.0.1]) by ppma02dal.us.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 1AP0MiHl011093; Thu, 25 Nov 2021 00:38:30 GMT Received: from b01cxnp22034.gho.pok.ibm.com (b01cxnp22034.gho.pok.ibm.com [9.57.198.24]) by ppma02dal.us.ibm.com with ESMTP id 3cerncs957-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 25 Nov 2021 00:38:30 +0000 Received: from b01ledav003.gho.pok.ibm.com (b01ledav003.gho.pok.ibm.com [9.57.199.108]) by b01cxnp22034.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 1AP0cT3D63045954 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 25 Nov 2021 00:38:29 GMT Received: from b01ledav003.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 60AE1B2064; Thu, 25 Nov 2021 00:38:29 +0000 (GMT) Received: from b01ledav003.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 46F8BB2068; Thu, 25 Nov 2021 00:38:29 +0000 (GMT) Received: from sbct-3.pok.ibm.com (unknown [9.47.158.153]) by b01ledav003.gho.pok.ibm.com (Postfix) with ESMTP; Thu, 25 Nov 2021 00:38:29 +0000 (GMT) From: Stefan Berger To: jarkko@kernel.org, linux-integrity@vger.kernel.org Cc: peterhuewe@gmx.de, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, skhan@linuxfoundation.org, Stefan Berger Subject: [PATCH v3 1/3] selftests: tpm2: Probe for available PCR bank Date: Wed, 24 Nov 2021 19:38:25 -0500 Message-Id: <20211125003827.1360432-2-stefanb@linux.vnet.ibm.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20211125003827.1360432-1-stefanb@linux.vnet.ibm.com> References: <20211125003827.1360432-1-stefanb@linux.vnet.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: flss9q9zMQk0ci612-yagsEEbcy2WI1s X-Proofpoint-ORIG-GUID: smPsZ5eqorEHNzKElpfcuT8WdxgNm0fo X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.790,Hydra:6.0.425,FMLib:17.0.607.475 definitions=2021-11-24_06,2021-11-24_01,2020-04-07_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 malwarescore=0 clxscore=1015 mlxlogscore=999 suspectscore=0 impostorscore=0 phishscore=0 lowpriorityscore=0 priorityscore=1501 adultscore=0 spamscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2110150000 definitions=main-2111250000 Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org From: Stefan Berger 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 for the TPM2 commands, such as the SHA-256 bank. Signed-off-by: Stefan Berger --- 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) From patchwork Thu Nov 25 00:38:26 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Berger X-Patchwork-Id: 12638265 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 866A1C4321E for ; Thu, 25 Nov 2021 00:40:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344792AbhKYAnr (ORCPT ); Wed, 24 Nov 2021 19:43:47 -0500 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:23578 "EHLO mx0b-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344872AbhKYAlo (ORCPT ); Wed, 24 Nov 2021 19:41:44 -0500 Received: from pps.filterd (m0127361.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 1AOMkTKv010842; Thu, 25 Nov 2021 00:38:31 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=eHgws6Wf+qHlJO679jheVoKil2upivq+jcL7XncWqkQ=; b=kJzhlvQlrLENeWZY2ETiqeqlviQaNuFYTBungREiTdL38cRCDoT/l+cJp9oYMng69Akh MfQ4xuE0OH6KpAVJ8oxx17RBOqaqWGa02+0fP6NbkIUQCx8mGjewbWDP2rjyzVdEAS1v w+ACfvUeSHC1BJb5RgV7K6nCapK5H+DXUoO6YV1EKAPvp5Vj3B9m3MIzs3199ReR5crA Ett0V/EO486Szcmuvt5C48ElJKQGVcmz6zxgEht3VjuGaXaEGFqGSkmxrZ6qym5VaT99 TDg6UrdjPmhQcHRefHsRcviksyiTqD1nnpVVgix0IHIepLS0my1l3ojr9oQlMF1m2v5r 7A== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com with ESMTP id 3chxfyhgus-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 25 Nov 2021 00:38:31 +0000 Received: from m0127361.ppops.net (m0127361.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.43/8.16.0.43) with SMTP id 1AP0cKJH004049; Thu, 25 Nov 2021 00:38:31 GMT Received: from ppma04dal.us.ibm.com (7a.29.35a9.ip4.static.sl-reverse.com [169.53.41.122]) by mx0a-001b2d01.pphosted.com with ESMTP id 3chxfyhguk-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 25 Nov 2021 00:38:31 +0000 Received: from pps.filterd (ppma04dal.us.ibm.com [127.0.0.1]) by ppma04dal.us.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 1AP0NA4I007152; Thu, 25 Nov 2021 00:38:30 GMT Received: from b01cxnp22034.gho.pok.ibm.com (b01cxnp22034.gho.pok.ibm.com [9.57.198.24]) by ppma04dal.us.ibm.com with ESMTP id 3cernchega-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 25 Nov 2021 00:38:30 +0000 Received: from b01ledav003.gho.pok.ibm.com (b01ledav003.gho.pok.ibm.com [9.57.199.108]) by b01cxnp22034.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 1AP0cT9b63308084 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 25 Nov 2021 00:38:29 GMT Received: from b01ledav003.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 7013EB205F; Thu, 25 Nov 2021 00:38:29 +0000 (GMT) Received: from b01ledav003.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 618FBB206B; Thu, 25 Nov 2021 00:38:29 +0000 (GMT) Received: from sbct-3.pok.ibm.com (unknown [9.47.158.153]) by b01ledav003.gho.pok.ibm.com (Postfix) with ESMTP; Thu, 25 Nov 2021 00:38:29 +0000 (GMT) From: Stefan Berger To: jarkko@kernel.org, linux-integrity@vger.kernel.org Cc: peterhuewe@gmx.de, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, skhan@linuxfoundation.org, Stefan Berger Subject: [PATCH v3 2/3] selftests: tpm2: Reset the dictionary attack lock Date: Wed, 24 Nov 2021 19:38:26 -0500 Message-Id: <20211125003827.1360432-3-stefanb@linux.vnet.ibm.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20211125003827.1360432-1-stefanb@linux.vnet.ibm.com> References: <20211125003827.1360432-1-stefanb@linux.vnet.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: l_lJ2Chsup2ssHdwBAoYUCt6U-ewlKmz X-Proofpoint-ORIG-GUID: f5mdSKbHvDDH3GjE8Xw3nk7sTisQeyOn X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.790,Hydra:6.0.425,FMLib:17.0.607.475 definitions=2021-11-24_06,2021-11-24_01,2020-04-07_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 suspectscore=0 bulkscore=0 mlxlogscore=999 phishscore=0 lowpriorityscore=0 spamscore=0 clxscore=1015 adultscore=0 priorityscore=1501 malwarescore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2110150000 definitions=main-2111250000 Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org From: Stefan Berger Reset the dictionary attack lock to avoid the following types of test failures after running the test 2 times: ====================================================================== ERROR: test_unseal_with_wrong_policy (tpm2_tests.SmokeTest) ---------------------------------------------------------------------- Traceback (most recent call last): File "/root/linux-ima-namespaces/tools/testing/selftests/tpm2/tpm2_tests.py", line 105, in test_unseal_with_wrong_policy blob = self.client.seal(self.root_key, data, auth, policy_dig) File "/root/linux-ima-namespaces/tools/testing/selftests/tpm2/tpm2.py", line 620, in seal rsp = self.send_cmd(cmd) File "/root/linux-ima-namespaces/tools/testing/selftests/tpm2/tpm2.py", line 397, in send_cmd raise ProtocolError(cc, rc) tpm2.ProtocolError: TPM_RC_LOCKOUT: cc=0x00000153, rc=0x00000921 Signed-off-by: Stefan Berger --- tools/testing/selftests/tpm2/tpm2_tests.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/testing/selftests/tpm2/tpm2_tests.py b/tools/testing/selftests/tpm2/tpm2_tests.py index 6b88ff0e47b9..ae88d8866e5d 100644 --- a/tools/testing/selftests/tpm2/tpm2_tests.py +++ b/tools/testing/selftests/tpm2/tpm2_tests.py @@ -104,6 +104,7 @@ class SmokeTest(unittest.TestCase): policy_dig = self.client.get_policy_digest(handle) finally: self.client.flush_context(handle) + self.client.reset_da_lock() blob = self.client.seal(self.root_key, data, auth, policy_dig) From patchwork Thu Nov 25 00:38:27 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Berger X-Patchwork-Id: 12638261 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6696DC4332F for ; Thu, 25 Nov 2021 00:40:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344718AbhKYAnq (ORCPT ); Wed, 24 Nov 2021 19:43:46 -0500 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:18776 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344884AbhKYAlo (ORCPT ); Wed, 24 Nov 2021 19:41:44 -0500 Received: from pps.filterd (m0098396.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 1AOMLeOr011603; Thu, 25 Nov 2021 00:38:32 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=zqRLq+GVbToq/+Z9iaVZtAC8OaGImnP+Xh2sqlalROg=; b=EHwfuO28X4Pkl93HzjRaGLCfK4mI8G5N8cv92YXfv620PwmzwiVKjuEWxjS6280s+64X JfwY6QvY8hLUpVQT+Lp96mpAMrDBEoOublMdYRf3j+1N9o97wOqCG9hWhEb16g+SkxHS VuDMa05D15pt1mpzvOInjTqVSVPMOw5h/KkNLZaOhmhMf4XGWsI0hdPjnHL3C+gdiLq9 SK8aLd033Rl1y/aJOZ7Y1Va5YyWJjgJgEZdDreSOl9mJmHFoSs9zy61v/Zxyd42C0QS8 aDMmLd98+kBh4yVtQ4EroxYJh3ZApyclFQCZTcCJbvryOYCdpfbX1YkuZqrdItFsnv0b pQ== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com with ESMTP id 3chx491ttt-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 25 Nov 2021 00:38:31 +0000 Received: from m0098396.ppops.net (m0098396.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.43/8.16.0.43) with SMTP id 1AP0bgMu023330; Thu, 25 Nov 2021 00:38:31 GMT Received: from ppma01wdc.us.ibm.com (fd.55.37a9.ip4.static.sl-reverse.com [169.55.85.253]) by mx0a-001b2d01.pphosted.com with ESMTP id 3chx491tth-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 25 Nov 2021 00:38:31 +0000 Received: from pps.filterd (ppma01wdc.us.ibm.com [127.0.0.1]) by ppma01wdc.us.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 1AP0M47m009996; Thu, 25 Nov 2021 00:38:30 GMT Received: from b01cxnp22034.gho.pok.ibm.com (b01cxnp22034.gho.pok.ibm.com [9.57.198.24]) by ppma01wdc.us.ibm.com with ESMTP id 3cernb48jy-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 25 Nov 2021 00:38:30 +0000 Received: from b01ledav003.gho.pok.ibm.com (b01ledav003.gho.pok.ibm.com [9.57.199.108]) by b01cxnp22034.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 1AP0cTwx63308086 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 25 Nov 2021 00:38:29 GMT Received: from b01ledav003.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 88877B2066; Thu, 25 Nov 2021 00:38:29 +0000 (GMT) Received: from b01ledav003.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 70364B2068; Thu, 25 Nov 2021 00:38:29 +0000 (GMT) Received: from sbct-3.pok.ibm.com (unknown [9.47.158.153]) by b01ledav003.gho.pok.ibm.com (Postfix) with ESMTP; Thu, 25 Nov 2021 00:38:29 +0000 (GMT) From: Stefan Berger To: jarkko@kernel.org, linux-integrity@vger.kernel.org Cc: peterhuewe@gmx.de, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, skhan@linuxfoundation.org, Stefan Berger Subject: [PATCH v3 3/3] selftests: tpm2: Add support for SHA-384 and SHA-512 Date: Wed, 24 Nov 2021 19:38:27 -0500 Message-Id: <20211125003827.1360432-4-stefanb@linux.vnet.ibm.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20211125003827.1360432-1-stefanb@linux.vnet.ibm.com> References: <20211125003827.1360432-1-stefanb@linux.vnet.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: 58NaiFV28obnf4T8x3fRy100Vk5mIerI X-Proofpoint-ORIG-GUID: GFt3U1FtsdGP9_xD5wZtzxC8wYngNKOU X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.790,Hydra:6.0.425,FMLib:17.0.607.475 definitions=2021-11-24_06,2021-11-24_01,2020-04-07_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=0 bulkscore=0 phishscore=0 lowpriorityscore=0 mlxlogscore=999 adultscore=0 impostorscore=0 clxscore=1015 malwarescore=0 priorityscore=1501 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2110150000 definitions=main-2111250000 Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org From: Stefan Berger Add support for SHA-384 and SHA-512 to the TPM2 library and extend the test case's PCR bank probing function to also probe for SHA-384 and SHA-512 banks in case SHA-1 and SHA-256 banks are not available for use. Signed-off-by: Stefan Berger --- tools/testing/selftests/tpm2/tpm2.py | 12 +++++++++++- tools/testing/selftests/tpm2/tpm2_tests.py | 3 ++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/tools/testing/selftests/tpm2/tpm2.py b/tools/testing/selftests/tpm2/tpm2.py index f34486cd7342..d0960fe0e029 100644 --- a/tools/testing/selftests/tpm2/tpm2.py +++ b/tools/testing/selftests/tpm2/tpm2.py @@ -37,6 +37,8 @@ TPM2_ALG_SHA1 = 0x0004 TPM2_ALG_AES = 0x0006 TPM2_ALG_KEYEDHASH = 0x0008 TPM2_ALG_SHA256 = 0x000B +TPM2_ALG_SHA384 = 0x000C +TPM2_ALG_SHA512 = 0x000D TPM2_ALG_NULL = 0x0010 TPM2_ALG_CBC = 0x0042 TPM2_ALG_CFB = 0x0043 @@ -67,6 +69,8 @@ HR_TRANSIENT = 0x80000000 SHA1_DIGEST_SIZE = 20 SHA256_DIGEST_SIZE = 32 +SHA384_DIGEST_SIZE = 48 +SHA512_DIGEST_SIZE = 64 TPM2_VER0_ERRORS = { 0x000: "TPM_RC_SUCCESS", @@ -186,16 +190,22 @@ RC_WARN = 0x900 ALG_DIGEST_SIZE_MAP = { TPM2_ALG_SHA1: SHA1_DIGEST_SIZE, TPM2_ALG_SHA256: SHA256_DIGEST_SIZE, + TPM2_ALG_SHA384: SHA384_DIGEST_SIZE, + TPM2_ALG_SHA512: SHA512_DIGEST_SIZE, } ALG_HASH_FUNCTION_MAP = { TPM2_ALG_SHA1: hashlib.sha1, - TPM2_ALG_SHA256: hashlib.sha256 + TPM2_ALG_SHA256: hashlib.sha256, + TPM2_ALG_SHA384: hashlib.sha384, + TPM2_ALG_SHA512: hashlib.sha512, } NAME_ALG_MAP = { "sha1": TPM2_ALG_SHA1, "sha256": TPM2_ALG_SHA256, + "sha384": TPM2_ALG_SHA384, + "sha512": TPM2_ALG_SHA512, } diff --git a/tools/testing/selftests/tpm2/tpm2_tests.py b/tools/testing/selftests/tpm2/tpm2_tests.py index ae88d8866e5d..3feca25038f5 100644 --- a/tools/testing/selftests/tpm2/tpm2_tests.py +++ b/tools/testing/selftests/tpm2/tpm2_tests.py @@ -29,7 +29,8 @@ class SmokeTest(unittest.TestCase): def determine_bank_alg(self): # Probe for available PCR bank - for bank_alg in [tpm2.TPM2_ALG_SHA1, tpm2.TPM2_ALG_SHA256]: + for bank_alg in [tpm2.TPM2_ALG_SHA1, tpm2.TPM2_ALG_SHA256, + tpm2.TPM2_ALG_SHA384, tpm2.TPM2_ALG_SHA512]: try: handle = self.client.start_auth_session(tpm2.TPM2_SE_TRIAL) self.client.policy_pcr(handle, [17], bank_alg=bank_alg)