1# Copyright 2017 The Chromium OS Authors. All rights reserved. 2# Use of this source code is governed by a BSD-style license that can be 3# found in the LICENSE file. 4 5import logging 6import time 7 8from autotest_lib.client.bin import test 9from autotest_lib.client.common_lib import error 10from autotest_lib.client.cros import cryptohome 11 12 13class firmware_SetFWMP(test.test): 14 """Set the FWMP flags and dev_key_hash.""" 15 version = 1 16 17 def own_tpm(self): 18 """Own the TPM""" 19 cryptohome.take_tpm_ownership() 20 for i in range(4): 21 status = cryptohome.get_tpm_status() 22 if status['Owned']: 23 return status 24 time.sleep(2) 25 raise error.TestFail('Failed to own the TPM %s' % status) 26 27 def run_once(self, fwmp_cleared=True, flags=None, dev_key_hash=None): 28 # make sure the FMWP is in the expected state 29 cryptohome.get_fwmp(fwmp_cleared) 30 status = cryptohome.get_tpm_status() 31 # Own the TPM 32 if not status['Owned']: 33 status = self.own_tpm() 34 35 # Verify we have access to the password 36 if not status['Password']: 37 logging.warning('No access to the password') 38 39 logging.info(status) 40 41 # Set the FWMP flags using a dev key hash 42 cryptohome.set_fwmp(flags, dev_key_hash) 43 44 # Check that the flags are set 45 fwmp = cryptohome.get_fwmp() 46 if flags and fwmp['flags'] != str(int(flags, 16)): 47 raise error.TestFail('Unexpected FWMP status: %s', fwmp) 48