Skip to content

download layout: load CryptoJS so installer can verify flash writes#1775

Merged
makermelissa merged 1 commit into
adafruit:mainfrom
makermelissa-piclaw:add-cryptojs-for-installer-md5-verification
May 14, 2026
Merged

download layout: load CryptoJS so installer can verify flash writes#1775
makermelissa merged 1 commit into
adafruit:mainfrom
makermelissa-piclaw:add-cryptojs-for-installer-md5-verification

Conversation

@makermelissa-piclaw
Copy link
Copy Markdown
Contributor

Summary

Follow-up to adafruit/web-firmware-installer-js#23, which fixed issue #22 (OPEN INSTALLER hang on Feather ESP32 V2).

The installer fix enables post-flash MD5 verification by passing a calculateMD5Hash callback to esptool-js's writeFlash. esptool-js only runs the readback hash check when that callback is supplied, and the callback in turn relies on a hashing library being present on the host page. To keep the installer drop-in for all consumers, that library is optional: when it isn't loaded, the installer's callback returns null and esptool-js skips verification (preserving the prior behavior).

This PR loads crypto-js on the download pages that render the installer, which is what activates the verification path in production.

Change

Adds one <script> tag to _layouts/download.html, inside the same {% if bootloader_info and bootloader_info.installer == true %} block that already loads cpinstaller.min.js, so the cost is bounded to pages where the installer is actually rendered. Source is the same cdn.jsdelivr.net we already use for the installer bundle.

<script src="https://cdn.jsdelivr.net/npm/crypto-js@4.2.0/crypto-js.min.js"></script>

Minified CryptoJS is ~50 kB. It loads in parallel with the installer module and is a no-op if cached.

Why this matters

Without this script tag, esptool-js silently trusts every flash write. On flaky USB-serial bridges (notably Pi 5 + CP2104) that masked active flash corruption and made boards boot-loop with invalid header: 0xffffffff after a successful-looking install — which is exactly what issue #22 was. With CryptoJS loaded, the installer now surfaces the upstream MD5 of file does not match data in flash! error instead of producing a silently bricked board.

Testing

  • adafruit/web-firmware-installer-js already detects CryptoJS at runtime, so once this change is deployed the verification path runs automatically for every installer launch. No installer-side change is required here.
  • Verified locally that the script ordering (crypto-js before the cpinstaller.min.js module) makes the global available when the module evaluates.

Related

The Web Firmware Installer (cpinstaller) asks esptool-js to verify each
flashed image by comparing the MD5 of the bytes we wrote against the MD5
the chip reports for the same flash region. esptool-js only performs
that check when the caller supplies a calculateMD5Hash function; the
installer obtains a hash via a CryptoJS global when one is available,
and silently skips verification when one isn't (which is the current
production state).

Skipping verification can mask flash corruption on some USB-serial
bridges (notably Pi 5 + CP2104) and was the underlying cause of the
"OPEN INSTALLER does not complete on Feather ESP32 V2" hang fixed in
adafruit/web-firmware-installer-js#23.

Loading CryptoJS from the same jsdelivr CDN we already use for the
installer bundle activates the verification path on every page that
renders the installer. CryptoJS is ~50 kB minified and only loads on
pages that also load the installer (gated by bootloader_info.installer
== true), so the cost is bounded to the small set of download pages
where it adds value.

Refs adafruit/web-firmware-installer-js#22
Refs adafruit/web-firmware-installer-js#23
@makermelissa-piclaw
Copy link
Copy Markdown
Contributor Author

Heads-up: adafruit/web-firmware-installer-js#23 is merged and released as 2.2.4. The existing @2 pin in this layout already resolves to 2.2.4 on jsdelivr, so no version bump is needed here — merging this one-line CryptoJS include is the last step to turn on MD5 verification in production.

Copy link
Copy Markdown
Collaborator

@makermelissa makermelissa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's exactly where I would have added it.

@makermelissa makermelissa merged commit 0fb58ab into adafruit:main May 14, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

OPEN INSTALLER does not complete on Feather ESP32 V2

2 participants