Fixed BACnet/SC secure connect VMAC, UUID, and initialization sequence (#1142)

* Refactored the BACnet/SC datalink initialization order by moving certificate file checks and hub connection registration to occur after datalink initialization
* Replaced stdlib rand() with platform-specific cryptographically secure random functions (RtlGenRandom for Windows, getrandom for Linux, arc4random_buf for BSD) to generate UUID and VMAC addresses, preventing duplicates that broke connections
* Enabled conditional debug output in BACnet/SC components when BUILD=debug is specified
This commit is contained in:
Steve Karg
2025-11-14 15:41:17 -06:00
committed by GitHub
parent 74972bd025
commit 25d14c7c15
30 changed files with 672 additions and 339 deletions
+23 -4
View File
@@ -1,11 +1,12 @@
/**
* @file
* @brief Implementation of mutex abstraction used in BACNet secure connect.
* @brief Implementation of port specific API used in BACNet secure connect.
* @author Kirill Neznamov <kirill.neznamov@dsr-corporation.com>
* @date August 2022
* @copyright SPDX-License-Identifier: GPL-2.0-or-later WITH GCC-exception-2.0
*/
#include <windows.h>
#include <ntsecapi.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
@@ -13,10 +14,8 @@
#include "bacnet/basic/sys/debug.h"
#include "bacnet/datalink/bsc/bsc-event.h"
#define DEBUG_BSC_EVENT 0
#undef DEBUG_PRINTF
#if DEBUG_BSC_EVENT == 1
#if DEBUG_BSC_EVENT
#define DEBUG_PRINTF printf
#else
#undef DEBUG_ENABLED
@@ -144,3 +143,23 @@ void bsc_wait_ms(int mseconds)
{
Sleep(mseconds);
}
void bsc_generate_random_vmac(BACNET_SC_VMAC_ADDRESS *p)
{
// Use RtlGenRandom (SystemFunction036) for cryptographically secure random
// bytes
RtlGenRandom(p->address, BVLC_SC_VMAC_SIZE);
/* According H.7.3 EUI-48 and Random-48 VMAC Address */
p->address[0] = (p->address[0] & 0xF0) | 0x02;
debug_printf_hex(
0, p->address, BVLC_SC_VMAC_SIZE, "bsc_generate_random_vmac:");
}
void bsc_generate_random_uuid(BACNET_SC_UUID *p)
{
RtlGenRandom(p->uuid, BVLC_SC_UUID_SIZE);
debug_printf_hex(
0, p->uuid, BVLC_SC_UUID_SIZE, "bsc_generate_random_uuid:");
}
+1 -3
View File
@@ -13,10 +13,8 @@
#include "bacnet/basic/sys/debug.h"
#include "websocket-global.h"
#define DEBUG_WEBSOCKET_CLIENT 0
#undef DEBUG_PRINTF
#if DEBUG_WEBSOCKET_CLIENT == 1
#if DEBUG_WEBSOCKET_CLIENT
#define DEBUG_PRINTF debug_printf
#else
#undef DEBUG_ENABLED
+1 -3
View File
@@ -13,10 +13,8 @@
#include "bacnet/basic/sys/debug.h"
#include "websocket-global.h"
#define DEBUG_WEBSOCKET_SERVER 0
#undef DEBUG_PRINTF
#if DEBUG_WEBSOCKET_SERVER == 1
#if DEBUG_WEBSOCKET_SERVER
#define DEBUG_PRINTF debug_printf
#else
#undef DEBUG_ENABLED