Skip to content

Add support for pushing to arbitrary certificate groups to the ServerPushConfigurationClient#3585

Draft
Tyrrx wants to merge 5 commits intoOPCFoundation:masterfrom
Tyrrx:feature/custom-certificate-group-support
Draft

Add support for pushing to arbitrary certificate groups to the ServerPushConfigurationClient#3585
Tyrrx wants to merge 5 commits intoOPCFoundation:masterfrom
Tyrrx:feature/custom-certificate-group-support

Conversation

@Tyrrx
Copy link

@Tyrrx Tyrrx commented Feb 26, 2026

Proposed changes

See: #3571.

  • Extend Add/RemoveCertificate methods to support arbitrary certificate groups and add overloads for backward compatibility.
  • Extend ReadTrustList API to support arbitrary certificate groups and add overloads for backward compatibility.
  • Extend UpdateTrustList to support arbitrary certificate groups and add overloads for backward compatibility.

Related Issues

Types of changes

What types of changes does your code introduce?
Put an x in the boxes that apply. You can also fill these out after creating the PR.

  • Bugfix (non-breaking change which fixes an issue)
  • Enhancement (non-breaking change which adds functionality)
  • Test enhancement (non-breaking change to increase test coverage)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected, requires version increase of Nuget packages)
  • Documentation Update (if none of the other choices apply)

Checklist

Put an x in the boxes that apply. You can also fill these out after creating the PR. If you're unsure about any of them, don't hesitate to ask. We're here to help! This is simply a reminder of what we are going to look for before merging your code.

  • I have read the CONTRIBUTING doc.
  • I have signed the CLA.
  • I ran tests locally with my changes, all passed.
  • I fixed all failing tests in the CI pipelines.
  • I fixed all introduced issues with CodeQL and LGTM.
  • I have added tests that prove my fix is effective or that my feature works and increased code coverage.
  • I have added necessary documentation (if appropriate).
  • Any dependent changes have been merged and published in downstream modules.

Further comments

Is there a auto formatting rule set that needs to be applied?
Do the new methods need additional tests because the back-ports technically already call them?
Do the new methods need additional documentation because I think they are self explanatory?
Would it make sense to make the ServerPushConfigurationClient partial in general so that it is easier for a library consumer to implement custom logic?

… groups and add overloads for backward compatibility.

Extend ReadTrustList API to support arbitrary certificate groups and add overloads for backward compatibility.
Extend UpdateTrustList to support arbitrary certificate groups and add overloads for backward compatibility.
@CLAassistant
Copy link

CLAassistant commented Feb 26, 2026

CLA assistant check
All committers have signed the CLA.

@romanett
Copy link
Contributor

@Tyrrx maybe you can add a fast path for the well known nodes, so no browse is issued for them

@codecov
Copy link

codecov bot commented Feb 26, 2026

Codecov Report

❌ Patch coverage is 72.26027% with 81 lines in your changes missing coverage. Please review.
✅ Project coverage is 65.97%. Comparing base (d25caff) to head (acb2ffb).
⚠️ Report is 126 commits behind head on master.

Files with missing lines Patch % Lines
...Gds.Client.Common/ServerPushConfigurationClient.cs 72.26% 79 Missing and 2 partials ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           master    #3585       +/-   ##
===========================================
+ Coverage   51.86%   65.97%   +14.10%     
===========================================
  Files         370      459       +89     
  Lines       78618    97763    +19145     
  Branches    13650    16326     +2676     
===========================================
+ Hits        40779    64496    +23717     
+ Misses      33705    28181     -5524     
- Partials     4134     5086      +952     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request adds support for operating on arbitrary certificate groups in the ServerPushConfigurationClient class, addressing issue #3571. Previously, the methods could only work with the default application certificate group. The changes enable library consumers to read, update, add, and remove certificates from any certificate group on the server.

Changes:

  • Extended ReadTrustListAsync, UpdateTrustListAsync, AddCertificateAsync, and RemoveCertificateAsync to accept an optional certificateGroupId parameter
  • Added backward-compatible overloads that default to the DefaultApplicationGroup
  • Implemented helper methods BrowseNodeIdAsync and FindChildByTypeDefinitionAsync to dynamically discover NodeIds for arbitrary certificate groups
  • Applied formatting changes throughout the file for consistency


