feat(dcl): move the OPC UA client to OPC Foundation SDK 2.0.1 (#125)
OPCFoundation.NetStandard.Opc.Ua.Client and the test-only .Server move 1.5.378.182 -> 2.0.1, the version OtOpcUa master runs (lmxopcua#782; #799 and #801 closed). Transitive Core/Core.Types/Types/Configuration/ Security.Certificates resolve to 2.0.1. API breaks fixed in the DCL adapter: - Built-in types are immutable structs (Variant, DataValue, NodeId, LocalizedText, StatusCode, ArrayOf<T>). New OpcUaValueBoundary restores the SDK 1.5 CLR shapes for every read, subscription and alarm-event value (byte[], UTC DateTime with no-timestamp = MinValue, Guid, detached arrays) and builds write variants with SDK 1.5's new Variant(object) semantics (byte[] = ByteString scalar). - StatusCodes members are no longer constants: switches/patterns over them (verify-outcome mapping, connection-level classification, BadResourceUnavailable) match by value. - CertificateIdentifier no longer caches a certificate and the CertificateValidator/CertificateValidation event is gone: the configuration's CertificateManager owns trust lists and the loaded application certificate and is disposed with the session; auto-accept and the verify probe's capture-and-reject use AcceptError. - new UserIdentity(X509Certificate2) is gone: X509 user identities use X509IdentityTokenHandler with an on-demand PFX provider (still fails fast on a missing file/key). - DefaultSessionFactory takes the telemetry context; collections are ArrayOf<T>; EventFilter select clauses and ContentFilter operands are built immutably. UserName identity (lmxopcua#880): SDK 2's default handler sends a password over 64 bytes - every 65-character OtOpcUa API key - as an RsaEncryptedSecret that SDK 1.5 servers reject with BadIdentityTokenInvalid and SDK 2 servers accept only within a 5-minute clock window (#873). The DCL now always uses LegacyRsaUserNameIdentityTokenHandler (ported from OtOpcUa be28aa44), i.e. exactly what it sent on SDK 1.5, so it logs in to both server generations during a mixed rollout. Tests: the in-process secured test server is ported to SDK 2 and can admit an API key; new tests cover the handler (mutation-checked: 5 of 7 fail with the SDK default handler), the value boundary, and a 65-char key end to end over None/Sign/SignAndEncrypt with a wrong key reaching the key check (BadIdentityTokenRejected). Claude-Session: https://claude.ai/code/session_01GT67ACmpMR7b9LGRPLijMi
This commit is contained in:
+38
-1
@@ -216,6 +216,42 @@ public sealed class RealOpcUaSecureConnectTests : IDisposable
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// ScadaBridge#125 / lmxopcua#880: a production-length (65-character) API key logs in over every
|
||||
/// security mode, end to end through the real adapter, and a wrong key of the same length reaches
|
||||
/// the server's key check (<c>BadIdentityTokenRejected</c>) rather than failing to decrypt
|
||||
/// (<c>BadIdentityTokenInvalid</c>). The server here is SDK 2, which reads both password formats;
|
||||
/// the SDK 1.5 direction is covered by the wire-compat harness and the handler's own tests.
|
||||
/// </summary>
|
||||
[Theory]
|
||||
[InlineData("None")]
|
||||
[InlineData("Sign")]
|
||||
[InlineData("SignAndEncrypt")]
|
||||
public async Task Connect_ProductionLengthApiKey_IsAdmitted_AndAWrongKeyReachesTheKeyCheck(string mode)
|
||||
{
|
||||
var key = OpcUaUserIdentitiesTests.ProductionLengthKey();
|
||||
using var clientCert = await ProvisionClientAsync();
|
||||
await using var server = await SecureOpcUaTestServer.StartWithApiKeyAsync(key, clientCert);
|
||||
ClientTrusts(server.Certificate);
|
||||
|
||||
OpcUaConnectionOptions WithKey(string password) => Secured(mode) with
|
||||
{
|
||||
UserIdentity = new OpcUaUserIdentityOptions("UsernamePassword", "apikey", password, null!, null!),
|
||||
};
|
||||
|
||||
await using (var client = new RealOpcUaClient(ClientOptions()))
|
||||
{
|
||||
await client.ConnectAsync(server.Url, WithKey(key));
|
||||
Assert.Equal(0u, (await client.ReadValueAsync(ServerStateNode)).StatusCode);
|
||||
}
|
||||
|
||||
var wrong = key[..^1] + (key[^1] == 'A' ? 'B' : 'A');
|
||||
await using var refused = new RealOpcUaClient(ClientOptions());
|
||||
var ex = await Assert.ThrowsAsync<Opc.Ua.ServiceResultException>(
|
||||
() => refused.ConnectAsync(server.Url, WithKey(wrong)));
|
||||
Assert.Equal(Opc.Ua.StatusCodes.BadIdentityTokenRejected, ex.StatusCode);
|
||||
}
|
||||
|
||||
/// <summary>None is unchanged: it connects without reading or creating the own store.</summary>
|
||||
[Fact]
|
||||
public async Task Connect_None_DoesNotTouchTheOwnStore()
|
||||
@@ -245,7 +281,8 @@ public sealed class RealOpcUaSecureConnectTests : IDisposable
|
||||
using var again = await ProvisionClientAsync();
|
||||
Assert.Equal(certs[0].Thumbprint, again.Thumbprint);
|
||||
Assert.Single(Directory.GetFiles(OwnCertsDir, "*.der"));
|
||||
Assert.True(Opc.Ua.X509Utils.CompareApplicationUriWithCertificate(again, "urn:localhost:SB121Client", out _),
|
||||
using var wrapped = new Opc.Ua.Security.Certificates.Certificate(again.RawData);
|
||||
Assert.True(Opc.Ua.X509Utils.CompareApplicationUriWithCertificate(wrapped, "urn:localhost:SB121Client", out _),
|
||||
"the certificate carries the configured ApplicationUri");
|
||||
}
|
||||
finally
|
||||
|
||||
Reference in New Issue
Block a user