Commit Graph

572 Commits

Author SHA1 Message Date
Zigby cbe886dcb0 Enable client support for multiple sessions on a single channel (#1659)
* Client API changes to support multiple sessions on a single channel
* Tested against freeopcua:python:server and ProSys simulation server
2022-04-01 14:27:32 +02:00
Martin Regen eda38cb6c2 XmlSerializer in .NET 6 Omits Line Breaks by Default (#1760)
* fix xml output in .NET 6
* unify the way xml writer settings are generated and used, add validation tests
2022-03-31 20:13:49 +02:00
Martin Regen 3a378e8644 Fix dual license headers (#1763)
Headers incorrectly state that the RCL applies to members, however the OPC Source Deliverables license states RCL is applicable only to corporate members. 

The OPC Foundation Technical Control Board on March 30th decided on the following changes with regard of the license headers:

• Change the dual license in the source files so that “members” are replaced with “corporate members”. 

Co-authored-by: Suciu Mircea Adrian <Mircea-Adrian.Suciu@softing.com>
2022-03-31 13:14:17 +02:00
Martin Regen 8ddda78aff Fix for Usertokenpolicy Anonymous, security policy default should be None (#1756)
- Only an issue if the configuration does not specify the security policy uri for anonymous token
- If the config does not specify the security policy, for anonymous user token the security profile Basic256Sha256 was chosen. 
- This setting requires for the client to trust the server certificate if it tries to connect with security None, may cause IOP issues when no security is chosen and encryption is required for the anonymous user token.
2022-03-30 09:20:13 +02:00
Martin Regen 1263881a7f Adapt logging abstractions version to target framework (#1751)
* fix the nuget versions

* revert targetframework

* avoid build warning
2022-03-28 14:01:42 +03:00
Suciu Mircea Adrian 244234cdf0 Changes for testing and fixing git bug #1694 (#1747)
* Changes for testing and fixing git bug 1694

* Removed the duplicate server address differing by port number
2022-03-25 10:32:48 +02:00
Martin Regen 24931cfea0 fix SByte vs Byte collection (#1740) 2022-03-22 08:29:31 +02:00
Martin Regen cfc68eeb10 Use .NET analyzers instead of Roslynator, fix warnings, no bug fixes (#1729)
-use latests analyzers in .NET instead of Roslynator.
-fix warnings and formatting, no bug fixes!
2022-03-14 16:39:09 +01:00
dependabot[bot] 2a74b44627 Bump Microsoft.Extensions.Logging.Abstractions from 6.0.0 to 6.0.1 (#1728)
Bumps [Microsoft.Extensions.Logging.Abstractions](https://github.com/dotnet/runtime) from 6.0.0 to 6.0.1.
- [Release notes](https://github.com/dotnet/runtime/releases)
- [Commits](https://github.com/dotnet/runtime/compare/v6.0.0...v6.0.1)

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

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

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-03-09 19:40:18 +01:00
ThomasNehring 3dc1d4beba Update BuiltInTests.cs with special case compare Null NodeId (#1609)
A  new unit test which will currently fail, due to incorrect treatment of node ids with numeric identifier 0 in the namespace with index 0. ( "NodeId nodeId = new NodeId (0,0)." ).

Of course such a node id is invalid. It seems to be present, however, in some PLCs under certain situations. We encountered such node ids in the context of a customer ticket. The node ids were read into instance of type "DataValue" using the read service call. The evaluation of the read result then failed due to comparisons like the ones in the unit test.

fixes #1610
2022-02-18 16:53:50 +01:00
Martin Regen efd04655a6 Bug fix for server registration issue (#1713)
-always use a clone of the configuration and replace cert validator when registration is active.
-fixes #1711
2022-02-18 08:30:40 +01:00
Martin Regen 7d9be41cf5 Doc updates and fixes for .368 preview, ref server improvements (#1695)
- Doc, docs, docs updates for new 368 support
- fix a missing null pointer check when ConditionRefresh is run
- Ref server: move NodeManager factory API to StandardServer, decoupling the NodeManager implementation from Ref server
- Ref server: add shadow mode flag, to allow to map a docker configuration in a mapped folder.
- Ref server: sample batch files how to run Github CR and local docker images
- Improve some misleading 'delete application certificate' log messages.
2022-02-11 09:19:40 +01:00
dependabot[bot] a7b561158b Bump System.Io.Pipelines from 6.0.1 to 6.0.2 (#1703)
* Bump System.Io.Pipelines from 6.0.1 to 6.0.2
* Fix the fast PR build

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Martin Regen <mregen@microsoft.com>
2022-02-10 19:01:41 +01:00
Martin Regen 5d9234eebe Handle subscription transfer special cases + tests (#1700)
- Fixed issue: After transfer, available sequence numbers were not properly ack/republished.
- Fixed issue: After transfer, race condition could delete subscription before transfer finished.
- Fixed issue: After reload of a subscription, duplicate client handles may have been used.
- Add tests which emulate the disconnection of a client/server, then transfers
- Add subscription variable to select if missing publish requests are just acknoledged (default) or republished after transfer completes. Set `Subscription.RepublishAfterTransfer` to `true`.
- Improve test framework to allow for testing against external servers using a .runsettings file
- improve publish request logging, by moving calls into `CoreClientUtils.EventLog`
- disable available sequence numbers check, it causes false negatives when many subscriptions are active
2022-02-07 17:37:01 +01:00
Martin Regen 8c1a659ecf Reference Server updates running CTT (#1689)
- Provide the CTT configuration used for 1.4.9.398: Added tests with arrays except Variant
- Match the Reference server config for CTT run (Console Server was used, others tbd)
- add a few cases in ref server node manager to enable skipped tests
- preset random generators to create deterministic node data 
CTT fixes:
- Trigger: fix a regression introduced with the TransferSubscription support, Trigger stopped working, revert change to remove LinkedList in MonitoredItems
- return BadDataEncodingUnsupported creating MonitoredItems
- ensure that MonitoredItem node data reported as required by CTT after initial reading, transfer and SetMonitoring

note: not yet 100% passy, a few uncritical failing tests are still under investigation

Co-authored-by: mrsuciu <Mircea-Adrian.Suciu@softing.com>
2022-01-31 13:32:58 +01:00
Suciu Mircea Adrian 5025648cbc GetEndpoints: Eliminate duplicate endpoints when Configured base addresses differ by port only (#1687)
- use case: specify the same endpoint protocol with two ports. The returned array  contains too many entries, because now the policyId in the UserTokenpolicies was fixed and no more duplicates were detected.
2022-01-29 14:47:05 +01:00
Martin Regen 430ff70de7 Implement Transfersubscription service (#1649)
- Implement client and server side of Transfersubscription service calls.
- New Transcription service has been tested with CTT 1.04.9.398
- Unit tests for native service calls and client SDK
- Client implements multiple ways to transfer sessions:
  - Client saves subscriptions to xml stream, restarts, loads subscriptions from stream and transfers on server.
  - Client creates a new sessions and transfers into new session, while the old session is still active.
  - Client closes old session with `DeleteSubscriptionsOnClose = false`, creates new session and transfers subscriptions to new session.
  - `SessionReconnectHandler` tries to transfer subscription before recreating the subscriptions.
- breaking change: INodeManager got a new TransferMonitoredItems method

Co-authored-by: Alexander Koepke <alexander.koepke@microsoft.com>
Co-authored-by: Peter Bryntesson <pbrynt@microsoft.com>
2022-01-28 13:21:20 +01:00
Martin Regen 079148f3ab ctt fixes (#1685)
* remove the SetDurableSubscription method, to skip the test cases
* DeleteSubscription returns BadSubscriptionIdInvalid
* MethodState return also BadTooManyArguments
* return AttributeIdInvalid for null attributes (fix UA Expert display)
* fix ToString of Variant array of ByteString
* fix Variant decoding 1-dim array of bytestring
2022-01-27 09:46:32 +02:00
Archie Miller 5d33c16188 Implement a common method for creating branches (#1603)
Implement a mechanism to create Alarm Branches, store them, allow AddComment, Acknowledge, and Confirm them.

Updates the Retain flag automatically.
Cleans up branches on Ack/Confirm

Allows servers to retrieve branches to clear them all if necessary.
2022-01-25 07:46:21 +01:00
Martin Regen 5cbffcfe77 Support async ICertificateStore CRL interface methods (#1666)
- integrate 'LoadPrivateKey' in the interface to allow to implement cert stores which require a passcode to load/store certificates
Change of behavior:
- Introduce a 'NoPrivateKeys' flag to reduce the risk of leaking a private key to a unsecure store.
  - CertificateStoreIdentifier opens 'NoPrivateKey' stores
  - CertificateTrustList opens 'NoPrivateKey' stores
  - CertificateIdentifier opens store with private keys for application or GDS authority certificates
- CertificateTrustList reuses a store if it is not disposed. A user can just close the store to keep the list of certificates in memory.
- DirectoryStore `Load` does not read private keys anymore, only file names for delete. Reading all private keys caused false errors, e.g. here: #1670 

Co-authored-by: mheege-abb <marcus.heege@de.abb.com>
Co-authored-by: mheege-abb <85437567+mheege-abb@users.noreply.github.com>
2022-01-25 07:16:28 +01:00
Martin Regen 3fe949559d Retry to load private key of a new certificate on import error. (#1676)
- In windows container this non deterministic error can occur:
`[WindowsCryptographicException] The specified network password is not correct.`
even if the private key was saved with empty password.
- Fix: After a delayed retry the private key can be loaded successfully.
- fixes #1670 
- see also https://github.com/OPCFoundation/UA-.NETStandard/commit/ae9ecac2be6b2f9ed6c639eb60205896c27791e0 for 367 milestone
2022-01-24 17:05:34 +01:00
Suciu Mircea Adrian 33ae73654c Improve initalization of BaseVariableState (#1672) 2022-01-20 06:50:48 +02:00
Suciu Mircea Adrian 213f37e28b Set the default value of the StatusCode on BaseVariableState to BadWaitingForInitialData. (#1668)
* Removed assigning a default value to any variable value in the AddReverseReferences method.
Set the default value of the StatusCode on BaseVariableState to BadWaitingForInitialData.

* Allow initalization from variable states with status code BadWaitingForInitialData
2022-01-19 09:25:27 +02:00
mheege-abb 61e204f1d9 Add support for custom certificate stores (#1420)
The current SDK supports only Windows and Directory certificate stores. For security reasons, it can be necessary to use custom certificate stores. 
* Add support for custom certificate stores
* Certificate Store Type UnitTests
* Start cleanup of ICertificateStore interface in the CRL section (Co-authored-by: Martin Regen <mregen@microsoft.com>)
2022-01-17 15:13:59 +01:00
ThomasNehring dd6f4a4c8d Updates for getIssuer(s) in the Certificate Validator class (#1632)
- Adapted getIssuer and getIssuers so that all findings get aggregated for later processing in the validation methods.
- Ensured that other methods calling getIssuer(s) will experience unchanged behavior
- Adapted unit tests
2022-01-14 16:11:31 +01:00
Martin Regen 6747b47192 Fix Authority Key Identifier in SubCA and cert validator return codes. (#1665)
- AuthorityKeyIdentifier in the SubCA contains the SubjectName of the Issuer instead of the IssuerName. Also an application certificate that is signed by a SubCA would contain the false information.
- The false information has no effect on Windows and macOS, however on linux OpenSSL tests all fields and a chain cannot be fully validated.
- For CTT tests a few error codes were return false codes because ServiceResult replaces the error code with the InnerException error.
- Do not allow to ignore PartialChain validation error, it may have different root cause then the error returned by GetIssuer.
2022-01-14 11:17:03 +01:00
Suciu Mircea Adrian 15f1fcb57f The UserToken PolicyId is made unique per server instance. (#1663)
* The UserToken PolicyId is made unique per server instance as in the specification.
2022-01-14 11:37:12 +02:00
Martin Regen fa6099b7ee Support semantic logging (#1648)
- For EventSource and legacy logger refactor logging to support the built in LogValueFormatter, which provides the format strings suitable for `string.Format`.
- **Breaking change**: For `TraceEvent` this is a breaking change, because there is no implementation yet to support to provide the reformatted format string. With this implementation if a logging framework is used which supports the semantic logging, there is no issue. With frameworks which do not understand semantic logging strings(e.g. log4net) it is a breaking change, string.format will throw exceptions --> move to ILogger hook using `SetLogger`. 
- **Warning**: When Microsoft.Extensions.Logger based loggers are used, format strings must follow this convention:
i) All variable entries must follow order and count up, e.g. "{0} -- {1}" etc., no mix of "{2}--{0}"
ii) in the same way the args must follow this strict ordering. 
- Format strings will be changed by future PR to include the semantic values.
2022-01-12 14:51:22 +01:00
dependabot[bot] 9188dcf672 Bump NUnit.Console from 3.13.0 to 3.13.1 (#1657)
* Fix an invalid format string causing exception in ILogger
* Bump NUnit.Console from 3.13.0 to 3.13.1

Bumps [NUnit.Console](https://github.com/nunit/nunit-console) from 3.13.0 to 3.13.1.
- [Release notes](https://github.com/nunit/nunit-console/releases)
- [Changelog](https://github.com/nunit/nunit-console/blob/master/CHANGES.txt)
- [Commits](https://github.com/nunit/nunit-console/compare/3.13...3.13.1)

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

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

* Fix format string exception with ILogger

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-01-05 18:03:20 +01:00
Martin Regen 74af8cab3e API improvements and minor cleanup / uncritical bug fixes (#1650)
* smaller API changes for .368 and minor cleanup / uncritical bug fixes
* refactor GDS server lib to get rid of UA configuration dependency
* app config builder enhancements to simplify someuse cases
-- add a few default parameter to simplify fluent API
-- Rejected folder doesn't default to pki root
-- if the leaf pki folder is already provided, the default leaf folder is stil added (e.g. becomes own/own)
* certificate validator match were to return true even if no keyId/serial number was checked
* Directory store delete cert add retry if cert is still in use.
* enable reverse connect tests on macOS
* fixes CVE-2020-1045 (High) detected in microsoft.aspnetcore.http.2.1.1.nupkg mregen/UA-.NetStandardLibrary#114
2021-12-30 19:38:38 +02:00
Martin Regen 0011f482a0 Use FrameworkReference for kestrel package for .NET Core App >= 3.1 (#1646)
- Kestrel server is end of life for .NET Core 2.1, only support for .NET framework and netstandard2.0
- Use FrameworkReference to include ASPNET services for .NET Core 3.x and later
- adjust the code signing for bindings.https
- deprecate complextypes.symbols package

- note: only netcoreapp3.1 and net6.0 frameworks yet support latest kestrel and allow to use MS.Ext.Logging library >=5.x with bindings.https. If netstandard2.0 or net462 is used, the Microsoft.Extensions.Logging library >= 3.x cause a TypeException in Microsoft...HttpHeader because a required class became obsolete in Platform.Extensions.
2021-12-23 18:35:20 +01:00
Martin Regen 7ae5c117fa Fix VS2017 build, lgtm warnings, license headers, flaky CI (#1641)
- vs2017 now only supports .NET 4.6.2 builds, .NET Core 2.1 is end of life. 
- Roslynator was not properly excluded in VS2017, change the condition to <Choose>
- fixes #1630 
- fix a few lgtm warnings
- fix a few license headers (everything outside of \Stack is MIT)
- fix flaky Hiresclock test.
2021-12-17 11:54:11 +01:00
Michi bcc573ad68 Fix: Server endpoints are not returned if GetHostEntry fails. (#1639)
Fix: Server endpoints are not returned if GetHostEntry fails.

* User had issues with DNS server which caused Dns.GetHostEntry to throw SocketExceptions.
* It caused that OPC UA servers couldn't return their endpoints to remote machines.
* fix catches the SocketExceptions on Dns.GetHostEntry.
2021-12-17 11:04:34 +01:00
Martin Regen a147eb55c5 Tracing and Logging improvements for the UA Core and libraries (#1631)
- support for Microsoft.Extensions.Logger.ILogger in Opc.Ua.Core as the new logging interface
- backward compatible with config and TraceEvents
- new API Utils.SetLogger allows to set ILogger
- updated Console samples to demonstrate ILogger support with Serilog
- support for EventSource logging
- see Docs/Logging.md for more info
2021-12-16 00:20:08 +01:00
Suciu Mircea Adrian b55ef388d1 Added BitwiseAnd and BitwiseOr filter operators and unit tests for existing filter operators (#1633)
* Added BitwiseAnd and BitwiseOr filter operators

* Added positive unit tests for filter operators; Changed Cast BitwiseAnd and BitwiseOr operators to return boolean values or null

* BitwiseAnd and BitwiseOr return the operation value; Improved unit tests

* Added missing handling of BitwiseAnd and BitwiseOr filter operators under the ContentFilterElement.Validate and ContentFilterElement.ToString methods

* Changed Cast operator to return value instead of bool; Fixed typos and adapted unit tests
2021-12-15 15:45:01 +02:00
dependabot[bot] cf13e7a367 Bump System.Io.Pipelines from 6.0.0 to 6.0.1
Bumps [System.Io.Pipelines](https://github.com/dotnet/runtime) from 6.0.0 to 6.0.1.
- [Release notes](https://github.com/dotnet/runtime/releases)
- [Commits](https://github.com/dotnet/runtime/compare/v6.0.0...v6.0.1)

---
updated-dependencies:
- dependency-name: System.Io.Pipelines
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2021-12-15 10:01:56 +00:00
opcfoundation-org 985035bdf7 Modelcompiler 1.04.10 (#1627)
Replace the xml versions with properly tagged 1.04.10. 
Note -- this merge does not require a rebuild of the Opc.Ua.Core library.
2021-12-05 11:09:04 +01:00
opcfoundation-org edadaa8eab Revert MethodDeclarationId change due to breaking code. (#1615)
* Revert MethodDeclarationId change due to breaking code.

* Delete duplicate of Opc.Ua.Nodeset2.xml

Co-authored-by: Randy Armstrong <randy@sparhawksoftware.com>
Co-authored-by: Martin Regen <mregen@microsoft.com>
2021-12-03 12:48:10 +02:00
Martin Regen 47370a953f Bump up Nuget packages to 6.0.0 (#1617)
* update package to 6.0

* bump
2021-11-29 11:01:51 +02:00
Martin Regen 2430a651ea Enforce Roslynator checks in CI build (#1608)
- The ci pass includes Roslynator checks, fails on warnings
- Fix all existing warnings
2021-11-24 14:44:31 +01:00
opcfoundation-org fdf31dca76 Modelcompiler 2021 11 24 (Fixes for MethodDeclarationId) (#1612)
- ModelCompiler Fixes for MethodDeclarationId
- Previous fix not only removed TypDefinitionId in certain cases but also removed the MethodDeclarationId
- This backward compatible fix should work with old and new nodeset files
2021-11-24 14:31:39 +01:00
Martin Regen 486e97b9b5 Fix export of TypeDefinitionId (#1604)
- the previous fix to remove TypeDefinitionId caused a regression with Alarms (#1574/#1576)
- This is a backward compatible fix to remove the TypeDefintionId where it is not needed in the nodeset but still fill the MethodDeclarationId.
2021-11-24 07:59:40 +01:00
Suciu Mircea Adrian 4137cfdd02 Binding to a specific NIC is implicitly implied when an IP address is specified instead of a hostname (#1596); should fix issue #1581
* Binding to a specific NIC is implicitly implied when an IP address is specified instead of a hostname; Removed the redundant flag BindToSpecifiedAddress.
2021-11-17 10:57:55 +02:00
Martin Regen 3b233c6f55 Bug fixes in ref server and more tests cases (#1590)
- fix the complex types of the test nodeset (requires https://github.com/OPCFoundation/UA-ModelCompiler/pull/96)
- improve some client / server tests
- add tests for complex types datatype definition integrity on ref server, validate bsd and xml dictionaries in the test server (open issue:  https://mantis.opcfoundation.org/view.php?id=7393, xml validation always failing)
- improve server fixture, to allow for custom config changes 
- fix an issue that caused kestrel not start on windows/.NET Core 3.1 and above, when a new certificate was issued, thereby ignoring all https client tests.
2021-11-11 06:39:23 +01:00
Martin Regen 860c9686c9 fix uncontrolled format string and clear text storage of sensitive information (#1591)
- fix uncontrolled format string and clear text storage of sensitive information issues flagged by CodeQL
2021-11-10 13:06:59 +01:00
Martin Regen e61594eff5 CI support for .NET 6.0 builds, tests and Nuget (#1580)
- Add pipeline steps with VS2022 hosted images and .NET 6 install on linux/mac
- Nuget build with net6.0 binaries
Co-authored-by: mrsuciu <Mircea-Adrian.Suciu@softing.com>
2021-11-09 07:56:45 +01:00
Suciu Mircea Adrian 372449b222 Definition is enumeration if at least a field is not default value -1, since there is a very small probability for an enumeration to contain one field only (#1579) 2021-11-08 07:57:04 +02:00
Alin Moldovean ea3444b9c4 Performance update - Add IEquatable interface for DataValue (#1577)
* Add IEquatable interface for DataValue, StatusCode and NumericRange types

- Performance update

Implement strongly typed Equals() method and IEquatable for DataValue, StatusCode and NumericRange types so no boxing is required.
This brings a performance improvement for servers with high number of dynamic nodes and monitored items created where the compare method of DataValue is called intensively (100k -200k/sec)
2021-11-05 11:03:17 +01:00
Martin Regen 7acddc0923 Fix binary export of surplus typedefinition (#1576)
- HasTypeDefinition and TypeDefinitionId should only exist for Object/Variable in .uanodes
- fix binary export for .uanodes
- #1574 missed the binary output case, only fixed xml export
- fixes #1532 
- fixes https://github.com/OPCFoundation/UA-ModelCompiler/issues/94
- fix the default and sample models in this repo

note --> ModelCompiler needs to use the updated core lib to produce the same output
2021-11-04 08:37:22 +01:00
Suciu Mircea Adrian f090f618aa Added null check to structureType.DefaultEncodingId (#1571)
Added null check to structureType.DefaultEncodingId in the ReadNonValueAttribute method
2021-11-02 13:02:18 +01:00