Set NoDelay=true to disable the Nagle algorithm and set Lingerstate to 5 seconds by default.
After careful evaluation of the PR provided by @sxleixer in #2882 we found that the default setting of the socket with NoDelay=false can not only cause issues on the client side, but also on the server side.
Due to the nature of Nagle's implementation the issue only occurs when many small service requests or responses are sent over the network. In that case, when packets are still in flight, the secondary small packets are delayed and combined until the MTU is exceeded or the previous packages are acknoledged.
The expectation in the UA protocol is to not add additional latency in the client-server communication.
As a conclusion defaulting to NoDelay=true appears to be the better default option which works for all use cases.
If there are new bandwidth issues related to more and larger packets imposed by this change, they should be solved at the UA application level by combining service requests of the same type.
Setting Lingerstate to 5 seconds should help to finish communications when sockets are closed.
Co-authored-by: @sxleixer <mail@ralfschleicher.de>
* Work In Progress
* Working Implementation of SupportsFilteredRetain
* Potential solution
Contains test debug messages that should be cleaned up
* Update comments showing discussion required
* Address Comments
* Use the NodeId from the ConditionState for the ConditionId.
Existing case was not guaranteed to be correct.
* enable nrts for CertificatIdentifier&CertificateStoreIdentifier&CertificateTrustList
* make RSA Utils and Certificate Stores nullable
* Make Certificate validator nullable
* fix nullability of CertificateTypeParameter
* Add tests to catch if NodeId.Null is modified in DEBUG, fix an issue where NodeId.Null was overwritten
* add (C)
* only enable immutable NodeId to catch issues
* typos and comments
* Remove older channel if not used by session, when number of channels reaches MaxChannelCount - 1
* Corrected channelCount and renamings
* Operate on snapshot
* Snapshot the entire concurentdictionary
* Generate ECC Certificates in Client Tests
* Add more tests
* reenable check of certificate
* fix tests
* Dont use random in test
* fix unsupported certificate types
* fix Hash algorithm for nistP384 curve on linux as the friendly name is ECDSA_P384 instead of nistP384
* use friendly name by default and add special case only for linux while taking care of nullability
* disable special casing for finding correct certificates
* fix tests on net 462
* update Certificate Identifier
* update ServerConfiguration Node to support multiple Application Certificates. Trust List Support for User Certificates & Https Certificates
* GDS ready for ECC Step1
* fix test
* fix build
* ensure hash algorithm is set
* update configurations to new format, fix minor ecc bugs
* implicitly set certificate type of certificate identifier
extend CertificateFactory to allow Revocation with ECC Issuer Certificate
* Revert "update configurations to new format, fix minor ecc bugs"
This reverts commit 9ee17f3aff.
* Allow GDS Certificate Group to have multiple CA Certificates with different Certificate Types
* fix minor bugs
* adress review feedback
* fix some issues
* fix creation of CA signed ECC Certificates
* Update configurations to new ApplicationCertificateFormat and add extra CA Certificates for ECC Certificates
* remove brainpool certs from configuration
* Generate ECC Certificates in Client Tests
* Revert "Generate ECC Certificates in Client Tests"
This reverts commit 90b395f4ff.
* fix crl tests on platforms not supporting ECC
* fix crl test
* Update READMEs for ECC
- Reduce memory allocations in JSON encoder by using stackalloc/ArrayPool
- Fix some new warnings in .NET9 code analyzers
- Fix fuzzing error in JsonDecoder
- do not use .NET9 libraries with .NET8 LTS builds #2931, #2940
- Bump langversion to 9 (max VS2019)
- Use official ASP.Net 2.3. libraries for .NET Framework (rel. Jan 15th)
* Add ECDSA support for reading private key from PEM
* Padded x, y EC point coordinates and the d private key with leading zeros to match keySize
* CreateCertificateWithPEMPrivateKey creates either ECDSA or RSA certificate depending on certificate type
* implicitly set certificate type of certificate identifier
extend CertificateFactory to allow Revocation with ECC Issuer Certificate
* Add Crl tests for ECC
* fix X509 PFXUtils VerifyECDsaKeyPair
* #2896: Write output arguments for good and uncertain status code
When a method state's call method is invoked the output arguments should be written in case the status code is good or uncertain. This behavior would be conform with the current specification.
* #2896: The service result corresponds the method call result
The result of the Call method in the CustomNodeManager2 class represents the status of the CallMethodResult. It does not correspond to the ServiceResult of the CallResponse, thus returning Good as a general response is incorrect behavior.
* Make NodeIdDictionary threadsafe by changing the underlying dict from `Dictionary` to `ConcurrentDictionary`
* reduce blocking in CustomNodeManager2 for GetManagerHandle & other uncritical supporting functions
* Use correctly and validate certificate ECDSA signature hash algorithm
* Added tests for validating length of EC certificate signature
* Improved invalidation condition of SignatureAlgorithm
* Changed result text
* Test fix
* Added helper method to set hash algorithm depending on key size;
Reverted ApplicationInstance code
* Fix test CreateSelfSignedForECDsaDefaultTest
* #2896: Write output arguments for good and uncertain status code
When a method state's call method is invoked the output arguments should be written in case the status code is good or uncertain. This behavior would be conform with the current specification.
* #2896: The service result corresponds the method call result
The result of the Call method in the CustomNodeManager2 class represents the status of the CallMethodResult. It does not correspond to the ServiceResult of the CallResponse, thus returning Good as a general response is incorrect behavior.
Fix server time source timestamp is not updated.
There are duplicate objects in generated code, on of which which holds the last timestamp was not updated.
Move all readerwriter locks outside of try/finally to avoid a SynchronizationLockException when a reader writer lock is disposed or is cancelled.
Currently there is no obvious fundamental bug in how the readerwriter locks are used, but outside the try/finally clause e.g. a disposed lock may not trigger a false exception.
In the read NodeId servcie call an enum is by default cast to Int32, so the cast to ushort is needed here to return the expected type for the AccessRestrictions.
A new configuration variable
<HttpsMutualTls>true</HttpsMutualTls>
enables the mutual TLS authentication support. The behavior of the TLS endpoint changes as the following:
HttpsMutualTls is true:
The server checks the trust on the certificate which is used by the client for TLS authentication. It must be a valid OPC UA application certificate which is trusted.
A client can still connect without providing a client certificate, but then it is only able to call discovery services.
In order to create a session, the client must use the same application certificate that was used for the TLS channel.
HttpsMutualTls is false:
- There is no application authentication. The server endpoint uses security None and there is no client application authentication.
Instead, only user authentication is used to secure the server, anonymous user authentication is disabled.
Discovery service calls are supported.
Co-authored-by: Martin Regen <mregen@microsoft.com>
An older OPC UA server returns well known extension object(811) which cannot be decoded by the client because the server doesn't set the length of the extension object.
Recently, based on fuzz testing, the length check has been changed to enforce an exact match, according to spec.
Workaround: Allow a value of -1 for the length, then allow to decode well known extension objects.
Also improve some internal calls to Safe Read functions by calling not via the interface.
For better client diagnostic it is important to have access to the channel token. Today tooling must monitor the channel token change to be aware of the current token, it is more efficient for the tooling to be called back when the token changes. This can be now accomplished in that the owner of a client (Discovery, Session) can retrieve the Transport channel after connect, read the current token and register a change callback.
* Add OnTokenActivated event for token change notifications
Added a new event `OnTokenActivated` to the `UaChannelBase` class in the `Opc.Ua` namespace to notify when a channel token is activated. Implemented this event in the `HttpsTransportChannel` class within the `Opc.Ua.Bindings` namespace. Introduced a protected internal `OnTokenActivated` event handler in the `UaSCBinaryChannel.Symmetric` class, invoked during token changes in the `ActivateToken` and `DiscardTokens` methods. Cleaned up the event handler in the `Dispose` method of the `UaSCBinaryClientChannel` class. Registered the event handler with the internal channel in the `UaSCBinaryTransportChannel` class. Added a new delegate `ChannelTokenActivatedEventHandler` in the `ITransportChannel` interface and updated the interface to include the `OnTokenActivated` event. Made minor formatting and comment adjustments for improved readability and consistency.
* Include channel in callback
Co-authored-by: Marc Schier <marcschier@users.noreply.github.com>
For better client diagnostic it is important to have access to the channel token. Today tooling must monitor the channel token change to be aware of the current token, it is more efficient for the tooling to be called back when the token changes. This can be now accomplished in that the owner of a client (Discovery, Session) can retrieve the Transport channel after connect, read the current token and register a change callback.
* Add OnTokenActivated event for token change notifications
Added a new event `OnTokenActivated` to the `UaChannelBase` class in the `Opc.Ua` namespace to notify when a channel token is activated. Implemented this event in the `HttpsTransportChannel` class within the `Opc.Ua.Bindings` namespace. Introduced a protected internal `OnTokenActivated` event handler in the `UaSCBinaryChannel.Symmetric` class, invoked during token changes in the `ActivateToken` and `DiscardTokens` methods. Cleaned up the event handler in the `Dispose` method of the `UaSCBinaryClientChannel` class. Registered the event handler with the internal channel in the `UaSCBinaryTransportChannel` class. Added a new delegate `ChannelTokenActivatedEventHandler` in the `ITransportChannel` interface and updated the interface to include the `OnTokenActivated` event. Made minor formatting and comment adjustments for improved readability and consistency.
* Include channel in callback
- reduce EscapeString overhead in JSON encoder
- client monitored items: allocate queues only if needed
- replace SortedDictionary with Dictionary for perf reasons
- revert a change in padding and reduce a log level
Clients that are failing too often to pass the security validationin a certain interval of time with the Basic128 security profile are now tracked and blocked.
- Channels are not disposed (client and server)
- During long running tests an HMAC object leak was observed.
- The HMAC and SymmetricSign objects were not disposed after use, leading to a small incremental memory leak per key renewal.
- The channel token lifetime is calculated by the system clock, which can change. Instead use the continous HiResClock.TickCount to calculate the lifetimes.
- Token renewal and connection requests are not removed from the request dictionary
Improvements:
- Make ChannelToken disposable. Dispose channels.
- Dispose HMAC and SymmetricSign objects after use.
- Use TickCount to calculate key renewal and key expiry.
- Introduce a 5% jitter to the token renewal timer, to avoid token renewal storms.
- Reduce the allocation per use of the HMAC objects by using ReadOnlySpan and avoid MemoryStream.
* improve crl handling in certificate stores by not loading CRL with invalid or unsupported content. Hence the revocation check for such certificates may fail.
- Port support for ECC NIST/Brainpool profiles from prototyping_ecc branch
- Implement CertProvider to load certs per connection / profile
- Backward compatibility of configuration for existing apps
- SecurityConfiguration specifies app cert types for each profile
- Autodetect the ECC support for brainpool/nist based on platform (mac OS 10 doesn't support brainpool)
- ECC supported on net48 / net5.0 / net 6.0 / netstandard2.1
- ECC supported on windows / linux / macOS (brainpool not < macOS11)
- Self signed certs for each profile are created on start similar to RSA
- RSA only profiles are supported on .NET standard 2.0
Co-authored-by: Martin Regen <mregen@microsoft.com>
The server under test has a extension object with a complex type. Type id = {nsu=http://opcfoundation.org/UA/Machinery/Result/;i=5008}. This contains something with a variant array that is null though (-1). SetProperty should support setting a Array that is null. Therefore, test for null collection (case when length was encoded as -1) before dereferencing ahead of the ToArrray() conversion to Array.