const int maxAttempts = 5;
for (int attempt = 0; ; attempt++)
for (int attempt = 0;; attempt++)
Copy link

Copilot AI Feb 26, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Formatting change removes space after semicolon in for loop condition. While this doesn't affect functionality, it's typically more readable to have a space after semicolons in for loops (e.g., for (int attempt = 0; ; attempt++)). This change appears to be inconsistent with common C# formatting conventions. Consider reverting this spacing change or confirming it matches the project's .editorconfig rules.

Suggested change
for (int attempt = 0;; attempt++)
for (int attempt = 0; ; attempt++)

Copilot uses AI. Check for mistakes.
Comment on lines +654 to +658
public async Task<bool> UpdateTrustListAsync(
TrustListDataType trustList,
NodeId certificateGroupId,
long maxTrustListSize,
CancellationToken ct = default)
Copy link

Copilot AI Feb 26, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new public method overload is missing XML documentation for the certificateGroupId parameter. This parameter should be documented with a <param name="certificateGroupId"> tag explaining that it is the identifier for the CertificateGroup to which the trust list update should be applied.

Copilot uses AI. Check for mistakes.
Comment on lines +795 to +796
/// Add certificate.
/// </summary>
Copy link

Copilot AI Feb 26, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new public method overload is missing XML documentation for the certificateGroupId parameter. This parameter should be documented with a <param name="certificateGroupId"> tag explaining that it is the identifier for the CertificateGroup to which the certificate should be added.

Suggested change
/// Add certificate.
/// </summary>
/// Add a certificate to the specified certificate group on the server.
/// </summary>
/// <param name="certificate">The certificate to add to the certificate group.</param>
/// <param name="isTrustedCertificate">If <c>true</c>, the certificate is added as a trusted certificate; otherwise it is added as an issuer certificate.</param>
/// <param name="certificateGroupId">The identifier for the CertificateGroup to which the certificate should be added.</param>
/// <param name="ct">The token that can be used to cancel the asynchronous operation.</param>
/// <returns>A task that represents the asynchronous add-certificate operation.</returns>

Copilot uses AI. Check for mistakes.

/// <summary>
/// Remove certificate.
/// </summary>
Copy link

Copilot AI Feb 26, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new public method overload is missing XML documentation for the certificateGroupId parameter. This parameter should be documented with a <param name="certificateGroupId"> tag explaining that it is the identifier for the CertificateGroup from which the certificate should be removed.

Suggested change
/// </summary>
/// </summary>
/// <param name="thumbprint">The thumbprint of the certificate to remove.</param>
/// <param name="isTrustedCertificate">Indicates whether the certificate is a trusted certificate.</param>
/// <param name="certificateGroupId">
/// The identifier for the CertificateGroup from which the certificate should be removed.
/// </param>
/// <param name="ct">The token to monitor for cancellation requests.</param>
/// <returns>A task that represents the asynchronous remove operation.</returns>

