Commit Graph

690 Commits

Author SHA1 Message Date
Martin Regen 613e1d27cf Fix nodestate remove for diagnostic infos (#2450) (#2456)
revert fix for regression introduced by fix for #2343, apply fix in nodemanagers which do not invert the inverse property, so bidirectional references were not removed.
2024-01-15 05:26:32 +01:00
Martin Regen 490d85cb4a Make CertStoreIdentifier.GetCertificateStoreTypeByName and RegisteredStoreTypeNames public (#2429)
Allow to check if there is already a regsitration.
2023-12-14 20:31:21 +01:00
Martin Regen 626bdcb9b8 Fix potential deadlocks with WaitAsync on a SemaphoreSlim (#2415)
Fix cases where a cancellable WaitAsync(ct) on a SemaphoreSlim within a try/finally could end up in a deadlock.
Fix: The WaitAsync must be outside the try/finally block. if the WaitAsync is cancelled, it should not release the semaphore
2023-12-07 19:55:05 +01:00
dependabot[bot] 4697c40b86 Bump Microsoft.Extensions.Logging.Abstractions from 3.1.32 to 8.0.0 (#2388)
* Bump Microsoft.Extensions.Logging.Abstractions from 3.1.32 to 8.0.0

Bumps [Microsoft.Extensions.Logging.Abstractions](https://github.com/dotnet/runtime) from 3.1.32 to 8.0.0.
- [Release notes](https://github.com/dotnet/runtime/releases)
- [Commits](https://github.com/dotnet/runtime/commits/v8.0.0)

---
updated-dependencies:
- dependency-name: Microsoft.Extensions.Logging.Abstractions
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>

* Update UA Server Controls.csproj

* Update UA Client Controls.csproj

* Update Opc.Ua.Core.csproj

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Martin Regen <mregen@microsoft.com>
2023-12-07 19:53:54 +01:00
Martin Regen 343f7b0fbc Add custom test targets to the build process, support for .NET 8. (#2410)
The goal is to reduce the overall number of builds, stop using end of life platforms in the build pipeline and to support
build of future/deprecated build targets in a custom build step, which is also triggered weekly in the ci builds.

In addition:
- added a doc which describes the release and versioning strategy of this project
- produce the Nuget packges with .NET 8 assemblies.
- produce a Docker build based on a .NET 8 based container.
- add custom test targets to test outdated platforms. Need a manual step to enable for VS or command line.
- bug fixes: the latest move to an alternate crypto library for Bouncy Castle, which is only used for the GDS support and  .NET Framework 4.6.2./netstandard2.0, revealed already a few issues which were previously not found. 
- only .NET8/.NET6/.NET Framework 4.8 are tested in Pull requests. Remaining builds in weekly scheduled builds.
2023-12-07 12:03:37 +01:00
Martin Regen 8a2cf92710 SHA-1 signatures will no longer be trusted by default (#2406)
Since some distributions stop to trust SHA1 signatures by default, replace some internal algorithm checks with SHA256 versions.
The test case to force signature check also reenables ECC tests for .NET 4.8 which had been previously disabled.
2023-12-01 09:36:45 +01:00
Martin Regen 65803c4967 Implement async reconnect (#2399)
- Implement the reconnect and republish with async service calls. 

bug fixes:
- subscription Ids should start from a random number
- the keep alive interval calculation is too short, adding +1 for the timeout
- on BadSessionIdInvalid recreate session immediately 
- on a restarted server with new certificate, also reload endpoints when BadCertificateInvalid is returned
2023-11-30 21:02:51 +01:00
dependabot[bot] 1437138550 Bump System.Text.Encodings.Web from 6.0.0 to 8.0.0 (#2386)
Bumps [System.Text.Encodings.Web](https://github.com/dotnet/runtime) from 6.0.0 to 8.0.0.
- [Release notes](https://github.com/dotnet/runtime/releases)
- [Commits](https://github.com/dotnet/runtime/compare/v6.0.0...v8.0.0)

---
updated-dependencies:
- dependency-name: System.Text.Encodings.Web
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-11-30 20:09:14 +01:00
Martin Regen 9138bb90e0 Support for subclassing of client sessions, subscriptions and monitored items (#2384)
Currently, due to some internal cloning of sessions, subscriptions and monitored items it is not possible to use subclassed variants which are properly recreated after a session reconnect.

- Add a  `ISessionInstantiator` interface to allow to subclass a `Session` and override virtual function.
- Add a `Subscription.CloneSubscription` and `MonitoredItem.CloneMonitoredItem` virtual method to recreate those with event handlers and client handles.
- A sample implementation with `TestableXXX` classes is provided to test the BadInvalidTimestamp fix by injecting modified timestamps in the session class.
- Remove duplicate `IDisposable` with `Session`. `IClientBase` is disposable already.
- adds `knownTypes` parameter to `Session.Load` and `Session.Save` to support save and restore of custom Subscriptions and Monitored items.

bug fixes:
- IOP: an empty DataTypeDictionary throws an exception when loaded by the complex type system, server are allowed to leave it empty to save memory.
- BadInvalidTimestamp should not be returned when the timestamp in the requestheader is out of sync. #2364
2023-11-28 21:17:56 +01:00
Martin Regen a109c81d22 fix .NET 8 build and warning (#2395)
Fix some warnings and build errors with .NET 8. To build as .NET 8, add net8.0 to target.props.
2023-11-27 18:35:47 +01:00
Martin Regen 8d1a366631 Fix for references that may cause a memory leak (#2345)
Root cause: Target's IsInverse flag which has incorrect value is used during the removal of source's reference 
Fix: Retrieve the source's reference by the targetId first and remove it.
2023-11-17 17:36:03 +01:00
MarkusHorstmann eeea34f5a3 Array xmlns encoding/decoding always uses UA namespace(#2309)
XmlEncoder.WriteArray and XmlDecoder.ReadArray always use the OPC UA XML namespace (http://opcfoundation.org/UA/2008/02/Types.xsd) for the field element that contains the array, regardless of the namespace that the caller may have pushed.
2023-11-17 15:25:53 +01:00
Martin Regen 973d342b29 Implement the close async codepath (#2381)
- CloseAsync still used the 'Close' synchronous function
- remove a duplicate definition of IDisposable on ISession
- reduce the log output when the server publish time is out of sync
2023-11-17 14:41:26 +01:00
Martin Regen 4c0880c800 Fix codesmells. No functional changes and bug fixes. (#2368)
Fix many warnings to improve code quality or simplify the code.
2023-11-07 10:34:42 +01:00
Martin Regen 71ad9afd1c Nested complex types which contain structure derived from an abstract type are not correctly encoded (#2349)
- bug: if the nested complex type is derived from an abstract type like a Union, the decoder uses the abstract type instead of the actual type to decode
- fix: the loop to determine the supertype of the type to be decoded stops too early and returns an invalid type reference, e.g. for Unions. Instead the loop will now continue until a valid BuiltInType or a Structure or Enumeration type is found.
2023-10-26 11:06:26 +02:00
Martin Regen d47bc853da Various async improvements and minor issues found in IOP testing (#2346)
- improve various log messages, comments etc.
- multiple internal improvements in naming convention handling of async functions
- add FetchSuperTypesAsync
- replace new UTFEncoding() with Encoding.UTF8 singleton
2023-10-20 21:29:03 +02:00
Martin Regen ec4c3cd323 Add property to disable auto certificate creation on app startup (#2348)
- Add a property to `ApplicationInstance` to `DisableCertificateAutoCreation`
- Add the test case to validate property function
- Refactor some private API to follow coding style with `Async`suffix
- By default behavior is unchanged
2023-10-20 14:26:48 +02:00
Mikael Borg 49c8c00f5b .NET target 5.0 and 6.0 use 6.0 version of Microsoft.Extensions.Logging.Abstractions (#2335)
Referencing package OPCFoundation.NetStandard.Opc.Ua.Core from a .NET6 targeted project that in it self are using Microsoft.Extensions.Logging.Abstractions 6.0.4 will cause downgrade problems.

Instead for .NET6 targeted applications reference 6.0.x versions of Microsoft.Extensions.Logging.Abstractions.
2023-10-15 17:44:18 +02:00
tomaszras-intive 9f0f4c56ff Make CertificateValidationEventArgs and CertificateUpdateEventArgs constructors public (#2329)
Making these constructors public will unblock testing important scenarios.
2023-10-11 16:02:20 +02:00
Stefan Zschocke 88f2592962 Port to bouncycastle cryptography (#2315)
* Port to bouncycastle cryptography
* fix X509SignatureFactory.cs for latest bouncy castle
2023-09-26 20:41:49 +02:00
Marc Schier af04893a37 Fix degradation to sync calls in the SDK on main paths used. (#2316)
- make session create fully async incl. loading of the complex type system
2023-09-22 12:17:03 +02:00
Martin Regen 5af60ef6b6 Make async service call use awaitable, session open improvements (#2318)
- Improvements when many sessions need to be opened
- Introduce a OpenAsync version which usesmore async calls for session creation
- add async interfaces to cert validator 
- refactor lock of encodeable factory
- add a `EndAsync` property to WriteRequest to allow to await a service call
- add a `EndSendRequestAsync` method to allow implementation of awaitable service calls
2023-09-22 07:45:47 +02:00
Camille Guérin c75bf9be00 Removed extra unnecessary code and fixed use of userWriteMask (#2269)
- Removed extra unnecessary code in  CompareArray<T>
- Fixed userWriteMask in NodeState.cs
2023-08-25 14:48:28 +02:00
bhnaphade 4e6d58e1a4 Fix for 'BadTooManyOperations' in session.publish / 'BadServerHalted' when server is stopped. (#2277)
* Fixed status code when server is shutdown
* Add latest statuscodes from 1.05.03 to support new BadServerTooBusy error code
* added default throttle delay in case an unknown error is returned on a publish request service call
2023-08-22 20:02:39 +02:00
dependabot[bot] 7f864c1ef6 Bump Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets (#2271)
Bumps [Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets](https://github.com/dotnet/aspnetcore) from 2.1.3 to 2.1.40.
- [Release notes](https://github.com/dotnet/aspnetcore/releases)
- [Changelog](https://github.com/dotnet/aspnetcore/blob/main/docs/ReleasePlanning.md)
- [Commits](https://github.com/dotnet/aspnetcore/commits)

---
updated-dependencies:
- dependency-name: Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-08-18 10:48:39 +02:00
dependabot[bot] 5f82d1b3d3 Bump Microsoft.Extensions.Logging.Abstractions from 3.1.32 to 7.0.1 (#2233)
* Bump Microsoft.Extensions.Logging.Abstractions from 3.1.32 to 7.0.1

Bumps [Microsoft.Extensions.Logging.Abstractions](https://github.com/dotnet/runtime) from 3.1.32 to 7.0.1.
- [Release notes](https://github.com/dotnet/runtime/releases)
- [Commits](https://github.com/dotnet/runtime/commits/v7.0.1)

---
updated-dependencies:
- dependency-name: Microsoft.Extensions.Logging.Abstractions
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>

* Update Opc.Ua.Core.csproj

* Update UA Server Controls.csproj

* Update UA Client Controls.csproj

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-08-14 08:34:11 +02:00
bhnaphade c7381cf9f7 '#' is not treated as a reserved character in RelativePath's text format (#2264)
* updated reserve char check in RelativePath
* updated logic and added tests
2023-08-12 07:44:04 +02:00
Suciu Mircea Adrian cb99f46599 Fixed NodeId.CompareTo() null reference exception (#2263)
* Fixed NodeId.CompareTo() null reference exception when InnerNodeId is null
* more test cases and guid compare as described
* special null NodeId check test case
2023-08-11 22:23:19 +02:00
Martin Regen 82ed6c8ca8 Refactor IEncoder/IDecoder to derive from IDisposable (#2254)
- Currently the `IEncoder`/`IDecoder` interface is not disposable, which makes it difficult to use the interfaces with `using`. Only the implementations are derived from `IDisposable`
- Change: Moved the `IDisposable` interface from implementations to the IEncoder/IDecoder
- To fully support the use of the interfaces across the codebase new methods are added: `Close` and `CloseAndReturnAsText`
- Breaking change: In the `XmlEncoder` the `Close` method which returns an encoded string is renamed to  `CloseAndReturnAsText`
- Refactor codebase to use `using` with IEncoder/IDecoder across the board. Use interfaces where possible.
- To support streaming better with `ArraySegmentStream`, derive this class from `MemoryStream` and implement `ToArray`
2023-08-11 11:56:47 +02:00
Martin Regen 0a51dd3d02 Complete ISessionFactory interface (#2255)
- A few use cases were still missing from the ISessionFactory interface to make the static `Session.Create` functions completely obsolete. 
- Follow naming conventions (Async) and add CancellationToken where missing.
2023-08-10 16:41:36 +02:00
Martin Regen 1e535dda09 Support client activities on all target platforms (#2256)
- Add the system diagnostics library for unsupported target platforms
- Integrate in clientfixture by adding IDisposable to support to enable/disable the activity tracing
- fix Traceable session dispose issue, do not null the disposed session
2023-08-10 09:48:36 +02:00
Martin Regen 81340c3473 Support for session reconnect from distributed clients (#2244)
- Support Client.Session API to save and restore session configuration information as xml or in a serializable data structure.
- Support to reactivate a session using a new secure channel. 
- API tests
2023-08-03 22:27:53 +02:00
Martin Regen e61664f586 Truncate inner diagnostics if nested depth too high (#2247)
- `DiagnosticInfo` contains the `InnerDiagnosticInfo` which can be nested. Limit the recursion to `MaxInnerDepth` in multiple places to prevent stack overflow / endless loops.
- The default value for MaxInnerDepth should not be more than 5.
2023-07-31 16:11:40 +02:00
Martin Regen 1f17aad109 Better NodeId/ExpandedNodeId built in types handling (#2230)
- A NodeId string can be assigned to a NodeId and is automatically parsed. However, if the string contains a "nsu=" it is considered a string type NodeId instead of decoding the namespaceUri. To avoid this error in the code an `ArgumentException` is thrown to uncover these coding errors. Such a variable needs to be an ExpandedNodeId to be decoded correctly.
- Breaking change: To reduce coding errors the user group decided to throw also on a constructor call which does not contain a nodeid type prefix and namespace index. e.g. `new NodeId("Testnode")`. If somebody wants a string NodeId in Namespace 0 then call the constructor `new NodeId("TestNode", 0)`
- Implement IEquatable<NodeId>/IEquatable<ExpandedNodeId>
- Tests to ensure .Distinct treats all Null NodeIds as identical.
- Unit tests for constructor behavior.
2023-07-28 14:38:37 +02:00
Martin Regen 04cd9bc66a Zip embedded Opc.Ua.NodeSet2.xml to reduce assembly size (#2232)
- Add only the zipped NodeSet2.xml as embedded resource
- Reduces assembly size by at least 2MB
- Breaking Change: Embedded resource Opc.Ua.NodeSet2.xml is now Opc.Ua.NodeSet2.xml.zip
2023-07-27 19:06:26 +02:00
Martin Regen 9256c2e0fe Improve ArraySegmentStream hotpath (#2241)
- Improve the encoding/decoding hotpath in the `ArraySegmentStream` by adding override for ReadByte/WriteByte and enforce inlining.
2023-07-27 19:05:13 +02:00
Marc Schier 7f851599a2 Always use ArrayPool.Shared for optimized use of buffers in buffer manager (#2224)
* The suggestion from .net team is to use shared pool if you have < 1mb buffers you need. 
* We now share buffers across connections which is far more efficient when many channels are created and closed.
2023-07-22 18:45:54 +02:00
Martin Regen c64eb53509 Fix corner cases of subscription transfer (#2227)
- With the `sequentialPublishing` flag enabled, no data is received after transfer. Fix: add a resync flag to update the last sequence counter after transfer.
- Instead of the semaphore slim use a dedicated Task per subscription. The task  is using `AsyncAutoResetEvent` to be task friendly, becasue every subscription gets a worker task.
- Add more tests for the use case republish with delayed ack.
- Add a test and a missing method to support reconnect of a session on a different secure channel without reconnect handler.
2023-07-21 13:10:00 +02:00
Martin Regen 0bf2e93d8c Add IJsonEncoder/IJsonDecoder interfaces (#2042)
- in order to abstract the implementation of a IEncoder/IDecoder  for Json with some extra methods and properties, derive JsonEncoder/Jsondecoder from a IJsonDecoder/IJsonEncoder interface
- breaking change: the use of reversible/non-reversible subencoding is handled by a new method:
`void UsingReversibleEncoding<T>(Action<string, T> action, string fieldName, T value, bool useReversibleEncoding)`
2023-07-20 15:37:54 +02:00
Suciu Mircea Adrian eaa3cb0af5 Bring back Microsoft.Extensions.Logging.Abstractions to V3.1.32 for older target frameworks (#2229) 2023-07-20 10:47:49 +03:00
dependabot[bot] 5a08618af0 Bump Microsoft.Extensions.Logging.Abstractions from 3.1.32 to 7.0.1 (#2194)
* Bump Microsoft.Extensions.Logging.Abstractions from 3.1.32 to 7.0.1

Bumps [Microsoft.Extensions.Logging.Abstractions](https://github.com/dotnet/runtime) from 3.1.32 to 7.0.1.
- [Release notes](https://github.com/dotnet/runtime/releases)
- [Commits](https://github.com/dotnet/runtime/commits/v7.0.1)

---
updated-dependencies:
- dependency-name: Microsoft.Extensions.Logging.Abstractions
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>

* Update Opc.Ua.Core.csproj

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Martin Regen <mregen@microsoft.com>
2023-07-19 10:33:07 +03:00
MarkusHorstmann 2738a2971c Support Dynamic Complex Types (#2146)
Complex Type support assumes that every OPC type is represented by exactly one .Net type, which in turn knows encoding ids, XML names etc.
These changes enable use of a single type that implements encoding/decoding based on OPC type information at runtime.
2023-07-16 09:50:18 +02:00
Martin Regen 17d4f0475f Fix stringtables for diagnostic results when service calls are batched (#2222)
- Issue fix: Currently when diagnostics is enabled in client calls, the string table in the response header is not updated when a service call is split into multiple service calls.  In this case the stringtables from all calls must be appended and the index in the diagnosticinfo must be updated to match the updated string list.
- To reduce the number of 'null' DiagnosticInfo allocations, the decoders now try to return null instead of a default DiagnosticInfo. A new property ÌsNullDiagnosticInfo' can be used to check for unused DiagnosticInfo entries.
- The tests were slightly improved to use test set data from the generated TestData namespace, which contains also a historical node.
- All `ServerFixtureUtils.ValidateXXX` checks were updated to include the check for diagnosticInfos and the string tables to catch issues.
2023-07-13 19:18:24 +02:00
Martin Regen cd38eca781 Various bugfixes for CTT and others (#2212)
- SessionClientBatched doesn't handle the case when diagnosticinfos are requested and the batched calls returns mixed empty or non empty diagnostic infos, then the returned infos did not match the number of requested items.
- write of arrays of analogItemState are not properly checked
- BuildInfo properties were empty because BuildInfoVariableValue is never initialized
- DataType and ReferenceType may return null attributes instead of BadAttributeIdInvalid.
- Add BuildInfo test and fix the NodeCacheTest
2023-07-04 16:44:06 +02:00
Martin Regen 49c85322bd Fix build on merged commits 2023-06-27 17:07:51 +02:00
Martin Regen ae00175fe8 Merge branch 'master' into master371_temp 2023-06-27 10:01:34 +02:00
Martin Regen 010a839ee8 Support custom cert store with flat directory structure (#2198)
In some use cases (e.g. Kubernetes secrets) it would be beneficial to store the certificates, private keys, crl etc. in a flat directory instead of having a root which contains a hierarchy with certs/crl/private etc. 
- Modify the `DirectoryCertificateStore` to allow it to use a flat structure by adding a special constructor.
- Add the configuration builder functions to allow to specify custom certificate stores for app/user/https.
- Add a test sample which shows how to use the 'flat store' with a custom cert store wrapper.
- By default, behavior of `DirectoryCertificateStore` is unchanged. Needs an external wrapper to expose the flat mode.
2023-06-22 16:31:21 +02:00
Suciu Mircea Adrian c81b6b0103 Added newly modified model compiler generated code for v1.04 (#2195)
Update the model compiler generated files with latest modifications which fix the embedded initializers of the generated classes.
2023-06-20 07:05:30 +03:00
Martin Regen e89b06e57b Add metadata to fast data and event callbacks notification. (#2176)
- if `DisableMonitoredItemCache` is set, the sequencenumber and publish time are unavailable. Add helpers to NotificationData to get the information in the fast data and event callbacks.
- new fast callback for keep alive messages
2023-06-14 09:47:21 +02:00
Martin Regen c7bd19dc46 Support use of opc.https endpoint url for client and server. (#2140)
Currently the https protocol doesn't support a spec compliant endpoint with a `opc.https` prefix., as client and server.
Fix:
- Add the client and server support for the `opc.https` prefix. 
- Continue support for `https` prefix for non compliant implementations.
- Any CancellationTokenSource should be disposed after being used.
- Follow coding guidelines
- Use macOS cert callback
2023-06-12 09:05:10 +02:00