diff mbox series

Add delta download over ssl

Message ID 3b13b79a-3112-40bb-a44c-1eb588f06cff@gmail.com
State Accepted
Delegated to: Stefano Babic
Headers show
Series Add delta download over ssl | expand

Commit Message

Matt Wood Oct. 10, 2023, 6:38 p.m. UTC
Rename suricatta_channel_settings to be generic, update existing calls,
and add call in start_delta_downloader function.

Add delta update section in swupdate.cfg example.

Signed-off-by: Matt Wood <matt.wood@microchip.com>
---
 corelib/server_utils.c              |  2 +-
 examples/configuration/swupdate.cfg | 18 ++++++++++++++++--
 handlers/delta_downloader.c         | 11 +++++++++++
 include/server_utils.h              |  2 +-
 suricatta/server_general.c          |  2 +-
 suricatta/server_hawkbit.c          |  2 +-
 6 files changed, 31 insertions(+), 6 deletions(-)

Comments

Stefano Babic Oct. 11, 2023, 7:43 a.m. UTC | #1
Hi Matt,

On 10.10.23 20:38, Matt Wood wrote:
> Rename suricatta_channel_settings to be generic,

Good idea, I had on my TODO, too.

> update existing calls,
> and add call in start_delta_downloader function.
> 
> Add delta update section in swupdate.cfg example.
> 
> Signed-off-by: Matt Wood <matt.wood@microchip.com>
> ---
>   corelib/server_utils.c              |  2 +-
>   examples/configuration/swupdate.cfg | 18 ++++++++++++++++--
>   handlers/delta_downloader.c         | 11 +++++++++++
>   include/server_utils.h              |  2 +-
>   suricatta/server_general.c          |  2 +-
>   suricatta/server_hawkbit.c          |  2 +-
>   6 files changed, 31 insertions(+), 6 deletions(-)
> 
> diff --git a/corelib/server_utils.c b/corelib/server_utils.c
> index d7d733d..025a57d 100644
> --- a/corelib/server_utils.c
> +++ b/corelib/server_utils.c
> @@ -15,7 +15,7 @@
>   #include <channel_curl.h>
>   #include "server_utils.h"
>   
> -void suricatta_channel_settings(void *elem, channel_data_t *chan)
> +void channel_settings(void *elem, channel_data_t *chan)
>   {
>   	char tmp[128];
>   
> diff --git a/examples/configuration/swupdate.cfg b/examples/configuration/swupdate.cfg
> index 46bf1f4..20edb8b 100644
> --- a/examples/configuration/swupdate.cfg
> +++ b/examples/configuration/swupdate.cfg
> @@ -165,10 +165,10 @@ identify : (
>   # 			  File with Public Certificate Authority
>   # sslkey		: string
>   #			  path of the file containing the key for SSL connection or pkcs11 URI
> -#                         (ex. "pkcs11:model=ATECC608B;token=0ABC;serial=0123456789abcdef;object=device;type=private")
> +#			  ex. "pkcs11:model=ATECC608B;token=0ABC;serial=0123456789abcdef;object=device;type=private")
>   # sslcert		: string
>   #			  path of the file containing the certificate for SSL connection or pkcs11 URI
> -                          (ex. "pkcs11:model=ATECC608B;token=0ABC;serial=0123456789abcdef;object=device;type=cert")
> +#			  (ex. "pkcs11:model=ATECC608B;token=0ABC;serial=0123456789abcdef;object=device;type=cert")
>   # targettoken	: string
>   #			  hawkBit target security token
>   # gatewaytoken	: string
> @@ -264,3 +264,17 @@ webserver :
>   	groupid		= 1000;
>   	timeout		= 20;
>   };
> +
> +# delta update section
> +#
> +# sslkey		: string
> +#			  path of the file containing the key for SSL connection or pkcs11 URI
> +#			  (ex. "pkcs11:model=ATECC608B;token=0ABC;serial=0123456789abcdef;object=device;type=private")
> +# sslcert		: string
> +#			  path of the file containing the certificate for SSL connection or pkcs11 URI
> +#			  (ex. "pkcs11:model=ATECC608B;token=0ABC;serial=0123456789abcdef;object=device;type=cert")
> +delta :
> +{
> +	sslkey		= "/etc/ssl/sslkey";
> +	sslcert		= "/etc/ssl/sslcert";
> +};
> diff --git a/handlers/delta_downloader.c b/handlers/delta_downloader.c
> index e080092..abc3969 100644
> --- a/handlers/delta_downloader.c
> +++ b/handlers/delta_downloader.c
> @@ -34,6 +34,8 @@
>   #include "swupdate_dict.h"
>   #include "delta_handler.h"
>   #include "delta_process.h"
> +#include "swupdate_settings.h"
> +#include "server_utils.h"
>   
>   /*
>    * Structure used in curl callbacks
> @@ -198,6 +200,15 @@ int start_delta_downloader(const char __attribute__ ((__unused__)) *fname,
>   		channel_data.range = &req->data[req->urllen + 1];
>   		channel_data.user = &priv;
>   
> +		swupdate_cfg_handle handle;
> +		swupdate_cfg_init(&handle);
> +
> +		if (swupdate_cfg_read_file(&handle, fname) == 0) {
> +			read_module_settings(&handle, "delta", channel_settings, &channel_data);
> +		}
> +
> +		swupdate_cfg_destroy(&handle);
> +
>   		if (channel->open(channel, &channel_data) == CHANNEL_OK) {
>   			transfer = channel->get_file(channel, (void *)&channel_data);
>   		} else {
> diff --git a/include/server_utils.h b/include/server_utils.h
> index 7df02e3..8b249d5 100644
> --- a/include/server_utils.h
> +++ b/include/server_utils.h
> @@ -14,6 +14,6 @@
>   
>   struct json_object;
>   
> -void suricatta_channel_settings(void *elem, channel_data_t *chan);
> +void channel_settings(void *elem, channel_data_t *chan);
>   server_op_res_t map_channel_retcode(channel_op_res_t response);
>   struct json_object *server_tokenize_msg(char *buf, size_t size);
> diff --git a/suricatta/server_general.c b/suricatta/server_general.c
> index e86bdee..218e429 100644
> --- a/suricatta/server_general.c
> +++ b/suricatta/server_general.c
> @@ -594,7 +594,7 @@ static int server_general_settings(void *elem, void  __attribute__ ((__unused__)
>   	get_field(LIBCFG_PARSER, elem, "polldelay",
>   		&server_general.polling_interval);
>   
> -	suricatta_channel_settings(elem, &channel_data_defaults);
> +	channel_settings(elem, &channel_data_defaults);
>   
>   	return 0;
>   }
> diff --git a/suricatta/server_hawkbit.c b/suricatta/server_hawkbit.c
> index e6006cf..349dc11 100644
> --- a/suricatta/server_hawkbit.c
> +++ b/suricatta/server_hawkbit.c
> @@ -1675,7 +1675,7 @@ static int server_hawkbit_settings(void *elem, void  __attribute__ ((__unused__)
>   	get_field(LIBCFG_PARSER, elem, "initial-report-resend-period",
>   		&server_hawkbit.initial_report_resend_period);
>   
> -	suricatta_channel_settings(elem, &channel_data_defaults);
> +	channel_settings(elem, &channel_data_defaults);
>   
>   	get_field(LIBCFG_PARSER, elem, "usetokentodwl",
>   		&server_hawkbit.usetokentodwl);

At first glance, it looks ok to me.

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

Best regards,
Stefano
diff mbox series

Patch

diff --git a/corelib/server_utils.c b/corelib/server_utils.c
index d7d733d..025a57d 100644
--- a/corelib/server_utils.c
+++ b/corelib/server_utils.c
@@ -15,7 +15,7 @@ 
 #include <channel_curl.h>
 #include "server_utils.h"
 
-void suricatta_channel_settings(void *elem, channel_data_t *chan)
+void channel_settings(void *elem, channel_data_t *chan)
 {
 	char tmp[128];
 
diff --git a/examples/configuration/swupdate.cfg b/examples/configuration/swupdate.cfg
index 46bf1f4..20edb8b 100644
--- a/examples/configuration/swupdate.cfg
+++ b/examples/configuration/swupdate.cfg
@@ -165,10 +165,10 @@  identify : (
 # 			  File with Public Certificate Authority
 # sslkey		: string
 #			  path of the file containing the key for SSL connection or pkcs11 URI
-#                         (ex. "pkcs11:model=ATECC608B;token=0ABC;serial=0123456789abcdef;object=device;type=private")
+#			  ex. "pkcs11:model=ATECC608B;token=0ABC;serial=0123456789abcdef;object=device;type=private")
 # sslcert		: string
 #			  path of the file containing the certificate for SSL connection or pkcs11 URI
-                          (ex. "pkcs11:model=ATECC608B;token=0ABC;serial=0123456789abcdef;object=device;type=cert")
+#			  (ex. "pkcs11:model=ATECC608B;token=0ABC;serial=0123456789abcdef;object=device;type=cert")
 # targettoken	: string
 #			  hawkBit target security token
 # gatewaytoken	: string
@@ -264,3 +264,17 @@  webserver :
 	groupid		= 1000;
 	timeout		= 20;
 };
+
+# delta update section
+#
+# sslkey		: string
+#			  path of the file containing the key for SSL connection or pkcs11 URI
+#			  (ex. "pkcs11:model=ATECC608B;token=0ABC;serial=0123456789abcdef;object=device;type=private")
+# sslcert		: string
+#			  path of the file containing the certificate for SSL connection or pkcs11 URI
+#			  (ex. "pkcs11:model=ATECC608B;token=0ABC;serial=0123456789abcdef;object=device;type=cert")
+delta :
+{
+	sslkey		= "/etc/ssl/sslkey";
+	sslcert		= "/etc/ssl/sslcert";
+};
diff --git a/handlers/delta_downloader.c b/handlers/delta_downloader.c
index e080092..abc3969 100644
--- a/handlers/delta_downloader.c
+++ b/handlers/delta_downloader.c
@@ -34,6 +34,8 @@ 
 #include "swupdate_dict.h"
 #include "delta_handler.h"
 #include "delta_process.h"
+#include "swupdate_settings.h"
+#include "server_utils.h"
 
 /*
  * Structure used in curl callbacks
@@ -198,6 +200,15 @@  int start_delta_downloader(const char __attribute__ ((__unused__)) *fname,
 		channel_data.range = &req->data[req->urllen + 1];
 		channel_data.user = &priv;
 
+		swupdate_cfg_handle handle;
+		swupdate_cfg_init(&handle);
+
+		if (swupdate_cfg_read_file(&handle, fname) == 0) {
+			read_module_settings(&handle, "delta", channel_settings, &channel_data);
+		}
+
+		swupdate_cfg_destroy(&handle);
+
 		if (channel->open(channel, &channel_data) == CHANNEL_OK) {
 			transfer = channel->get_file(channel, (void *)&channel_data);
 		} else {
diff --git a/include/server_utils.h b/include/server_utils.h
index 7df02e3..8b249d5 100644
--- a/include/server_utils.h
+++ b/include/server_utils.h
@@ -14,6 +14,6 @@ 
 
 struct json_object;
 
-void suricatta_channel_settings(void *elem, channel_data_t *chan);
+void channel_settings(void *elem, channel_data_t *chan);
 server_op_res_t map_channel_retcode(channel_op_res_t response);
 struct json_object *server_tokenize_msg(char *buf, size_t size);
diff --git a/suricatta/server_general.c b/suricatta/server_general.c
index e86bdee..218e429 100644
--- a/suricatta/server_general.c
+++ b/suricatta/server_general.c
@@ -594,7 +594,7 @@  static int server_general_settings(void *elem, void  __attribute__ ((__unused__)
 	get_field(LIBCFG_PARSER, elem, "polldelay",
 		&server_general.polling_interval);
 
-	suricatta_channel_settings(elem, &channel_data_defaults);
+	channel_settings(elem, &channel_data_defaults);
 
 	return 0;
 }
diff --git a/suricatta/server_hawkbit.c b/suricatta/server_hawkbit.c
index e6006cf..349dc11 100644
--- a/suricatta/server_hawkbit.c
+++ b/suricatta/server_hawkbit.c
@@ -1675,7 +1675,7 @@  static int server_hawkbit_settings(void *elem, void  __attribute__ ((__unused__)
 	get_field(LIBCFG_PARSER, elem, "initial-report-resend-period",
 		&server_hawkbit.initial_report_resend_period);
 
-	suricatta_channel_settings(elem, &channel_data_defaults);
+	channel_settings(elem, &channel_data_defaults);
 
 	get_field(LIBCFG_PARSER, elem, "usetokentodwl",
 		&server_hawkbit.usetokentodwl);