0% found this document useful (0 votes)
36 views6 pages

C PID6129769

The paper describes extensions made to existing OTA update libraries for the ESP8266 microcontroller that allow for remote validation of updates using a SHA1 hash. This provides basic capabilities for self-protection of ESP8266 devices from invalid firmware updates. Testing showed the approach works as intended and could be expanded to larger distributed systems.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
36 views6 pages

C PID6129769

The paper describes extensions made to existing OTA update libraries for the ESP8266 microcontroller that allow for remote validation of updates using a SHA1 hash. This provides basic capabilities for self-protection of ESP8266 devices from invalid firmware updates. Testing showed the approach works as intended and could be expanded to larger distributed systems.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Extending Over–The–Air Libraries to Secure

ESP8266 Updates
Xinchi He Mauricio Papa Rose Gamble
Tandy School of Computer Science Tandy School of Computer Science Tandy School of Computer Science
The University of Tulsa The University of Tulsa The University of Tulsa
Tulsa, OK, USA Tulsa, OK, USA Tulsa, OK, USA
[email protected] [email protected] [email protected]

Abstract—The ESP8266 is a popular Arduino-compatible SoC ESP8266 boards can be updated directly through a serial
chip that has been adopted by many IoT (Internet of Things) connection following a simple sequence of steps: (i) create
device manufacturers. Available OTA (Over–The–Air) libraries the Arduino program, (ii) compile the code into binary, and
to upload programs to the chip exist, but they offer limited
security mechanisms. This paper describes extensions to those (iii) upload the binary through the available UART (Universal
libraries that allow incremental computation of a SHA1 hash Asynchronous Receiver/Transmitter). However, this approach,
over program fragments and the ability to validate its value using which is mainly used for development purposes, requires
an authenticated remote service through RESTful APIs. This is physical access to the board. This process would not be cost–
an important feature that offers basic primitives to incorporate efficient nor practical for large scale deployments such as in
self-protection strategies into the platform. Testing on a proof-of-
concept system shows promising results and potential to extend a smart city.
the approach to a large distributed domain. For this reason, several available Arduino libraries allow the
Index Terms—wireless security, over–the–air updates, self pro- ESP8266 boards to receive updates in an OTA manner through
tection, ESP8266, Arduino, Internet of Things Wi–Fi [3]. However, these libraries offer minimal verification
I. I NTRODUCTION capabilities to validate the legitimacy of the update; leaving
the system vulnerable to cyber attacks. Current libraries allow
The ESP8266 [1] is a widely used SoC (System on Chip) developers to upload a binary and its associated MD5 check-
with Wi–Fi capabilities that has been used in IoT devices and sum as a limited mechanism to validate the integrity of the
boards such as Wemos D1 Mini and Adafruit Feather HUZ- update. However, this approach is susceptible to cyber attacks.
ZAH. It is Arduino-compatible, has GPIO (General-Purpose In particular, since the party uploading the update also sends
Input/Output) pins and includes a 10-bit ADC (analog-to- the MD5, it would be trivial for an attacker with access to
digital converter). calculate a valid MD5 for an update that may include malware.
Boards using this chip have a small footprint and they
It is important to note that MD5 checksums are not always
are very affordable. For instance, the Wemos D1 Mini board
enabled by default.
(Figure 1) is only 25.6mm by 34.2mm and, at the time of
This paper presents an approach that serves two purposes:
this writing, its cost was approximately $2–$3, making it an
attractive IoT development platform. 1) Extend existing ESP8266 Arduino OTA libraries by
allowing remote verification using a more robust SHA1
[4] hashing scheme.
2) Provide developers with primitives to incorporate self-
protection strategies that are suitable for more critical
applications and large distributed environments.
The approach was tested using the ESP8266–based Wemos
D1 Mini board and a remote web service to validate the SHA1
hash. A Python script library was used to verify that the
SHA1 calculated by the extended library is correct. A trusted
Fig. 1. Wemos D1 Mini (left), US quarter (middle), and relay shield (right)
web service was also deployed to allow the ESP8266 board
As for most network-capable devices, program updates are to validate the authenticity of the update. Preliminary results
an essential part of the development and deployment lifecycle indicate that the proposed extension to the ESP8266 Arduino
for ESP8266–based solutions. Updates are important for a OTA update libraries can be used to protect the process from
number of reasons; they can be used to fix and address invalid updates.
security vulnerabilities, add new functionality, incorporate new The following sections give an overview of the self-
communication protocols and satisfy compliance requirements protection concept, the ESP8266 SoC and then describe our
[2]. approach and experimental results in detail.

