Files
Marc Schier 70b4498db8 Certificate manager and ref counted certificate type (#3688)
* New certificate and secrete abstraction with certificate infrastructure and certificate/secret stores. 
* leak testing for certificate resources to validate new ref counting in every test assembly
* Migration guide updated and documentation added for all
* Remove IDisposable from Nodestate and UserIdentity.
* UserCertificateTokenHandler now just points into certificate registry/stores, no dispose required
* Fix CA2000 warnings and cleanup of other diagnostics, increase warning levels in .editorconfig
2026-05-12 07:56:38 +02:00

234 lines
12 KiB
C#

/* ========================================================================
* Copyright (c) 2005-2025 The OPC Foundation, Inc. All rights reserved.
*
* OPC Foundation MIT License 1.00
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*
* The complete license agreement can be found here:
* http://opcfoundation.org/License/MIT/1.00/
* ======================================================================*/
using System.Threading;
using System.Threading.Tasks;
using Opc.Ua.Security.Certificates;
namespace Opc.Ua.Client
{
/// <summary>
/// Object that creates instances of an ISessions object.
/// </summary>
public interface ISessionFactory
{
/// <summary>
/// Set diagnostics for all sessions created by the factory
/// </summary>
DiagnosticsMasks ReturnDiagnostics { get; set; }
/// <summary>
/// Telemetry configuration to use when creating sessions.
/// </summary>
ITelemetryContext Telemetry { get; }
/// <summary>
/// Creates a new unconnected session with the channel to the server.
/// </summary>
/// <param name="channel">The channel for the server.</param>
/// <param name="configuration">The configuration for the client application.</param>
/// <param name="endpoint">The endpoint for the server.</param>
/// <param name="clientCertificate">The certificate to use for the client.</param>
/// <param name="clientCertificateChain">The certificate chain for the client cert.</param>
/// <param name="availableEndpoints">The list of available endpoints returned by
/// server in GetEndpoints() response.</param>
/// <param name="discoveryProfileUris">The value of profileUris used in
/// GetEndpoints() request.</param>
ISession Create(
ITransportChannel channel,
ApplicationConfiguration configuration,
ConfiguredEndpoint endpoint,
Certificate? clientCertificate = null,
CertificateCollection? clientCertificateChain = null,
ArrayOf<EndpointDescription> availableEndpoints = default,
ArrayOf<string> discoveryProfileUris = default);
/// <summary>
/// Creates a new communication session with a server by invoking the CreateSession service
/// </summary>
/// <param name="configuration">The configuration for the client application.</param>
/// <param name="endpoint">The endpoint for the server.</param>
/// <param name="updateBeforeConnect">If set to <c>true</c> the discovery endpoint is used
/// to update the endpoint description before connecting.</param>
/// <param name="sessionName">The name to assign to the session.</param>
/// <param name="sessionTimeout">The timeout period for the session.</param>
/// <param name="identity">The identity.</param>
/// <param name="preferredLocales">The user identity to associate with the session.</param>
/// <param name="ct">The cancellation token</param>
/// <returns>The new session object</returns>
Task<ISession> CreateAsync(
ApplicationConfiguration configuration,
ConfiguredEndpoint endpoint,
bool updateBeforeConnect,
string sessionName,
uint sessionTimeout,
IUserIdentity? identity,
ArrayOf<string> preferredLocales,
CancellationToken ct = default);
/// <summary>
/// Creates a new communication session with a server by invoking the CreateSession
/// service
/// </summary>
/// <param name="configuration">The configuration for the client application.</param>
/// <param name="endpoint">The endpoint for the server.</param>
/// <param name="updateBeforeConnect">If set to <c>true</c> the discovery endpoint is
/// used to update the endpoint description before connecting.</param>
/// <param name="checkDomain">If set to <c>true</c> then the domain in the certificate
/// must match the endpoint used.</param>
/// <param name="sessionName">The name to assign to the session.</param>
/// <param name="sessionTimeout">The timeout period for the session.</param>
/// <param name="identity">The user identity to associate with the session.</param>
/// <param name="preferredLocales">The preferred locales.</param>
/// <param name="ct">The cancellation token</param>
/// <returns>The new session object.</returns>
Task<ISession> CreateAsync(
ApplicationConfiguration configuration,
ConfiguredEndpoint endpoint,
bool updateBeforeConnect,
bool checkDomain,
string sessionName,
uint sessionTimeout,
IUserIdentity? identity,
ArrayOf<string> preferredLocales,
CancellationToken ct = default);
/// <summary>
/// Creates a secure channel to the specified endpoint.
/// </summary>
/// <param name="configuration">The application configuration.</param>
/// <param name="connection">The client endpoint for the reverse connect.</param>
/// <param name="endpoint">A configured endpoint to connect to.</param>
/// <param name="updateBeforeConnect">Update configuration based on server
/// prior connect.</param>
/// <param name="checkDomain">Check that the certificate specifies a valid
/// domain (computer) name.</param>
/// <param name="ct">The cancellation token.</param>
/// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
Task<ITransportChannel> CreateChannelAsync(
ApplicationConfiguration configuration,
ITransportWaitingConnection connection,
ConfiguredEndpoint endpoint,
bool updateBeforeConnect,
bool checkDomain,
CancellationToken ct = default);
/// <summary>
/// Creates a new communication session with a server using a reverse connection.
/// </summary>
/// <param name="configuration">The configuration for the client application.</param>
/// <param name="connection">The client endpoint for the reverse connect.</param>
/// <param name="endpoint">The endpoint for the server.</param>
/// <param name="updateBeforeConnect">If set to <c>true</c> the discovery endpoint
/// is used to update the endpoint description before connecting.</param>
/// <param name="checkDomain">If set to <c>true</c> then the domain in the
/// certificate must match the endpoint used.</param>
/// <param name="sessionName">The name to assign to the session.</param>
/// <param name="sessionTimeout">The timeout period for the session.</param>
/// <param name="identity">The user identity to associate with the session.</param>
/// <param name="preferredLocales">The preferred locales.</param>
/// <param name="ct">The cancellation token</param>
/// <returns>The new session object.</returns>
Task<ISession> CreateAsync(
ApplicationConfiguration configuration,
ITransportWaitingConnection connection,
ConfiguredEndpoint endpoint,
bool updateBeforeConnect,
bool checkDomain,
string sessionName,
uint sessionTimeout,
IUserIdentity? identity,
ArrayOf<string> preferredLocales,
CancellationToken ct = default);
/// <summary>
/// Creates a new communication session with a server using a reverse connect manager.
/// </summary>
/// <param name="configuration">The configuration for the client application.</param>
/// <param name="reverseConnectManager">The reverse connect manager for the client
/// connection.</param>
/// <param name="endpoint">The endpoint for the server.</param>
/// <param name="updateBeforeConnect">If set to <c>true</c> the discovery endpoint
/// is used to update the endpoint description before connecting.</param>
/// <param name="checkDomain">If set to <c>true</c> then the domain in the certificate
/// must match the endpoint used.</param>
/// <param name="sessionName">The name to assign to the session.</param>
/// <param name="sessionTimeout">The timeout period for the session.</param>
/// <param name="userIdentity">The user identity to associate with the session.</param>
/// <param name="preferredLocales">The preferred locales.</param>
/// <param name="ct">The cancellation token.</param>
/// <returns>The new session object.</returns>
Task<ISession> CreateAsync(
ApplicationConfiguration configuration,
ReverseConnectManager reverseConnectManager,
ConfiguredEndpoint endpoint,
bool updateBeforeConnect,
bool checkDomain,
string sessionName,
uint sessionTimeout,
IUserIdentity? userIdentity,
ArrayOf<string> preferredLocales,
CancellationToken ct = default);
/// <summary>
/// Recreates a session based on a specified template.
/// </summary>
/// <param name="sessionTemplate">The ISession object to use as template</param>
/// <param name="ct">The cancellation token.</param>
/// <returns>The new session object.</returns>
Task<ISession> RecreateAsync(
ISession sessionTemplate,
CancellationToken ct = default);
/// <summary>
/// Recreates a session based on a specified template.
/// </summary>
/// <param name="sessionTemplate">The ISession object to use as template</param>
/// <param name="connection">The waiting reverse connection.</param>
/// <param name="ct">The cancellation token.</param>
/// <returns>The new session object.</returns>
Task<ISession> RecreateAsync(
ISession sessionTemplate,
ITransportWaitingConnection connection,
CancellationToken ct = default);
/// <summary>
/// Recreates a session based on a specified template using the provided channel.
/// </summary>
/// <param name="sessionTemplate">The Session object to use as template</param>
/// <param name="transportChannel">The channel to use to recreate the session.</param>
/// <param name="ct">The cancellation token.</param>
/// <returns>The new session object.</returns>
Task<ISession> RecreateAsync(
ISession sessionTemplate,
ITransportChannel transportChannel,
CancellationToken ct = default);
}
}