Skip to content

Commit

Permalink
Various updates in preparation for release 0.7.
Browse files Browse the repository at this point in the history
  • Loading branch information
riclolsen committed Feb 25, 2021
1 parent 4d5c032 commit da28a76
Show file tree
Hide file tree
Showing 23 changed files with 3,008 additions and 1,702 deletions.
22 changes: 14 additions & 8 deletions conf-templates/Opc.Ua.DefaultClient.Config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,20 @@
schemaLocation="./Schema/ApplicationConfiguration.xsd"
>
<ApplicationName>JSON-SCADA OPC-UA Client</ApplicationName>
<ApplicationUri>urn:localhost:json-scada:OPCUAClient</ApplicationUri>
<ApplicationUri>urn:localhost:OPCUA:JSON_SCADA_OPCUAClient</ApplicationUri>
<ProductUri>http://json-scada.org/UA/ClientDriver</ProductUri>
<ApplicationType>Client_1</ApplicationType>

<SecurityConfiguration>

<!-- Where the application instance certificate is stored (MachineDefault) -->
<ApplicationCertificate>
<StoreType>X509Store</StoreType>
<StorePath>CurrentUser\My</StorePath>
<SubjectName>CN=UA Core Sample Client, C=US, S=Arizona, O=OPC Foundation, DC=localhost</SubjectName>
</ApplicationCertificate>


<ApplicationCertificate>
<StoreType>Directory</StoreType>
<StorePath>%LocalApplicationData%/OPC Foundation/pki/own</StorePath>
<SubjectName>CN=JSON-SCADA OPC-UA Client, C=US, S=Arizona, O=OPC Foundation, DC=localhost</SubjectName>
</ApplicationCertificate>

<!-- Where the issuer certificate are stored (certificate authorities) -->
<TrustedIssuerCertificates>
<StoreType>Directory</StoreType>
Expand All @@ -40,8 +41,13 @@
for easy debugging purposes ONLY and turned off for production deployments! -->
<AutoAcceptUntrustedCertificates>true</AutoAcceptUntrustedCertificates>

</SecurityConfiguration>
<!-- WARNING: SHA1 signed certficates are by default rejected and should be phased out.-->
<RejectSHA1SignedCertificates>false</RejectSHA1SignedCertificates>
<MinimumCertificateKeySize>1024</MinimumCertificateKeySize>

</SecurityConfiguration>


<TransportConfigurations/>

<TransportQuotas>
Expand Down
13 changes: 7 additions & 6 deletions conf/Opc.Ua.DefaultClient.Config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@
<SecurityConfiguration>

<!-- Where the application instance certificate is stored (MachineDefault) -->
<ApplicationCertificate>
<StoreType>X509Store</StoreType>
<StorePath>CurrentUser\My</StorePath>
<SubjectName>CN=UA Core Sample Client, C=US, S=Arizona, O=OPC Foundation, DC=localhost</SubjectName>
</ApplicationCertificate>


<ApplicationCertificate>
<StoreType>Directory</StoreType>
<StorePath>%LocalApplicationData%/OPC Foundation/pki/own</StorePath>
<SubjectName>CN=JSON-SCADA OPC-UA Client, C=US, S=Arizona, O=OPC Foundation, DC=localhost</SubjectName>
</ApplicationCertificate>

