# A Framework for Constructing a Secure Domain of Sensor Nodes
## 4 Procedures for Creating a Secure Domain of Sensor Nodes
### The Procedure for the Registration Node in the Security Domain  
This procedure is intended to register the sensor node in the security domain. The data from the NTAG, N_ID, NSK key, NAD, and SQ of the R node, which were generated during the node preparation procedure, are bound using the public part of the DK and are then sent to the M node. The M node creates the description of the registered node and saves it in its EEPROM. It is assumed that the R node registered in the security domain as the first node will play the GATEWAY role in the domain of transmitting sensory data. It results in the generation of an NTK key for the domain. As a confirmation of registration, the R node in the security domain M node sends the following data to the R node: the updated role (RN) in the security domain, the gateway address (GAD), and the key (NTK+IV) used in the domain of transmitting sensory data. During the registration procedure, the wireless XBee link is used. The final stage of registering the R node involves performing the backup of the security domain description in the resources of the R node. The sequence diagram of the procedure for registration of the sensor node in the domain is shown in Figure 7.  
Figure 6: The sequence diagram for the M node initialization procedure (**A**) and data stored on the M node (**B**) after the end of the initialization procedure. Figure 7: The sequence diagram for the R node registration procedure. The result of the node registration procedure in the security domain is the update of data in the M node resources and the resources of the registered node. On the M node side, this update consists of entering the designation of the role performed by the node (i.e., R or R + G) to the appropriate entry in the domain description, the value of its NSK key, and the address (NAD) of that node. If the node being registered is a node that will act as a Gateway, its NAD address is also saved in the GAD field and will be passed as the gateway address to all other registered nodes. Additionally, for each registered node, its status data are updated in the RAM of the M node. On the side of the registered node in the NVRAM of the TPM, the values of NTK and NDK and the GAD address are saved. Also, a copy of the domain description is saved in the EEPROM of the registered node. All of this data are obtained from the M node. The contents of the M node and the first registered node in the domain are shown in Figure 8 and after the registration of the second node in Figure 9. In both drawings, the updated data are highlighted in yellow. Detailed descriptions of the most important steps of the procedure (in Figure 7, the numbers in parentheses (e.g., (3)) preceding the descriptions indicate the numbers of the individual steps) are as follows:  
**(3) Generate node registration request**--a node registration request sent to the M node is also a request to send an NTK key back to the R node. Do the following:  
* Prepare the _transfer_key_req_ packet (Figure 10) containing the following data: N_ID, NTAG, NSK key, NAD, and SQ of the registered R node. The packet is bound using the public part of the DK (the blob includes the the bound data and its length (4 bytes)),
* Send a _transfer_key_req_ packet from the R node to the M node. **(5) Update the R node description in the M node EEPROM. ** Do the following:  
* On the M node, unbind the data from the _transfer_key_req_ packet using the private part of the DK and verify the correctness of the NTAG field. If it is not correct, print the message and stop the procedure, On the M node, prepare the R node description, and then encrypt this description using the NK and the IV vector of the M node and update the R node description in M node resources. The fields of the description should have the following values: N_ID = the content  
Figure 8: The data updated on the M node and R node (highlighted in yellow) at the end of the procedure of registering the FIRST R node in the security domain.