Commit Graph

249 Commits

Author SHA1 Message Date
Martin Regen ba2899eb01 Merge branch 'release/1.5.372' into master1.5.372 2023-12-18 16:57:54 +01:00
dependabot[bot] 8b3126bd47 Bump MQTTnet from 4.3.1.873 to 4.3.3.952 (#2419)
* Bump MQTTnet from 4.3.1.873 to 4.3.3.952

Bumps [MQTTnet](https://github.com/dotnet/MQTTnet) from 4.3.1.873 to 4.3.3.952.
- [Release notes](https://github.com/dotnet/MQTTnet/releases)
- [Commits](https://github.com/dotnet/MQTTnet/compare/v4.3.1.873...v4.3.3.952)

---
updated-dependencies:
- dependency-name: MQTTnet
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

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

* Update Opc.Ua.PubSub.csproj force a rebuild

---------

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-15 08:09:31 +01:00
Suciu Mircea Adrian f85361a7bf Add Pubsub uadp discovery for Publisher Server Endpoints and DataSetWriter configuration (#2428) 2023-12-14 20:35:33 +01:00
bhnaphade 32fbc8077c Propagate tracing data to RequestHeader(AdditionaHeader) (#2322)
Sample code to show how to customize a session and how to add OTEL telemetry for activities to the additional header field of a request header.
2023-12-14 20:30:01 +01:00
JSGInray e2b3f6f359 Complex types builder should emit BuiltInType.Variant for DataTypes.Decimal (#2426) 2023-12-14 16:44:09 +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
romanett 75f96724c4 GDS: manage GDS Server users in Database and make it possible to avoid hardcoded passwords (#2402)
Manage the GDS Server Users in a Database. The implementation is based on the IUsersDatabase Interface which allows the User of the library to provide its own implementaion.
For testing a Json/Linq Users Database implementation is provided.
Passwords are hashed with the PBKDF2 with 10k iterations.

In the default config the standard users with the demo passwords are created, so the behaviour for existing applications is not changed.
2023-12-07 18:36:03 +01:00
romanett 14befa0eeb GDS: Trust own CA & add revoked Certificates to CRL (#2333)
With this Pull Request i improve the reusability of the Code by changing reverences to CertificateGroup to the Interface ICertificateGroup, through this change users can extend the functionality of CertificateGroup by providing an own implementation.
Furthermore I fix two issues of the GDS:
- The GDS does not trust its own CA Certificate, therefore it rejects connection attempts from clients with a CA signed certificate (e.g. after a sucessful registration & a new CA signed Application certificate received -> Client tries to connect with the new certificate to get the TrustList -> gets rejected)
-> new Method AddOwnCertificateToTrustedStoreAsync added to Class ApplicationInstance
-> you can call this after starting the GDS Server with CA-Certificate of the GDS as parameter

- The GDS does not revoke Certificate in the TrustedList Store CRL, so OPC UA Applications can´t get revoked certs
-> this is fixed by adding a call to UpdateAuthorityCertInTrustedList to the method RevokeCertificateAsync
2023-12-07 17:38: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
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
romanett adafd2c03b GDS: add ArgumentException to Method CreateCACertificateAsync (#2336)
Introduces an exception, to notify the user when supplying an invalid argument to the method CreateCACertificateAsync
This exception was introduced, as in the current implementation the same subject name has to be used as in the configuration or else the certificate is not copied to the trusted store.
2023-11-17 15:27:28 +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
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
dependabot[bot] 229b124f80 Bump MQTTnet from 4.2.1.781 to 4.3.1.873 (#2303)
Bumps [MQTTnet](https://github.com/dotnet/MQTTnet) from 4.2.1.781 to 4.3.1.873.
- [Release notes](https://github.com/dotnet/MQTTnet/releases)
- [Commits](https://github.com/dotnet/MQTTnet/compare/v4.2.1.781...v4.3.1.873)

---
updated-dependencies:
- dependency-name: MQTTnet
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-09-20 10:51:37 +03:00
Suciu Mircea Adrian 49bc6a9476 Bump to MQTTnet v4.3.0.858 and replace deprecated call. (#2298)
* Replaced obsolete WithTls method call with WithTlsOptions method call as MQTTnet v4.3.0.858 recommends.

* Dispose mqtt client certificates
2023-09-20 09:51:53 +03:00
bhnaphade 5d4e962315 some TraceableSession functions do not await the activity (#2294)
* added await for some TraceableSession functions
* added missing configureAwait()
2023-09-02 07:29:27 +02:00
Martin Regen 5f9b7fe471 Merge 1.05.03 release candidate updates (#2286)
- Merge latest Nodeset for rc bits

Co-authored-by: Randy Armstrong <randy@sparhawksoftware.com>
2023-08-28 20:46:46 +02:00
bhnaphade da5db41a34 Publish state change does not correctly handle subscription transferred case (#2281)
If the subscription is transferred there was still try to publish on the subscription which is not active anymore and failed.
2023-08-25 20:10:22 +02:00
Martin Regen b88e2da4d8 Use the request queue to return GoodSubscriptionTransferred immediately (#2280)
Issues:
- The expectation is for a client session to receive a `GoodSubscriptionTransferred` status after a subscription is transferred to another session. However there is a corner case exposed in our tests, when all subscriptions are transferred so that the client subscriptiona has no active subscriptions left, only `BadNoSubscription` is returned by the server for allpending requests, instead of the status. As a workaround, to get the status, the client session has to send an additional publish request which is unexpected after a `BadNoSubscription` error.
- The status message is only returned on the next publish request, which can lead to undesired delay of the notification.

Fix: Return the status message immediately if pending requests are available.

Other fixes:
- Make client subscription class cloneable
- Improve the test which didn't receive the status messages
- Use the publish request queue to return a status message immediately
2023-08-25 11:29:16 +02:00
Martin Regen e02f22368d Add event for the session configuration changed (#2278)
- Add the event `SessionConfigurationChanged` which indicates that the `SaveSessionConfiguration` should be called again because some session configuration was changed, e.g. after a reconnect, locale, server nonce or the user impersonation changed.
2023-08-25 10:39:47 +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
KneShell b28b51570a Update MQTTnet nuget package version 3.1.1 to 4.2.1.781 (#2272) (#2273)
Change code to be compatible with MQTTnet 4.2.781 version.
And check if all test passed. (It is)
2023-08-19 06:56:58 +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
bhnaphade cfb3ac49bf Support ActivitySource in OPC UA client to enable tracing (.NET6) (#2251)
- Add traceable client session with factory to support ActivitySource on .NET 6
- Only traces the public API calls, inner calls are not yet supported.
- Uses the name: Opc.Ua.Client-TraceableSession-ActivitySource
2023-08-04 12:11:05 +02:00
Martin Regen e6f3004d6e Improve client subscription implementation (#2245)
- shutdown the worker tasks with a ManualResetEvent instead of timer null check
- Breaking change: Decorate the PublishStateChanged event handler with state information:
- - Stopped/Recovered if publish times out/restarts
- Breaking change: PublishStateChange fired for every received publish response, which doesn`t really indicate a state change. 
-- new behavior: fires only if a Keep alive or republish is triggered.
2023-08-04 10:17:38 +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 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
Marc Schier d99c4bc9fa Add Filter Result property to monitored item status (#2219)
Adds a property to the monitored item status to expose the filter result returned from the server.
2023-07-14 06:00:30 +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 ae00175fe8 Merge branch 'master' into master371_temp 2023-06-27 10:01:34 +02:00
Martin Regen 1dfda2bf3b Make client NodeCache thread safe (#2201)
-Add a readwritelockslim to NodeCache functions which access the underlying NodeTable and TypeTree, to support multi threading
2023-06-27 09:53:23 +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
Martin Regen 85c032133b Fix session reconnect exponential backoff (#2185)
- With exponential backoff enabled, a KeepAlive calling `BeginReconnect` could retrigger the timer in a way that a reconnect would never occur.
- Throttle `ISession.BeginPublish` on `BadTooManyOperations` error.
- Add reverse connect option to console client to test reconnect with reverse connect manager.
- null events in session on dispose to suppress spurious events.
- mark `TransferSubscription` service calls obsolete to avoid accidential use by applications.
- for reverse connection testing of session reconnect handler, add options for no security and reverse connect endpoint to console client
2023-06-20 09:40:43 +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
Andreas Heisel 266e29b383 Fixes an issue in Session.LoadDataTypeSystem. (#2166)
Starting with line 1857 a dictionary of namespaces is populated in an defensive manner. If a namespace value can't be read, it is silently ignored. If this happens, it will result in an KeyNotFoundException when populating the imports dictionary.
This fix adds a warning if a namespace value can't be read and populates the imports dictionary also defensivly.
2023-06-01 10:20:55 +02:00