Skip to content

Commit cb9f327

Browse files
authored
Merge pull request #170 from json-scada/master
Update libiec61850, add TLS to iec61850 client driver
2 parents 0fce397 + 55a7de3 commit cb9f327

File tree

2,153 files changed

+982785
-9992
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

2,153 files changed

+982785
-9992
lines changed

bin/README.md

-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
11
# Bin Folder
22

33
Here should be installed the compiled binaries for the system.
4-
5-
6-

compile-docker/docker-compose.yaml

+9-5
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,16 @@ services:
3333
cd /src/libplctag/libplctag.NET/src/libplctag &&
3434
rm -rf obj bin &&
3535
apt-get update &&
36-
apt-get -y install gcc make &&
36+
apt-get -y install build-essential cmake &&
3737
cd /src/libiec61850 &&
38+
mkdir -p build &&
39+
cd build &&
40+
cmake .. &&
3841
make &&
39-
make install &&
40-
cd dotnet/core/2.0 &&
41-
dotnet publish --no-self-contained --runtime linux-x64 -c Release IEC61850.NET.core.2.0 &&
42-
cd iec61850_client &&
42+
cp src/libiec61850.so src/libiec61850.so.1.6.0 /publish_bin/ &&
43+
cd ../dotnet/core/2.0/IEC61850.NET.core.2.0 &&
44+
dotnet publish --no-self-contained --runtime linux-x64 -c Release &&
45+
cd /src/iec61850_client &&
4346
dotnet publish --no-self-contained --runtime linux-x64 -p:PublishReadyToRun=true -c Release -o /publish_bin/ &&
4447
rm -rf obj bin &&
4548
cd /src/libiec61850/dotnet/core/2.0/IEC61850.NET.core.2.0/ &&
@@ -50,6 +53,7 @@ services:
5053
- DOTNET_CLI_TELEMETRY_OPTOUT=1
5154
#command: tail -f /dev/null
5255
volumes:
56+
- ../src/iec61850_client:/src/iec61850_client
5357
- ../src/libiec61850:/src/libiec61850
5458
- ../src/lib60870.netcore:/src/lib60870.netcore
5559
- ../src/OPC-UA-Client:/src/OPC-UA-Client

platform-linux/build.sh

+9-8
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,17 @@ cd src/dnp3/Dnp3Client
2121
dotnet publish --self-contained --runtime win-x64 -p:PublishReadyToRun=true -c Release -o ../../../bin-wine/ Dnp3Client.csproj
2222

2323
cd ../../libiec61850
24+
mkdir build
25+
cd build
26+
cmake ..
2427
make
25-
make install
26-
cd dotnet/core/2.0
27-
dotnet publish --no-self-contained --runtime $ARG1 -c Release IEC61850.NET.core.2.0
28-
cd iec61850_client
29-
dotnet publish --no-self-contained --runtime $ARG1 -p:PublishReadyToRun=true -c Release -o ../../../../../../bin/
28+
cp src/libiec61850.so src/libiec61850.so.1.6.0 ../../../bin/
29+
cd ../dotnet/core/2.0/IEC61850.NET.core.2.0
30+
dotnet publish --no-self-contained --runtime $ARG1 -c Release
31+
cd ../../../../../iec61850_client
32+
dotnet publish --no-self-contained --runtime $ARG1 -p:PublishReadyToRun=true -c Release -o ../../bin/
3033

31-
cd ../../../../../lib60870.netcore
34+
cd ../lib60870.netcore
3235
dotnet publish --no-self-contained --runtime $ARG1 -p:PublishReadyToRun=true -c Release -o ../../bin/
3336

3437
cd ../OPC-UA-Client
@@ -68,8 +71,6 @@ cd ../grafana_alert2event
6871
npm install
6972
cd ../demo_simul
7073
npm install
71-
cd ../server_realtime
72-
npm install
7374
cd ../server_realtime_auth
7475
npm install
7576
cd ../updateUser

platform-mac/build.sh

