From: Ayoub Zaki <
ayoub...@embexus.com>
When a target is created within hawkBit a specific security token (32 alphanumeric character) is generated.
This can be used to authenticate the target through a HTTP-Authorization header with a custom scheme TargetToken.
Signed-off-by: Ayoub Zaki <
ayoub...@embexus.com>
Signed-off-by: Diego Rondini <
diego....@kynetics.com>
---
Changes in v2: used generic "header" concept in channel_curl code
corelib/channel_curl.c | 8 ++++++++
examples/configuration/swupdate.cfg | 3 +++
include/channel_curl.h | 1 +
suricatta/server_hawkbit.c | 6 ++++++
4 files changed, 18 insertions(+)
diff --git a/corelib/channel_curl.c b/corelib/channel_curl.c
index 0dec551..2f572d4 100644
--- a/corelib/channel_curl.c
+++ b/corelib/channel_curl.c
@@ -385,6 +385,14 @@ channel_op_res_t channel_set_options(channel_t *this,
}
}
+ if (channel_data->header != NULL) {
+ if (((channel_curl->header = curl_slist_append(
+ channel_curl->header, channel_data->header)) == NULL)) {
+ result = CHANNEL_EINIT;
+ goto cleanup;
+ }
+ }
+
switch (method) {
case CHANNEL_GET:
if (curl_easy_setopt(channel_curl->handle, CURLOPT_CUSTOMREQUEST,
diff --git a/examples/configuration/swupdate.cfg b/examples/configuration/swupdate.cfg
index 5c9e122..213f8be 100644
--- a/examples/configuration/swupdate.cfg
+++ b/examples/configuration/swupdate.cfg
@@ -105,6 +105,8 @@ identify : (
# path of the file containing the key for ssl connection
# sslcert : string
# path of the file containing the certificate for SSL connection
+# token : string
+# Hawkbit security token
# proxy : string
# in case the server is reached via a proxy
@@ -126,6 +128,7 @@ suricatta :
cafile = "/etc/ssl/cafile";
sslkey = "/etc/ssl/sslkey";
sslcert = "/etc/ssl/sslcert";
+ token = "3bc13b476cb3962a0c63a5c92beacfh7";
*/
};
diff --git a/include/channel_curl.h b/include/channel_curl.h
index 2133744..b13e9cf 100644
--- a/include/channel_curl.h
+++ b/include/channel_curl.h
@@ -37,6 +37,7 @@ typedef struct {
char *sslcert;
char *proxy;
char *info;
+ char *header;
unsigned int retry_sleep;
unsigned int offs;
unsigned int method;
diff --git a/suricatta/server_hawkbit.c b/suricatta/server_hawkbit.c
index 02ffb3a..480750d 100644
--- a/suricatta/server_hawkbit.c
+++ b/suricatta/server_hawkbit.c
@@ -1521,6 +1521,12 @@ static int suricatta_settings(void *elem, void __attribute__ ((__unused__)) *da
GET_FIELD_STRING_RESET(LIBCFG_PARSER, elem, "proxy", tmp);
if (strlen(tmp))
SETSTRING(channel_data_defaults.proxy, tmp);
+ GET_FIELD_STRING_RESET(LIBCFG_PARSER, elem, "token", tmp);
+ if (strlen(tmp)) {
+ char *token_header;
+ if (asprintf(&token_header, "Authorization: TargetToken %s", tmp))
+ SETSTRING(channel_data_defaults.header, token_header);
+ }
return 0;
--
2.14.3