Home | History | Annotate | Download | only in platform_Attestation
      1 # Copyright (c) 2012 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 from autotest_lib.client.bin import test, utils
      6 from autotest_lib.client.common_lib import error
      7 from autotest_lib.client.cros import cryptohome
      8 
      9 
     10 class platform_Attestation(test.test):
     11     version = 1
     12 
     13     def enroll(self):
     14         utils.system(cryptohome.CRYPTOHOME_CMD +
     15                      ' --action=tpm_attestation_start_enroll' +
     16                      ' --file=/tmp/__attestation_enroll_request')
     17         utils.system('curl' +
     18                      ' --data-binary "@/tmp/__attestation_enroll_request"' +
     19                      ' -o "/tmp/__attestation_enroll_response"' +
     20                      ' -H "Content-Type: application/octet-stream"' +
     21                      ' https://chromeos-ca.gstatic.com/enroll')
     22         utils.system(cryptohome.CRYPTOHOME_CMD +
     23                      ' --action=tpm_attestation_finish_enroll' +
     24                      ' --file=/tmp/__attestation_enroll_response')
     25 
     26     def cert_request(self):
     27         utils.system(cryptohome.CRYPTOHOME_CMD +
     28                      ' --action=tpm_attestation_start_cert_request' +
     29                      ' --file=/tmp/__attestation_cert_request')
     30         utils.system('curl --data-binary "@/tmp/__attestation_cert_request"' +
     31                      ' -o "/tmp/__attestation_cert_response"' +
     32                      ' -H "Content-Type: application/octet-stream"' +
     33                      ' https://chromeos-ca.gstatic.com/sign')
     34         utils.system(cryptohome.CRYPTOHOME_CMD +
     35                      ' --action=tpm_attestation_finish_cert_request' +
     36                      ' --file=/tmp/__attestation_cert_response' +
     37                      ' --name=attest-ent-machine')
     38 
     39     def run_once(self):
     40         status = cryptohome.get_tpm_attestation_status()
     41         if (not status['Prepared']):
     42             raise error.TestFail('Attestation enrollment is not possible.')
     43         self.enroll()
     44         status = cryptohome.get_tpm_attestation_status()
     45         if (not status['Enrolled']):
     46             raise error.TestFail('Attestation not successfully enrolled.')
     47         self.cert_request()
     48