{'fraction_non_alphanumeric': 0.02264784328152304, 'fraction_numerical': 0.007196725834636255, 'mean_word_length': 5.016461474616129, 'pattern_counts': {'":': 0, '<': 0, '<?xml version=': 0, '>': 0, 'https://': 1, '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}}
Providing reliability and auditability to the IoT LwM2M protocol through Blockchain

Blockchain has come to provide transparency, reliability as well as to increase the security in computer systems, especially in distributed ones like the Internet of Things (IoT). A few integrations have been proposed in this context so far; however, most of these solutions do not pay special attention to the interoperability of the IoT, one of the biggest challenges in this field. In this paper, a Blockchain solution has been integrated into the OMA Lightweight M2M (LwM2M), a promising industry IoT protocol for global interoperability. This integration provides reliability and auditability to the LwM2M protocol enabling IoT devices (LwM2M clients) to transparently interact with the protocol. Furthermore, a missing reliable API to allow users and applications to securely interact with the system and an interface to store critical information like anomalies for auditability have been defined.


I. INTRODUCTION
It is unquestionable that the Internet of Things (IoT) [1] is offering an unprecedented revolution to society. The IoT ability to reduce the gap between the physical world and the digital one allows the automation and optimization of multiple processes and services in addition to providing a better knowledge of physical phenomena. The possibilities offered by this field are uncountable as demonstrated daily by industrial, domestic and institutional examples such as Industry 4.0, connected health or smart cities.
Centralized architectures like the ones used in cloud computing have significantly contributed to the development of IoT applications [2]. However, regarding data transparency they act as black boxes and network participants do not have a clear vision of how and where the information they provide is going to be used. In this regard, Blockchain reduces the reliability and security problems of centralized environments, while improving its adaptation to merely distributed systems such as the IoT [3]. Blockchain is based on the concept of "chain of blocks", in which information is grouped into sets (blocks), which are interconnected with each other through a timeline in such a way that, thanks to cryptographic techniques and consensus protocols, it is not possible to edit or repudiate this information without modifying the entire timeline, something that is costly in computational terms.
The development of IoT applications involves the management of IoT devices, which may include their identifica- tion, registration, credential management and access control to applications. Despite their high availability, centralized architectures like cloud environments can suffer transparency and reliability issues and, in addition to this, present a single point of failure due to their centralized nature. Furthermore, transparency and reliability can also be required to the IoT produced information itself, especially when a secure proof of facts is needed. As seen in other mission-critical systems like black boxes in airplanes, the recording of events is of critical importance to reconstruct their whole sequence, especially when a disaster occurs. In the IoT field, this is not well extended yet; however, there may be situations where it could be adequately incorporated. For instance, in Structural Health Monitoring [4] it might be worth having the log of events that led into a bridge or a tunnel collapse to study its origin and to be able to identify the root cause. On the other hand, open standards are the only way to ensure IoT interoperability, which is overwhelmed with many protocols and solutions. In this regard, most of the solutions tend to provide vertical silos which limit even more the adoption of the IoT in the society.
To overcome these challenges, in this work we present an integration between the IoT and Blockchain, a system that provides secure and reliable management of IoT devices, applications and critical information. The system architecture has been designed to have a minimal impact on the IoT devices, which are limited per se. Through an accessible Web interface, users can easily manage the credentials of IoT devices and applications. An Application Programming Interface (API) has been defined to provide authorized applications the ability to register immutable and tamper-proof critical events.
This work has been built over the Lightweight Machineto-Machine (LwM2M) [5] standard. LwM2M was defined by the Open Mobile Alliance (OMA) to satisfy the need for a device management protocol, semantics for resource identification and access, and end-to-end security in the Industry 4.0. LwM2M has been built on top of popular IoT Constrained Application Protocol (CoAP) and the IETF stack and is intended to be the de facto solution for global interoperability in the IoT. This protocol enables the management of IoT devices, firmware updates and applications to acquire sensing information through a standard specification. As discussed in [6], LwM2M provides a straightforward solution for access control, but can be limited to handle dynamic IoT environments. This protocol has been extended in this work to provide reliable management of device and application credentials and critical information through Blockchain, which also enables the secure mobility of devices between LwM2M deployments. Therefore, the main contributions of this paper are: arXiv:2008.06694v1 [cs.CR] 15 Aug 2020 1) Extend the LwM2M protocol to enable reliable and auditable management of IoT device credentials in Blockchain. 2) Incorporate a secure and reliable API in LwM2M to manage the access control of IoT applications through Blockchain. 3) Provide a reliable service to register critical IoT information for auditability. The rest of the paper is organized as follows. Section II presents a background on Blockchain and LwM2M. Related work is discussed in Section III. In Section IV the system architecture and its components are presented. The system implementation is detailed in Section V and evaluation is presented in Section VI. Lastly, our conclusions and future work are presented in Section VII.