+9-8
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,17 @@ cd src/dnp3/Dnp3Client
1919
dotnet publish --self-contained --runtime win-x64 -p:PublishReadyToRun=true -c Release -o ../../../bin-wine/ Dnp3Client.csproj
2020

2121
cd ../../libiec61850
22+
mkdir build
23+
cd build
24+
cmake ..
2225
make
23-
make install
24-
cd dotnet/core/2.0
25-
dotnet publish --no-self-contained --runtime $ARG1 -c Release IEC61850.NET.core.2.0
26-
cd iec61850_client
27-
dotnet publish --no-self-contained --runtime $ARG1 -p:PublishReadyToRun=true -c Release -o ../../../../../../bin/
26+
cp src/libiec61850.so src/libiec61850.so.1.6.0 ../../../bin/
27+
cd ../dotnet/core/2.0/IEC61850.NET.core.2.0
28+
dotnet publish --no-self-contained --runtime $ARG1 -c Release
29+
cd ../../../../../iec61850_client
30+
dotnet publish --no-self-contained --runtime $ARG1 -p:PublishReadyToRun=true -c Release -o ../../bin/
2831

29-
cd ../../../../../lib60870.netcore
32+
cd ../lib60870.netcore
3033
dotnet publish --no-self-contained --runtime $ARG1 -p:PublishReadyToRun=true -c Release -o ../../bin/
3134

3235
cd ../OPC-UA-Client
@@ -58,8 +61,6 @@ cd ../grafana_alert2event
5861
npm install
5962
cd ../demo_simul
6063
npm install
61-
cd ../server_realtime
62-
npm install
6364
cd ../server_realtime_auth
6465
npm install
6566
cd ../updateUser

platform-rhel9/json-scada-install-aarch64.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ sudo subscription-manager repos --enable codeready-builder-for-rhel-9-$(arch)-rp
2626
sudo dnf -y install https://dl.fedoraproject.org/pub/epel/epel-release-latest-9.noarch.rpm
2727
sudo dnf -y install epel-release
2828
sudo dnf config-manager --set-enabled crb
29-
sudo dnf -y install tar vim nano nginx wget chkconfig dotnet-sdk-8.0 java-21-openjdk php curl
29+
sudo dnf -y install tar vim nano nginx wget chkconfig dotnet-sdk-8.0 java-21-openjdk php curl cmake
3030
sudo dnf -y install libpcap-devel
3131

3232
# to compile inkscape

platform-rhel9/json-scada-install.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ sudo subscription-manager repos --enable codeready-builder-for-rhel-9-$(arch)-rp
2626
sudo dnf -y install https://dl.fedoraproject.org/pub/epel/epel-release-latest-9.noarch.rpm
2727
sudo dnf -y install epel-release
2828
sudo dnf config-manager --set-enabled crb
29-
sudo dnf -y install tar vim nano nginx wget chkconfig dotnet-sdk-8.0 java-21-openjdk php curl
29+
sudo dnf -y install tar vim nano nginx wget chkconfig dotnet-sdk-8.0 java-21-openjdk php curl cmake
3030
sudo dnf -y install libpcap-devel
3131

3232
# docker/podman can be used to run DNP3 and OPC-DA on linux

platform-windows/build.bat

+12-3
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,28 @@ copy %SRCPATH%\dnp3\Dnp3Client\Dependencies\OpenSSL\*.dll %BINPATH% /y
1818

1919
set DOTNET_CLI_TELEMETRY_OPTOUT=1
2020

