From 577158ec6eaee5c9f63090fc083faaeea3d7546a Mon Sep 17 00:00:00 2001 From: Michael Zillgith Date: Tue, 12 Dec 2017 08:08:27 +0100 Subject: [PATCH] - updated documentation - tls_server_example uses AcseAuthenticator - IsoConnectionParameters: remove TLSConfiguration when compiled without TLS support --- README.md | 9 +++++++ .../server_example_password_auth.c | 3 ++- .../tls_server_example/tls_server_example.c | 26 +++++++++++++++++++ src/mms/inc/iso_connection_parameters.h | 6 ++--- src/mms/inc/mms_common.h | 7 ++++- .../iso_common/iso_connection_parameters.c | 4 +-- .../iso_mms/client/mms_client_connection.c | 4 +++ 7 files changed, 52 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 1cd1ac84..69dfb2ab 100644 --- a/README.md +++ b/README.md @@ -46,6 +46,15 @@ on the Linux command line. You can test the server examples by using a generic client or the provided client example applications. +## Building the library with TLS support + +Download, unpack, and copy mbedtls-2.6.0 into the third_party/mbedtls folder. + +In the main libiec61850 folder run + +``` +make WITH_MBEDTLS=1 +``` ## Installing the library and the API headers diff --git a/examples/server_example_password_auth/server_example_password_auth.c b/examples/server_example_password_auth/server_example_password_auth.c index 92f7aac5..40f3d804 100644 --- a/examples/server_example_password_auth/server_example_password_auth.c +++ b/examples/server_example_password_auth/server_example_password_auth.c @@ -37,7 +37,8 @@ void sigint_handler(int signalId) static char* password1 = "user1@testpw"; static char* password2 = "user2@testpw"; -static void printAppTitle(ItuObjectIdentifier* oid) +static void +printAppTitle(ItuObjectIdentifier* oid) { int i; diff --git a/examples/tls_server_example/tls_server_example.c b/examples/tls_server_example/tls_server_example.c index 5708b16a..46316994 100644 --- a/examples/tls_server_example/tls_server_example.c +++ b/examples/tls_server_example/tls_server_example.c @@ -77,6 +77,30 @@ connectionHandler (IedServer self, ClientConnection connection, bool connected, printf("Connection closed\n"); } +static void +printAppTitle(ItuObjectIdentifier* oid) +{ + int i; + + for (i = 0; i < oid->arcCount; i++) { + printf("%i", oid->arc[i]); + + if (i != (oid->arcCount - 1)) + printf("."); + } +} + +static bool +clientAuthenticator(void* parameter, AcseAuthenticationParameter authParameter, void** securityToken, IsoApplicationReference* appRef) +{ + printf("ACSE Authenticator:\n"); + printf(" client ap-title: "); printAppTitle(&(appRef->apTitle)); printf("\n"); + printf(" client ae-qualifier: %i\n", appRef->aeQualifier); + printf(" auth-mechanism: %i\n", authParameter->mechanism); + + return true; +} + int main(int argc, char** argv) { @@ -118,6 +142,8 @@ main(int argc, char** argv) iedServer = IedServer_createWithTlsSupport(&iedModel, tlsConfig); + IedServer_setAuthenticator(iedServer, clientAuthenticator, NULL); + /* Install handler for operate command */ IedServer_setControlHandler(iedServer, IEDMODEL_GenericIO_GGIO1_SPCSO1, (ControlHandler) controlHandlerForBinaryOutput, diff --git a/src/mms/inc/iso_connection_parameters.h b/src/mms/inc/iso_connection_parameters.h index 8f4ce65e..8d9a054a 100644 --- a/src/mms/inc/iso_connection_parameters.h +++ b/src/mms/inc/iso_connection_parameters.h @@ -123,9 +123,9 @@ struct sIsoConnectionParameters { AcseAuthenticationParameter acseAuthParameter; -//#if (CONFIG_MMS_SUPPORT_TLS == 1) +#if (CONFIG_MMS_SUPPORT_TLS == 1) TLSConfiguration tlsConfiguration; -//#endif +#endif const char* hostname; int tcpPort; @@ -154,7 +154,7 @@ typedef struct sIsoConnectionParameters* IsoConnectionParameters; * NOTE: This function used internally by the MMS client library. When using the MMS or IEC 61850 API * there should be no reason for the user to call this function. * - * \return new IsoConnectionParameters instanceextern "C" { + * \return new IsoConnectionParameters */ IsoConnectionParameters IsoConnectionParameters_create(void); diff --git a/src/mms/inc/mms_common.h b/src/mms/inc/mms_common.h index 0c3832e5..59d172b4 100644 --- a/src/mms/inc/mms_common.h +++ b/src/mms/inc/mms_common.h @@ -155,12 +155,17 @@ typedef struct typedef struct sMmsNamedVariableList* MmsNamedVariableList; typedef struct sMmsAccessSpecifier* MmsNamedVariableListEntry; - +/** + * \brief ITU (International Telecommunication Union) object identifier (OID) + */ typedef struct { uint16_t arc[10]; int arcCount; } ItuObjectIdentifier; +/** + * \brief ISO application reference (specifies an ISO application endpoint) + */ typedef struct { ItuObjectIdentifier apTitle; int aeQualifier; diff --git a/src/mms/iso_common/iso_connection_parameters.c b/src/mms/iso_common/iso_connection_parameters.c index 07d343fb..912b10fd 100644 --- a/src/mms/iso_common/iso_connection_parameters.c +++ b/src/mms/iso_common/iso_connection_parameters.c @@ -81,9 +81,9 @@ IsoConnectionParameters_destroy(IsoConnectionParameters self) void IsoConnectionParameters_setTlsConfiguration(IsoConnectionParameters self, TLSConfiguration tlsConfig) { -//#if (CONFIG_MMS_SUPPORT_TLS == 1) +#if (CONFIG_MMS_SUPPORT_TLS == 1) self->tlsConfiguration = tlsConfig; -//#endif +#endif } diff --git a/src/mms/iso_mms/client/mms_client_connection.c b/src/mms/iso_mms/client/mms_client_connection.c index 67592ffa..dbab9435 100644 --- a/src/mms/iso_mms/client/mms_client_connection.c +++ b/src/mms/iso_mms/client/mms_client_connection.c @@ -1206,10 +1206,14 @@ bool MmsConnection_connect(MmsConnection self, MmsError* mmsError, const char* serverName, int serverPort) { if (serverPort == -1) { +#if (CONFIG_MMS_SUPPORT_TLS == 1) if (self->isoParameters->tlsConfiguration) serverPort = 3782; else serverPort = 102; +#else + serverPort = 102; +#endif } IsoConnectionParameters_setTcpParameters(self->isoParameters, serverName, serverPort);