A. LwM2M
Lightweight M2M (LwM2M) is an Open Mobile Alliance (OMA) protocol that provides a light and fast solution for managing M2M and IoT devices. LwM2M aims to meet the growing market demand for M2M solutions in the Industry 4.0. It is specially designed to achieve a reduction in energy and data consumption, ideal for low-capacity devices and networks that require efficient use of bandwidth.
The LwM2M protocol architecture operates under the client-server paradigm extending the Constrained Application Protocol (CoAP) [7]. Unlike CoAP, LwM2M clients offer resources in IoT devices that are securely accessible and managed in a standardized way through LwM2M servers. LwM2M defines four interfaces for communication between clients and servers: 1) Bootstrap 2) Client Registration 3) Device Management and Service Enablement 4) Information Reporting The protocol defines a simple model where client information is organized as resources that can be accessed through the previous interfaces. Resources are organized into different objects within the client, and each object can have multiple instances. Each object and resource has a unique identifier. For example, objects 0 and 1 are assigned to LwM2M security and the connection with LwM2M server respectively, and /1/0/8 is the Registration Update Trigger resource in the instance 0 of the resource 1 (connection with LwM2M server).
The Bootstrap interface is provided by the Bootstrap servers and manages the credentials and bootstrapping to the different LwM2M clients so that they can later register to the LwM2M servers. The Client Registration interface registers LwM2M clients on LwM2M servers. Three operations are provided by this interface: registering an LWM2M client on an LWM2M server, updating the registration (this operation allows to have a control of connected LwM2M clients), and de-registering to delete a client registration on an LwM2M server.
The Device Management and Service Enablement interface allows LwM2M servers to access the object instances and resources available on the LwM2M clients connected to them. This interface performs the interaction between clients and servers through the use of operations such as Read, Write and Execute.
Finally, the Information Reporting interface allows LwM2M clients to report asynchronously information about any changes in their resources to LwM2M servers. The observation is initialized by the Observe operation from LwM2M servers to an object, resource or instance of an LwM2M client and it is maintained until the operation is canceled. Fig. 1 shows all the interactions between a client and an LwM2M server through the operations of these four interfaces.
The LwM2M enabler uses CoAP and therefore UDP links, but it can also use a SMS link. Security over UDP is provided by DTLS (Datagram Transport Layer Security).
There are different implementations of LwM2M. Currently, the most used are Wakaama [8] and Leshan [9]. Wakaama is a C implementation of LwM2M clients and servers. It is designed to be portable on POSIX compliant systems. To test the capabilities of the Bootstrap server, some samples and tests are available in its official repository. Wakaama belongs to the open source community of the Eclipse Foundation. On the other hand, Leshan is a Java implementation of LwM2M servers and clients. Leshan is based on a CoAP implementation Californium and the DTLS implementation Scandium. Like Wakaama, it belongs to the Eclipse foundation and some samples and tests are also available in its official repository. In addition, a web UI (user interface) for both Bootstrap and LwM2M servers and a public test sandbox with a Bootstrap server and an LwM2M server are available so that its functionality can be tested quickly and easily.

