diff mbox series

[V2,08/10] cpio_utils: Add argument imgaeskey to __swupdate_copy interface

Message ID 20231204100620.27789-9-Michael.Glembotzki@iris-sensing.com
State Changes Requested
Headers show
Series [V2,01/10] util: BUG: set_aes_key does not fail on invalid aes key or ivt | expand

Commit Message

Michael Glembotzki Dec. 4, 2023, 10:05 a.m. UTC
Signed-off-by: Michael Glembotzki <Michael.Glembotzki@iris-sensing.com>
---
 core/cpio_utils.c           | 13 +++++++++----
 core/installer.c            |  1 +
 core/stream_interface.c     |  6 +++---
 corelib/lua_interface.c     |  2 ++
 handlers/copy_handler.c     |  1 +
 handlers/delta_handler.c    |  1 +
 handlers/rdiff_handler.c    |  1 +
 handlers/readback_handler.c |  1 +
 include/util.h              |  6 ++++--
 9 files changed, 23 insertions(+), 9 deletions(-)
diff mbox series

Patch

diff --git a/core/cpio_utils.c b/core/cpio_utils.c
index 0a6ebc1..4556033 100644
--- a/core/cpio_utils.c
+++ b/core/cpio_utils.c
@@ -431,7 +431,8 @@  static int zstd_step(void* state, void* buffer, size_t size)
 
 static int __swupdate_copy(int fdin, unsigned char *inbuf, void *out, size_t nbytes, unsigned long *offs, unsigned long long seek,
 	int skip_file, int __attribute__ ((__unused__)) compressed,
-	uint32_t *checksum, unsigned char *hash, bool encrypted, const char *imgivt, writeimage callback)
+	uint32_t *checksum, unsigned char *hash, bool encrypted,
+	const char __attribute__ ((__unused__)) *imgaeskey, const char *imgivt, writeimage callback)
 {
 	unsigned int percent, prevpercent = 0;
 	int ret = 0;
@@ -707,7 +708,8 @@  copyfile_exit:
 
 int copyfile(int fdin, void *out, size_t nbytes, unsigned long *offs, unsigned long long seek,
 	int skip_file, int __attribute__ ((__unused__)) compressed,
-	uint32_t *checksum, unsigned char *hash, bool encrypted, const char *imgivt, writeimage callback)
+	uint32_t *checksum, unsigned char *hash, bool encrypted,
+	const char *imgaeskey, const char *imgivt, writeimage callback)
 {
 	return __swupdate_copy(fdin,
 				NULL,
@@ -720,12 +722,13 @@  int copyfile(int fdin, void *out, size_t nbytes, unsigned long *offs, unsigned l
 				checksum,
 				hash,
 				encrypted,
+				imgaeskey,
 				imgivt,
 				callback);
 }
 
 int copybuffer(unsigned char *inbuf, void *out, size_t nbytes, int __attribute__ ((__unused__)) compressed,
-	unsigned char *hash, bool encrypted, const char *imgivt, writeimage callback)
+	unsigned char *hash, bool encrypted, const char *imgaeskey, const char *imgivt, writeimage callback)
 {
 	return __swupdate_copy(-1,
 				inbuf,
@@ -738,6 +741,7 @@  int copybuffer(unsigned char *inbuf, void *out, size_t nbytes, int __attribute__
 				NULL,
 				hash,
 				encrypted,
+				imgaeskey,
 				imgivt,
 				callback);
 }
@@ -754,6 +758,7 @@  int copyimage(void *out, struct img_type *img, writeimage callback)
 			&img->checksum,
 			img->sha256,
 			img->is_encrypted,
+			img->aeskey_ascii,
 			img->ivt_ascii,
 			callback);
 }
@@ -839,7 +844,7 @@  int cpio_scan(int fd, struct swupdate_cfg *cfg, off_t start)
 		 * we do not have to provide fdout
 		 */
 		if (copyfile(fd, NULL, fdh.size, &offset, 0, 1, 0, &checksum, img ? img->sha256 : NULL,
-				false, NULL, NULL) != 0) {
+				false, NULL, NULL, NULL) != 0) {
 			ERROR("invalid archive");
 			return -1;
 		}
diff --git a/core/installer.c b/core/installer.c
index 20b5b51..db86075 100644
--- a/core/installer.c
+++ b/core/installer.c
@@ -145,6 +145,7 @@  static int extract_scripts(struct imglist *head)
 				&checksum,
 				script->sha256,
 				script->is_encrypted,
+				script->aeskey_ascii,
 				script->ivt_ascii,
 				NULL);
 		close(fdin);
diff --git a/core/stream_interface.c b/core/stream_interface.c
index 0b78329..bfafa30 100644
--- a/core/stream_interface.c
+++ b/core/stream_interface.c
@@ -104,7 +104,7 @@  static int extract_file_to_tmp(int fd, const char *fname, unsigned long *poffs,
 		return -1;
 
 	if (copyfile(fd, &fdout, fdh.size, poffs, 0, 0, 0, &checksum, NULL,
-		     encrypted, NULL, NULL) < 0) {
+		     encrypted, NULL, NULL, NULL) < 0) {
 		close(fdout);
 		return -1;
 	}
