<jupyter_start><jupyter_text>Introduction MUST READ: This Notebook tutorial will allow you to setup with Azure account for custom_pki_azure example. By using this Notebook, its possible to update account credentials to Azure cli, Register the Signer and device.Before running this Notebook, 1. docs/Azure_iot_hub_details.csv file should have updated with azure iot hub name.2. Run TFLXTLS Resource Generator.ipynb notebook to ensure root and signer certificates are generated.3. Make sure CryptoAuth Trust Platform is having factory reset program  1.1.Tutorial Prerequisites:    The following code is runs on python 3.x environment. This step of the tutorial will attempt to load all the necessary modules and their dependencies on your machine. If the above modules are already installed you can safely step over the next Tutorial step.> pip install -U module_name  Note 1. Installation time for prerequisites depends upon system and network speed.2. Installing prerequisites for the first time takes more time and watch the kernel status for progress. Following image helps to locate the Kernel status,3. Installing prerequisites gives the following error and it can be safely ignored. Functionality remains unaffected.    -  azure-cli 2.0.76 has requirement colorama~=0.4.1, but you'll have colorama 0.3.9 which is incompatible.    -  azure-cli 2.0.76 has requirement pytz==2019.1, but you'll have pytz 2019.3 which is incompatible.     -  Extension 'azure-cli-iot-ext' is already installed.<jupyter_code>import sys, os

home_path = os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.realpath(os.getcwd())))))
module_path = os.path.join(home_path, 'assets', 'python')
if not module_path in sys.path:
    sys.path.append(module_path)

from requirements_helper import requirements_installer
obj = requirements_installer(os.path.join(home_path, 'assets', 'requirements.txt'))
!az extension add --name azure-cli-iot-ext<jupyter_output><empty_output><jupyter_text>Load the necessary modules and helper functions<jupyter_code>from azure_register_signer import *
from ipywidgets import *
from IPython.display import display
from tkinter import Tk, filedialog
from cryptoauthlib import *
from cryptoauthlib.iface import *
import binascii

from trustplatform import *

print("Importing modules - Successful")

#TFLXTLS device I2C address 0x6C; #TNGTLS device I2C address 0x6A; 
common_helper.connect_to_secure_element('ATECC608', ATCAKitType.ATCA_KIT_I2C_IFACE, 0x6C)
print("Device initialization - Successful")

# Request the Serial Number
serial_number = bytearray(9)
assert atcab_read_serial_number(serial_number) == Status.ATCA_SUCCESS

device_reg_id = "sn" + binascii.hexlify(serial_number).decode("utf-8").upper()
print ("\r\nDevice ID: {}".format(device_reg_id))<jupyter_output><empty_output><jupyter_text>The following steps assist to perform    1. Azure account login    2. Registering the Signer module    3. Registering the Device Azure account login (1. Account Login)This helps to update user Azure credentials to Azure-cli. Azure-cli will be used for any interactions with Azure cloud from the PC.This can be skipped if the azure login update to azure cli is already done. Registering the Signer module (2. Register signer)This will register the signer generated during resource generation step to Azure iot hub account. Clicking the 'Register signer' button will trigger signer registration.  Register the Device (3. Register device)This will register the device ID of the TrustFLEX to Azure iot hub account. Clicking the 'Register device' button will trigger device registration.   1. Azure account loginThis step helps to initialise the Azure cli tools with azure account credentials.<jupyter_code>def execute_azure_login(b):
    Azure_login.button_style = azure_account_login()
    
Azure_login = widgets.Button(description = "Azure login")
Azure_login.on_click(execute_azure_login)<jupyter_output><empty_output><jupyter_text>2. Register Signer CertificateThis step of the tutorial registers the signer certificate to the Azure IOT Hub. MUST READ: The Signer name should be unique in the iot hub. If the signer name is already present in iot hub, it will raise an error.<jupyter_code>def execute_register_signer(b):   
    azure_reg_signer.button_style = register_azure_signer()
      
azure_reg_signer = widgets.Button(description = "Register signer")
azure_reg_signer.on_click(execute_register_signer)<jupyter_output><empty_output><jupyter_text>3. Register Device IDThis step of the tutorial registers the device ID to the Azure IOT Hub.<jupyter_code>def execute_device_register(b):
        reg_device.button_style = register_device(device_reg_id)
  
reg_device = widgets.Button(description = "Register device")
reg_device.on_click(execute_device_register)

display(widgets.HBox((Azure_login, azure_reg_signer, reg_device)))<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.06708938433217426, 'fraction_numerical': 0.011454285129883411, 'mean_word_length': 5.644021739130435, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 22, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '338503', 'license': 'MIT', 'n_tokens_mistral': 1428, 'n_tokens_neox': 1378, 'n_words': 516, 'path': 'TrustFLEX/10_cloud_connect/notebook/azure/TFLXTLS_azure_connect.ipynb', 'repo_name': 'rashedtalukder/cryptoauth_trustplatform_designsuite', 'size': '4889'}