B. Blockchain
At any digital system, the trust in the incoming and outcoming information is one of its biggest concerns. And this situation is even more challenging when no verification mechanisms are provided, particularly when the system has to deal with sensitive data. In 2008, two innovative concepts appeared in this context and they were introduced by Satoshi Nakamoto [10]: Bitcoin and Blockchain. Bitcoin is the wellknown first cryptocurrency, a purely peer-to-peer version of electronic cash. This system allows people to make payments without a third party intermediary like a bank or any other financial institution. The second concept presented by Nakamoto, Blockchain, is the mechanism under the hood of Bitcoin. And nowadays its popularity and applicability are larger than the cryptocurrency itself.
Blockchain is defined by Bashir [11] as "a peer-to-peer, distributed ledger that is cryptographically secure, appendonly, immutable, and updateable only via consensus or agreement among peers". A Blockchain is a distributed ledger of a chronological chain of records in the form of encrypted blocks made up by all transactions executed by the participants. Initially, Blockchain was only the distributed ledger system for the Bitcoin cryptocurrency but currently is being researched and applied in many areas as financial services, supply chain and logistics, healthcare, IoT, smart cities, among other applications. There are three types of Blockchain networks: public, private and consortium. The last two types are also called permissioned. Public Blockchain has absolutely no restrictions and are open to the public; anyone can send transactions, run applications and join the network. This kind of network utilizes some type of a Proof of Work (PoW) or Proof of Stake (PoS) algorithm as consensus protocol. Bitcoin is the most famous public Blockchain. Another well-known public Blockchain network is Ethereum [12]. According to its inventor, Vitalik Buterin, Ethereum is "a Blockchain with a built-in fully fledged Turing-complete programming language that can be used to create 'contracts' ... simply by writing up the logic in a few lines of code". And this is the main difference with Bitcoin: Ethereum Blockchain allows smart contracts.
A smart contract is a computer program that encapsulates source code and the business logic necessary to execute a function when certain conditions are met. The concept of smart contract was defined by Nick Szabo at the end of the last century [13]. Before Blockchain, Szabo's idea could not become a reality, and so it was only a definition/concept. With the advent of this technology, the first smart contracts could be created. Not all Blockchains support smart contracts. For example, Bitcoin does not allow to code this kind of computer program.
Permissioned blockchains are Blockchain networks where access is controlled by one or more organizations. As explained previously, private and consortium blockchains are permissioned. The main difference between them is that private blockchains are managed by one single organization while consortium blokchains are controlled by more than one party. Permissioned blockchains are more popular within industry and business areas for which role definition, security and identity are important. The most famous example of permissioned Blockchain is the Hyperledger project [14]. Hyperledger is not a project by itself; it is an open-source umbrella project composed by frameworks, libraries and tools for enterprise-grade Blockchain developments. Started in December 2015 by the Linux Foundation, Hyperledger collaborates with more than 250 companies (IBM, Inter, SAP Ariba, among others) and has six Blockchain framework projects. The best-known project is Hyperledger Fabric [15], an enterprise-grade permissioned distributed ledger written in Go. At the beginning of 2019 the first long-term-support version of Fabric was released.
III. RELATED WORK The IoT and Blockchain are mainly decentralized and distributed [16], and this is maybe why they complement very well each other: by providing real world information and enabling decentralized, reliable and auditable authentication and access control to IoT devices respectively.
In [17] and [18] an architecture for managing decentralized roles and permissions in the IoT through Blockchain is proposed. Although LwM2M is also adopted as backbone IoT protocol, this architecture requires the communication of IoT devices with a new entity known as Management Hub, which is responsible for the interaction with the Blockchain network. In our architecture, IoT devices and external users and applications just interact with LwM2M components (Bootstrap and LwM2M servers) as proposed by the specification, therefore the flow in the LwM2M standard has not been altered. The architecture presented in this paper aims at improving the reliability and auditability on the LwM2M standard in a transparent way to IoT devices and end users and applications. Moreover, centralizing all the communications through the Management Hub can also have a negative impact to resourceconstrained IoT devices.
The authors in [19] present a Blockchain framework for secure and scalable transactions in the IoT. The fundamental principle of the framework is that IoT devices do not interact directly with a Blockchain peer, but with an intermediate entity in a Local Peer (Lpeer) network, which comprises a local ledger that restricts the number of transactions entering the global Blockchain. An Lpeer network also includes a Certificate Authority (CA) that provides authentication and registration for IoT devices and an Lpeer node that enables the interaction with the main Blockchain. Although this work speeds the transactions in IoT networks, the authentication and authenticity of devices and users are guaranteed by CAs that can be secured but may present the weakness of centralized architectures.
Limitations on IoT devices can suppose a barrier to apply directly Blockchain on them. To overcome that, many works go to edge and fog computing as intermediary entity between the IoT and Blockchain. In [20] a Blockchain access control management based on edge computing is presented. A selfcertified public key-based system is used for the registration and authentication of IoT devices, and the identities and certificates are stored in a Blockchain network composed of edge centers. Thanks to the Blockchain network, a trust relationship between edge centers and IoT devices can be established. Access control rights can be transferred from one edge center to another, thus enabling IoT mobility between edge networks. In [21] a hierarchical Blockchain architecture for IoT authentication based on edge computing is also presented. However, as also happens in BSeIn [22], these works merely focus on authentication and control access and do not provide an interoperable and standard protocol to interact with IoT devices like the one presented in this paper.
In [23], a user authentication scheme using Blockchainenabled fog nodes to IoT devices is proposed. This work also adopts Ethereum smart contracts network and has the source code available on GitHub. Users authenticate directly in the Blockchain network, and in case of success, a token is generated, which with a public key could authenticate with fog servers to interact with IoT devices. Finally, users can establish a normal secure SSL connection with IoT devices. The main drawback of this solution is the high requirements imposed by SSL connections, specially for resource-constrained devices.
In [24], a decentralized authentication method for IoT devices based on Blockchain is proposed. In this work the concept "bubbles of trust" is introduced, in which secure virtual zones are created where only authorized devices can communicate each other in a secure way. The dependency of a public Blockchain and the consequences of this in terms of cryptocurrencies and latency are addressed by [25] by providing an authentication scheme through a hybrid Blockchain in wireless sensors networks. Although these works are not based on a open standard for IoT interactions, they do provide a fine control of inter-device interactions that will be taken into account as future work.
BlockBDM [26] is a hierarchical Blockchain architecture for big data management and secure consumption. The architecture is organized as follows: 1) a permissioned Blockchain enables trust management, security proof of data sources and history usage; 2) a public token-based Blockchain encourages users to provide high-quality content obtaining economic profit; 3) and finally, InterPlanetary File System (IPFS), a Blockchain data storage, is adopted to store big data (e.g., multimedia or remote sensing image) in a reliable, decentralized and flexible way. In general, BlockBDM provides a good solution for data management, sharing and accountability in big data systems. The solution presented in this paper focuses on IoT applications that require device and user management in a standard IoT protocol and, at the same time, enables the recording of critical events for forensics.
Unlike Sensor-Chain [27], Tornado [28] and other approaches to enabling Blockchain in IoT, our work just uses Blockchain for data accountability and reliability as a service. Despite the promising future of this integration and the continuous advances made to reduce power consumption and adapt Blockchain to the IoT, this work has adopted a Blockchainas-a-service approach because: 1) IoT devices do not notice the presence of Blockchain, since they communicate with Bootstrap and LwM2M servers and interact through them with the Blockchain network; 2) the no presence of a Blockchain allows to remove its dependency and facilitates the adaption of the system to already running deployments; and finally 3) in spite of the improvements and relaxed consensus protocols, enabling Blockchain in the IoT has still an overhead which may seriously reduce the life expectancy of battery-powered IoT nodes.