@@ -243,7 +243,7 @@  static int extract_files(int fd, struct swupdate_cfg *software)
 					close(fdout);
 					return -1;
 				}
-				if (copyfile(fd, &fdout, fdh.size, &offset, 0, 0, 0, &checksum, img->sha256, false, NULL, NULL) < 0) {
+				if (copyfile(fd, &fdout, fdh.size, &offset, 0, 0, 0, &checksum, img->sha256, false, NULL, NULL, NULL) < 0) {
 					close(fdout);
 					return -1;
 				}
@@ -255,7 +255,7 @@  static int extract_files(int fd, struct swupdate_cfg *software)
 				break;
 
 			case SKIP_FILE:
-				if (copyfile(fd, &fdout, fdh.size, &offset, 0, skip, 0, &checksum, NULL, false, NULL, NULL) < 0) {
+				if (copyfile(fd, &fdout, fdh.size, &offset, 0, skip, 0, &checksum, NULL, false, NULL, NULL, NULL) < 0) {
 					return -1;
 				}
 				if (!swupdate_verify_chksum(checksum, &fdh)) {
diff --git a/corelib/lua_interface.c b/corelib/lua_interface.c
index af7b554..1533e9d 100644
--- a/corelib/lua_interface.c
+++ b/corelib/lua_interface.c
@@ -401,6 +401,7 @@  static int l_copy2file(lua_State *L)
 				 &checksum,
 				 img.sha256,
 				 img.is_encrypted,
+				 img.aeskey_ascii,
 				 img.ivt_ascii,
 				 NULL);
 	update_table(L, &img);
@@ -473,6 +474,7 @@  static int l_istream_read(lua_State* L)
 				 &checksum,
 				 img.sha256,
 				 img.is_encrypted,
+				 img.aeskey_ascii,
 				 img.ivt_ascii,
 				 istream_read_callback);
 
diff --git a/handlers/copy_handler.c b/handlers/copy_handler.c
index e463bb5..d09ca52 100644
--- a/handlers/copy_handler.c
+++ b/handlers/copy_handler.c
@@ -131,6 +131,7 @@  static int copy_single_file(const char *path, ssize_t size, struct img_type *img
 			&checksum,
 			0, /* no sha256 */
 			false, /* no encrypted */
+			NULL, /* no AES Key */
 			NULL, /* no IVT */
 			NULL);
 
diff --git a/handlers/delta_handler.c b/handlers/delta_handler.c
index d1ff783..a5ee2a6 100644
--- a/handlers/delta_handler.c
+++ b/handlers/delta_handler.c
@@ -169,6 +169,7 @@  static int network_process_data(multipart_parser* p, const char *at, size_t leng
 						 hash,
 						 0,
 						 NULL,
+						 NULL,
 						 NULL);
 			} else
 				ret = 0; /* skipping, nothing to be copied */
diff --git a/handlers/rdiff_handler.c b/handlers/rdiff_handler.c
index e01a127..3f09ec2 100644
--- a/handlers/rdiff_handler.c
+++ b/handlers/rdiff_handler.c
@@ -347,6 +347,7 @@  static int apply_rdiff_patch(struct img_type *img,
 			&img->checksum,
 			img->sha256,
 			img->is_encrypted,
+			img->aeskey_ascii,
 			img->ivt_ascii,
 			apply_rdiff_chunk_cb);
 	if (ret != 0) {
diff --git a/handlers/readback_handler.c b/handlers/readback_handler.c
index 4b910bd..6d2eefa 100644
--- a/handlers/readback_handler.c
+++ b/handlers/readback_handler.c
@@ -113,6 +113,7 @@  static int readback_postinst(struct img_type *img)
 			NULL,  /* no checksum */
 			hash,
 			false,     /* no encrypted */
+			NULL,  /* no AES Key */
 			NULL,     /* no IVT */
 			NULL); /* no callback */
 	if (status == 0) {
diff --git a/include/util.h b/include/util.h
index 958274c..7ad588d 100644
--- a/include/util.h
+++ b/include/util.h
@@ -203,10 +203,12 @@  strlcpy(char *dst, const char * src, size_t size);
 int copyfile(int fdin, void *out, size_t nbytes, unsigned long *offs,
 	unsigned long long seek,
 	int skip_file, int compressed, uint32_t *checksum,
-	unsigned char *hash, bool encrypted, const char *imgivt, writeimage callback);
+	unsigned char *hash, bool encrypted, const char *imgaeskey, const char *imgivt,
+	writeimage callback);
 int copyimage(void *out, struct img_type *img, writeimage callback);
 int copybuffer(unsigned char *inbuf, void *out, size_t nbytes, int compressed,
-	unsigned char *hash, bool encrypted, const char *imgivt, writeimage callback);
+	unsigned char *hash, bool encrypted, const char *imgaeskey, const char *imgivt,
+	writeimage callback);
 int openfileoutput(const char *filename);
 int mkpath(char *dir, mode_t mode);
 int swupdate_file_setnonblock(int fd, bool block);