Home | History | Annotate | Download | only in cros
      1 # Copyright 2018 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 time
      6 
      7 def StartU2fd(client):
      8     """Starts u2fd on the client.
      9 
     10     @param client: client object to run commands on.
     11     """
     12     client.run('stop u2fd', ignore_status=True)
     13     old_dev = client.run('ls /dev/hidraw*',
     14                           ignore_status=True).stdout.strip().split('\n')
     15     client.run_background('u2fd --force_g2f')
     16 
     17     # TODO(louiscollard): Replace this with something less fragile.
     18     cr50_dev = set()
     19     timeout_count = 0
     20     while (len(cr50_dev) == 0 and timeout_count < 5):
     21       time.sleep(1)
     22       timeout_count += 1
     23       new_dev = client.run('ls /dev/hidraw*',
     24                             ignore_status=True).stdout.strip().split('\n')
     25       cr50_dev = set(new_dev) - set(old_dev)
     26 
     27     return cr50_dev.pop()
     28 
     29 def G2fRegister(client, dev, challenge, application, p1=0):
     30     """Returns a dictionary with TPM status.
     31 
     32     @param client: client object to run commands on.
     33     """
     34     return client.run('g2ftool --reg --dev=' + dev +
     35                       ' --challenge=' + challenge +
     36                       ' --application=' + application +
     37                       ' --p1=' + str(p1),
     38                       ignore_status=True)
     39 
     40 def G2fAuth(client, dev, challenge, application, key_handle, p1=0):
     41     """Returns a dictionary with TPM status.
     42 
     43     @param client: client object to run commands on.
     44     """
     45     return client.run('g2ftool --auth --dev=' + dev +
     46                       ' --challenge=' + challenge +
     47                       ' --application=' + application +
     48                       ' --key_handle=' + key_handle +
     49                       ' --p1=' + str(p1),
     50                       ignore_status=True)
     51