def prereq(): with open('configure.json') as file: json_text = json.load(file) # Validate that the entries in the JSON are valid. validate_json_text(json_text) # Create a Thing thing_name = json_text['thing_name'] thing_obj = thing.Thing(thing_name) if not thing_obj.create(): # Create a Certificate cert_obj = certs.Certificate() result = cert_obj.create() # Store certId cert_id = result['certificateId'] cert_id_filename = thing_name + '_cert_id_file' print('Writing certificate ID to: {}'.format(cert_id_filename)) cert_id_file = open(cert_id_filename, 'w') cert_id_file.write(cert_id) cert_id_file_path = os.path.abspath(cert_id_filename) os.chmod(cert_id_file_path, 0o444) cert_id_file.close() # Store cert_pem as file cert_pem = result['certificatePem'] cert_pem_filename = thing_name + '_cert_pem_file' print('Writing certificate PEM to: {}'.format(cert_pem_filename)) cert_pem_file = open(cert_pem_filename, 'w') cert_pem_file.write(cert_pem) cert_pem_file_path = os.path.abspath(cert_pem_filename) os.chmod(cert_pem_file_path, 0o444) cert_pem_file.close() # Store private key PEM as file private_key_pem = result['keyPair']['PrivateKey'] private_key_pem_filename = thing_name + '_private_key_pem_file' print( 'Writing private key PEM to: {}'.format(private_key_pem_filename)) private_key_pem_file = open(private_key_pem_filename, 'w') private_key_pem_file.write(private_key_pem) private_key_pem_file_path = os.path.abspath(private_key_pem_filename) os.chmod(private_key_pem_file_path, 0o444) private_key_pem_file.close() # Create a Policy policy_document = misc.create_policy_document() policy_name = thing_name + '_amazon_freertos_policy' policy_obj = policy.Policy(policy_name, policy_document) policy_obj.create() # Attach certificate to Thing cert_obj.attach_thing(thing_name) # Attach policy to certificate cert_obj.attach_policy(policy_name) print("Completed prereq operation!")
def prereq(): with open('configure.json') as configure_file: json_text = json.load(configure_file) # Create a Thing thing_name = json_text['thing_name'] thing_obj = thing.Thing(thing_name) if not thing_obj.create(): # Create a Certificate cert_obj = certs.Certificate() result = cert_obj.create() # Store certId cert_id = result['certificateId'] cert_id_filename = thing_name + '_cert_id_file.txt' cert_id_file = open(cert_id_filename, 'w') cert_id_file.write(cert_id) cert_id_file_path = os.path.abspath(cert_id_filename) os.chmod(cert_id_file_path, 0o444) cert_id_file.close() # Store cert_pem as file cert_pem = result['certificatePem'] cert_pem_filename = thing_name + '_cert_pem_file.pem' cert_pem_file = open(cert_pem_filename, 'w') cert_pem_file.write(cert_pem) cert_pem_file_path = os.path.abspath(cert_pem_filename) os.chmod(cert_pem_file_path, 0o444) cert_pem_file.close() # Store private key PEM as file private_key_pem = result['keyPair']['PrivateKey'] private_key_pem_filename = thing_name + '_private_key_pem_file.pem' private_key_pem_file = open(private_key_pem_filename, 'w') private_key_pem_file.write(private_key_pem) private_key_pem_file_path = os.path.abspath(private_key_pem_filename) os.chmod(private_key_pem_file_path, 0o444) private_key_pem_file.close() # Create a Policy policy_document = misc.create_policy_document() policy_name = thing_name + '_amazon_freertos_policy' policy_obj = policy.Policy(policy_name, policy_document) policy_obj.create() # Attach certificate to Thing cert_obj.attach_thing(thing_name) # Attach policy to certificate cert_obj.attach_policy(policy_name)
def prereq(): with open('configure.json') as file: json_text = json.load(file) aws_config = json_text["aws_config"] optiga_config = json_text["optiga_trust_config"] # Create a Certificate cert_obj = certs.Certificate() result = cert_obj.create(optiga_config['executable_path'], optiga_config['i2c_device'], optiga_config['privatekey_objectid'], optiga_config['certificate_objectid']) # Create a Thing if doesn't exist thing_name = aws_config['thing_name'] thing_obj = thing.Thing(thing_name) if not thing_obj.exists(): thing_obj.create() # Store certId cert_id = result['certificateId'] cert_id_filename = thing_name + '_cert_id_file' cert_id_file = open(cert_id_filename, 'w') cert_id_file.write(cert_id) cert_id_file_path = os.path.abspath(cert_id_filename) os.chmod(cert_id_file_path, 0o444) cert_id_file.close() # Store cert_pem as file cert_pem = result['certificatePem'] cert_pem_filename = thing_name + '_cert_pem_file' cert_pem_file = open(cert_pem_filename, 'w') cert_pem_file.write(cert_pem) cert_pem_file_path = os.path.abspath(cert_pem_filename) os.chmod(cert_pem_file_path, 0o444) cert_pem_file.close() # Create a Policy if doesn't exist policy_obj = policy.Policy(aws_config['policy_name']) if not policy_obj.exists(): policy_document = misc.create_policy_document() policy_obj.attach_rules(policy_document) policy_obj.create() # Attach certificate to Thing cert_obj.attach_thing(aws_config['thing_name']) # Attach policy to certificate cert_obj.attach_policy(aws_config['policy_name'])
def setup(): with open('configure.json') as file: json_text = json.load(file) # Create a Thing thing_name = json_text['thing_name'] thing_obj = thing.Thing(thing_name) if not thing_obj.create(): # Create a Certificate cert_obj = certs.Certificate() result = cert_obj.create() # Store cert_pem cert_pem = result['certificatePem'] # Store Private key PEM private_key_pem = result['keyPair']['PrivateKey'] wifi_ssid = json_text['wifi_ssid'] wifi_passwd = json_text['wifi_password'] wifi_security = json_text['wifi_security'] # Modify 'aws_clientcredential.h' file misc.client_credential( wifi_ssid = wifi_ssid, wifi_passwd = wifi_passwd, wifi_security = wifi_security, thing_name = thing_name, credentials_or_keys = "client_credential") # Modify 'aws_clientcredential_keys.h' file misc.client_credential( client_certificate_pem = cert_pem, clientprivate_key_pem = private_key_pem, credentials_or_keys = "client_keys") # Create a Policy policy_document = misc.create_policy_document() policy_name = thing_name + '_amazon_freertos_policy' policy_obj = policy.Policy(policy_name, policy_document) policy_obj.create() # Attach certificate to Thing cert_obj.attach_thing(thing_name) # Attach policy to certificate cert_obj.attach_policy(policy_name)