Skip to content
Draft
1 change: 1 addition & 0 deletions common/Makefile.mk
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ common_libolacommon_la_LIBADD += -lWs2_32 -lIphlpapi
endif

include common/base/Makefile.mk
include common/crypto/Makefile.mk
include common/dmx/Makefile.mk
include common/export_map/Makefile.mk
include common/file/Makefile.mk
Expand Down
46 changes: 46 additions & 0 deletions common/crypto/HMAC.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* HMAC.cpp
* HMAC Crypto functions.
* Copyright (C) 2026 Peter Newman
*/

#include "ola/crypto/HMAC.h"

#include <openssl/evp.h>
#include <openssl/hmac.h>
#include "ola/Logging.h"

namespace ola {
namespace crypto {

bool HMACSHA256(const uint8_t *key,
const unsigned int key_length,
const uint8_t *data,
const unsigned int data_length,
uint8_t *hmac,
unsigned int *hmac_length) {
/*HMAC_CTX ctx;
HMAC_Init(&ctx, key, key_length, );
HMAC_Update(&ctx, data, data_length);
HMAC_Final(&ctx, hmac, hmac_length);
HMAC_cleanup(&ctx);*/
HMAC(EVP_sha256(), key, key_length, data, data_length, hmac, hmac_length);

return true;
}
} // namespace crypto
} // namespace ola
68 changes: 68 additions & 0 deletions common/crypto/HMACTest.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* HMACTest.cpp
* Unittest for HMAC Crypto functions.
* Copyright (C) 2026 Peter Newman
*/

#include <cppunit/extensions/HelperMacros.h>

#include "ola/crypto/HMAC.h"
#include "ola/testing/TestUtils.h"

using ola::crypto::HMACSHA256;

class HMACTest: public CppUnit::TestFixture {
CPPUNIT_TEST_SUITE(HMACTest);
CPPUNIT_TEST(testHMACSHA256);
CPPUNIT_TEST_SUITE_END();

public:
void testHMACSHA256();
};


CPPUNIT_TEST_SUITE_REGISTRATION(HMACTest);

/*
* Test the HMACSHA256 function
*/
void HMACTest::testHMACSHA256() {
// RFC 4231 - Test Case 1
// uint8_t hmac[EVP_MAX_MD_SIZE];
uint8_t hmac[100];
unsigned int len = 0;

const uint8_t key[] = {
0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
0x0b, 0x0b, 0x0b, 0x0b, 0x0b
};

const uint8_t data[] = { 'H', 'i', ' ', 'T', 'h', 'e', 'r', 'e' };

uint8_t expected_hmac[32] = {
0xB0, 0x34, 0x4C, 0x61, 0xD8, 0xDB, 0x38, 0x53,
0x5C, 0xA8, 0xAF, 0xCE, 0xAF, 0x0B, 0xF1, 0x2B,
0x88, 0x1D, 0xC2, 0x00, 0xC9, 0x83, 0x3D, 0xA7,
0x26, 0xE9, 0x37, 0x6C, 0x2E, 0x32, 0xCF, 0xF7
};

OLA_ASSERT_TRUE(HMACSHA256(key, sizeof(key), data, sizeof(data), hmac, &len));
OLA_ASSERT_DATA_EQUALS(expected_hmac, sizeof(expected_hmac),
hmac, len);
}
27 changes: 27 additions & 0 deletions common/crypto/Makefile.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# LIBRARIES
##################################################
if HAVE_LIBCRYPTO
noinst_LTLIBRARIES += common/crypto/libolacrypto.la
common_crypto_libolacrypto_la_SOURCES = \
common/crypto/HMAC.cpp
common_crypto_libolacrypto_la_LIBADD = $(libcrypto_LIBS)

# TODO(Peter): Fixme for Windows
# if USING_WIN32
# Work around limitations with Windows library linking
# common_crypto_libolacrypto_la_LIBADD = common/libolacommon.la
# endif

# TESTS
################################################
test_programs += common/crypto/HMACTester

COMMON_CRYPTO_TEST_LDADD = $(COMMON_TESTING_LIBS) \
common/crypto/libolacrypto.la

common_crypto_HMACTester_SOURCES = \
common/crypto/HMACTest.cpp
common_crypto_HMACTester_CXXFLAGS = $(COMMON_TESTING_FLAGS)
common_crypto_HMACTester_LDADD = $(COMMON_CRYPTO_TEST_LDADD)
endif

