diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 5c97a8f6..0439896a 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -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. diff --git a/doc/index.rst b/doc/index.rst index 54bacfee..33c14704 100644 --- a/doc/index.rst +++ b/doc/index.rst @@ -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:: diff --git a/doc/layout-config-reference.rst b/doc/layout-config-reference.rst index 053737c2..2c0e903b 100644 --- a/doc/layout-config-reference.rst +++ b/doc/layout-config-reference.rst @@ -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 @@ -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. @@ -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. @@ -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. diff --git a/doc/usage.rst b/doc/usage.rst index 7d24f51a..7f6776ec 100644 --- a/doc/usage.rst +++ b/doc/usage.rst @@ -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 @@ -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 diff --git a/src/pu-emmc.c b/src/pu-emmc.c index 1100c172..aba9f6ad 100644 --- a/src/pu-emmc.c +++ b/src/pu-emmc.c @@ -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) { @@ -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; } } @@ -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) { @@ -552,18 +552,18 @@ 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, @@ -571,8 +571,8 @@ pu_emmc_write_data(PuFlash *flash, 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; } } diff --git a/src/pu-mtd.c b/src/pu-mtd.c index ea35e991..dc895dd6 100644 --- a/src/pu-mtd.c +++ b/src/pu-mtd.c @@ -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; @@ -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; } }