978-1-7281-5092-5/19/$31.00 ©2019 IEEE


II. E NABLING S ELF -P ROTECTION F EATURES I2S (Inter-IC Sound), two UART, four PWM outputs, one IR
Self-protection in a system is broadly defined as a mecha- remote control, and one 10-bit ADC.
nism or capability that allows it to detect and mitigate security ESP8266 boards can be programmed in a number of differ-
threats at runtime [5]. Traditional security models, such as sys- ent environments, such as Arduino, NodeMCU and MicroPy-
tems using fixed rules and policies, often carry static and rigid thon. The flash memory has a simple structure consisting of
limitations. In contrast, dynamic models are usually adopted the following partitions (Figure 2):
by self-protection mechanisms to leverage the robustness of • Sketch stores the current running Arduino program.
the system and enhance them through reconfiguration and • OTA Update is the space that has been reserved for OTA
adaptation. updates (actual space amount varies by vendor).
Self-protection techniques have been applied in various • File System is the SPIFFS (SPI Flash File System) based
fields, such as distributed systems, sensor networks and file system that provides secondary storage.
SCADA (supervisory control and data acquisition). Squic- • EEPROM stores state and settings associated with
ciarini et al. [6] introduce the notion of autonomous self- ESP8266 boards.
controlling objects (SCO) with the help of object–oriented • Non-OS SDK stores Espressif-proprietary APIs to expose
programmed techniques. Sensitive data is then encapsulated basic ESP8266 functionality.
within SCOs and protected by adaptive security policies for The UART download method uploads compiled Arduino
data protection in a distributed system. programs directly to the Sketch partition (replacing the old
Wang et al. [7] state that protection and area coverage sketch in the process). OTA updates work in a slightly different
capabilities of wireless sensor networks (WSN) can be signifi- manner. Compiled binary fragments are stored in the OTA
cantly affected when small sets of sensors are interfered with. Update partition and later moved to the Sketch section once
A self-protection approximation algorithm is then proposed all the fragments have arrived.
and developed for centrally controlled sensors to ensure the
protection/coverage capabilities of WSNs.
Chen and Abdelwahed [8] propose an automatic security
model for self-protecting SCADA systems. The idea in this
case is to implement a closed-loop feedback control ecosystem
with risk assessment, early warning and prevention, intrusion
detection, live forensics analysis and active response to protect
SCADA devices from cyber attacks.
This paper describes enhancements to existing ESP8266 Fig. 2. ESP8266 flash layout in Arduino environment
OTA update protection mechanisms by using a runtime, dy-
namic self-protecting technique that includes interactions with
IV. A RDUINO OTA L IBRARIES
an authenticated remote service to validate updates. The goal
is to provide developers with primitives that can then be Several OTA libraries have been built to provide wireless
readily used to incorporate more sophisticated self-protection update capabilities for the ESP8266 board. These libraries
strategies. either expose the ESP8266 board as an HTTP server (such as
the ESP 8266HT T P U pdateServer library) where updates
III. ESP8266 are uploaded through a web browser or they open UDP ports
Manufactured by Espressif [9], the ESP8266 uses a Ten- for direct OTA updates (such as the ArduinoOT A library).
silica L106 Diamond series 32-bit RISC processor, on-chip Since OTA updates are not possible by default, use of any of
SRAM, and built–in 2.4GHz wireless module to provide low these OTA libraries require a one–time initialization through
power and highly integrated Wi–Fi solutions. Using on-board the UART to activate the capability.
GPIOs, the ESP8266 can easily interface with a variety of
A. ESP8266HTTPUpdateServer
external sensors (e.g. SHT-30 temperature/humidity sensor)
and actuators (e.g., relays and switches). It is a versatile This library exposes a named web service through
platform for embedded applications and the deployment of mDN S (a multicast DNS service for small networks).
IoT solutions. The default page for used to upload the update is
The Wi–Fi module in the ESP8266 supports the 802.11 esp8266-webupdate.local/update. The one–time
b/g/n protocols and may run in one of three modes: (i) Station, initialization is conducted by uploading the W ebU pdater
(ii) SoftAP (access point), and (iii) SoftAP+Station (dual module.
mode). High level protocols and connectivity such as IPv4, The W ebU pdater module operates by setting the
TCP, UDP and HTTP are supported through Espressif’s pro- ESP8266’s Wi–Fi module to SoftAP+Station mode, launching
prietary Non-OS software development kit [10]. Specifically, a HTTP web server on port 80 with mDNS service, and then
the ESP8266 includes the following capabilities: sixteen GPIO enabling OTA update capabilities.
pins, one SDIO (Secure Digital Input/Output), two SPI (Serial OTA updates then proceed as follows:
Peripheral Interface), one I2C (Inter-Integrated Circuit), one 1) Open the default update web page in a browser.

