Lines Matching +full:self +full:-

1 # SPDX-License-Identifier: (GPL-2.0 OR BSD-3-Clause)
14 def setUp(self): argument
15 self.client = tpm2.Client()
16 self.root_key = self.client.create_root_key()
18 def tearDown(self): argument
19 self.client.flush_context(self.root_key)
20 self.client.close()
22 def test_seal_with_auth(self): argument
26 blob = self.client.seal(self.root_key, data, auth, None)
27 result = self.client.unseal(self.root_key, blob, auth, None)
28 self.assertEqual(data, result)
30 def determine_bank_alg(self, mask): argument
31 pcr_banks = self.client.get_cap_pcrs()
37 def test_seal_with_policy(self): argument
38 bank_alg = self.determine_bank_alg(1 << 16)
39 self.assertIsNotNone(bank_alg)
41 handle = self.client.start_auth_session(tpm2.TPM2_SE_TRIAL)
48 self.client.policy_pcr(handle, pcrs, bank_alg=bank_alg)
49 self.client.policy_password(handle)
51 policy_dig = self.client.get_policy_digest(handle)
53 self.client.flush_context(handle)
55 blob = self.client.seal(self.root_key, data, auth, policy_dig)
57 handle = self.client.start_auth_session(tpm2.TPM2_SE_POLICY)
60 self.client.policy_pcr(handle, pcrs, bank_alg=bank_alg)
61 self.client.policy_password(handle)
63 result = self.client.unseal(self.root_key, blob, auth, handle)
65 self.client.flush_context(handle)
68 self.assertEqual(data, result)
70 def test_unseal_with_wrong_auth(self): argument
75 blob = self.client.seal(self.root_key, data, auth, None)
77 result = self.client.unseal(self.root_key, blob,
78 auth[:-1] + 'B'.encode(), None)
82 self.assertEqual(rc, tpm2.TPM2_RC_AUTH_FAIL)
84 def test_unseal_with_wrong_policy(self): argument
85 bank_alg = self.determine_bank_alg(1 << 16 | 1 << 1)
86 self.assertIsNotNone(bank_alg)
88 handle = self.client.start_auth_session(tpm2.TPM2_SE_TRIAL)
95 self.client.policy_pcr(handle, pcrs, bank_alg=bank_alg)
96 self.client.policy_password(handle)
98 policy_dig = self.client.get_policy_digest(handle)
100 self.client.flush_context(handle)
102 blob = self.client.seal(self.root_key, data, auth, policy_dig)
108 self.client.extend_pcr(1, ('X' * ds).encode(), bank_alg=bank_alg)
110 handle = self.client.start_auth_session(tpm2.TPM2_SE_POLICY)
113 self.client.policy_pcr(handle, pcrs, bank_alg=bank_alg)
114 self.client.policy_password(handle)
116 result = self.client.unseal(self.root_key, blob, auth, handle)
118 self.client.flush_context(handle)
121 self.assertEqual(data, result)
125 self.client.extend_pcr(16, ('X' * ds).encode(), bank_alg=bank_alg)
127 handle = self.client.start_auth_session(tpm2.TPM2_SE_POLICY)
132 self.client.policy_pcr(handle, pcrs, bank_alg=bank_alg)
133 self.client.policy_password(handle)
135 result = self.client.unseal(self.root_key, blob, auth, handle)
138 self.client.flush_context(handle)
140 self.client.flush_context(handle)
143 self.assertEqual(rc, tpm2.TPM2_RC_POLICY_FAIL)
145 def test_seal_with_too_long_auth(self): argument
152 blob = self.client.seal(self.root_key, data, auth, None)
156 self.assertEqual(rc, tpm2.TPM2_RC_SIZE)
158 def test_too_short_cmd(self): argument
168 self.client.send_cmd(cmd)
173 self.assertEqual(rejected, True)
175 def test_read_partial_resp(self): argument
183 self.client.tpm.write(cmd)
184 hdr = self.client.tpm.read(10)
186 rsp = self.client.tpm.read()
189 self.assertEqual(sz, 10 + 2 + 32)
190 self.assertEqual(len(rsp), 2 + 32)
192 def test_read_partial_overwrite(self): argument
200 self.client.tpm.write(cmd)
202 rsp1 = self.client.tpm.read(15)
205 self.client.tpm.write(cmd)
208 rsp2 = self.client.tpm.read()
211 self.assertEqual(len(rsp1), 15)
212 self.assertEqual(len(rsp2), 10 + 2 + 32)
214 def test_send_two_cmds(self): argument
223 self.client.tpm.write(cmd)
225 # expect the second one to raise -EBUSY error
226 self.client.tpm.write(cmd)
227 rsp = self.client.tpm.read()
231 rsp = self.client.tpm.read()
236 self.assertEqual(rejected, True)
239 def setUp(self): argument
242 def test_make_two_spaces(self): argument
256 def test_flush_context(self): argument
266 def test_get_handles(self): argument
278 self.assertEqual(len(handles), 2)
283 def test_invalid_cc(self): argument
287 TPM2_CC_INVALID = tpm2.TPM2_CC_FIRST - 1
303 self.assertEqual(rc, tpm2.TPM2_RC_COMMAND_CODE |
307 def setUp(self): argument
310 def test_async(self): argument
319 def test_flush_invalid_context(self): argument
332 self.assertEqual(rc, 22)