Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
- Add the global ``-V, --version`` option for printing the program version. The
``version`` command is deprecated in favor of this option and prints a
warning when used.
- Verify the automatically read-back output data with a SHA256 sum instead of
a SHA1 sum. SHA1 is considered insecure, while SHA256 is only marginally
slower for this use case. This does not change any layout configuration
options, as this checksum is generated and compared internally.
- Add a FAQ section to the documentation explaining the ``Filesystem has
unsupported feature(s)`` error of ``resize2fs``, caused by the ext4
``orphan_file`` feature and old e2fsprogs versions.
Expand Down
2 changes: 1 addition & 1 deletion doc/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Main Features
- Write files and extract archives to partitions
- Write raw binaries to device at specified offset
- Checksum verification for input files (MD5, SHA256) and automatic read-back
verification of written raw data (SHA1)
verification of written raw data (SHA256)
- Set PARTUUID and partition flags

.. toctree::
Expand Down
8 changes: 4 additions & 4 deletions doc/layout-config-reference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ The section ``raw`` contains a sequence of mappings describing data that is
written outside of partitions.

Since :ref:`release-2.1.0`, the written output is always being verified by
reading it back from the device and checking it against the input's SHA1 sum,
reading it back from the device and checking it against the input's SHA256 sum,
including any given offsets. The checksum is not being verified when
``--skip-checksums`` is given as a runtime argument. Note, that this checksum is
independent from the input's ``sha256sum`` option. See
Expand Down Expand Up @@ -245,7 +245,7 @@ Binary files are specified by a scalar named ``binaries`` containing a sequence
of mappings with at least an ``input``.

Since :ref:`release-3.0.0`, the written output is always being verified by
reading it back from the device and checking it against the input's SHA1 sum,
reading it back from the device and checking it against the input's SHA256 sum,
including any given offsets. For eMMC boot partitions the read-back verification
is performed on both boot partitions (``boot0`` and ``boot1``). The checksum is
not being verified when ``--skip-checksums`` is given as a runtime argument.
Expand Down Expand Up @@ -302,7 +302,7 @@ contained partitions of an MTD. Each entry may contain the following options:
An input mapping. See :ref:`input-files`.

The written output is always being verified by reading it back from the
device and checking it against the input's SHA1 sum, including any given
device and checking it against the input's SHA256 sum, including any given
offsets. The checksum is not being verified when ``--skip-checksums`` is
given as a runtime argument. Note, that this checksum is independent from the
input's ``sha256sum`` option. See :ref:`checksum-verification` for details.
Expand All @@ -316,7 +316,7 @@ Input files are specified by a scalar named ``input`` containing a mapping with
at least a ``filename``. For verifying the checksum of the given input file by
``filename``, an optional checksum can be provided with ``md5sum`` and/or
``sha256sum``. These sums are verified before writing. Note that the automatic
SHA1 read-back verification of the written data is only performed for raw and
SHA256 read-back verification of the written data is only performed for raw and
binary writes, not for input files copied into a filesystem, archives extracted
into a filesystem, or raw ext[234] filesystem images. See
:ref:`checksum-verification` for a complete description of both mechanisms.
Expand Down
14 changes: 7 additions & 7 deletions doc/usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ install [OPTION…] *PACKAGE* *DEVICE*
-s, --skip-checksums Skip all checksum verification. This disables both
the optional verification of input files (``md5sum``
and ``sha256sum``) before writing and the automatic
SHA1 read-back verification of written raw data after
writing. See :ref:`checksum-verification`.
SHA256 read-back verification of written raw data
after writing. See :ref:`checksum-verification`.

package [OPTION…] *PACKAGE* *FILES…*
Create a partup PACKAGE with the contents FILES
Expand Down Expand Up @@ -185,16 +185,16 @@ In addition to the optional input verification, partup *automatically* verifies
that raw data has been written correctly by reading it back from the device.
This mechanism does not require any configuration and works as follows:

