/* ======================================================================== * 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; using System.Diagnostics.CodeAnalysis; using System.Threading; using System.Threading.Tasks; using System.Xml; namespace Opc.Ua.Configuration { /// /// A fluent API to build the application configuration. /// public interface IApplicationConfigurationBuilder : IApplicationConfigurationBuilderTypes, IApplicationConfigurationBuilderTransportQuotasSet, IApplicationConfigurationBuilderServerSelected, IApplicationConfigurationBuilderServerOptions, IApplicationConfigurationBuilderClientSelected, IApplicationConfigurationBuilderSecurity, IApplicationConfigurationBuilderSecurityOptions, IApplicationConfigurationBuilderSecurityOptionStores, IApplicationConfigurationBuilderServerPolicies, IApplicationConfigurationBuilderCreate; /// /// The client or server configuration types to choose. /// public interface IApplicationConfigurationBuilderTypes : IApplicationConfigurationBuilderTransportQuotas ; /// /// The set transport quota state. /// public interface IApplicationConfigurationBuilderTransportQuotas : IApplicationConfigurationBuilderServer, IApplicationConfigurationBuilderClient { /// /// Set the transport quotas for this application (client and server). /// /// The object with the new transport quotas. IApplicationConfigurationBuilderTransportQuotasSet SetTransportQuotas( TransportQuotas transportQuotas); /// /// applies to /// The operation timeout in ms. IApplicationConfigurationBuilderTransportQuotas SetOperationTimeout(int operationTimeout); /// /// applies to /// The max string length. IApplicationConfigurationBuilderTransportQuotas SetMaxStringLength(int maxStringLength); /// /// applies to /// The max byte string length. IApplicationConfigurationBuilderTransportQuotas SetMaxByteStringLength( int maxByteStringLength); /// /// applies to /// The max array length. IApplicationConfigurationBuilderTransportQuotas SetMaxArrayLength(int maxArrayLength); /// /// applies to /// The max message size. IApplicationConfigurationBuilderTransportQuotas SetMaxMessageSize(int maxMessageSize); /// /// applies to /// The max buffer size. IApplicationConfigurationBuilderTransportQuotas SetMaxBufferSize(int maxBufferSize); /// /// applies to IApplicationConfigurationBuilderTransportQuotas SetMaxEncodingNestingLevels( int maxEncodingNestingLevels); /// /// applies to IApplicationConfigurationBuilderTransportQuotas SetMaxDecoderRecoveries( int maxDecoderRecoveries); /// /// applies to /// The lifetime. IApplicationConfigurationBuilderTransportQuotas SetChannelLifetime(int channelLifetime); /// /// applies to /// The lifetime in milliseconds. IApplicationConfigurationBuilderTransportQuotas SetSecurityTokenLifetime( int securityTokenLifetime); } /// /// The set transport quota state. /// public interface IApplicationConfigurationBuilderTransportQuotasSet : IApplicationConfigurationBuilderServer, IApplicationConfigurationBuilderClient; /// /// The interfaces to implement if a server is selected. /// public interface IApplicationConfigurationBuilderServerSelected : IApplicationConfigurationBuilderServerPolicies, IApplicationConfigurationBuilderServerOptions ; /// /// The options which can be set if a server is selected. /// public interface IApplicationConfigurationBuilderServerOptions : IApplicationConfigurationBuilderClient, IApplicationConfigurationBuilderSecurity { /// IApplicationConfigurationBuilderServerOptions SetMinRequestThreadCount( int minRequestThreadCount); /// IApplicationConfigurationBuilderServerOptions SetMaxRequestThreadCount( int maxRequestThreadCount); /// IApplicationConfigurationBuilderServerOptions SetMaxQueuedRequestCount( int maxQueuedRequestCount); /// IApplicationConfigurationBuilderServerOptions SetDiagnosticsEnabled( bool diagnosticsEnabled); /// IApplicationConfigurationBuilderServerOptions SetMaxSessionCount(int maxSessionCount); /// /// applies to /// The lifetime. IApplicationConfigurationBuilderServerOptions SetMaxChannelCount(int maxChannelCount); /// IApplicationConfigurationBuilderServerOptions SetMinSessionTimeout(int minSessionTimeout); /// IApplicationConfigurationBuilderServerOptions SetMaxSessionTimeout(int maxSessionTimeout); /// IApplicationConfigurationBuilderServerOptions SetMaxBrowseContinuationPoints( int maxBrowseContinuationPoints); /// IApplicationConfigurationBuilderServerOptions SetMaxQueryContinuationPoints( int maxQueryContinuationPoints); /// IApplicationConfigurationBuilderServerOptions SetMaxHistoryContinuationPoints( int maxHistoryContinuationPoints); /// IApplicationConfigurationBuilderServerOptions SetMaxRequestAge(int maxRequestAge); /// IApplicationConfigurationBuilderServerOptions SetMinPublishingInterval( int minPublishingInterval); /// IApplicationConfigurationBuilderServerOptions SetMaxPublishingInterval( int maxPublishingInterval); /// IApplicationConfigurationBuilderServerOptions SetPublishingResolution( int publishingResolution); /// IApplicationConfigurationBuilderServerOptions SetMaxSubscriptionLifetime( int maxSubscriptionLifetime); /// IApplicationConfigurationBuilderServerOptions SetMaxMessageQueueSize( int maxMessageQueueSize); /// IApplicationConfigurationBuilderServerOptions SetMaxNotificationQueueSize( int maxNotificationQueueSize); /// IApplicationConfigurationBuilderServerOptions SetMaxNotificationsPerPublish( int maxNotificationsPerPublish); /// IApplicationConfigurationBuilderServerOptions SetMinMetadataSamplingInterval( int minMetadataSamplingInterval); /// IApplicationConfigurationBuilderServerOptions SetAvailableSamplingRates( ArrayOf availableSampleRates); /// IApplicationConfigurationBuilderServerOptions SetRegistrationEndpoint( EndpointDescription registrationEndpoint); /// IApplicationConfigurationBuilderServerOptions SetMaxRegistrationInterval( int maxRegistrationInterval); /// IApplicationConfigurationBuilderServerOptions SetNodeManagerSaveFile( string nodeManagerSaveFile); /// IApplicationConfigurationBuilderServerOptions SetMinSubscriptionLifetime( int minSubscriptionLifetime); /// IApplicationConfigurationBuilderServerOptions SetMaxPublishRequestCount( int maxPublishRequestCount); /// IApplicationConfigurationBuilderServerOptions SetMaxSubscriptionCount( int maxSubscriptionCount); /// IApplicationConfigurationBuilderServerOptions SetMaxEventQueueSize( int setMaxEventQueueSize); /// /// Add a server profile to the array. IApplicationConfigurationBuilderServerOptions AddServerProfile(string serverProfile); /// IApplicationConfigurationBuilderServerOptions SetShutdownDelay(int shutdownDelay); /// /// The server capability to add. IApplicationConfigurationBuilderServerOptions AddServerCapabilities( string serverCapability); /// IApplicationConfigurationBuilderServerOptions SetSupportedPrivateKeyFormats( ArrayOf supportedPrivateKeyFormats); /// IApplicationConfigurationBuilderServerOptions SetMaxTrustListSize(int maxTrustListSize); /// IApplicationConfigurationBuilderServerOptions SetMultiCastDnsEnabled( bool multiCastDnsEnabled); /// IApplicationConfigurationBuilderServerOptions SetReverseConnect( ReverseConnectServerConfiguration reverseConnectConfiguration); /// IApplicationConfigurationBuilderServerOptions SetOperationLimits( OperationLimits operationLimits); /// IApplicationConfigurationBuilderServerOptions SetAuditingEnabled(bool auditingEnabled); /// IApplicationConfigurationBuilderServerOptions SetHttpsMutualTls(bool mTlsEnabled); /// IApplicationConfigurationBuilderServerOptions SetDurableSubscriptionsEnabled( bool durableSubscriptionsEnabled); /// IApplicationConfigurationBuilderServerOptions SetMaxDurableNotificationQueueSize( int maxDurableNotificationQueueSize); /// IApplicationConfigurationBuilderServerOptions SetMaxDurableEventQueueSize( int maxDurableEventQueueSize); /// IApplicationConfigurationBuilderServerOptions SetMaxDurableSubscriptionLifetime( int maxDurableSubscriptionLifetimeInHours); } /// /// The interfaces to implement if a client is selected. /// public interface IApplicationConfigurationBuilderClientSelected : IApplicationConfigurationBuilderClientOptions; /// /// The options to set if a client is selected. /// public interface IApplicationConfigurationBuilderClientOptions : IApplicationConfigurationBuilderSecurity { /// IApplicationConfigurationBuilderClientOptions SetDefaultSessionTimeout( int defaultSessionTimeout); /// /// The well known discovery server url to add. IApplicationConfigurationBuilderClientOptions AddWellKnownDiscoveryUrls( string wellKnownDiscoveryUrl); /// /// The discovery server endpoint description to add. IApplicationConfigurationBuilderClientOptions AddDiscoveryServer( EndpointDescription discoveryServer); /// IApplicationConfigurationBuilderClientOptions SetEndpointCacheFilePath( string endpointCacheFilePath); /// IApplicationConfigurationBuilderClientOptions SetMinSubscriptionLifetime( int minSubscriptionLifetime); /// IApplicationConfigurationBuilderClientOptions SetReverseConnect( ReverseConnectClientConfiguration reverseConnect); /// IApplicationConfigurationBuilderClientOptions SetClientOperationLimits( OperationLimits operationLimits); } /// /// Add the server configuration (optional). /// public interface IApplicationConfigurationBuilderServer { /// /// Configure instance to be used for UA server. /// IApplicationConfigurationBuilderServerSelected AsServer( string[] baseAddresses, string[]? alternateBaseAddresses = null); } /// /// Add the client configuration (optional). /// public interface IApplicationConfigurationBuilderClient { /// /// Configure instance to be used for UA client. /// IApplicationConfigurationBuilderClientSelected AsClient(); } /// /// Add the supported server policies. /// public interface IApplicationConfigurationBuilderServerPolicies { /// /// Add the unsecure security policy type none to server configuration. /// /// Add policy if true. IApplicationConfigurationBuilderServerSelected AddUnsecurePolicyNone(bool addPolicy = true); /// /// Add the sign security policies to the server configuration. /// /// Add policies if true. IApplicationConfigurationBuilderServerSelected AddSignPolicies(bool addPolicies = true); /// /// Add the sign and encrypt security policies to the server configuration. /// /// Add policies if true. IApplicationConfigurationBuilderServerSelected AddSignAndEncryptPolicies( bool addPolicies = true); /// /// Add the ECCsign security policies to the server configuration. /// /// /// The policies are only added if the platform supports the ECC policies. /// IApplicationConfigurationBuilderServerSelected AddEccSignPolicies(); /// /// Add the ECC sign and encrypt security policies to the server configuration. /// /// /// The policies are only added if the platform supports the ECC policies. /// IApplicationConfigurationBuilderServerSelected AddEccSignAndEncryptPolicies(); /// /// Add the specified security policy with the specified security mode. /// /// The message security mode to add the policy to. /// The security policy Uri string. IApplicationConfigurationBuilderServerSelected AddPolicy( MessageSecurityMode securityMode, string securityPolicy); /// /// Add user token policy to the server configuration. /// /// The user token type to add. IApplicationConfigurationBuilderServerSelected AddUserTokenPolicy( UserTokenType userTokenType); /// /// Add user token policy to the server configuration. /// /// The user token policy to add. IApplicationConfigurationBuilderServerSelected AddUserTokenPolicy( UserTokenPolicy userTokenPolicy); } /// /// Add the security configuration (mandatory). /// public interface IApplicationConfigurationBuilderSecurity { /// /// Add the security configuration. /// /// /// The pki root path default to the certificate store /// location as defined in /// A defaults to the corresponding default store location. /// /// Application certificate subject name as distinguished name. A DC=localhost entry is converted to the hostname. The common name CN= is mandatory. /// The path to the pki root. By default all cert stores use the pki root. /// The path to the app cert store, if different than the pki root. /// The path to the rejected certificate store. [Obsolete( "Use AddSecurityConfiguration(ArrayOf certIdList, string pkiRoot = null, string rejectedRoot = null) instead." )] IApplicationConfigurationBuilderSecurityOptions AddSecurityConfiguration( string subjectName, string? pkiRoot = null, string? appRoot = null, string? rejectedRoot = null); /// /// Add the security configuration. /// /// /// The pki root path default to the certificate store /// location as defined in /// A defaults to the corresponding default store location. /// /// A list of Certificate identifiers /// The path to the pki root. By default all cert stores use the pki root. /// The path to the rejected certificate store. IApplicationConfigurationBuilderSecurityOptions AddSecurityConfiguration( ArrayOf certIdList, string? pkiRoot = null, string? rejectedRoot = null); /// /// Add the security configuration for mandatory application, issuer and trusted stores. /// /// Application certificate subject name as distinguished name. /// A DC=localhost entry is converted to the hostname. The common name CN= is mandatory. /// The path to the app cert store. /// The path to the trusted cert store. /// The path to the issuer cert store. /// The path to the rejected certificate store. IApplicationConfigurationBuilderSecurityOptionStores AddSecurityConfigurationStores( string subjectName, string appRoot, string trustedRoot, string issuerRoot, string? rejectedRoot = null); } /// /// Add security options to the configuration. /// public interface IApplicationConfigurationBuilderSecurityOptionStores : IApplicationConfigurationBuilderSecurityOptions { /// /// Add the security configuration for the user certificate issuer and trusted stores. /// /// The path to the trusted cert store. /// The path to the issuer cert store. IApplicationConfigurationBuilderSecurityOptionStores AddSecurityConfigurationUserStore( string trustedRoot, string issuerRoot); /// /// Add the security configuration for the https certificate issuer and trusted stores. /// /// The path to the trusted cert store. /// The path to the issuer cert store. IApplicationConfigurationBuilderSecurityOptionStores AddSecurityConfigurationHttpsStore( string trustedRoot, string issuerRoot); } /// /// Add security options to the configuration. /// public interface IApplicationConfigurationBuilderSecurityOptions : IApplicationConfigurationBuilderGlobalConfiguration, IApplicationConfigurationBuilderExtension { /// /// The certificate types that should be supported. /// /// /// At this time the following types are supported, if the platform OS and .NET version can handle it. /// Rsa,nistP256,nistP384,brainpoolP256r1,brainpoolP384r1 /// /// A list of Certificate identifiers IApplicationConfigurationBuilderSecurityOptions SetApplicationCertificates( ArrayOf certIdList); /// /// The number of rejected certificates to keep in the store. /// /// /// The number of certificates to keep in the rejected store before it is updated. /// to keep all rejected certificates. /// A negative number to keep no history. /// IApplicationConfigurationBuilderSecurityOptions SetMaxRejectedCertificates( int maxRejectedCertificates); /// /// Whether an unknown application certificate should be accepted /// once all other security checks passed. /// /// to accept unknown application certificates. IApplicationConfigurationBuilderSecurityOptions SetAutoAcceptUntrustedCertificates( bool autoAccept); /// /// Whether a newly created application certificate should be added to the trusted store. /// This function is only useful if multiple UA applications share the same trusted store. /// /// to add the cert to the trusted store. IApplicationConfigurationBuilderSecurityOptions SetAddAppCertToTrustedStore( bool addToTrustedStore); /// /// Reject SHA1 signed certificates. /// /// to accept SHA1 signed certificates. IApplicationConfigurationBuilderSecurityOptions SetRejectSHA1SignedCertificates( bool rejectSHA1Signed); /// /// Reject chain validation with CA certs with unknown revocation status, /// e.g. when the CRL is not available or the OCSP provider is offline. /// /// to accept CA certs with unknown revocation status. IApplicationConfigurationBuilderSecurityOptions SetRejectUnknownRevocationStatus( bool rejectUnknownRevocationStatus); /// /// Use the validated certificates for fast Validation. /// /// to use the validated certificates. IApplicationConfigurationBuilderSecurityOptions SetUseValidatedCertificates( bool useValidatedCertificates); /// /// Whether to suppress errors which are caused by clients and servers which provide /// zero nonce values or nonce with insufficient entropy. /// Suppressing this error is a security risk and may allow an attacker to decrypt user tokens. /// Only use if interoperability issues with legacy servers or clients leave no other choice to operate. /// /// to suppress nonce validation errors. IApplicationConfigurationBuilderSecurityOptions SetSuppressNonceValidationErrors( bool suppressNonceValidationErrors); /// /// Whether a certificate chain should be sent with the application certificate. /// Only used if the application certificate is CA signed. /// /// to send the certificate chain with the application certificate. IApplicationConfigurationBuilderSecurityOptions SetSendCertificateChain( bool sendCertificateChain); /// /// The minimum RSA key size to accept. /// By default the key size is set to . /// /// The minimum RSA key size to accept. IApplicationConfigurationBuilderSecurityOptions SetMinimumCertificateKeySize( ushort keySize); /// /// Add a certificate password provider. /// /// The certificate password provider to use. IApplicationConfigurationBuilderSecurityOptions AddCertificatePasswordProvider( ICertificatePasswordProvider certificatePasswordProvider); } /// /// Add extensions configuration. /// public interface IApplicationConfigurationBuilderExtension : IApplicationConfigurationBuilderTraceConfiguration { /// /// Add an extension to the configuration using an encoder function (AOT-safe). /// /// The type of the object to add as an extension. /// The name of the extension, null to use the type name. /// The object to add and encode. /// A function that writes the value to an . [Experimental("UA_NETStandard_1")] IApplicationConfigurationBuilderExtension AddExtension( XmlQualifiedName elementName, T value, Action encoderFunc); /// /// Add an IEncodeable extension to the configuration (AOT-safe). /// /// The type of the object to add as an extension (must implement IEncodeable). /// The name of the extension, null to use the type name. /// The IEncodeable object to add and encode. IApplicationConfigurationBuilderExtension AddExtension( XmlQualifiedName? elementName, T value) where T : IEncodeable; } /// /// Add some global configuration settings. /// public interface IApplicationConfigurationBuilderGlobalConfiguration : IApplicationConfigurationBuilderCreate, IApplicationConfigurationBuilderTraceConfiguration { /// /// Set the high resolution clock to disabled or enabled. /// /// true if high resolution clock is disabled; otherwise, false. IApplicationConfigurationBuilderGlobalConfiguration SetHiResClockDisabled( bool hiResClockDisabled); } /// /// Add the trace configuration. /// public interface IApplicationConfigurationBuilderTraceConfiguration : IApplicationConfigurationBuilderCreate { /// IApplicationConfigurationBuilderTraceConfiguration SetOutputFilePath(string outputFilePath); /// IApplicationConfigurationBuilderTraceConfiguration SetDeleteOnLoad(bool deleteOnLoad); /// IApplicationConfigurationBuilderTraceConfiguration SetTraceMasks(int traceMasks); } /// /// Create and validate the application configuration. /// public interface IApplicationConfigurationBuilderCreate { /// /// Creates and updates the application configuration. /// Task CreateAsync(CancellationToken ct = default); } }