IV. RELIABLE AND AUDITABLE ARCHITECTURE FOR IOT LWM2M NETWORKS
The system presented in this paper offers not only reliable and auditable management of IoT devices and applications, but also the ability to record critical events when required for later data forensics. This is of special interest to reconstruct the whole sequence of events during a critical occurrence like a natural disaster and for auditability. Through this system, whose architecture is shown in Fig. 2, the management of IoT devices, applications and critical events can be auditable in a reliable way through Blockchain. Next, each component of the architecture is detailed.

A. Blockchain network and smart contracts
As previously explained, the recording of critical events needs to be reliable and auditable. And to achieve this, these critical events must be stored in a secure way for later forensics. This is the main reason, along with the authentication management in IoT devices, to use Blockchain in the proposed architecture. As described in subsection II-B, there are three main types of Blockchain networks: public, consortium and private. For this architecture, we have adopted a public Blockchain since the system needs to be world-wide reliable and not only be trusted by one organization or within a set of partners (private or consortium network, respectively).
The architecture also requires the definition of smart contracts. These smart contracts are open to anyone (because they are deployed in a public Blockchain network), but the interaction with them must be limited. Only certain users could interact with the defined contracts, executing transactions on them. The system needs three different smart contracts: one to register LwM2M clients; another to store critical information for auditability; and the last one to manage users and applications who can use the Management Web UI and the APIs of the different LwM2M servers deployed respectively.

