# Security Architecture for Swarms of Autonomous Vehicles in Smart Farming
## 3 Results
### Security Architecture for Swarms of Autonomous Vehicles
#### 3.2.3 Protection of Data Integrity  
In cybersecurity, data integrity refers to the accuracy of the data. The objective of the techniques that guarantee the integrity of the data is to prevent the data from being modified or misused by an unauthorised party. Altered data in agriculture could cause damages to livestock (e.g., withholding feed or water) or crops (e.g., applying fertilizer in an area of risk) [7]. Data validation is another requisite for data integrity, so it is important to check the accuracy, completeness and consistency of data: e.g., discarding incomplete or out-of-range data. The most common tool for ensuring data integrity is HMAC (keyed Hashed Message Authentication Code), which uses symmetric cryptography to reduce data to a message digest (i.e., a short string of numbers). A secret key is randomly generated by the inherent HMAC algorithm, and this key must only be shared with trusted parties. The hash is unique to the information being processed, so any change in the data produces a completely different message digest. The message digest must be sent together with the data. By comparing the digest received with the digest generated from the incoming data, the recipient of the data ensures that the information remains unaltered. The strength of the HMAC depends on the cryptographic strength of the hash function and on the quality and size of the secret key. TLS provides an implementation of HMAC based on the cryptographic functions MD5 and SHA-1. Digital signature is another option for data integrity. The difference between HMAC and digital signature is that HMAC values are generated and verified using the same secret key, which implies that the sender and receiver agree on the same key before initiating communications, which provides a faster performance than digital signature. Another option to ensure data integrity is the use of Blockchain, a technology based on a decentralised-shared database that records transactions in an immutable ledger. Each of these transactions is a block of the blockchain and every block contains information about the transaction time, its details and previous transactions. Once recorded, a block cannot be altered, which ensures the integrity of the data stored in the blockchain. As a drawback of this technology, it can be mentioned that its implementation is a costly process. Moreover, there still exist some regulatory barriers that have to be removed [36]. The measures recommended to guarantee the integrity of the data in the case under study are described below:  
* Communication channel A: the integrity of data exchanged between the operator's browser and the Mission Console can be ensured by TLS (and implemented by OpenSSL). In this case, message transport should include a message integrity check based on SHA-1 (HMAC algorithm). The secret key is randomly generated by the inherent HMAC algorithm. Per each of the requests to the Mission Console, the client creates a unique HMAC by hashing data requested with the secret key and sending it together with the request. Once the Mission Console receives the request, it calculates its own unique HMAC and compares it with the one received. If they coincide, the client is trusted and the request is executed. * Communication channel B: as in the case of communication channel A, the integrity of this data link can be guaranteed by TLS. For JSON-based message exchanges where TLS is not possible, it is recommended to use JOSE (JavaScript Object Signing and Encryption). JOSE is a framework that provides a collection of specifications to ensure cybersecurity in JavaScript-based message exchanges. JOSE is able to provide not only integrity but also confidentiality, authentication and non-repudiation. JOSE guarantees integrity through HMAC algorithms based on SHA-2. In addition to data integrity checks, in the case of JSON data formats, it is also interesting to validate the data against its schema.