21-
cd %SRCPATH%\libiec61850\build
21+
cd %SRCPATH%\libiec61850
22+
rem mkdir build
23+
cd build
24+
rem Run the line below to create solution file for Visual Studio 2022
25+
rem cmake -G "Visual Studio 17 2022" .. -A x64 -DCMAKE_SUPPRESS_REGENERATION=ON
26+
msbuild libiec61850.sln /p:Configuration=Release
27+
28+
rem cd %SRCPATH%\libiec61850\build
2229
rem set VCTargetsPath=C:\ProgramFiles\Microsoft Visual Studio\2022\Community\MSBuild\Microsoft\VC\v170\
2330
rem set VCTargetsPath=D:\ProgramFiles\Microsoft Visual Studio\2022\Community\MSBuild\Microsoft\VC\v170\
31+
rem set VCTargetsPath=C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\MSBuild\Microsoft\VC\v170\
2432
rem set VCToolsInstallDir=D:\ProgramFiles\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.40.33807\
33+
rem set VCToolsInstallDir=C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC\14.41.34120\
2534
rem dotnet clean -c Release libiec61850.sln
35+
rem dotnet publish --no-self-contained --runtime win-x64 -c Release libiec61850.sln
2636

27-
dotnet publish --no-self-contained --runtime win-x64 -c Release libiec61850.sln
2837
copy %SRCPATH%\libiec61850\build\src\Release\iec61850.dll %BINPATH%
2938

3039
cd %SRCPATH%\libiec61850\dotnet\core\2.0\
3140
dotnet publish --no-self-contained --runtime win-x64 -c Release -o %BINPATH% IEC61850.NET.core.2.0
3241

33-
cd %SRCPATH%\libiec61850\dotnet\core\2.0\iec61850_client
42+
cd %SRCPATH%\iec61850_client
3443
dotnet publish --no-self-contained --runtime win-x64 -p:PublishReadyToRun=true -c Release -o %BINPATH%
3544

3645
cd %SRCPATH%\lib60870.netcore\lib60870.netcore\

platform-windows/buildupd.bat

+15-6
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,28 @@ copy %SRCPATH%\dnp3\Dnp3Client\Dependencies\OpenSSL\*.dll %BINPATH% /y
1818

1919
set DOTNET_CLI_TELEMETRY_OPTOUT=1
2020

21-
cd %SRCPATH%\libiec61850\build
22-
rem set VCTargetsPath="C:\ProgramFiles\Microsoft Visual Studio\2022\Community\MSBuild\Microsoft\VC\v170\"
23-
rem set VCTargetsPath="D:\ProgramFiles\Microsoft Visual Studio\2022\Community\MSBuild\Microsoft\VC\v170\"
24-
rem set VCToolsInstallDir="D:\ProgramFiles\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.39.33519\"
21+
cd %SRCPATH%\libiec61850
22+
rem mkdir build
23+
cd build
24+
rem Run the line below to create solution file for Visual Studio 2022
25+
rem cmake -G "Visual Studio 17 2022" .. -A x64 -DCMAKE_SUPPRESS_REGENERATION=ON
26+
msbuild libiec61850.sln /p:Configuration=Release
27+
28+
rem cd %SRCPATH%\libiec61850\build
29+
rem set VCTargetsPath=C:\ProgramFiles\Microsoft Visual Studio\2022\Community\MSBuild\Microsoft\VC\v170\
30+
rem set VCTargetsPath=D:\ProgramFiles\Microsoft Visual Studio\2022\Community\MSBuild\Microsoft\VC\v170\
31+
rem set VCTargetsPath=C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\MSBuild\Microsoft\VC\v170\
32+
rem set VCToolsInstallDir=D:\ProgramFiles\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.40.33807\
33+
rem set VCToolsInstallDir=C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC\14.41.34120\
2534
rem dotnet clean -c Release libiec61850.sln
35+
rem dotnet publish --no-self-contained --runtime win-x64 -c Release libiec61850.sln
2636

27-
dotnet publish --no-self-contained --runtime win-x64 -c Release libiec61850.sln
2837
copy %SRCPATH%\libiec61850\build\src\Release\iec61850.dll %BINPATH%
2938

3039
cd %SRCPATH%\libiec61850\dotnet\core\2.0\
3140
dotnet publish --no-self-contained --runtime win-x64 -c Release -o %BINPATH% IEC61850.NET.core.2.0
3241

33-
cd %SRCPATH%\libiec61850\dotnet\core\2.0\iec61850_client
42+
cd %SRCPATH%\iec61850_client
3443
dotnet publish --no-self-contained --runtime win-x64 -p:PublishReadyToRun=true -c Release -o %BINPATH%
3544

