# Blockchain-Based Multistage Continuous Authentication for Smart Devices
## 5 Experimental Simulation
### Implementation of Blockchain Networks  
(1) Environment settings  
The blockchain was implemented using the Hyperledger Fabric 2.4 technology framework. Smart contracts were developed using the Go language. The nodes of the blockchain network were run in Docker containers, which were configured according to the image via Docker compose files. This included one orderer node, two Org organizations, one CouchDB service, and one CA service, and each organization included four peer nodes; each peer node was configured with the appropriate role.  
Figure 16: Process of user authentication.  
2. Consensus mechanism  
We used the Solo single-node consensus algorithm in this paper. After a node in a federation chain submits a transaction request, the orderer node sorts and packages the transactions that meet the conditions, and it backs up the transactions once at each node.
3. Smart contract  
The system designed two smart contracts for registering information and performing user authentication. The parameters to be stored in the smart contracts and the corresponding functions needed to be determined. We stored the following data in the smart contracts: (1) user name index, (2) timestamp of each transaction, (3) signInfo hash of the signed credential information, and (4) public information \(P\). The details are as follows.  
In the registration information smart contract, the algorithm is defined as follows (Algorithm 1):  
```
1 Input : Identifier \(ID_{i}\), Document information \(Info\), Feature Key \(HR_{i}\), Client public key \(EPK\)
2 Use identifier \(ID_{i}\) as key to find its corresponding value
3 if there is no corresponding value, then
4{ Set the username to the value of identifier \(ID_{i}\). Save \(HR_{i}\) as a feature key into IPFS and deposit \(Info,EPK\) into the blockchain.
5 return success
6]
7 else
8{if \(Info^{\prime}=Info\) then
9{ Update feature key \(HR_{i}\) value into IPFS and save Info, EPK into blockchain
10 return true
11}
12 else return false
13{
```  
**Algorithm 1**Smart Contract I : Identity Registration  
In smart contract I, the user's identity information is first verified whether it exists; if not, the user's identity is directly saved. If it exists, the ID information of the already existing identity information user is first verified. If it matches with this caller, the user's identity information is updated. Otherwise, it returns an error.  
The authentication smart contract algorithm is defined as follows (Algorithm 2):  
```
1 Input : Identifier \(ID_{i}\), Document information \(Info^{\prime}\), Feature Key \(HR_{i}^{\prime}\), Login time \(T_{0}\)
2 Get identifier \(ID_{i}\) from the input information and use \(ID_{i}\) as key to get the corresponding value
3 if there is no corresponding value, then
4 return false
5 else
6{ Decrypt the message using the private key to get \(Info^{\prime}\)
7 if \(Info^{\prime}=Info\) then
8 return IPFS address
9{ if \(HR_{i}^{\prime}=HR_{i}\) then
10 return true
11}
12 else return false
```  
**Algorithm 2**Smart Contract II: Identity Verification  
In the authentication smart contract, the implementation looks up the identity information based on the user's name. If the information exists, the signature is authenticated, and the IPFS address is returned for biometric authentication. Then, if the biometric authentication is successful, it means the user's identity is successfully authenticated.  
Access control  
We performed the on-chain read step after completing the chain code publishing and deploying the smart contract. It includes adding the user's identity information, querying the fabric network for the user's identity information, using the get operation and the user updating biometric information. Figure 17 below shows the successful authentication of the user's identity.