in src/Azure.IIoT.OpcUa.Publisher/src/Stack/Runtime/OpcUaClientConfig.cs [115:429]
public override void PostConfigure(string? name, OpcUaClientOptions options)
{
if (string.IsNullOrEmpty(options.ApplicationName))
{
options.ApplicationName = GetStringOrDefault(ApplicationNameKey);
if (string.IsNullOrEmpty(options.ApplicationName) ||
options.ApplicationName == "Azure.IIoT.OpcUa.Publisher.Module")
{
options.ApplicationName = ApplicationNameDefault;
}
}
if (string.IsNullOrEmpty(options.ApplicationUri))
{
options.ApplicationUri = GetStringOrDefault(ApplicationUriKey,
string.Format(CultureInfo.InvariantCulture,
ApplicationUriDefault, options.ApplicationName));
}
if (string.IsNullOrEmpty(options.ProductUri))
{
options.ProductUri = GetStringOrDefault(ProductUriKey,
ProductUriDefault);
}
if (options.DefaultSessionTimeoutDuration == null)
{
var sessionTimeout = GetIntOrDefault(DefaultSessionTimeoutKey,
DefaultSessionTimeoutDefaultSec);
if (sessionTimeout > 0)
{
options.DefaultSessionTimeoutDuration = TimeSpan.FromSeconds(sessionTimeout);
}
}
if (options.DefaultServiceCallTimeoutDuration == null)
{
var serviceCallTimeout = GetIntOrDefault(DefaultServiceCallTimeoutKey,
DefaultServiceCallTimeoutDefaultSec);
if (serviceCallTimeout > 0)
{
options.DefaultServiceCallTimeoutDuration = TimeSpan.FromSeconds(serviceCallTimeout);
}
}
if (options.DefaultConnectTimeoutDuration == null)
{
var connectTimeout = GetIntOrNull(DefaultConnectTimeoutKey);
if (connectTimeout > 0)
{
options.DefaultConnectTimeoutDuration = TimeSpan.FromSeconds(connectTimeout.Value);
}
}
if (options.KeepAliveIntervalDuration == null)
{
var keepAliveInterval = GetIntOrDefault(KeepAliveIntervalKey,
KeepAliveIntervalDefaultSec);
if (keepAliveInterval > 0)
{
options.KeepAliveIntervalDuration = TimeSpan.FromSeconds(keepAliveInterval);
}
}
if (options.CreateSessionTimeoutDuration == null)
{
var createSessionTimeout = GetIntOrDefault(CreateSessionTimeoutKey,
CreateSessionTimeoutDefaultSec);
if (createSessionTimeout > 0)
{
options.CreateSessionTimeoutDuration = TimeSpan.FromSeconds(createSessionTimeout);
}
}
options.ReverseConnectPort ??= GetIntOrDefault(ReverseConnectPortKey,
ReverseConnectPortDefault);
if (options.MinReconnectDelayDuration == null)
{
var reconnectDelay = GetIntOrDefault(MinReconnectDelayKey,
MinReconnectDelayDefault);
if (reconnectDelay > 0)
{
options.MinReconnectDelayDuration = TimeSpan.FromMilliseconds(reconnectDelay);
}
}
if (options.MaxReconnectDelayDuration == null)
{
var reconnectDelay = GetIntOrDefault(MaxReconnectDelayKey,
MaxReconnectDelayDefault);
if (reconnectDelay > 0)
{
options.MaxReconnectDelayDuration = TimeSpan.FromMilliseconds(reconnectDelay);
}
}
if (options.LingerTimeoutDuration == null)
{
var lingerTimeout = GetIntOrDefault(LingerTimeoutSecondsKey);
if (lingerTimeout > 0)
{
options.LingerTimeoutDuration = TimeSpan.FromSeconds(lingerTimeout);
}
}
options.DisableComplexTypePreloading ??= GetBoolOrDefault(DisableComplexTypePreloadingKey);
options.MinPublishRequests ??= GetIntOrNull(MinPublishRequestsKey);
options.MaxPublishRequests ??= GetIntOrNull(MaxPublishRequestsKey);
options.PublishRequestsPerSubscriptionPercent ??= GetIntOrNull(
PublishRequestsPerSubscriptionPercentKey);
options.MaxNodesPerReadOverride ??= GetIntOrNull(MaxNodesPerReadOverrideKey);
options.MaxNodesPerBrowseOverride ??= GetIntOrNull(MaxNodesPerBrowseOverrideKey);
if (options.Security.MinimumCertificateKeySize == 0)
{
options.Security.MinimumCertificateKeySize = (ushort)GetIntOrDefault(
MinimumCertificateKeySizeKey, MinimumCertificateKeySizeDefault);
}
if (options.Security.AutoAcceptUntrustedCertificates == null)
{
options.Security.AutoAcceptUntrustedCertificates = GetBoolOrDefault(
AutoAcceptUntrustedCertificatesKey, AutoAcceptUntrustedCertificatesDefault);
}
if (options.Security.RejectSha1SignedCertificates == null)
{
options.Security.RejectSha1SignedCertificates = GetBoolOrDefault(
RejectSha1SignedCertificatesKey, RejectSha1SignedCertificatesDefault);
}
if (options.Security.AddAppCertToTrustedStore == null)
{
options.Security.AddAppCertToTrustedStore = GetBoolOrDefault(
AddAppCertToTrustedStoreKey, AddAppCertToTrustedStoreDefault);
}
if (options.Security.RejectUnknownRevocationStatus == null)
{
options.Security.RejectUnknownRevocationStatus = GetBoolOrDefault(
RejectUnknownRevocationStatusKey, RejectUnknownRevocationStatusDefault);
}
// https://github.com/OPCFoundation/UA-.NETStandard/blob/master/Docs/Certificates.md
if (options.Security.PkiRootPath == null)
{
options.Security.PkiRootPath = GetStringOrDefault(PkiRootPathKey,
PkiRootPathDefault);
}
if (options.Security.ApplicationCertificates == null)
{
options.Security.ApplicationCertificates = new()
{
StorePath = GetStringOrDefault(ApplicationCertificateStorePathKey,
$"{options.Security.PkiRootPath}/own"),
StoreType = GetStringOrDefault(ApplicationCertificateStoreTypeKey,
CertificateStoreType.Directory),
SubjectName = GetStringOrDefault(ApplicationCertificateSubjectNameKey,
$"CN={options.ApplicationName}, C=DE, S=Bav, O=Microsoft, DC=localhost")
};
}
if (options.Security.RejectedCertificateStore == null)
{
options.Security.RejectedCertificateStore = new()
{
StorePath = GetStringOrDefault(RejectedCertificateStorePathKey,
$"{options.Security.PkiRootPath}/rejected"),
StoreType = GetStringOrDefault(RejectedCertificateStoreTypeKey,
CertificateStoreType.Directory)
};
}
if (options.Security.TrustedIssuerCertificates == null)
{
//
// Returns the legacy 'issuers' if folder already exists or per
// specification.
//
var legacyPath = $"{options.Security.PkiRootPath}/issuers";
var path = Directory.Exists(legacyPath) ? legacyPath :
$"{options.Security.PkiRootPath}/issuer";
options.Security.TrustedIssuerCertificates = new()
{
StorePath = GetStringOrDefault(TrustedIssuerCertificatesPathKey,
path),
StoreType = GetStringOrDefault(TrustedIssuerCertificatesTypeKey,
CertificateStoreType.Directory)
};
}
if (options.Security.TrustedPeerCertificates == null)
{
options.Security.TrustedPeerCertificates = new()
{
StorePath = GetStringOrDefault(TrustedPeerCertificatesPathKey,
$"{options.Security.PkiRootPath}/trusted"),
StoreType = GetStringOrDefault(TrustedPeerCertificatesTypeKey,
CertificateStoreType.Directory)
};
}
if (options.Quotas.ChannelLifetime == 0)
{
options.Quotas.ChannelLifetime = GetIntOrDefault(ChannelLifetimeKey,
ChannelLifetimeDefault);
}
if (options.Quotas.MaxArrayLength == 0)
{
options.Quotas.MaxArrayLength = GetIntOrDefault(MaxArrayLengthKey,
MaxArrayLengthDefault);
}
if (options.Quotas.MaxBufferSize == 0)
{
options.Quotas.MaxBufferSize = GetIntOrDefault(MaxBufferSizeKey,
MaxBufferSizeDefault);
}
if (options.Quotas.MaxByteStringLength == 0)
{
options.Quotas.MaxByteStringLength = GetIntOrDefault(MaxByteStringLengthKey,
MaxByteStringLengthDefault);
}
if (options.Quotas.MaxMessageSize == 0)
{
options.Quotas.MaxMessageSize = GetIntOrDefault(MaxMessageSizeKey,
MaxMessageSizeDefault);
}
if (options.Quotas.MaxStringLength == 0)
{
options.Quotas.MaxStringLength = GetIntOrDefault(MaxStringLengthKey,
MaxStringLengthDefault);
}
if (options.Quotas.OperationTimeout == 0)
{
options.Quotas.OperationTimeout = GetIntOrDefault(OperationTimeoutKey,
OperationTimeoutDefault);
}
if (options.Quotas.SecurityTokenLifetime == 0)
{
options.Quotas.SecurityTokenLifetime = GetIntOrDefault(SecurityTokenLifetimeKey,
SecurityTokenLifetimeDefault);
}
options.OpcUaKeySetLogFolderName ??= GetStringOrDefault(OpcUaKeySetLogFolderNameKey);
options.EnableOpcUaStackLogging ??= GetBoolOrNull(EnableOpcUaStackLoggingKey);
if (options.Security.TrustedUserCertificates == null)
{
options.Security.TrustedUserCertificates = new()
{
StorePath = GetStringOrDefault(TrustedUserCertificatesPathKey,
$"{options.Security.PkiRootPath}/user"),
StoreType = GetStringOrDefault(TrustedUserCertificatesTypeKey,
CertificateStoreType.Directory)
};
}
if (options.Security.TrustedHttpsCertificates == null)
{
options.Security.TrustedHttpsCertificates = new()
{
StorePath = GetStringOrDefault(TrustedHttpsCertificatesPathKey,
$"{options.Security.PkiRootPath}/https"),
StoreType = GetStringOrDefault(TrustedHttpsCertificatesTypeKey,
CertificateStoreType.Directory)
};
}
if (options.Security.HttpsIssuerCertificates == null)
{
options.Security.HttpsIssuerCertificates = new()
{
StorePath = GetStringOrDefault(HttpsIssuerCertificatesPathKey,
$"{options.Security.PkiRootPath}/https/issuer"),
StoreType = GetStringOrDefault(HttpsIssuerCertificatesTypeKey,
CertificateStoreType.Directory)
};
}
if (options.Security.UserIssuerCertificates == null)
{
options.Security.UserIssuerCertificates = new()
{
StorePath = GetStringOrDefault(UserIssuerCertificatesPathKey,
$"{options.Security.PkiRootPath}/user/issuer"),
StoreType = GetStringOrDefault(UserIssuerCertificatesTypeKey,
CertificateStoreType.Directory)
};
}
if (options.Security.ApplicationCertificatePassword == null)
{
options.Security.ApplicationCertificatePassword =
GetStringOrDefault(ApplicationCertificatePasswordKey);
}
if (options.Security.TryUseConfigurationFromExistingAppCert == null)
{
options.Security.TryUseConfigurationFromExistingAppCert =
GetBoolOrNull(TryConfigureFromExistingAppCertKey);
}
}