Copilot uses AI. Check for mistakes.
NodeId referenceTypeId,
CancellationToken ct = default)
{
Node node = await Session.ReadNodeAsync(searchNodeId, ct).ConfigureAwait(false);
Copy link

Copilot AI Feb 26, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ReadNodeAsync call on line 1373 may fail if the searchNodeId cannot be resolved in the server's namespace (e.g., if namespace mappings differ). Consider wrapping this in a try-catch block with a more specific error message indicating that the standard node definition could not be read, which would help with debugging issues related to namespace mismatches.

Suggested change
Node node = await Session.ReadNodeAsync(searchNodeId, ct).ConfigureAwait(false);
Node node;
try
{
node = await Session.ReadNodeAsync(searchNodeId, ct).ConfigureAwait(false);
}
catch (ServiceResultException ex)
{
m_logger.LogError(
ex,
"Failed to read standard node definition for NodeId {SearchNodeId}. " +
"This may indicate a namespace mapping mismatch between client and server.",
searchNodeId);
throw;
}

Copilot uses AI. Check for mistakes.
Comment on lines 582 to 594
if (IsConnected)
{
NodeId closeMethodId =
await BrowseNodeIdAsync(trustListNodeId,
Ua.MethodIds.FileType_Close, ReferenceTypeIds.HasComponent, ct)
.ConfigureAwait(false);

await session.CallAsync(
ExpandedNodeId.ToNodeId(
Ua.ObjectIds.ServerConfiguration_CertificateGroups_DefaultApplicationGroup_TrustList,
session.NamespaceUris
),
ExpandedNodeId.ToNodeId(
Ua.MethodIds
.ServerConfiguration_CertificateGroups_DefaultApplicationGroup_TrustList_Close,
session.NamespaceUris
),
ct,
fileHandle)
trustListNodeId,
closeMethodId,
ct,
fileHandle)
.ConfigureAwait(false);
Copy link

Copilot AI Feb 26, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error handler attempts to call BrowseNodeIdAsync and session.CallAsync to close the file handle, but these calls can also fail (e.g., if the connection is lost or if there's a timeout). Consider wrapping these cleanup calls in a try-catch block to prevent the original exception from being masked by a cleanup failure. This pattern is important for ensuring the original error is always propagated to the caller.

Copilot uses AI. Check for mistakes.
@Tyrrx
Copy link
Author

Tyrrx commented Feb 26, 2026

@Tyrrx maybe you can add a fast path for the well known nodes, so no browse is issued for them

Yes, I also thought about that and I added it here: 293f281. But now the problem is that the actual browse methods are not covered by the tests anymore. Is it possible to introduce a custom group in the sample server and if so, how?

@Tyrrx Tyrrx force-pushed the feature/custom-certificate-group-support branch from b062a99 to 293f281 Compare February 26, 2026 20:52
@romanett
Copy link
Contributor

@Tyrrx thank you for the fast fix, for the Server it is not that easy. However the GDS has this functionality to specifiy additional certificate groups in the configuration. Maybe you can add a tests utilizing that in the GDS.Tests project?

Copy link
Collaborator

@marcschier marcschier left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add tests too, please?

@Tyrrx
Copy link
Author

Tyrrx commented Feb 27, 2026

@Tyrrx thank you for the fast fix, for the Server it is not that easy. However the GDS has this functionality to specifiy additional certificate groups in the configuration. Maybe you can add a tests utilizing that in the GDS.Tests project?

@romanett: I checked the implementation of ICertificateGroup. It seems like there is no mapping from the config to the actual node ID except for the hard coded default groups:

image

The actual node id is inferred by the certificate types in the group in Opc.Ua.Gds.Server.ApplicationsNodeManager.SetCertificateGroupNodes.
I tought, I could use the Opc.Ua.Gds.Server.CertificateGroupConfiguration.Id to specify the node id of a custom group as far as I see it is only used internally. Can I extend the Opc.Ua.Gds.Server.CertificateGroupConfiguration with a NodeId (for the defaults optional) or how should I proceed?

@romanett
Copy link
Contributor

@Tyrrx i think an extenstion is just needed in applicationsNodeManager.SetCertificateGroupNodes to check the existing certificategroup.Id config.

Thank you👍.

If this doesnt work I See No harm in adding the optional NodeId config propery

@Tyrrx
Copy link
Author

Tyrrx commented Feb 27, 2026

@romanett Okay I took a closer look and it seems like it's not done by just adding a nodeId or extending the SetCertificateGroupNodes. Or am I missing something? But we have certificate groups already and a custom certificate group should behave as a default one so I would propose to just add a flag for disabling the lookup and use it during the tests. What do you mean?

@Tyrrx
Copy link
Author

Tyrrx commented Feb 27, 2026

Another option would be to test the private methods but I think that's worse.

@marcschier marcschier marked this pull request as draft February 28, 2026 06:43
@romanett
Copy link
Contributor

@Tyrrx Copilot implemented the Support we can Test it and merge before yours, than you can base the integration Test on that.
#3589
Before Version 1.6 is Release will take some more time anyway, so your PR will end p in 1.6

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ServerPushConfigurationClient lacks overloads that accept an arbitrary certificate group id

5 participants