978-1-7281-5092-5/19/$31.00 ©2019 IEEE


2) Select and upload update binary by clicking the update library that provides support for different types of input data
button. (such as strings and raw bytes). However, this library currently
3) ESP8266 board receives update fragments and then supports calculating hash only at once.
reboots. Close inspection of the OTA library revealed that, since
Note that no security mechanism is offered to protect the communication occurs over the network, the update binary is
integrity of the update. actually received (but not checked) in fragments. The Hash
library was then modified to aggregate fragment calculations
B. ArduinoOTA due to the fact that the ESP8266 board does not have sufficient
This library (by default) exposes UDP port 8266 to receive memory to calculate the SHA1 hash at once. This approach
updates. The one–time initialization is conducted by uploading results in a seamless integration of both libraries where the
the BasicOT A module. OTA received fragments are directly passed to the modified
A Python script, espota.py, acts as a client to push the version of the Hash library.
update to the ESP8266 board. OTA updates then proceed as The Hash library includes a widely–used and accepted
follows: C implementation of the SHA1 algorithm (also used by
1) Use espota.py to select and push update binary. OpenSSL [13]) that is exposed through the following three API
2) espota.py computes the MD5 checksum of the update calls: SHA1Init(), SHA1Update(), and SHA1Final().
binary and sends it along with the update binary. The first function, SHA1Init() initializes the necessary
3) ESP8266 board receives the update in fragments and states for SHA1 computation and it must be called once at the
temporarily stores them in the OTA Update partition. beginning of the hash computation process. SHA1Update()
4) The MD5 checksum is validated after all fragments are is used for the incremental computation of the hash by storing
received (the process is aborted if the MD5 check fails). partial results with every fragment passed to the function.
5) Once validated, update is moved from the OTA Update Finally, SHA1Final() produces the final result once all
to the Sketch partition and the board reboots. fragments have been processed. This method is also only
While the MD5 check offers some validation, the verifi- called once at the end of the hash computation process. Our
cation is conducted locally with the provided checksum. This extensions for the Hash library make use of these three
implementation suffers from three weaknesses: (i) the provided methods.
MD5 checksum and update binary can be intercepted (while B. External authenticated verification services
in transit) and altered by an adversary, (ii) MD5 verification
is entirely local (no remote validation), and (iii) MD5 is not Use of a remote verification service further increases the
as robust as SHA1 for integrity protection [11], [12]. robustness of the existing OTA update solutions. To provide
this additional support, the OTA libraries are further extended
V. A PPROACH (Figure 3) to support the use of RESTful API calls that
In order to address the weaknesses in the existing OTA up- provide an authenticated mechanism for external SHA1 hash
date libraries, we propose the following strategy to strengthen verification.
this process by extending the existing libraries for ESP8266
OTA updates:
• Utilize SHA1 as the integrity check value rather than an
MD5 checksum. SHA1, while less secure than SHA256,
is more secure than MD5 checksums and requires more
modest computational resources. At the moment, com-
puting a SHA256 would be too resource-intensive for
the ESP8266. The proposed solution could easily be
updated to use SHA256 when enough computing power
is available in future models. It would be a simple matter Fig. 3. Remote OTA update verification
of swapping the SHA1 code with the SHA256 code.
• Use external authenticated services to verify the integrity Algorithm 1 summarizes the entire approach of (i)
of the SHA1 rather than having only local MD5 check- computing the SHA1 hash using partial fragments
sum verification. This will enhance the robustness of the (sha1_aggregate() in lines 6 and 17) followed by
OTA update process and reduce the attack surface on (ii) an external verification abstracted by the verify()
ESP8266 boards. function in line 7. The entire proposed solution then proceeds
as follows: (i) programmer pushes binary fragments over
A. SHA1 hash using the aggregating method the air, (ii) library extension incrementally calculates SHA1
Two approaches are often used to calculate a SHA1 hash: hash using the aggregating method, (iii) ESP8266 uses
it is either calculated over the entire data or by aggregating authenticated remote services to verify the update, (iv) if
partial results computed over data that has been fragmented. verification succeeds, update program and reboot (otherwise
The ESP8266 Arduino library comes with a Hash SHA1 abort the process and reboot).

