Verifying OpenWrt firmware binary

Today's Internet is a high-threat environment. In particular, supply chain attacks, in which an attacker compromises the process of downloading software and updates, are now frequent. Completely verifying any software you download before you install and use it is thus important.

Doing so for OpenWrt requires understanding the organization of the Web server that supplies the binaries you install. Using the 19.07.7 release for the [NETGEAR R6230|Netgear R6230] as an example, the structure is:

The 19.07.7 signing key verifies the signature in the sha256sums.asc file. The signature in the sha256sums.asc file verifies the integrity of the sha256sums file. The SHA256 hash in the sha256sums file verifies the integrity of the individual files in the mt27621 directory. The same goes for all the other supported architectures. Note that the URLs above are all https: not http: - some of the relevant links on https://openwrt.org are http: but if you find one you should change it to https: before using the URL. http: connections are vulnerable to interception and corruption.

In order to fully verify a firmware file it is necessary to download:

  • The firmware file itself
  • The shasums file
  • The sha256sums.asc file
  • The public signing key

Then the steps are:

  • Verify the signature for the sha256sums file.
  • Use the sha256sums file to verify the SHA256 hash of the firmware file.

If you assume that you are not the victim of a supply chain attack, that no-one has compromised downloads.openwrt.org or your connection to it, it is possible to perform a partial verification by omitting the signature check. This is not recommended.

If the signature check fails or if the SHA256 hashes do not match do not flash the downloaded firmware. Your download might be corrupted and brick your router, or it might be malware and open your network to ransomware.

Before verifying the GPG signature you need the appropriate public signing key for the release, which can be found here: https://openwrt.org/docs/guide-user/security/signatures For the 19.07.7 release you should add the public signing key to your keyring by:

% gpg --receive-keys 28A39BC32074BE7A

where 28A39BC32074BE7A is the name of the key from the signatures page, then check that the fingerprint on the that page matches the output of:

% gpg --fingerprint 28A39BC32074BE7A

The process to fully verify an example firmware file on a Linux system is:

% curl --progress-bar -o openwrt-19.07.7-ramips-mt7621-netgear_r6350-squashfs-factory.img https://downloads.openwrt.org/releases/19.07.7/targets/ramips/mt7621/openwrt-19.07.7-ramips-mt7621-netgear_r6350-squashfs-factory.img
% curl --progress-bar -o sha256sums https://downloads.openwrt.org/releases/19.07.7/targets/ramips/mt7621/sha256sums
% curl --progress-bar -o sha256sums.gpg https://downloads.openwrt.org/releases/19.07.7/targets/ramips/mt7621/sha256sums.asc
% gpg --status-fd 1 --with-fingerprint --verify "sha256sums.gpg" "sha256sums"
% sha256sum -c --ignore-missing "sha256sums"

For Linux systems there is a script called download.sh that automates the process. Note that it will fail if you ask it to download and verify an http: URL; it works only with https: URLs.

Here is an edited recording of a session using download.sh after adding the public signing key to the keyring:

% Download.sh https://downloads.openwrt.org/releases/19.07.7/targets/ramips/mt7621/openwrt-19.07.7-ramips-mt7621-netgear_r6350-squashfs-factory.img

1) Downloading image file
=========================
[progress bar]
2) Downloading checksum file
============================
[progress bar]
3) Downloading the GPG signature
================================
[progress bar]
4) Verifying GPG signature
==========================
gpg: Signature made Wed 17 Feb 2021 07:10:01 AM PST
gpg:                using RSA key D9C6901F45C9B86858687DFF28A39BC32074BE7A
gpg: Good signature from "OpenWrt Build System (PGP key for 19.07 release builds) <pgpsign-19.07@openwrt.org>" [ultimate]
Primary key fingerprint: D9C6 901F 45C9 B868 5868  7DFF 28A3 9BC3 2074 BE7A

5) Verifying SHA256 checksum
============================
openwrt-19.07.7-ramips-mt7621-netgear_r6350-squashfs-factory.img: OK

