Commit 793c0340 authored by Yong Cong Sin's avatar Yong Cong Sin Committed by Christopher Friedt
Browse files

subsys/mgmt/hawkbit: Implement DDI API authentication



Implement Hawkbit DDI API authentication for the client.

Signed-off-by: default avatarYong Cong Sin <yongcong.sin@gmail.com>
parent 8ffb5e2f
Loading
Loading
Loading
Loading
+29 −0
Original line number Diff line number Diff line
@@ -52,6 +52,35 @@ config HAWKBIT_PORT
	help
	  Configure the hawkbit port number.

choice
	prompt "Hawkbit DDI API authentication modes"
	default HAWKBIT_DDI_NO_SECURITY

config HAWKBIT_DDI_NO_SECURITY
	bool "No authentication security"
	help
	  No authentication security for the Hawkbit DDI API.

config HAWKBIT_DDI_TARGET_SECURITY
	bool "Use target security token authentication"
	help
	  Use target security token authentication for the Hawkbit DDI API.

config HAWKBIT_DDI_GATEWAY_SECURITY
	bool "Use gateway security token authentication"
	help
	  Use gateway security token authentication for the Hawkbit DDI API.

endchoice

config HAWKBIT_DDI_SECURITY_TOKEN
	string "Authentication security token"
	depends on HAWKBIT_DDI_TARGET_SECURITY || HAWKBIT_DDI_GATEWAY_SECURITY
	default ""
	help
	  Authentication security token for the configured Hawkbit DDI
	  authentication mode.

module = HAWKBIT
module-str = Log Level for hawkbit
module-help = Enables logging for Hawkbit code.
+13 −0
Original line number Diff line number Diff line
@@ -868,6 +868,16 @@ static bool send_request(enum http_method method,
	const char *fini = hawkbit_status_finished(finished);
	const char *exec = hawkbit_status_execution(execution);
	char device_id[DEVICE_ID_HEX_MAX_SIZE] = { 0 };
#ifndef CONFIG_HAWKBIT_DDI_NO_SECURITY
	static const char * const headers[] = {
#ifdef CONFIG_HAWKBIT_DDI_GATEWAY_SECURITY
		"Authorization: GatewayToken "CONFIG_HAWKBIT_DDI_SECURITY_TOKEN"\r\n",
#else
		"Authorization: TargetToken "CONFIG_HAWKBIT_DDI_SECURITY_TOKEN"\r\n",
#endif /* CONFIG_HAWKBIT_DDI_GATEWAY_SECURITY */
		NULL
	};
#endif /* CONFIG_HAWKBIT_DDI_NO_SECURITY */

	if (!hawkbit_get_device_identity(device_id, DEVICE_ID_HEX_MAX_SIZE)) {
		hb_context.code_status = HAWKBIT_METADATA_ERROR;
@@ -883,6 +893,9 @@ static bool send_request(enum http_method method,
	hb_context.http_req.response = response_cb;
	hb_context.http_req.recv_buf = hb_context.recv_buf_tcp;
	hb_context.http_req.recv_buf_len = sizeof(hb_context.recv_buf_tcp);
#ifndef CONFIG_HAWKBIT_DDI_NO_SECURITY
	hb_context.http_req.header_fields = (const char **)headers;
#endif
	hb_context.final_data_received = false;

	switch (type) {