B. Management web UI
To manage the system, an accessible and user-friendly management web UI has been defined and implemented. There are two different roles in the management Web: admin and normal user. On the one hand, users with the admin role can create user and device credentials. They can also manage existing users and devices and visualize all existing critical information stored in Blockchain like anomalies. On the other hand, normal users can only access to the critical information stored in smart contracts at the Blockchain network. Fig. 3 summarizes all the described use cases depending on the user role.
The management web UI also provides an interface where external users and applications can store critical information  As described in subsection II-A, Bootstrap servers manage the credentials and bootstrapping to the different LwM2M clients so that they can later register into the LwM2M servers.
In this system, we have modified the Bootstrap servers so they can access the Blockchain network to query all the necessary client information for authentication and registration. A smart contract (ClientStore contract) request is made every time a client's information needs to be obtained. This interaction with the Bootstrap server is shown in Fig. 4.
Clients authenticate to the Bootstrap server using a preshared key (PSK), the authentication scheme supported for the time being by this system. The Bootstrap server consults in the ClientStore contract the information of the clients that make the request. This search is performed by the registered endpoint name. Once the client is successfully authenticated, the Bootstrap server provides the necessary configuration to connect to the LwM2M server. The configuration consists of the credentials and the LwM2M server URL. Finally, the LwM2M server needs to verify the client's credentials, so it checks this information in the same smart contract as the Bootstrap server.

D. LwM2M clients
LwM2M clients are responsible for making measurements of physical parameters on the environment or infrastructures. The objective of this project is to provide a system where devices are reliable and where the information generated maintains its integrity and veracity over time, having the minimum repercussion to them.
The register and authentication of the devices are achieved through the Bootstrap mechanism and the Blockchain network. On the other hand, the integrity of the data of interest is guaranteed by storing them (when needed) on the Blockchain.

E. LwM2M servers and secure API
The objective of LwM2M servers is to allow the monitoring of the environment through the LwM2M clients that are registered on them and their management. As mentioned in subsection II-A, the LwM2M protocol allows a quick and easy interaction with clients, making it possible to obtain their information, modify their parameters, initiate an observation and even update the firmware of the device.
LwM2M servers also use Blockchain technology to verify the authenticity of LwM2M clients. Every time a client tries to connect to an LwM2M server, a query is performed to the ClientStore smart contract that stores the security data of all LwM2M clients. This contract is the same one used in the bootstrapping. In this way, a double check is made during client registration, first on the Bootstrap server and later on the LwM2M server itself.
An Application Programming Interface (API) REST is provided on each LwM2M server to allow the access to LwM2M clients and their resources by third-party applications. To make use of this API, it is necessary to have a register with the corresponding permissions. To verify the authenticity of users, the contract UserStore is used, where all registered users are stored.

F. External applications
Different applications and users can securely interact with the LwM2M devices deployed in the system. These interactions are carried out through the secure API that LwM2M servers expose. Before that, an authentication process is required where applications and users are verified with their credentials through Blockchain technology.
Through the APIs offered by the LwM2M servers, users and applications can list the LwM2M clients connected to each LwM2M server and interact with them through the LwM2M protocol. Moreover, they can also access to the interface offered by the management web UI to register critical information like anomalies when required.

V. IMPLEMENTATION
This section describes the implementation of the architecture and components presented in Section IV. This implementation is openly available at our GitHub repository 1 . To show an overview of the main components and their interactions, a sequence diagram of the LwM2M client registration process is shown in Fig. 5. The diagram begins with a user (admin role) interacting with the web UI, that registers an LwM2M client on the Blockchain network. After this, the LwM2M client requests its credentials to the Bootstrap server and registers itself in an LwM2M server.
Below, the implementation of each component is described.