Verification done!
==================
Firmware image placed in '~/Downloads/OpenWrt/R6230/openwrt-19.07.7-ramips-mt7621-netgear_r6350-squashfs-factory.img'.

Cleaning up.

If download.sh returns an error code, consult the script for an explanation of the cause of the error.

Since the download.sh script automates the process of fully verifying a firmware download it is strongly recommended that you use it. If this is not possible, you can assume you are not the victim of a supply chain attack and perform a partial verification from the command line by:

% curl --progress-bar -o openwrt-19.07.7-ramips-mt7621-netgear_r6350-squashfs-factory.img https://downloads.openwrt.org/releases/19.07.7/targets/ramips/mt7621/openwrt-19.07.7-ramips-mt7621-netgear_r6350-squashfs-factory.img
% curl --progress-bar -o sha256sums https://downloads.openwrt.org/releases/19.07.7/targets/ramips/mt7621/sha256sums
% sha256sum -c --ignore-missing "sha256sums"

Checksums are stored in the folder view of the download server's webpage. Obtain it by following those steps:

  1. Strip of everything behind the last / and open the URL in your browser. E.g. https://downloads.openwrt.org/releases/18.06.1/targets/ar71xx/generic/
  2. Find the file you downloaded. The string in the column sha256sum is the checksum. E.g. 4686a0254fbd44b3d0e8ffd66ac7aba5836fe7f0847bdf7c1bf82281f95f08fb

TBD

  • Newer Windows has a built-in tool to calculate sha256sums called certutil, but it has no graphical user interface so we will have to use the command line to interact with it.
  • Older Windows version need to download a sha256 tool, for example MD5 & SHA Checksum Utility (the free version).

To use the built-in certutil:

  1. Click the Windows icon, type “cmd” and hit enter.
  2. Execute (assuming you downloaded the file to your Downloads folder):
    certutil -hashfile "%USERPROFILE%\Downloads\openwrt-file-name-here" sha256
  3. This will print a checksum like this (file name followed by string with letters and numbers),
    SHA256-Hash of file C:\Users\USERNAME\Downloads\openwrt-18.06.1-...-factory.bin:
    79 f9 4e fa d3 2c 14 8f f1 95 3f 09 6d 98 c7 41 c0 ff 8f 7e b4 68 8c 9d 5b f9 fb 01 c0 90 fb ab
  4. Remove spaces from this checksum output (e.g. using replace function in notepad):
    79f94efad32c148ff1953f096d98c741c0ff8f7eb4688c9d5bf9fb01c090fbab
  5. Check that the checksum string without blanks matches the one you can find in the sha256sums field on the download page you retrieved by following the instructions above.

Checksums are stored in the folder view of the download server's webpage. Obtain it by following those steps:

  1. Strip of everything behind the last / and open the URL in your browser. E.g. https://downloads.openwrt.org/releases/18.06.1/targets/ar71xx/generic/
  2. Find the file you downloaded. The string in the column sha256sum is the checksum. E.g. 4686a0254fbd44b3d0e8ffd66ac7aba5836fe7f0847bdf7c1bf82281f95f08fb

TBD

Mac has an integrated tool to check sha256sums, but it has no graphical user interface so we will have to use the Terminal to interact with it.

  1. Click the Finder icon in the Dock.
  2. Click Applications in the Favorites list.
  3. Find the Utilities folder and click to open it.
  4. Locate Terminal and double-click the icon to open the program.
  5. Open a terminal window, and execute (assuming you downloaded the file on the desktop):
    shasum -a 256 ./Desktop/file-name-here
  6. it will print something like this (string with letters and numbers followed by file name),
    1a7c8bba93584fc44045629888e6b147851917cd0c83fcc91a7e6dbe90bdce76 
    openwrt-18.06.1-...-sysupgrade.bin
  7. Check that the checksum string matches the one you can find in the sha256sums field on the download page you retrieved by following the instructions above.
This website uses cookies. By using the website, you agree with storing cookies on your computer. Also you acknowledge that you have read and understand our Privacy Policy. If you do not agree leave the website.More information about cookies
  • Last modified: 2021/04/15 15:27
  • by dshr