feat(opcuaclient): opt-in server-certificate host-name check; NAT fixture keeps its PKI (#816, #818)
#816 finding: the SDK checks that the server certificate names the host only when a session is created with checkDomain:true. The driver, the AdminUI browser and Client.Shared all called the 8-argument DefaultSessionFactory.CreateAsync, which forwards checkDomain:false — so no host-name check ever ran (why a trusted NAT cert for *.invalid browsed fine over an IP in #813). When enabled the SDK (Session.OpenAsync -> ValidateDomains -> FindDomain) compares ConfiguredEndpoint.EndpointUrl.IdnHost — the CONFIGURED host, because OpcUaEndpointSelection/EndpointSelector rewrote the advertised one — against the cert's DNS/IP SANs; secured sessions only, and the auto-accept handler accepts a mismatch. Policy: certificateValidation.validateServerHostName, tri-state. Unset = OpcUaCertificateValidationOptions.DefaultValidateServerHostName = false, the pre-#816 behaviour, so nothing changes on upgrade; true = validate the configured host; false = explicit NAT/port-publish opt-out. Threaded into the driver, the AdminUI browser (same JSON) and the AdminUI form (a select that keeps "unset" unset), Client.Shared ConnectionSettings.ValidateServerHostName and the CLI --validate-host-name. A driver refusal names the opt-out. #818: the NAT fixture's /app/pki is on the opc-plc-nat-pki volume (verified: same thumbprint across --force-recreate), its PUBLIC cert is committed as Docker/nat/opc-plc-nat-server.der, and NatPublishedEndpointBrowseTests run every secure browse on a throwaway PKI (internal browser seam): refusal with nothing trusted, positive with the cert trusted (unset/false host check), and a BadCertificateHostNameInvalid refusal with the check on. The trusted cert is OPCUA_NAT_SERVER_CERT or the committed one (skip on thumbprint mismatch); OPCUA_NAT_SERVER_CERT_TRUSTED is retired. CI exports its throwaway NAT container's public cert. ServerHostNameValidationTests pin the driver against the plain opc-plc. MIN_EXECUTED not raised (needs a hosted run): +6 in v2-integration (440 -> 446), documented in scripts/ci/README.md.
This commit is contained in:
+29
@@ -231,6 +231,35 @@ public sealed record OpcUaCertificateValidationOptions
|
||||
/// operator-managed CRL set. <c>null</c>/empty (default) = <c>%LocalAppData%/OtOpcUa/pki/issuers</c>.
|
||||
/// </summary>
|
||||
public string? IssuerStorePath { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// The value an unset <see cref="ValidateServerHostName"/> resolves to. <c>false</c> keeps the behaviour every
|
||||
/// deployment had before Gitea #816 (the SDK never checked the host name for this driver family).
|
||||
/// </summary>
|
||||
public const bool DefaultValidateServerHostName = false;
|
||||
|
||||
/// <summary>
|
||||
/// Gitea #816 — whether the server certificate must list the host the operator CONFIGURED (the endpoint URL's
|
||||
/// host, which the shared <see cref="OpcUaEndpointUrlRewriter"/> keeps in place of the server-advertised one)
|
||||
/// among its DNS / IP subject-alternative names. A mismatch refuses the session with
|
||||
/// <c>BadCertificateHostNameInvalid</c>.
|
||||
/// <list type="bullet">
|
||||
/// <item><c>null</c> (default) = <see cref="DefaultValidateServerHostName"/> (off).</item>
|
||||
/// <item><c>true</c> = validate. Worth it when trust comes from a CA (a trusted issuer vouches for every
|
||||
/// certificate it signed, so only the host check ties the certificate to THIS server); adds little when the
|
||||
/// server's own self-signed certificate is pinned in the trusted-peer store.</item>
|
||||
/// <item><c>false</c> = explicit opt-out — the NAT / port-publish / IP-addressed case, where the server's
|
||||
/// certificate names its private host and the reachable address is something else.</item>
|
||||
/// </list>
|
||||
/// Only applies to secured sessions (a <c>None</c> channel validates no server certificate at all), and
|
||||
/// <see cref="OpcUaClientDriverOptions.AutoAcceptCertificates"/> accepts a host-name mismatch like any other
|
||||
/// certificate error.
|
||||
/// </summary>
|
||||
public bool? ValidateServerHostName { get; init; }
|
||||
|
||||
/// <summary><see cref="ValidateServerHostName"/> with the default applied.</summary>
|
||||
[System.Text.Json.Serialization.JsonIgnore]
|
||||
public bool EffectiveValidateServerHostName => ValidateServerHostName ?? DefaultValidateServerHostName;
|
||||
}
|
||||
|
||||
/// <summary>OPC UA message security mode.</summary>
|
||||
|
||||
Reference in New Issue
Block a user