diff mbox series

lib: add swupdate_set_aes() to the library

Message ID 20201109205644.380112-1-sbabic@denx.de
State Accepted
Headers show
Series lib: add swupdate_set_aes() to the library | expand

Commit Message

Stefano Babic Nov. 9, 2020, 8:56 p.m. UTC
Add function to send AES key for symmetric decryption to SWUpdate.

Signed-off-by: Stefano Babic <sbabic@denx.de>
---
 include/network_ipc.h |  1 +
 ipc/network_ipc-if.c  | 31 +++++++++++++++++++++++++++++--
 2 files changed, 30 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/include/network_ipc.h b/include/network_ipc.h
index f7a48ef..b30f10b 100644
--- a/include/network_ipc.h
+++ b/include/network_ipc.h
@@ -94,6 +94,7 @@  int ipc_wait_for_complete(getstatus callback);
 int swupdate_image_write(char *buf, int size);
 int swupdate_async_start(writedata wr_func, getstatus status_func,
 				terminated end_func, bool dry_run);
+int swupdate_set_aes(char *key, char *ivt);
 
 #ifdef __cplusplus
 }   // extern "C"
diff --git a/ipc/network_ipc-if.c b/ipc/network_ipc-if.c
index 06cf74c..6db1522 100644
--- a/ipc/network_ipc-if.c
+++ b/ipc/network_ipc-if.c
@@ -1,13 +1,13 @@ 
 /*
- * (C) Copyright 2008-2017
+ * (C) Copyright 2008-2020
  * Stefano Babic, DENX Software Engineering, sbabic@denx.de.
- * 	on behalf of ifm electronic GmbH
  *
  * SPDX-License-Identifier:     LGPL-2.1-or-later
  */
 
 #include <stdio.h>
 #include <stdlib.h>
+#include <string.h>
 #include <errno.h>
 #include <signal.h>
 #include <pthread.h>
@@ -144,3 +144,30 @@  int swupdate_image_write(char *buf, int size)
 
 	return ipc_send_data(rq->connfd, buf, size);
 }
+
+/*
+ * Set via IPC the AES key for decryption
+ * key is passed as ASCII string
+ */
+int swupdate_set_aes(char *key, char *ivt)
+{
+	ipc_message msg;
+
+	if (!key || !ivt)
+		return -EINVAL;
+	if (strlen(key) != 64 && strlen(ivt) != 32)
+		return -EINVAL;
+
+	memset(&msg, 0, sizeof(msg));
+
+	msg.magic = IPC_MAGIC;
+	msg.type = SET_AES_KEY;
+
+	/*
+	 * Lenght for key and IVT are fixed
+	 */
+	strncpy(msg.data.aeskeymsg.key_ascii, key, sizeof(msg.data.aeskeymsg.key_ascii) - 1);
+	strncpy(msg.data.aeskeymsg.ivt_ascii, ivt, sizeof(msg.data.aeskeymsg.ivt_ascii) - 1);
+
+	return ipc_send_cmd(&msg);
+}