978-1-7281-5092-5/19/$31.00 ©2019 IEEE


Algorithm 1: OTA update process
1 function update() (d, s, h, ctx);
Input: fragment bytes d, fragment size s, locally
calculated hash h, partial aggregated hash storage
ctx
2 if OTA update is started then
3 SHA1Init(ctx);
4 else if OTA update is in progress then
5 if last fragment then
6 sha1 aggregate(d, s, h, ctx, true);
7 verif y(h);
8 if verified then
9 write d to buffer;
10 move update to sketch;
11 reboot;
12 else
13 reboot;
14 end
15 else
16 write d to buffer;
17 sha1 aggregate(d, s, h, ctx, f alse);
18 end
19 end

VI. I MPLEMENTATION AND E VALUATION


In order to implement the proposed exten-
sions, two ESP8266 Arduino OTA libraries
(ESP 8266HT T P U pdateServer and Hash) are modified
and then tested on a Wemos D1 Mini board.
A new function sha1_aggregate() is added to the
Hash library to compute the SHA1 hash with the ag- Fig. 4. ESP 8266HT T P U pdateServer library extensions (snippet) for
OTA updates
gregating method. This function will be called by the
ESP 8266HT T P U pdateServer library to calculate the hash.
Also, a new function verified() is added to the imports the extended library with the added features. The
ESP 8266HT T P U pdateServer library to interface with a assumption is that the current version of the program is 1.0
remote verification service through RESTful API calls. Pro- (Line 33) and that it will later be updated to version 2.0.
grammers can then use the ESP 8266HT T P Client library
to establish RESTful API calls and the ArduinoJson library A. Verifying SHA1 hash calculation
to parse JSON–based HTTP responses. Since the Hash Arduino library had to be modified to
Figure 4 shows parts of the actual implementation of support calculation of the hash using the aggregating method,
Algorithm 1. In particular, line 11 checks whether the cur- it was important to verify that the new implementation would
rent fragment is the last fragment, lines 17-20 converts the produce the correct hash value. The Python hashlib already
aggregated hash to human readable format using hex represen- has the ability to calculate a SHA1 hash over a file using the
tation, lines 24-25 verify the calculated hash with the external aggregating method. The size of a fragment was set to 2048
remote verification service and line 29 immediately reboots bytes, which is the same value used by the Arduino OTA
the ESP8266 should the verification process fail. update library. Partial and final results given by the Python
For implementation purposes, it is important to (i) ver- library matched the results given by our extensions to the OTA
ify that local computation of the hash using the aggre- libraries (Figure 6) for the same fragment size.
gating method is correct (Subsection A below) and (ii)
that a remote verification service could be effectively used B. Hash validation using remote services
to validate the hash (Subsection B below). This is done Before the update is applied, the hash calculated in the pre-
by simply incorporating calls to the extended libraries vious step needs to be validated by an authenticated third party
in the sample W ebU pdater program distributed with the (e.g. a simple web service) that supplies remote validation
ESP 8266HT T P U pdateServer library (Figure 5). Line 5 services. This validation is a two–step process: first, the IoT

978-1-7281-5092-5/19/$31.00 ©2019 IEEE


Fig. 7. Successful OTA update verification with authenticated web service

Fig. 8. Failed OTA update verification with authenticated web service

Fig. 5. Program template for OTA updates in Arduino IDE


The ESP8266 reported a successful update and rebooted when
the verification succeeded (Figure 7). We then attempted to
upload a modified update binary file that would produce a
different hash value. As expected, Figure 8 shows partial
output on the Arduino serial console indicating that the
verification had failed (Line 11).

VII. C ONCLUSIONS AND F UTURE W ORK


