From 214bcaa39df7cce4c29686e1b41e1ed5209fbc5b Mon Sep 17 00:00:00 2001 From: Michael Zillgith Date: Sun, 10 Dec 2017 15:16:35 +0100 Subject: [PATCH] - IEC 61850/MMS: added TLS for IedConnection - fixed Makefile to use correct TLS configuration --- Makefile | 2 +- src/iec61850/client/ied_connection.c | 38 ++++++++++++++++++++-------- src/iec61850/inc/iec61850_client.h | 15 +++++++++++ src/vs/libiec61850-wo-goose.def | 3 ++- src/vs/libiec61850.def | 3 ++- 5 files changed, 48 insertions(+), 13 deletions(-) diff --git a/Makefile b/Makefile index 2890447e..f4ccb697 100644 --- a/Makefile +++ b/Makefile @@ -70,7 +70,7 @@ LIB_SOURCE_DIRS += third_party/mbedtls/mbedtls-2.6.0/library LIB_SOURCE_DIRS += src/tls/mbedtls LIB_INCLUDE_DIRS += third_party/mbedtls/mbedtls-2.6.0/include LIB_INCLUDE_DIRS += src/tls/mbedtls -MBEDTLS_CONFIG_FILE = "mbedtls_config.h" +CFLAGS += -D'MBEDTLS_CONFIG_FILE="mbedtls_config.h"' CFLAGS += -D'CONFIG_MMS_SUPPORT_TLS=1' endif diff --git a/src/iec61850/client/ied_connection.c b/src/iec61850/client/ied_connection.c index fdad55db..30c8a502 100644 --- a/src/iec61850/client/ied_connection.c +++ b/src/iec61850/client/ied_connection.c @@ -470,27 +470,45 @@ informationReportHandler(void* parameter, char* domainName, MmsValue_delete(value); } -IedConnection -IedConnection_create() +static IedConnection +createNewConnectionObject(TLSConfiguration tlsConfig) { IedConnection self = (IedConnection) GLOBAL_CALLOC(1, sizeof(struct sIedConnection)); - self->enabledReports = LinkedList_create(); - self->logicalDevices = NULL; - self->clientControls = LinkedList_create(); + if (self) { + self->enabledReports = LinkedList_create(); + self->logicalDevices = NULL; + self->clientControls = LinkedList_create(); - self->connection = MmsConnection_create(); + if (tlsConfig) + self->connection = MmsConnection_createSecure(tlsConfig); + else + self->connection = MmsConnection_create(); - self->state = IED_STATE_IDLE; + self->state = IED_STATE_IDLE; - self->stateMutex = Semaphore_create(1); - self->reportHandlerMutex = Semaphore_create(1); + self->stateMutex = Semaphore_create(1); + self->reportHandlerMutex = Semaphore_create(1); - self->connectionTimeout = DEFAULT_CONNECTION_TIMEOUT; + self->connectionTimeout = DEFAULT_CONNECTION_TIMEOUT; + } return self; } +IedConnection +IedConnection_create() +{ + return createNewConnectionObject(NULL); +} + +IedConnection +IedConnection_createWithTlsSupport(TLSConfiguration tlsConfig) + +{ + return createNewConnectionObject(tlsConfig); +} + void IedConnection_setConnectTimeout(IedConnection self, uint32_t timeoutInMs) { diff --git a/src/iec61850/inc/iec61850_client.h b/src/iec61850/inc/iec61850_client.h index d319c109..be85acb0 100644 --- a/src/iec61850/inc/iec61850_client.h +++ b/src/iec61850/inc/iec61850_client.h @@ -178,6 +178,21 @@ typedef enum { IedConnection IedConnection_create(void); +/** + * \brief create a new IedConnection instance that has support for TLS + * + * This function creates a new IedConnection instance that is used to handle a connection to an IED. + * It allocated all required resources. The new connection is in the "idle" state. Before it can be used + * the connect method has to be called. The connection will use TLS when a TLSConfiguration object is + * provided. + * + * \param tlsConfig the TLS configuration to be used + * + * \return the new IedConnection instance + */ +IedConnection +IedConnection_createWithTlsSupport(TLSConfiguration tlsConfig); + /** * \brief destroy an IedConnection instance. * diff --git a/src/vs/libiec61850-wo-goose.def b/src/vs/libiec61850-wo-goose.def index 6b48bb0e..804f4fea 100644 --- a/src/vs/libiec61850-wo-goose.def +++ b/src/vs/libiec61850-wo-goose.def @@ -574,4 +574,5 @@ EXPORTS IedServer_udpateDbposValue MmsServer_setLocalIpAddress MmsServer_isRunning - IedServer_createWithTlsSupport \ No newline at end of file + IedServer_createWithTlsSupport + IedConnection_createWithTlsSupport \ No newline at end of file diff --git a/src/vs/libiec61850.def b/src/vs/libiec61850.def index 762a77f8..a5324701 100644 --- a/src/vs/libiec61850.def +++ b/src/vs/libiec61850.def @@ -655,4 +655,5 @@ EXPORTS IedServer_udpateDbposValue MmsServer_setLocalIpAddress MmsServer_isRunning - IedServer_createWithTlsSupport \ No newline at end of file + IedServer_createWithTlsSupport + IedConnection_createWithTlsSupport \ No newline at end of file