3645
cd %SRCPATH%\lib60870.netcore\lib60870.netcore\

src/OPC-UA-Client/OPC-UA-Client.csproj

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
<PackageReference Include="Mono.Options" Version="6.12.0.148" />
1313
<PackageReference Include="OPCFoundation.NetStandard.Opc.Ua.Client" Version="1.5.374.78" />
1414
<PackageReference Include="OPCFoundation.NetStandard.Opc.Ua.Configuration" Version="1.5.374.78" />
15+
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.1" />
1516
</ItemGroup>
1617

1718
</Project>

src/libiec61850/dotnet/core/2.0/iec61850_client/AsduReceiveHandler.cs src/iec61850_client/AsduReceiveHandler.cs

+50-6
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,11 @@
2222
using System.Threading;
2323
using System.Globalization;
2424
using System.Linq;
25+
using System.Security.Cryptography.X509Certificates;
2526
using IEC61850.Client;
2627
using IEC61850.Common;
28+
using IEC61850.TLS;
29+
using System.Net.Security;
2730

2831
namespace IEC61850_Client
2932
{
@@ -597,16 +600,54 @@ static void Process(Iec61850Connection srv)
597600
}
598601
else
599602
{
600-
IedConnection con = new IedConnection();
603+
IedConnection con = null;
601604
try
602605
{
606+
if (srv.useSecurity)
607+
{
608+
Log(srv.name + " Using TLS");
609+
TLSConfiguration tlsConfig = new TLSConfiguration();
610+
if (srv.localCertFilePath.Trim() != "")
611+
tlsConfig.SetOwnCertificate(new X509Certificate2(srv.localCertFilePath));
612+
if (srv.privateKeyFilePath.Trim() != "")
613+
tlsConfig.SetOwnKey(srv.privateKeyFilePath, null);
614+
foreach (var peerCertFilePath in srv.peerCertFilesPaths)
615+
tlsConfig.AddAllowedCertificate(new X509Certificate2(peerCertFilePath));
616+
// Add a CA certificate to check the certificate provided by the server - not required when ChainValidation == false
617+
if (srv.rootCertFilePath.Trim() != "")
618+
tlsConfig.AddCACertificate(new X509Certificate2(srv.rootCertFilePath));
619+
// Check if the certificate is signed by a provided CA
620+
tlsConfig.ChainValidation = srv.chainValidation;
621+
// Check that the shown server certificate is in the list of allowed certificates
622+
tlsConfig.AllowOnlyKnownCertificates = srv.allowOnlySpecificCertificates;
623+
tlsConfig.SetMinTlsVersion(TLSConfigVersion.TLS_1_0);
624+
tlsConfig.SetMaxTlsVersion(TLSConfigVersion.TLS_1_3);
625+
if (!srv.allowTLSv10)
626+
tlsConfig.SetMinTlsVersion(TLSConfigVersion.TLS_1_1);
627+
if (srv.allowTLSv11)
628+
tlsConfig.SetMaxTlsVersion(TLSConfigVersion.TLS_1_1);
629+
else
630+
tlsConfig.SetMinTlsVersion(TLSConfigVersion.TLS_1_2);
631+
if (srv.allowTLSv12)
632+
tlsConfig.SetMaxTlsVersion(TLSConfigVersion.TLS_1_2);
633+
else
634+
tlsConfig.SetMinTlsVersion(TLSConfigVersion.TLS_1_3);
635+
if (srv.allowTLSv13)
636+
tlsConfig.SetMaxTlsVersion(TLSConfigVersion.TLS_1_3);
637+
con = new IedConnection(tlsConfig);
638+
}
639+
else
640+
{
641+
con = new IedConnection();
642+
}
643+
603644
if (srv.password != "")
604645
{
605646
IsoConnectionParameters parameters = con.GetConnectionParameters();
606647
parameters.UsePasswordAuthentication(srv.password);
607648
}
608649

609-
Log("Connect to " + srv.name);
650+
Log(srv.name + " Connecting to " + srv.ipAddresses[0]);
610651
var tcpPort = 102;
611652
string[] ipAddrPort = srv.ipAddresses[0].Split(':');
612653
if (ipAddrPort.Length > 1)
@@ -1048,10 +1089,13 @@ static void Process(Iec61850Connection srv)
10481089
Log(e);
10491090
else
10501091
Log(e.Message);
1051-
if (con.GetState() == IedConnectionState.IED_STATE_CONNECTED)
1052-
con.Abort();
1053-
con.Dispose();
1054-
con = null;
1092+
if (con != null)
1093+
{
1094+
if (con.GetState() == IedConnectionState.IED_STATE_CONNECTED)
1095+
con.Abort();
1096+
con.Dispose();
1097+
con = null;
1098+
}
10551099
Thread.Sleep(5000);
10561100
}
10571101
}