1. A SHA1 sum is computed from the input file (honoring any given
1. A SHA256 sum is computed from the input file (honoring any given
``input-offset``).
2. After the data has been written, the same range is read back from the target
device (honoring any given ``output-offset``).
3. The SHA1 sum of the data read back from the device is compared against the
SHA1 sum computed from the input file.
3. The SHA256 sum of the data read back from the device is compared against the
SHA256 sum computed from the input file.

This read-back verification is independent from the ``md5sum`` and ``sha256sum``
options and always uses SHA1. It is applied only to writes that go directly to
the raw device, namely:
options and always uses SHA256. It is applied only to writes that go directly
to the raw device, namely:

- the ``raw`` section of MMC and HD devices (since :ref:`release-2.1.0`),
- eMMC boot partition ``binaries`` -- verified on both boot partitions
Expand Down
32 changes: 16 additions & 16 deletions src/pu-emmc.c
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ pu_emmc_write_data(PuFlash *flash,
PuEmmcInput *input = bin->input;
g_autofree gchar *path = NULL;
gsize size = 0;
g_autofree gchar *output_sha1sum = NULL;
g_autofree gchar *output_checksum = NULL;

path = pu_path_from_filename(input->filename, prefix, error);
if (path == NULL) {
Expand Down Expand Up @@ -464,15 +464,15 @@ pu_emmc_write_data(PuFlash *flash,
return FALSE;

if (!skip_checksums) {
output_sha1sum = pu_checksum_new_from_file(path, bin->input_offset *
self->device->sector_size,
G_CHECKSUM_SHA1, error);
g_debug("Verifying SHA1 sum of written output: %s", output_sha1sum);
output_checksum = pu_checksum_new_from_file(path, bin->input_offset *
self->device->sector_size,
G_CHECKSUM_SHA256, error);
g_debug("Verifying SHA256 sum of written output: %s", output_checksum);
if (!pu_checksum_verify_raw(self->device->path, bin->output_offset *
self->device->sector_size,
size - bin->input_offset *
self->device->sector_size, output_sha1sum,
G_CHECKSUM_SHA1, error))
self->device->sector_size, output_checksum,
G_CHECKSUM_SHA256, error))
return FALSE;
}
}
Expand Down Expand Up @@ -502,7 +502,7 @@ pu_emmc_write_data(PuFlash *flash,
PuEmmcBinary *bin = i->data;
g_autofree gchar *path = NULL;
gsize size = 0;
g_autofree gchar *output_sha1sum = NULL;
g_autofree gchar *output_checksum = NULL;

path = pu_path_from_filename(bin->input->filename, prefix, error);
if (path == NULL) {
Expand Down Expand Up @@ -552,27 +552,27 @@ pu_emmc_write_data(PuFlash *flash,
return FALSE;

if (!skip_checksums) {
output_sha1sum = pu_checksum_new_from_file(
output_checksum = pu_checksum_new_from_file(
path, bin->input_offset * self->device->sector_size,
G_CHECKSUM_SHA1, error);
g_debug("Verifying SHA1 sum of written output: %s",
output_sha1sum);
G_CHECKSUM_SHA256, error);
g_debug("Verifying SHA256 sum of written output: %s",
output_checksum);
if (!pu_checksum_verify_raw_bootpart(self->device->path, 0,
bin->output_offset *
self->device->sector_size,
size - bin->input_offset *
self->device->sector_size,
output_sha1sum,
G_CHECKSUM_SHA1, error))
output_checksum,
G_CHECKSUM_SHA256, error))
return FALSE;

if (!pu_checksum_verify_raw_bootpart(self->device->path, 1,
bin->output_offset *
self->device->sector_size,
size - bin->input_offset *
self->device->sector_size,
output_sha1sum,
G_CHECKSUM_SHA1, error))
output_checksum,
G_CHECKSUM_SHA256, error))
return FALSE;
}
}
Expand Down
9 changes: 5 additions & 4 deletions src/pu-mtd.c
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ pu_mtd_write_data(PuFlash *flash,
while (TRUE) {
g_autofree gchar *cmd = NULL;
g_autofree gchar *path = NULL;
g_autofree gchar *output_sha1sum = NULL;
g_autofree gchar *output_checksum = NULL;
g_autofree gchar *part_dev = NULL;
const PuMtdPartition *p = NULL;

Expand Down Expand Up @@ -458,10 +458,11 @@ pu_mtd_write_data(PuFlash *flash,
}

if (!skip_checksums) {
output_sha1sum = pu_checksum_new_from_file(path, 0, G_CHECKSUM_SHA1, error);
g_debug("Verifying SHA1 sum of written output: %s", output_sha1sum);
output_checksum = pu_checksum_new_from_file(path, 0, G_CHECKSUM_SHA256,
error);
g_debug("Verifying SHA256 sum of written output: %s", output_checksum);
if (!pu_checksum_verify_raw(part_dev, 0, p->input->_size,
output_sha1sum, G_CHECKSUM_SHA1, error))
output_checksum, G_CHECKSUM_SHA256, error))
return FALSE;
}
}
Expand Down