A. Blockchain network and smart contracts
As discussed in subsection IV-A, the Blockchain network should meet two requirements: be public and allow the deployment of smart contracts. Following these constraints, the selected Blockchain network was Ropsten [29], a testnet of Ethereum which uses the same algorithm of consensus that Ethereum Mainnet (PoW). In the same way as Ethereum Mainnet, Ropsten needs Ether to deploy smart contracts or to execute transactions, but it is possible to get free Ethers from this network through faucets. A faucet is a mechanism that sends an Ether amount to one account.
To communicate with the Ropsten network, the Infura [30] project is used. Infura is an infrastructure that allows an easy connection to the Ethereum Mainnet and to all Ethereum testnets including Ropsten through a suite of tools. Once an account and a project are created in Infura, a URL endpoint is provided for each network. These endpoints can be used  Figure 5. Sequence diagram of an LwM2M client registration in the system and authentication on an LwM2M server to deploy smart contracts and to push transactions onto the Ethereum networks.
The proposed system provides three different smart contracts. All of them have been developed using Solidity, an object-oriented, high-level language for implementing smart contracts. The main functionality of each smart contract is described below: • ClientStore. All the data about the registered LwM2M clients are saved here. This information includes the client endpoint name, one LwM2M Bootstrap server URL, one LwM2M server URL and client credentials to connect to both servers. The contract has transactions to register new clients, get one or all existing clients and remove a client. • AnomalyStore. This contract stores critical information such as anomalies, the timestamp when this piece of data was collected and the LwM2M client who provides this information. It is possible to add new critical information entries and get all of them through transactions. • UserStore. Users management in the Web UI and external applications is carried out by this contract. For each user, a username, an email, a password and a role will be stored. Roles are the same as for the Web UI (see IV-B) plus an additional one assigned to the external applications. Available transactions allow to add, get and update users plus validate login attempts.
Algorithms 1, 2 and 3 present the pseudocode of smart contracts ClientStore, AnomalyStore and UserStore, respectively. As shown on these algorithms, Solidity built-in function revert() is used when an error occurs (i.e. when trying to add a user that already exists). Besides the main functionality of the smart contracts, each one has an auxiliary function to verify if a client/critical information entry/user exists on smart contract storage.

B. Management web UI
The management web UI follows the traditional clientserver model, having an Angular client at the presentation layer (front-end) and a Java/Spring server at the data access layer (back-end). The main difference with the client-server model is the use of a Blockchain instead of a centralized database to store LwM2M client/anomaly/user data.
The communication with smart contracts is carried out through the library web3j 2 . This library allows the interaction between Ethereum smart contracts and a Java program. With 2 https://github.com/web3j/web3j web3j is possible to generate wrapper code to ease the communication with the smart contracts. Then the server needs to know three parameters to interact with each smart contract: • URL of a Blockchain network node: The different queries are made from a Blockchain network node. Infura has been used for this. • Ethereum account: An Ethereum wallet with ethers is required to execute transactions. • Smart contract address: After contract deployment, the Blockchain network returns the address where the smart contract is located. If the address number is lost, contract information cannot be retrieved. The previous parameters are configured when the web UI is deployed. The login mechanism implemented for this application makes use of the Blockchain contract UserStore to validate credentials through method validateLogin. To access the server REST API resources, users must be authenticated. And this authentication is implemented using JSON Web Token (JWT).
JWT is a JSON-based open source standard to create access tokens that allows to secure communication between clients and servers. A JWT process is divided into two phases: authentication and authorization. Firstly, the client sends the user's identity, in this case, username/email and password. Then, the server verifies these credentials using the contract UserStore and, if the authentication was successful, a JWT is generated. Depending on the user's role, the token will give access to all resources to admins and restricting LwM2M clients and users management to normal users.
For the next requests, users must include this token as a header to access the protected resources. The server decrypts the token and checks if the clients have permissions to access the desired resource. All this data flow is displayed on Fig. 6.
Once a user is logged into the management web UI, he/she could perform operations according to his/her role, as for example the secure and reliable register of an LwM2M client into the system (Fig. 7).