src/libiec61850/dotnet/core/2.0/iec61850_client/Main.cs src/iec61850_client/Main.cs

+4-5
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,13 @@ partial class MainClass
3535
{
3636
public static String CopyrightMessage = "{json:scada} IEC61850 Client Driver - Copyright 2023 - 2024 Ricardo Olsen";
3737
public static String ProtocolDriverName = "IEC61850";
38-
public static String DriverVersion = "0.1.8";
38+
public static String DriverVersion = "0.2.0";
3939
public static bool Active = false; // indicates this driver instance is the active node in the moment
4040
public static Int32 DataBufferLimit = 20000; // limit to start dequeuing and discarding data from the acquisition buffer
4141
public static Int32 BulkWriteLimit = 1250; // limit of each bulk write to mongodb
4242

4343
public static void Main(string[] args)
4444
{
45-
// var browse = false;
46-
4745
CultureInfo ci = new CultureInfo("en-US");
4846
Thread.CurrentThread.CurrentCulture = ci;
4947
Thread.CurrentThread.CurrentUICulture = ci;
@@ -60,8 +58,9 @@ public static void Main(string[] args)
6058
bool res = int.TryParse(args[1], out num);
6159
if (res) LogLevel = num;
6260
}
63-
Log(CopyrightMessage + " Version " + DriverVersion);
64-
Log("Using libiec61850 v" + LibIEC61850.GetVersionString());
61+
Log(CopyrightMessage);
62+
Log("Driver version " + DriverVersion);
63+
Log("Using libiec61850 version " + LibIEC61850.GetVersionString());
6564
Log("Log level: " + LogLevel);
6665

6766
string fname = JsonConfigFilePath;

src/libiec61850/dotnet/core/2.0/iec61850_client/iec61850_client.csproj src/iec61850_client/iec61850_client.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
</ItemGroup>
1212

1313
<ItemGroup>
14-
<ProjectReference Include="..\IEC61850.NET.core.2.0\IEC61850.NET.core.2.0.csproj" />
14+
<ProjectReference Include="..\libiec61850\dotnet\core\2.0\IEC61850.NET.core.2.0\IEC61850.NET.core.2.0.csproj" />
1515
</ItemGroup>
1616

1717
</Project>
+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.5.002.0
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "iec61850_client", "iec61850_client.csproj", "{FDD5BF4C-41EE-4C9E-B76C-8ADC8AB2D237}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{FDD5BF4C-41EE-4C9E-B76C-8ADC8AB2D237}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{FDD5BF4C-41EE-4C9E-B76C-8ADC8AB2D237}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{FDD5BF4C-41EE-4C9E-B76C-8ADC8AB2D237}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{FDD5BF4C-41EE-4C9E-B76C-8ADC8AB2D237}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
GlobalSection(ExtensibilityGlobals) = postSolution
23+
SolutionGuid = {596C5E25-19FF-42F0-A7F4-35F89908A3B7}
24+
EndGlobalSection
25+
EndGlobal

src/libiec61850/.gitignore

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
build/
2+
/Debug/
3+
third_party/mbedtls
4+
third_party/winpcap
5+
third_party/sqlite

0 commit comments

Comments
 (0)