Hi John,
On 16.03.23 14:42, John Michael Edgware wrote:
> Hi,
>
> It would be great to be able to encrypt zchunk header in update file
> otherwise hashes are in plain text and can be used to reconstruct large
> parts of image if similar image is available.
>
> Right now encrypting zchunk file itself seems complicated because
> AES-CBC does not support random access. It could be achieved with
> AES-CTR combined with ranges on AES block boundaries.
>
It cannot be done in this way - let me explain.
To add (full) encryption to zchunk, we need to add this to the format,
that means zchunk must be extended (as I did for the uncompressed files)
to add "zst+encryption" to the chunks. That means, chunks are not only
compressed via zst, but then they are encrypted and the information for
the encription must be added to the meta data, that is in the header.
This should be first discussed zchunk's maintainer (Jonathan Dieter) to
check if it is a suitable way for his project.
> At least by having both zchunk header and sw-description encrypted it is
> possible to use un-guessable HTTPS URL without leaking secrets. This of
> course requires server authentication to avoid man in the middle.
So you are not going to encrypt zchunk (see above), but you want to hide
the URL (more or less) and the meta (zck header).
>
> Support for HTTPS client authentication with or without PKCS11would be a
> solution however that also requires access to server configuration which
> might be challenging to some.
> Here is the patch which allows encryption of zchunk header. Not knowing
> internals of swupdate I am not sure it is the best approach:
>
> diff --git a/handlers/delta_handler.c b/handlers/delta_handler.c
> index e848f15..e078157 100644
> --- a/handlers/delta_handler.c
> +++ b/handlers/delta_handler.c
> @@ -37,6 +37,7 @@
> #include <pctl.h>
> #include <pthread.h>
> #include <fs_interface.h>
> +#include <sys/mman.h>
> #include "delta_handler.h"
> #include "multipart_parser.h"
> #include "installer.h"
> @@ -840,7 +841,7 @@ static int install_delta(struct img_type *img,
> {
> struct hnd_priv *priv;
> int ret = -1;
> -int dst_fd = -1, in_fd = -1;
> +int dst_fd = -1, in_fd = -1, mem_fd = -1;
> zckChunk *iter;
> zckCtx *zckSrc = NULL, *zckDst = NULL;
> char *FIFO = NULL;
> @@ -965,7 +966,37 @@ static int install_delta(struct img_type *img,
> zck_get_error(zckSrc));
> goto cleanup;
> }
> -if (!zck_init_read(zckDst, img->fdin)) {
File is copied at least twice. If artifact is encrypted, the generic
code should already have decompress / decrypted the incoming stream and
the decrypted header should be already availbale to img->fdin (of
course, it works not yet, but I don't think it should be copied again).
Best regards,
Stefano Babic
> +
> +mem_fd = memfd_create("zchunk header", 0);
> +if (mem_fd == -1) {
> +ERROR("Cannot create memory file: %s", strerror(errno));
> +goto cleanup;
> +}
> +
> +ret = copyfile(img->fdin,
> +&mem_fd,
> +img->size,
> +(unsigned long *)&img->offset,
> +img->seek,
> +0,
> +img->compressed,
> +&img->checksum,
> +img->sha256,
> +img->is_encrypted,
> +img->ivt_ascii,
> +NULL);
> +
> +if (ret != 0) {
> +ERROR("Error %d copying zchunk header, aborting.", ret);
> +goto cleanup;
> +}
> +
> +if (lseek(mem_fd, 0, SEEK_SET) < 0) {
> +ERROR("Seeking start of memory file");
> +goto cleanup;
> +}
> +
> +if (!zck_init_read(zckDst, mem_fd)) {
> ERROR("Unable to read ZCK header from %s : %s",
> img->fname,
> zck_get_error(zckDst));
> @@ -1020,6 +1051,8 @@ static int install_delta(struct img_type *img,
> memset(priv_hnd->img.sha256, 0, SHA256_HASH_LENGTH);
> strlcpy(priv_hnd->img.type, priv->chainhandler, sizeof(priv_hnd->img.type));
> priv_hnd->img.fdin = pipes[PIPE_READ];
> +/* zchunk files are not encrypted, CBC is not suitable for range
> download */
> +priv_hnd->img.is_encrypted = false;
>
> signal(SIGPIPE, SIG_IGN);
>
> @@ -1064,6 +1097,7 @@ cleanup:
> if (zckDst) zck_free(&zckDst);
> close(dst_fd);
> close(in_fd);
> +close(mem_fd);
> if (FIFO) {
> unlink(FIFO);
> free(FIFO);
>
>
> --
> You received this message because you are subscribed to the Google
> Groups "swupdate" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to
swupdate+u...@googlegroups.com
> <mailto:
swupdate+u...@googlegroups.com>.
> To view this discussion on the web visit
>
https://groups.google.com/d/msgid/swupdate/44735c49-8e29-40ec-90f7-199155583352n%40googlegroups.com <
https://groups.google.com/d/msgid/swupdate/44735c49-8e29-40ec-90f7-199155583352n%40googlegroups.com?utm_medium=email&utm_source=footer>.
--
=====================================================================
DENX Software Engineering GmbH, Managing Director: Erika Unter
HRB 165235 Munich, Office: Kirchenstr.5, 82194 Groebenzell, Germany
Phone:
+49-8142-66989-53 Fax:
+49-8142-66989-80 Email:
sba...@denx.de
=====================================================================