diff mbox series

[v5,07/16] parser: Read aes-key from sw-description into struct img_type

Message ID 20250904115704.58413-8-Michael.Glembotzki@iris-sensing.com
State Changes Requested
Delegated to: Stefano Babic
Headers show
Series Add support for asymmetric decryption | expand

Commit Message

Michael Glembotzki Sept. 4, 2025, 11:49 a.m. UTC
Signed-off-by: Michael Glembotzki <Michael.Glembotzki@iris-sensing.com>
---
 include/swupdate_image.h |  1 +
 parser/parser.c          | 23 +++++++++++++++++++++++
 2 files changed, 24 insertions(+)

Comments

Stefano Babic Sept. 14, 2025, 9:25 a.m. UTC | #1
On 04.09.25 13:49, Michael Glembotzki wrote:
> Signed-off-by: Michael Glembotzki <Michael.Glembotzki@iris-sensing.com>
> ---
>   include/swupdate_image.h |  1 +
>   parser/parser.c          | 23 +++++++++++++++++++++++
>   2 files changed, 24 insertions(+)
> 
> diff --git a/include/swupdate_image.h b/include/swupdate_image.h
> index 8c58a40c..1bb37dc8 100644
> --- a/include/swupdate_image.h
> +++ b/include/swupdate_image.h
> @@ -59,6 +59,7 @@ struct img_type {
>   	bool is_encrypted;
>   	cipher_t cipher;
>   	char ivt_ascii[33];
> +	char aes_ascii[65]; /* AES_256_KEY_LEN*2+1 */
>   	bool install_directly;
>   	int is_script;
>   	int is_partitioner;
> diff --git a/parser/parser.c b/parser/parser.c
> index a2d8ff51..84bf036c 100644
> --- a/parser/parser.c
> +++ b/parser/parser.c
> @@ -437,6 +437,28 @@ static void get_ivt_value(parsertype p, void *elem, char *ivt_ascii)
>   	}
>   }
>   
> +static void get_aes_value(parsertype p, void *elem, char *aes_ascii)
> +{
> +	size_t keylen;
> +	const char *s = NULL;
> +	s = get_field_string(p, elem, "aes-key");
> +	if (s) {
> +		keylen = strnlen(s, SWUPDATE_GENERAL_STRING_SIZE);
> +
> +		switch (keylen) {
> +		case AES_128_KEY_LEN * 2:
> +		case AES_192_KEY_LEN * 2:
> +		case AES_256_KEY_LEN * 2:
> +			// valid hex string size for AES 128/192/256
> +			break;
> +		default:
> +			ERROR("Invalid aes-key length");
> +			return;
> +		}
> +		get_field_string_with_size(p, elem, "aes-key", aes_ascii, keylen);
> +	}
> +}
> +
>   static int parse_common_attributes(parsertype p, void *elem, struct img_type *image, struct swupdate_cfg *cfg)
>   {
>   	char seek_str[MAX_SEEK_STRING_SIZE];
> @@ -508,6 +530,7 @@ static int parse_common_attributes(parsertype p, void *elem, struct img_type *im
>   		image->cipher = AES_CBC;
>   	}
>   	get_ivt_value(p, elem, image->ivt_ascii);
> +	get_aes_value(p, elem, image->aes_ascii);
>   
>   	if (is_image_installed(&cfg->installed_sw_list, image)) {
>   		image->skip = SKIP_SAME;


Reviewed-by: Stefano Babic <stefano.babic@swupdate.org>
diff mbox series

Patch

diff --git a/include/swupdate_image.h b/include/swupdate_image.h
index 8c58a40c..1bb37dc8 100644
--- a/include/swupdate_image.h
+++ b/include/swupdate_image.h
@@ -59,6 +59,7 @@  struct img_type {
 	bool is_encrypted;
 	cipher_t cipher;
 	char ivt_ascii[33];
+	char aes_ascii[65]; /* AES_256_KEY_LEN*2+1 */
 	bool install_directly;
 	int is_script;
 	int is_partitioner;
diff --git a/parser/parser.c b/parser/parser.c
index a2d8ff51..84bf036c 100644
--- a/parser/parser.c
+++ b/parser/parser.c
@@ -437,6 +437,28 @@  static void get_ivt_value(parsertype p, void *elem, char *ivt_ascii)
 	}
 }
 
+static void get_aes_value(parsertype p, void *elem, char *aes_ascii)
+{
+	size_t keylen;
+	const char *s = NULL;
+	s = get_field_string(p, elem, "aes-key");
+	if (s) {
+		keylen = strnlen(s, SWUPDATE_GENERAL_STRING_SIZE);
+
+		switch (keylen) {
+		case AES_128_KEY_LEN * 2:
+		case AES_192_KEY_LEN * 2:
+		case AES_256_KEY_LEN * 2:
+			// valid hex string size for AES 128/192/256
+			break;
+		default:
+			ERROR("Invalid aes-key length");
+			return;
+		}
+		get_field_string_with_size(p, elem, "aes-key", aes_ascii, keylen);
+	}
+}
+
 static int parse_common_attributes(parsertype p, void *elem, struct img_type *image, struct swupdate_cfg *cfg)
 {
 	char seek_str[MAX_SEEK_STRING_SIZE];
@@ -508,6 +530,7 @@  static int parse_common_attributes(parsertype p, void *elem, struct img_type *im
 		image->cipher = AES_CBC;
 	}
 	get_ivt_value(p, elem, image->ivt_ascii);
+	get_aes_value(p, elem, image->aes_ascii);
 
 	if (is_image_installed(&cfg->installed_sw_list, image)) {
 		image->skip = SKIP_SAME;