3 changes: 3 additions & 0 deletions common/protocol/Ola.proto
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ enum PluginIds {
OLA_PLUGIN_GPIO = 22;
OLA_PLUGIN_SPIDMX = 23;
OLA_PLUGIN_NANOLEAF = 24;
OLA_PLUGIN_E133 = 25;
OLA_PLUGIN_LLRP = 26;
OLA_PLUGIN_SIGNET = 27;

/*
* To obtain a new plugin ID, open a ticket at
Expand Down
23 changes: 23 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -760,6 +760,28 @@ AS_IF([test "x$enable_osc" != xno],
AS_IF([test "x$have_liblo" = xyes],
[AC_DEFINE([HAVE_LIBLO], [1], [define if liblo is installed])])

# COAP Support.
# look for libcoap if the user asked us to
AC_ARG_ENABLE(
[signet],
[AS_HELP_STRING([--disable-signet],
[Disable the Sig-Net plugin even if libcoap exists])])

have_libcoap="no"
#AS_IF([test "x$enable_signet" != xno],
# [PKG_CHECK_MODULES(libcoap, [libcoap-1 >= 4.1.2], [have_libcoap="yes"], [true])])
AS_IF([test "x$enable_signet" != xno],
[PKG_CHECK_MODULES(libcoap, [libcoap-2 >= 4.2.1], [have_libcoap="yes"], [true])])
AS_IF([test "x$have_libcoap" = xyes],
[AC_DEFINE([HAVE_LIBCOAP], [1], [define if libcoap is installed])])

have_libcrypto="no"
AS_IF([test "x$enable_signet" != xno],
[PKG_CHECK_MODULES(libcrypto, [libcrypto >= 1.0.2g], [have_libcrypto="yes"], [true])])
AM_CONDITIONAL([HAVE_LIBCRYPTO], [test "x$have_libcrypto" = xyes])
AS_IF([test "x$have_libcrypto" = xyes],
[AC_DEFINE([HAVE_LIBCRYPTO], [1], [define if libcrypto is installed])])

# Python API
AC_ARG_ENABLE(
[python-libs],
Expand Down Expand Up @@ -920,6 +942,7 @@ PLUGIN_SUPPORT(pathport, USE_PATHPORT)
PLUGIN_SUPPORT(renard, USE_RENARD)
PLUGIN_SUPPORT(sandnet, USE_SANDNET)
PLUGIN_SUPPORT(shownet, USE_SHOWNET)
PLUGIN_SUPPORT(signet, USE_SIGNET, [$have_libcoap])
PLUGIN_SUPPORT(spi, USE_SPI, [$have_spi])
PLUGIN_SUPPORT(spidmx, USE_SPIDMX, [$have_spi])
PLUGIN_SUPPORT(stageprofi, USE_STAGEPROFI)
Expand Down
1 change: 1 addition & 0 deletions include/ola/Makefile.mk
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
include include/ola/acn/Makefile.mk
include include/ola/base/Makefile.mk
include include/ola/client/Makefile.mk
include include/ola/crypto/Makefile.mk
include include/ola/dmx/Makefile.mk
include include/ola/e133/Makefile.mk
include include/ola/file/Makefile.mk
Expand Down
52 changes: 52 additions & 0 deletions include/ola/crypto/HMAC.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* HMAC.h
* HMAC Crypto functions.
* Copyright (C) 2026 Peter Newman
*/

/**
* @file ola/crypto/HMAC.h
* @brief HMAC crypto functions
*/

#ifndef INCLUDE_OLA_CRYPTO_HMAC_H_
#define INCLUDE_OLA_CRYPTO_HMAC_H_

#include <stdint.h>

namespace ola {
namespace crypto {

/**
* @brief Generate the SHA256 HMAC of some data.
* @param[in] key pointer to the key
* @param[in] key_length length of the key
* @param[in] data pointer to the data to generate the HMAC of
* @param[in] data_length length of the data to generate the HMAC of
* @param[out] hmac pointer to where the HMAC will be stored
* @param[out] hmac_length pointer to where the length of the generated HMAC
* will be stored
*/
bool HMACSHA256(const uint8_t *key,
const unsigned int key_length,
const uint8_t *data,
const unsigned int data_length,
uint8_t *hmac,
unsigned int *hmac_length);
} // namespace crypto
} // namespace ola
#endif // INCLUDE_OLA_CRYPTO_HMAC_H_
3 changes: 3 additions & 0 deletions include/ola/crypto/Makefile.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
olacryptoincludedir = $(pkgincludedir)/crypto/
olacryptoinclude_HEADERS = \
include/ola/crypto/HMAC.h
2 changes: 1 addition & 1 deletion include/ola/rdm/RDMCommand.h
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ class RDMCommand {

/**
* @brief Extract a RDMCommand from raw data.
* @param data The data excluding the state code.
* @param data The data excluding the start code.
* @param length The length of the data.
* @returns NULL if the RDM command is invalid.
*/
Expand Down
9 changes: 9 additions & 0 deletions olad/DynamicPluginLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@
#include "plugins/shownet/ShowNetPlugin.h"
#endif // USE_SHOWNET

#ifdef USE_SIGNET
#include "plugins/signet/SigNetPlugin.h"
#endif // USE_SIGNET

#ifdef USE_SPI
#include "plugins/spi/SPIPlugin.h"
#endif // USE_SPI
Expand Down Expand Up @@ -216,6 +220,11 @@ void DynamicPluginLoader::PopulatePlugins() {
new ola::plugin::shownet::ShowNetPlugin(m_plugin_adaptor));
#endif // USE_SHOWNET

#ifdef USE_SIGNET
m_plugins.push_back(
new ola::plugin::signet::SigNetPlugin(m_plugin_adaptor));
#endif // USE_SIGNET

#ifdef USE_SPI
m_plugins.push_back(
new ola::plugin::spi::SPIPlugin(m_plugin_adaptor));
Expand Down
4 changes: 4 additions & 0 deletions olad/Makefile.mk
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ ola_server_sources += olad/HttpServerActions.cpp \
ola_server_additional_libs += common/http/libolahttp.la
endif

if HAVE_LIBCRYPTO
ola_server_additional_libs += common/crypto/libolacrypto.la
endif

# lib olaserver
lib_LTLIBRARIES += olad/libolaserver.la

Expand Down
1 change: 1 addition & 0 deletions plugins/Makefile.mk
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ include plugins/pathport/Makefile.mk
include plugins/renard/Makefile.mk
include plugins/sandnet/Makefile.mk
include plugins/shownet/Makefile.mk
include plugins/signet/Makefile.mk
include plugins/spi/Makefile.mk
include plugins/spidmx/Makefile.mk
include plugins/stageprofi/Makefile.mk
Expand Down
37 changes: 37 additions & 0 deletions plugins/signet/Makefile.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# LIBRARIES
##################################################
if USE_SIGNET
# This is a library which isn't coupled to olad
noinst_LTLIBRARIES += plugins/signet/libolasignetnode.la
plugins_signet_libolasignetnode_la_SOURCES = \
plugins/signet/SigNetEnums.h \
plugins/signet/SigNetNode.cpp \
plugins/signet/SigNetNode.h \
plugins/signet/SigNetTIDs.h
plugins_signet_libolasignetnode_la_CXXFLAGS = $(COMMON_CXXFLAGS) $(libcoap_CFLAGS)
plugins_signet_libolasignetnode_la_LIBADD = $(libcoap_LIBS)

lib_LTLIBRARIES += plugins/signet/libolasignet.la

# Plugin description is generated from README.md
built_sources += plugins/signet/SigNetPluginDescription.h
nodist_plugins_signet_libolasignet_la_SOURCES = \
plugins/signet/SigNetPluginDescription.h
plugins/signet/SigNetPluginDescription.h: plugins/signet/README.md plugins/signet/Makefile.mk plugins/convert_README_to_header.sh
sh $(top_srcdir)/plugins/convert_README_to_header.sh $(top_srcdir)/plugins/signet $(top_builddir)/plugins/signet/SigNetPluginDescription.h

plugins_signet_libolasignet_la_SOURCES = \
plugins/signet/SigNetDevice.cpp \
plugins/signet/SigNetDevice.h \
plugins/signet/SigNetPlugin.cpp \
plugins/signet/SigNetPlugin.h \
plugins/signet/SigNetPort.cpp \
plugins/signet/SigNetPort.h
plugins_signet_libolasignet_la_CXXFLAGS = $(COMMON_CXXFLAGS) $(libcoap_CFLAGS)
plugins_signet_libolasignet_la_LIBADD = \
olad/plugin_api/libolaserverplugininterface.la \
plugins/signet/libolasignetnode.la
endif

EXTRA_DIST += \
plugins/signet/README.md
17 changes: 17 additions & 0 deletions plugins/signet/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
Sig-Net Plugin
===============================

This plugin allows OLA to send and receive
[Sig-Net](https://sig-net.net/) messages.


## Config file: `ola-signet.conf`

`input_ports = <int>`
The number of input ports to create.

`output_ports = <int>`
The number of output ports to create.

`udp_listen_port = <int>`
The UDP Port to listen on for Sig-Net messages.
Loading
Loading