Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 1 | # Copyright (C) 2019 Armin Kuster <akuster808@gmail.com> |
| 2 | # |
| 3 | from oeqa.runtime.case import OERuntimeTestCase |
| 4 | from oeqa.core.decorator.depends import OETestDepends |
| 5 | from oeqa.runtime.decorator.package import OEHasPackage |
| 6 | |
| 7 | |
| 8 | class Tpm2Test(OERuntimeTestCase): |
| 9 | def check_endlines(self, results, expected_endlines): |
| 10 | for line in results.splitlines(): |
| 11 | for el in expected_endlines: |
| 12 | if line == el: |
| 13 | expected_endlines.remove(el) |
| 14 | break |
| 15 | |
| 16 | if expected_endlines: |
| 17 | self.fail('Missing expected line endings:\n %s' % '\n '.join(expected_endlines)) |
| 18 | |
Brad Bishop | 26bdd44 | 2019-08-16 17:08:17 -0400 | [diff] [blame] | 19 | @OEHasPackage(['tpm2-tools']) |
Andrew Geissler | d583833 | 2022-05-27 11:33:10 -0500 | [diff] [blame] | 20 | @OEHasPackage(['tpm2-abrmd']) |
| 21 | @OEHasPackage(['swtpm']) |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 22 | @OETestDepends(['ssh.SSHTest.test_ssh']) |
Andrew Geissler | d583833 | 2022-05-27 11:33:10 -0500 | [diff] [blame] | 23 | def test_tpm2_swtpm_socket(self): |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 24 | cmds = [ |
Andrew Geissler | d583833 | 2022-05-27 11:33:10 -0500 | [diff] [blame] | 25 | 'mkdir /tmp/myvtpm', |
| 26 | 'swtpm socket --tpmstate dir=/tmp/myvtpm --tpm2 --ctrl type=tcp,port=2322 --server type=tcp,port=2321 --flags not-need-init &', |
| 27 | 'export TPM2TOOLS_TCTI="swtpm:port=2321"', |
| 28 | 'tpm2_startup -c' |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 29 | ] |
| 30 | |
| 31 | for cmd in cmds: |
| 32 | status, output = self.target.run(cmd) |
| 33 | self.assertEqual(status, 0, msg='\n'.join([cmd, output])) |
| 34 | |
Andrew Geissler | d583833 | 2022-05-27 11:33:10 -0500 | [diff] [blame] | 35 | @OETestDepends(['tpm2.Tpm2Test.test_tpm2_swtpm_socket']) |
| 36 | def test_tpm2_pcrread(self): |
| 37 | (status, output) = self.target.run('tpm2_pcrread') |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 38 | expected_endlines = [] |
Andrew Geissler | d583833 | 2022-05-27 11:33:10 -0500 | [diff] [blame] | 39 | expected_endlines.append(' sha1:') |
| 40 | expected_endlines.append(' 0 : 0x0000000000000000000000000000000000000000') |
| 41 | expected_endlines.append(' 1 : 0x0000000000000000000000000000000000000000') |
| 42 | expected_endlines.append(' sha256:') |
| 43 | expected_endlines.append(' 0 : 0x0000000000000000000000000000000000000000000000000000000000000000') |
| 44 | expected_endlines.append(' 1 : 0x0000000000000000000000000000000000000000000000000000000000000000') |
| 45 | |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 46 | |
| 47 | self.check_endlines(output, expected_endlines) |
| 48 | |
Andrew Geissler | d583833 | 2022-05-27 11:33:10 -0500 | [diff] [blame] | 49 | |
| 50 | @OEHasPackage(['p11-kit']) |
| 51 | @OEHasPackage(['tpm2-pkcs11']) |
| 52 | @OETestDepends(['tpm2.Tpm2Test.test_tpm2_swtpm_socket']) |
| 53 | def test_tpm2_pkcs11(self): |
| 54 | (status, output) = self.target.run('p11-kit list-modules -v') |
| 55 | self.assertEqual(status, 0, msg="Modules missing: %s" % output) |
| 56 | |
| 57 | @OETestDepends(['tpm2.Tpm2Test.test_tpm2_pkcs11']) |
| 58 | def test_tpm2_swtpm_reset(self): |
| 59 | (status, output) = self.target.run('swtpm_ioctl -i --tcp :2322') |
| 60 | self.assertEqual(status, 0, msg="swtpm reset failed: %s" % output) |