This paper proposes a solution that achieves two goals:
(i) secure OTA updates for ESP8266–based IoT boards by
extending already existing Arduino libraries and (ii) provide
primitives that can be used to incorporate self-protection
strategies. The extensions to the OTA update libraries allow the
use of SHA1 hashes to verify the validity of an update using
Fig. 6. SHA1 from Python script (top) and ESP8266 board (bottom) authenticated remote services. The modifications include the
use of an aggregating method that enables hash calculation
board contacts an authenticated server to request that a hash using the very limited resources available in the ESP8266.
for a particular update be validated and second, a response A proof–of–concept system was implemented to ensure that
from the authenticated server (using RESTful API calls) as to the aggregating method produced the correct results and that
whether or not the update should be applied. the external validation through a RESTful API worked as
Two tests were conducted to validate an update intended.
to version 2.0. It was assumed the web service Our future research will focus on interfacing the ESP8266
already had the correct SHA1 hash for the board with a more robust remote verification process. In partic-
update to version 2.0 (in our case the hash was ular we plan to use a blockchain-based framework with support
457de643c3113667f18660bf12c999db721a3fc4). for smart contracts and self-protection [14]. The goal is to

978-1-7281-5092-5/19/$31.00 ©2019 IEEE


demonstrate feasibility of the approach in a large distributed [8] Q. Chen and S. Abdelwahed, Towards realizing self-protecting SCADA
environment. system, in Proceedings of the 9th Annual Cyber and Information
Security Research Conference (CISR’14), Oak Ridge, Tennessee, 2014,
R EFERENCES pp. 105-108.
[9] Espressif Systems, ESP8266EX Datasheet,
[1] N. Kumar, K. M. Sundaram and Anusuya, IoT based smart charger: an https://www.espressif.com/sites/default/files/documentation/0a-
ESP8266 based automatic charger, in Proceedings of the International esp8266ex datasheet en.pdf, 2018, [Online: accessed January 2019].
Conference on Big Data and Internet of Things (BDIOT2017), London, [10] Espressif Systems, ESP8266 Non-OS SDK API Reference,
2017, pp. 153-157. https://www.espressif.com/sites/default/files/documentation/2c-
[2] J. Kim and P. H. Chou, Energy-efficient progressive remote update for esp8266 non os sdk api reference en.pdf, 2018, [Online: accessed
flash-based firmware of networked embedded systems, ACM Transac- January 2019].
tions on Design Automation of Electronic Systems (TODAES), vol. 16, [11] X. Chan and G. Liu, Discussion of one improved hash algorithm
no.1, pp. 1-26, November 2010. based on MD5 and SHA1, in Proceedings of the World Congress on
[3] I. Grokhotkov, ESP8266 Arduino Core Document, Engineering and Computer Science (WCECS 2007), San Francisco,
https://media.readthedocs.org/pdf/arduino-esp8266/latest/arduino- 2007, pp. 270-273.
esp8266.pdf, 2019, [Online: accessed January 2019]. [12] C. Teat and S. Peltsverger, The security of cryptographic hashes, in
[4] E. Barker, FIPS 180-1, Secure Hash Standard (SHS), NIST, 1995. Proceedings of the 49th Annual Southeast Regional Conference (ACM-
[5] E. Yuan and S. Malek, A taxonomy and survey of self-protecting SE’11), Kennesaw, Georgia, 2011, pp. 103-108.
software systems, in Proceedings of 2012 7th International Symposium [13] J. Viega, M. Messier and P. Chandra, Network Security with OpenSSL:
on Software Engineering for Adaptive and Self-Managing Systems Cryptography for Secure Communications, Sebastopol, CA: O’Reilly
(SEAMS), Zurich, 2012, pp. 109-118. Media, 2002, pp. 259-264.
[6] A. C. Squicciarini, G. Petracca and E. Bertino, Adaptive data protection [14] X. He, S. Alqahtani, R. Gamble and M. Papa, Securing Over-The-Air
in distributed systems, in Proceedings of the third ACM conference on IoT firmware updates using blockchain, in Proceedings of the Inter-
Data and application security and privacy (CODASPY’13), San Antonio, national Conference on Omni-Layer Intelligent Systems (COINS’19),
Texas, 2013, pp. 365-376. Crete, Greece, 2019, pp. 164-171.
[7] D. Wang, Q. Zhang and J. Liu, The self-protection problem in wireless
sensor networks, ACM Transactions on Sensor Networks (TOSN), vol.
3, no. 20, pp. 1-24, October 2007.

978-1-7281-5092-5/19/$31.00 ©2019 IEEE

You might also like