Home | History | Annotate | Download | only in hardware_TPMLoadKey
      1 # Copyright (c) 2011 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 
      5 import logging
      6 from autotest_lib.client.bin import test, utils
      7 from autotest_lib.client.common_lib import error
      8 
      9 class hardware_TPMLoadKey(test.test):
     10 
     11     # This test determines the TPM can execute a TPM LoadKey function
     12     #
     13     # The test sequence follows the steps below:
     14     #   1. Create a local file containing a text file to be "sealed"
     15     #   2. Execute the TPM Tools command for tpm_sealdata
     16     #   3. Parse response of tpm_sealdata for LoadKey function execution
     17     #   4. Test passes if LoadKey reports success.
     18     #
     19 
     20     version = 1
     21 
     22     # Runs a command, logs the output, and returns the exit status.
     23     def __run_cmd(self, cmd):
     24         result = utils.system_output(cmd, retain_output=True,
     25                                      ignore_status=False)
     26         logging.info(result)
     27         return result
     28 
     29     def run_once(self):
     30         # Create the test input file
     31         create_input_file_cmd = "echo 'This is a test' > in.dat"
     32         output = self.__run_cmd(create_input_file_cmd)
     33 
     34         # Execute the TPM Tools command for sealdata, causing a LoadKey
     35         #    event, and filter for a debug message indicating success
     36         seal_data_cmd = \
     37             "tpm_sealdata -i in.dat -o out.dat -z -l debug 2>&1 | grep LoadKey"
     38         output = self.__run_cmd(seal_data_cmd)
     39 
     40         # Confirm the LoadKey message reports success
     41         if (output.find("success") < 0):
     42             raise error.TestError("LoadKey execution did not succeed")
     43