<!-- Where the issuer certificate are stored (certificate authorities) -->
<TrustedIssuerCertificates>
<StoreType>Directory</StoreType>
Expand Down
1 change: 1 addition & 0 deletions demo-docker/mongo_seed/files/demo_connections.json
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
{"_id":{"$oid":"5f108e3e3d8adfd3eccb206e"},"protocolDriver":"IEC60870-5-104_SERVER","protocolDriverInstanceNumber":1.0,"protocolConnectionNumber":1001.0,"name":"IEC104DIST","description":"Demo distribution of IEC 104","enabled":true,"commandsEnabled":true,"ipAddressLocalBind":"0.0.0.0:2404","ipAddresses":[],"localLinkAddress":1.0,"remoteLinkAddress":2.0,"giInterval":null,"testCommandInterval":0.0,"timeSyncInterval":0.0,"sizeOfCOT":2.0,"sizeOfCA":2.0,"sizeOfIOA":3.0,"k":12.0,"w":8.0,"t0":10.0,"t1":15.0,"t2":10.0,"t3":20.0,"serverModeMultiActive":true,"maxClientConnections":20.0,"maxQueueSize":5000.0}
{"_id":{"$oid":"5f1090143d8adfd3eccb206f"},"protocolDriver":"IEC60870-5-104","protocolDriverInstanceNumber":1.0,"protocolConnectionNumber":61.0,"name":"IEC104DEMO","description":"Demo via IEC60870-5-104","enabled":true,"commandsEnabled":true,"ipAddressLocalBind":"","ipAddresses":["207.180.242.96:2404"],"localLinkAddress":2.0,"remoteLinkAddress":1.0,"giInterval":250.0,"testCommandInterval":60.0,"timeSyncInterval":650.0,"sizeOfCOT":2.0,"sizeOfCA":2.0,"sizeOfIOA":3.0,"k":12.0,"w":8.0,"t0":10.0,"t1":15.0,"t2":10.0,"t3":20.0}
{"_id":{"$oid":"5ff3512268d80d68205b403f"},"protocolDriver":"OPC-UA","protocolDriverInstanceNumber":1,"protocolConnectionNumber":1003,"name":"OPCClient1","description":"OPC Client 1","enabled":true,"commandsEnabled":true,"stats":{"nodeName":"mainNode","timeTag":{"$date":"2021-02-23T10:54:54.433Z"}},"endpointURLs":["opc.tcp://opcua.demo-this.com:51210/UA/SampleServer"],"configFileName":"c:\\json-scada\\conf\\Opc.Ua.DefaultClient.Config.xml","autoCreateTags":true,"useSecurity":false}
1 change: 1 addition & 0 deletions demo-docker/mongo_seed/files/demo_instances.json
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
{"_id":{"$oid":"5f05e02bbdf73ca11a22bc91"},"protocolDriver":"IEC60870-5-104","protocolDriverInstanceNumber":1.0,"enabled":true,"logLevel":1.0,"nodeNames":["mainNode"],"activeNodeName":"mainNode","activeNodeKeepAliveTimeTag":{"$date":"2020-07-24T14:21:01.736Z"},"keepProtocolRunningWhileInactive":false}
{"_id":{"$oid":"5f1057663d8adfd3eccb206b"},"protocolDriver":"IEC60870-5-104_SERVER","protocolDriverInstanceNumber":1.0,"enabled":true,"logLevel":1.0,"nodeNames":["mainNode"],"activeNodeName":"mainNode","activeNodeKeepAliveTimeTag":{"$date":"2020-07-16T13:34:30.869Z"},"keepProtocolRunningWhileInactive":false}
{"_id":{"$oid":"5fe33f4817755e4c4c5e3cfa"},"protocolDriver":"OPC-UA","protocolDriverInstanceNumber":1,"enabled":true,"logLevel":1,"nodeNames":["mainNode"],"keepProtocolRunningWhileInactive":false,"activeNodeKeepAliveTimeTag":{"$date":"2021-02-23T10:54:54.429Z"},"activeNodeName":"mainNode"}
4 changes: 3 additions & 1 deletion sql/create_tables.sql
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ comment on column hist.flags is 'Bit mask 0x80=value invalid, 0x40=Time tag at s
-- timescaledb hypertable, partitioned by day
SELECT create_hypertable('hist', 'time_tag', chunk_time_interval=>86400000000);
-- data retention policy (older data will be deleted)
SELECT add_drop_chunks_policy('hist', INTERVAL '45 days');

-- SELECT add_drop_chunks_policy('hist', INTERVAL '45 days'); -- this is for timescaledb < 2.0
SELECT add_retention_policy('hist', INTERVAL '45 days');

