Home | History | Annotate | Download | only in scripts
      1 #!/usr/bin/python
      2 
      3 # Copyright (c) 2013 The Chromium OS Authors. All rights reserved.
      4 # Use of this source code is governed by a BSD-style license that can be
      5 # found in the LICENSE file.
      6 
      7 import sys
      8 
      9 import common
     10 from autotest_lib.client.cros.networking import shill_proxy
     11 
     12 def usage():
     13     """ Print a usage message for this script. """
     14     cmd = sys.argv[0]
     15     common_args = ['<certificate>', '<public_key>', '<nonce>',
     16                    '<signed_data>', '<destination_udn>',
     17                    '<hotspot_ssid>', '<hotspot_bssid>']
     18     print cmd, 'encrypt', ' '.join(common_args)
     19     print cmd, 'verify', ' '.join(common_args), '<data to encrypt>'
     20     return False
     21 
     22 
     23 def main(args):
     24     """ Call methods related to destinations.
     25 
     26     @param args arguments to the script, not including the script name.
     27 
     28     """
     29     NUM_VERIFY_ARGS = 7
     30     NUM_ENCRYPT_ARGS = NUM_VERIFY_ARGS + 1
     31     if len(args) < 1:
     32         return usage()
     33     command = args[0]
     34     args = args[1:]
     35     shill = shill_proxy.ShillProxy()
     36     if command == 'verify':
     37         if len(args) < NUM_VERIFY_ARGS:
     38             return usage()
     39 
     40         if shill.manager.VerifyDestination(*args[0:NUM_VERIFY_ARGS]):
     41             print 'Valid destination'
     42             return True
     43 
     44     if command == 'encrypt':
     45         if len(args) < NUM_ENCRYPT_ARGS:
     46             return usage()
     47 
     48         print shill.manager.VerifyAndEncryptData(*args[0:NUM_ENCRYPT_ARGS])
     49         return True
     50 
     51     return usage()
     52 
     53 
     54 if __name__ == '__main__':
     55     if not main(sys.argv[1:]):
     56         sys.exit(1)
     57