C. LwM2M Bootstrap servers
Leshan LwM2M implementation has been used as the base implementation to be extended in this work. Leshan is the most stable and used open-source LwM2M implementation and it provides better documentation and community support than others. Leshan also provides the necessary infrastructure to develop the proposed system in this work, since it implements the four mentioned LwM2M interfaces. Specifically, the way in which Leshan accesses and stores the security information of the different LwM2M clients is modified in such a way that it is consulted in Blockchain and not in a JSON file or in memory as its current implementation does.
To develop the Bootstrap server, a Maven 3 project was created where the Leshan dependency was included to be able to access all the functionalities and characteristics that Leshan offers. In addition, it was necessary to add the web3j library as a dependency to interact with Ethereum smart contracts through Java as mentioned in subsection IV-B. LwM2M clients are composed of different objects. Each object has different resources and these objects and resources are identified with an identifier with the form Object/InstanceObject/Resource. By default, LwM2M clients are created with three mandatory objects: Security, Server and Device. This can be used by any official LwM2M client implementation. This system has been evaluated using the Leshan LwM2M client implementation.
The Security object configures the client to connect to a Bootstrap server using a pre-shared key in order to obtain the necessary credentials to connect to the LwM2M server. The Server object provides the data related to the LwM2M server, but as in this case it connects to a Bootstrap server, it does not have an associated instance. Lastly, the Device object provides a range of device-related information which can be queried by the LWM2M Server, in addition to a device reboot function.
Along with these three mandatory objects, it is possible to add more objects predefined by OMA such as temperature, humidity sensors, etc., or custom-made objects.

E. LwM2M servers and secure API
A secure REST API, not available yet in LwM2M Leshan, has been developed to allow external and authorized applications to access LwM2M servers using the Spring framework. Spring is the most used framework in Java to develop API REST easily. The Spring Boot tool has been used to create the server project since it makes working with dependencies easier.
As mentioned above, clients provide different objects. The LwM2M server needs to load those object models used to know the type of data it expects to receive when it performs a request to a client resource.
LwM2M servers are configured so that only clients that make secure connections through CoAPS are allowed. LwM2M offers three modes of secure connections: using preshared key, with certificate or through Raw Public Key (RPK). Currently, pre-shared key is supported in this project. The Figure 8. Validation application to interact with LwM2M clients after secure authentication verification of the pre-shared key of the clients is carried out in the same way as in the Bootstrap server, consulting the Blockchain network. To do so, the server is deployed and configured with a URL of a Blockchain network node, an Ethereum account with ethers and the address of the deployed smart contract as mentioned in subsection V-B.
In the same way as the management UI, the REST API of each LwM2M server enables authentication using JWT and the deployed smart contract UserStore.

F. External applications
External and authorized applications can use the REST API offered by LwM2M servers. For this, applications should perform a REST request in any programming language with their credentials and then use the JWT received, the authentication mechanism implemented after authentication, to be able to perform requests and interact with the LwM2M clients through the secure REST API.
For validation purposes, an application has been defined using the popular JavaScript framework Angular. Once a user/application has been authenticated into an LwM2M server, the accessible clients to interact with are displayed (Fig.  8). Along with each client, a button has been added to perform a GET request an LwM2M to a temperature resource created in the LwM2M clients.

VI. EVALUATION
This section exhibits the validation carried out on the proposed system and its main functionalities: 1) devices management and authentication; 2) applications and users management and authentication; and 3) critical information management. The average time of 100 tests has been taken for all the cases. The evaluation has been performed in a computer with the following configuration: The Ropsten test network, deployed publicly around the globe, has also been used to validate the previous smart contracts. When working with Ethereum Mainnet or one of its testnets, it is necessary to set a gas price and a gas limit for transactions. Gas price refers to the cost necessary to perform a transaction on the network while gas limit is the maximum amount of gas that the interested party is willing to spend on a particular transaction. Both parameters are expressed in Gwei 4 . These values influence the time taken and the Gwei amount spent on each transaction. If both parameters are high, the transactions will be faster and more expensive. On the other hand, if the price of gas is low, the commission earned by miners will not be high, so it will not be an attractive transaction and will take longer to be selected and executed.
To carry out the evaluation, a limit of 4712388 wei 5 and a price per gas of 40 gwei has been established. For the selection of these values, the recommended values in [31] have been taken into account. It is important to note that these values change frequently, so the times may vary.

