Application of blockchain and IoT-Khadas’ 1st Community Competition

Application of blockchain and IoT

Khadas’ 1st Community Competition

We are interested in Blockchain technology.In addition to e-money,we want to use it to do something else to give full play to its technical features such as Tamper Proof, Traceability, Decentralization and use it in the IOT (Internet of Things) information security.

First we used Hyperledger’s fabric project and built a Consortium Blackchain. Due to equipment limitations we use docker to run peer and order nodes.

At the same time, we have designed a simple Smart Contract demo to IoT devices management, related data queriers, key management and other functions.

Function name input parameter Function description
ClientSubscribe clientID、subEvent、topic Create a composite key to store client subscription records
ClientConnect clientID、conEvent、host Create a composite key to store client connection records
CreateClient clientID、username、password Create a new client
QueryClientByUsername username Query all clients under user
QueryClientOfEvent clientID、event Query the historical event record of the client
GetHistoryFromService —— Get all connection records of mqtt server
QueryClient clientID Query client information
4 Likes

Considering the huge time delay and storage pressure of storing and retrieving IOT working data with Blockchain.We use a Khadas VM3 as an MQTT server to be a blockchain application node and an MQTT broker. The Blockchain issues special certificates for it to perform some special methods, such as recording the connection time, IP and header information of the client. In this way, we subscribe to relevant topics to obtain the working data of IoT devices.If two devices exchange working data, they do not need to connect directly (there is a risk of IP leakage) and communicate asynchronously.
image
Log results of MQTT server operation

1 Like

Since MQTT has some information security risks (plaintext transmission, identity authentication, etc.),we have to consider how to protect the data communicated through MQTT. Based on the powerful hashrate of Khadas VM3.We transplanted three encryption algorithms SM2, SM3 and SM4 for khadas VM3.SM2 is used to log in to the MQTT server (the Blockchain is responsible for issuing and verifying certificates) and SM4 is used to encrypt the working data of the device. Do you remember the storage pressure of the Blockchain mentioned? We package the working data of the device and store it in another database, extract its data digest with SM3, and store the data digest, SM4 key, database address, client ID in the Blockchain.

1 Like

New Smart Contract function table

Function name input parameter Function description
ConnectAuth clientID、username、sign Client login verification
ExchangeKey username/type/id、sign、EnKey Upload SM4 communication key of client
ClientSubscribeAuth clientID、topicName Client subscription topic permission verification
ClientSubscribe clientID、subEvent、topic Create a composite key to store client subscription records
ClientConnect clientID、conEvent、host Create a composite key to store client connection records
RegisterUserKey Username、SM2 Random number of key Create SM2 key pair, store public key and return private key
CreateClient clientID、username、password Create a new client
QueryUserPubKey username Query user’s public key
QueryClientByUsername username Query all clients under user
QueryClientOfEvent clientID、event Query the historical event record of the client
GetHistoryFromService —— Get all connection records of mqtt server
GetDisposableTopicHashToken clientID、topic、time、target Get a one-time key for subscribing to topic permissions
GetDisposableDataHashToken Client、DataID Get a one-time key for shared data
AddPubTopicsForClient clientID、topic、auth、type、qos Add Publishing topic information for clients
AddSubTopicsForClient clientID、token Add subscription topic permissions for clients
GetDataInformation token Obtain the communication key and data summary of the data
UploadDataHash clientID、SM3Key、DataID Upload the summary of the data block published by the client

image
Enable Blockchain-related functions on the MQTT server:

1 Like

By the way, we added Homomorphic Encryption, which can be used to let the server help the device with the calculation without exposing the data content.
image

1 Like

We extended ZigBee communication for Khadas VM3, using a Khadas as an MQTT client to transmit encrypted data.
image
MQTT Data Transmission Test (SM4 Encryption)

1 Like

Although the data sent by the device is encrypted, we still do not want others to subscribe to my topic casually.We added a related method of subscribing to the topic in the Smart Contract.In short, Blockchain stores which topics are published and subscribed to by the device.If you want to subscribe to other people’s topics,you need to get the topic authorization through a key. A similar approach is used to obtain database data.

Based on the above-mentioned approaches, we basically solved the security risks that may exist in the exchange of data between IoT devices.We are still developing web applications for this project.Due to the lack of front-end development capabilities we used an open source demo.


Front-end web management interface

1 Like

We tested the throughput of the device login certification and the effect was relatively satisfactory.Because we did not have more than 1,000 devices that would connect to the server at the same time.

image

1 Like

The following are the results of smart contract execution:

2 Likes

Because the Blockchain program test has all certificates, we can choose any Blockchain member certificate to execute the program.

image

1 Like

Here are some Smart Contract methods that can be executed:

image

1 Like

Select Query Device Information:
c0f025eb25e6c4e617db20b6d4f6305

2 Likes

Finally, this is a picture of our equipment during the test.

2 Likes

That‘s great,guys.It’s interesting!

Thank you!!!