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 """Own the TPM and set the FWMP.""" 29 # make sure the FMWP is in the expected state 30 cryptohome.get_fwmp(fwmp_cleared) 31 status = cryptohome.get_tpm_status() 32 # Own the TPM 33 if not status['Owned']: 34 status = self.own_tpm() 35 36 logging.info(status) 37 38 # Set the FWMP flags using a dev key hash 39 cryptohome.set_fwmp(flags, dev_key_hash) 40 41 # Check that the flags are set 42 fwmp = cryptohome.get_fwmp() 43 if flags and fwmp['flags'] != str(int(flags, 16)): 44 raise error.TestFail('Unexpected FWMP status: %s', fwmp) 45