demo/secure_element/resources/generation_scripts/generate_certificates.py

1 #
2 # EVALUATION AND USE OF THIS SOFTWARE IS SUBJECT TO THE TERMS AND
3 # CONDITIONS OF THE CONTROLLING LICENSE AGREEMENT FOUND AT LICENSE.md
4 # IN THIS SDK. IF YOU DO NOT AGREE TO THE LICENSE TERMS AND CONDITIONS,
5 # PLEASE RETURN ALL SOURCE FILES TO SILICON LABORATORIES.
6 # (c) Copyright 2018, Silicon Laboratories Inc. All rights reserved.
7 #
8 
9 import optparse
10 import traceback
11 
12 from ca_create_root import ca_create_root
13 from ca_create_signer import ca_create_signer
14 from ca_create_server import ca_create_server
15 from device_provision import device_provision
16 
17 
18 
19 def generate_certificates(hostname):
20  ca_create_root()
21  ca_create_server()
22  ca_create_signer(hostname)
23  device_provision(hostname)
24 
25 
26 
27 
28 
29 
30 
31 if __name__ == '__main__':
32  parser = optparse.OptionParser(description='Generates a server certificate for local testing')
33  parser.add_option('--hostname',
34  help="Required, Hostname of local testing server, typically this should be your computer's IP address. NOTE: You can also update your computer's 'hosts' file to use a domain")
35 
36  args = parser.parse_args()
37 
38  if not parser.hostname:
39  raise Exception('Must provide --hostname argument')
40 
41  try:
42  generate_certificates(parser.hostname)
43  except Exception as e:
44  traceback.print_exc()
45  print(e)
46