-- DROP TABLE realtime_data;
CREATE TABLE IF NOT EXISTS realtime_data (
Expand Down
103 changes: 69 additions & 34 deletions src/OPC-UA-Client/AsduReceiveHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,60 +110,92 @@ public void Run()

private async Task ConsoleClient()
{
Log(conn_name + " - " + "Create an Application Configuration.");
Log(conn_name + " - " + "Create an Application Configuration...");
exitCode = ExitCode.ErrorCreateApplication;

ApplicationInstance application = new ApplicationInstance
{
ApplicationName = "JSON-SCADA OPC-UA Client",
ApplicationType = ApplicationType.Client,
ConfigSectionName = ""
ConfigSectionName = "",
};

// load the application configuration.
ApplicationConfiguration config = await application.LoadApplicationConfiguration(OPCUA_conn.configFileName, false);
config.SecurityConfiguration.AutoAcceptUntrustedCertificates = true;
bool haveAppCertificate = false;
ApplicationConfiguration config = null;

// check the application certificate.
bool haveAppCertificate = await application.CheckApplicationInstanceCertificate(false, 0);

if (!haveAppCertificate)
try
{
throw new Exception("Application instance certificate invalid!");
}
// load the application configuration.
Log(conn_name + " - " + "Load config from " + OPCUA_conn.configFileName);
config = await application.LoadApplicationConfiguration(OPCUA_conn.configFileName, false);
// config.SecurityConfiguration.AutoAcceptUntrustedCertificates = true;

if (haveAppCertificate)
{
config.ApplicationUri = X509Utils.GetApplicationUriFromCertificate(config.SecurityConfiguration.ApplicationCertificate.Certificate);
if (config.SecurityConfiguration.AutoAcceptUntrustedCertificates)
// check the application certificate.
haveAppCertificate = await application.CheckApplicationInstanceCertificate(false, 0);

if (!haveAppCertificate)
{
Log(conn_name + " - " + "FATAL: Application instance certificate invalid!", LogLevelNoLog);
Environment.Exit(1);
}

if (haveAppCertificate)
{
autoAccept = true;
config.ApplicationUri = X509Utils.GetApplicationUriFromCertificate(config.SecurityConfiguration.ApplicationCertificate.Certificate);
if (config.SecurityConfiguration.AutoAcceptUntrustedCertificates)
{
autoAccept = true;
}
config.CertificateValidator.CertificateValidation += new CertificateValidationEventHandler(CertificateValidator_CertificateValidation);
}
else
{
Log(conn_name + " - " + "WARN: missing application certificate, using unsecure connection.");
}
config.CertificateValidator.CertificateValidation += new CertificateValidationEventHandler(CertificateValidator_CertificateValidation);
}
else
catch (Exception e)
{
Log(conn_name + " - " + "WARN: missing application certificate, using unsecure connection.");
Log(conn_name + " - WARN: " + e.Message);
}

Log(conn_name + " - " + "Discover endpoints of " + OPCUA_conn.endpointURLs[0]);
exitCode = ExitCode.ErrorDiscoverEndpoints;
var selectedEndpoint = CoreClientUtils.SelectEndpoint(OPCUA_conn.endpointURLs[0], haveAppCertificate && OPCUA_conn.useSecurity, 15000);
Log(conn_name + " - " + "Selected endpoint uses: " +
selectedEndpoint.SecurityPolicyUri.Substring(selectedEndpoint.SecurityPolicyUri.LastIndexOf('#') + 1));
if (config == null)
{
Log(conn_name + " - " + "FATAL: error in XML config file!", LogLevelNoLog);
Environment.Exit(1);
}

try
{
Log(conn_name + " - " + "Discover endpoints of " + OPCUA_conn.endpointURLs[0]);
exitCode = ExitCode.ErrorDiscoverEndpoints;
var selectedEndpoint = CoreClientUtils.SelectEndpoint(OPCUA_conn.endpointURLs[0], haveAppCertificate && OPCUA_conn.useSecurity, 15000);
Log(conn_name + " - " + "Selected endpoint uses: " +
selectedEndpoint.SecurityPolicyUri.Substring(selectedEndpoint.SecurityPolicyUri.LastIndexOf('#') + 1));

Log(conn_name + " - " + "Create a session with OPC UA server.");
exitCode = ExitCode.ErrorCreateSession;
var endpointConfiguration = EndpointConfiguration.Create(config);
var endpoint = new ConfiguredEndpoint(null, selectedEndpoint, endpointConfiguration);
Log(conn_name + " - " + "Create a session with OPC UA server.");
exitCode = ExitCode.ErrorCreateSession;
var endpointConfiguration = EndpointConfiguration.Create(config);
var endpoint = new ConfiguredEndpoint(null, selectedEndpoint, endpointConfiguration);

await Task.Delay(50);
session = await Session.Create(config, endpoint, false, "OPC UA Console Client", 60000, new UserIdentity(new AnonymousIdentityToken()), null);
// Log("" + session.KeepAliveInterval); // default is 5000
session.KeepAliveInterval = System.Convert.ToInt32(OPCUA_conn.timeoutMs);
await Task.Delay(50);
session = await Session.Create(config, endpoint, false, "OPC UA Console Client", 60000, new UserIdentity(new AnonymousIdentityToken()), null);

// register keep alive handler
session.KeepAlive += Client_KeepAlive;
// Log("" + session.KeepAliveInterval); // default is 5000
session.KeepAliveInterval = System.Convert.ToInt32(OPCUA_conn.timeoutMs);

// register keep alive handler
session.KeepAlive += Client_KeepAlive;
}
catch (Exception e)
{
Log(conn_name + " - WARN: " + e.Message);
}

if (session == null)
{
Log(conn_name + " - " + "FATAL: error creating session!", LogLevelNoLog);
Environment.Exit(1);
}

Log(conn_name + " - " + "Browsing the OPC UA server namespace.");
exitCode = ExitCode.ErrorBrowseNamespace;
Expand Down Expand Up @@ -204,6 +236,9 @@ private async Task ConsoleClient()
}
private async Task FindObjects(Opc.Ua.Client.Session session, NodeId nodeid)
{
if (session == null)
return;

try
{
ReferenceDescriptionCollection references;
Expand Down
1 change: 1 addition & 0 deletions src/OPC-UA-Client/OPC-UA-Client.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="MongoDB.Bson" Version="2.11.6" />
<PackageReference Include="MongoDB.Driver" Version="2.11.6" />
<PackageReference Include="Mono.Options" Version="6.6.0.161" />
<PackageReference Include="OPCFoundation.NetStandard.Opc.Ua.Client" Version="1.4.365.23" />
Expand Down
12 changes: 6 additions & 6 deletions src/alarm_beep/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/alarm_beep/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@
"dependencies": {
"a1-beep": "^1.2.1",
"fs": "0.0.1-security",
"mongodb": "^3.6.3"
"mongodb": "^3.6.4"
}
}
12 changes: 6 additions & 6 deletions src/grafana_alert2event/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/grafana_alert2event/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"dependencies": {
"express": "^4.17.1",
"fs": "0.0.1-security",
"mongodb": "^3.6.3",
"mongodb": "^3.6.4",
"queue-fifo": "^0.2.6"
}
}
Loading

0 comments on commit da28a76

Please sign in to comment.