A. Devices management and authentication
The first test performed aims to evaluate the response time when registering and authenticating new LwM2M clients data in our Blockchain-based system compared with the one offered by the LwM2M implementation of Eclipse Leshan, testing with a different number of clients registered. As Fig. 9 shows, the total elapsed time on Blockchain is higher. This is due to the overhead provided by Blockchain. However, for this system these times are within an acceptable range since latency is less than 1.3 seconds to register a client information when 500 clients are stored. It is important to note that storing information in memory (as Leshan currently works by default) is meaningless in a real environment. In any case, it should be stored in a database, so response time in Eclipse Leshan should be higher. 4 1 Gwei = 10 −9 Ether 5 1 wei = 10 -9 gwei On the other hand, it has been also evaluated how the number of stored clients affects latency when adding and removing information in the smart contract. Fig. 10 shows the average times to add and remove clients in the smart contract depending on the total number of clients that are added or removed. In this case, the times obtained have been much higher, around half a minute. This is because this project uses a public Blockchain network, so the execution of transactions (due to the consensus protocol) is slow. In this case, the elapsed time is about tens of seconds. Note that these transactions will not be very frequent since registration of LwM2M clients is usually performed only once for each client.

B. Users/applications management and authentication
For this smart contract, the latency of the validation process of users'/applications' credentials is evaluated through Blockchain. Fig. 11 shows the average times obtained depending on the number of users/applications stored in the smart contract. The average query time is around 150-200 ms, a similar response time than the one obtained in the device authentication. On the other hand, the performance is evaluated when adding and modifying applications/users. As in the previous smart contract, when operations that modify the contract are executed, the times obtained are around half a minute as shown in Fig. 12. These operations may not be very frequent, so the impact of this latency is not very important in the proposed system. Finally, the response time when querying critical information for auditability by authorized users and applications was evaluated. As explained on subsection V-A, a critical information entry is composed by the timestamp when data were collected, the LwM2M client who provided this information and the critical information itself. Fig. 13 shows the elapsed time when varying the information stored to evaluate how this also affects latency. As expected, the response time is higher when the information stored is higher due to the features of Blockchain. In any case, the latency is in the order of centiseconds. Critical information is stored securely and transparently and in an immutable way in the proposed solution for auditability, thereby it should not be updated nor deleted. For this reason, only the response time when adding new information regarding previous information stored was measured (Fig. 14). As evaluated in previous contracts, the response time is in the order of tens of seconds when adding new information.

VII. CONCLUSIONS AND FUTURE WORK
A new integration between the IoT and Blockchain has been proposed in this paper. However, unlike others, this integration focuses on IoT interoperability and provides reliability and auditability to the IoT protocol LwM2M. In particular, the authentication of IoT devices (LwM2M clients) is carried out in the same way as established in the LwM2M standard; however, credentials are securely and transparently stored in Ropsten, a testnet of Ethereum, and are easily registered through a management Web UI by authorized users. A secure API has been defined to manage the access to external users and applications in LwM2M servers, and thereby to underlying LwM2M clients. Finally, an interface is provided by the management web UI, which can be distributively deployed,  Figure 14. Performance of storing critical information to allow applications to register critical information needed for data forensics.
This work mainly focuses on authentication, and even though the access control of applications and users can be managed with this, a more precise access control (e.g., until resource level) is needed in the Industry 4.0. Therefore, new approaches, and a possible integration with the access control list in the LwM2M protocol, will be explored. On the other hand, this work exploits a public Blockchain whose latency can be admissible for device authentication. However, for inter-device communications, this latency may not be acceptable. For this, a hybrid Blockchain considering a private Blockchain will be explored. Finally, a comprehensive evaluation using IoT devices and the application of this work to a real use case are in the roadmap.