fe2a6db786
rust / build / test / clippy / fmt (push) Has been cancelled
Layout:
- src/ .NET 10 x64 reference: MxNativeCodec, MxNativeClient,
MxAsbClient, probes, tests, harnesses. Executable spec.
- design/ Architectural plan for the Rust port (M0–M6), error
model, protocol invariants, risks (R1–R16), adversarial
review log (review.md).
- rust/ Rust workspace. M0 skeleton + M1 codec parity.
mxaccess-codec: 215 unit tests + 2 cross-implementation
parity tests (byte-identical against .NET reference).
Other crates are M0 stubs awaiting M2+.
- captures/ Frida + netsh + pcap evidence per CLAUDE.md
("captures are evidence, not throwaway logs").
- analysis/ Decompiled C# (frida/proxy/decompiled-*),
Ghidra exports for native DLLs (`exports/` only —
working state at `projects/` and AVEVA's input
binaries at `input/` are gitignored).
- docs/ Reverse-engineering reference docs.
- tools/ Setup-LiveProbeEnv.ps1 (Infisical credential fetcher),
Compute-Crc.ps1 (.NET parity helper).
- .github/workflows/ Rust CI: fmt + build + test + clippy on Windows.
- LICENSE MIT (Joseph Doherty, 2026).
Verified:
- cargo test --workspace → 217 passed (215 unit + 2 .NET parity), 0 failed
- cargo clippy --workspace -- -D warnings → clean
- cargo fmt --all -- --check → clean
- cargo publish --dry-run -p mxaccess-codec → packages cleanly
Excluded from history (see .gitignore):
- **/bin, **/obj, **/target — build artifacts
- analysis/ghidra/projects/ — Ghidra working state (regenerable)
- analysis/ghidra/input/ — AVEVA proprietary DLLs (vendor IP)
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
143 lines
6.4 KiB
C#
143 lines
6.4 KiB
C#
using System;
|
|
using System.Globalization;
|
|
using System.Text;
|
|
using ArchestrAServices.Common;
|
|
|
|
namespace Asb.Base.V2;
|
|
|
|
public class SystemAuthenticationClientAuthentication : SystemAuthenticationConnectionBase
|
|
{
|
|
public uint Timeout { get; set; }
|
|
|
|
public SystemAuthenticationClientAuthentication(string asbSolution)
|
|
: base(asbSolution)
|
|
{
|
|
Reset();
|
|
base.ReasonSecureSessionNotEstablished = "Constructed";
|
|
}
|
|
|
|
public static bool EstablishSecureSession(string asbSolution, ClientMetadata clientMetadata, Func<ConnectRequest, ConnectResponse> connectDelegate, Func<AuthenticateMeRequest, AuthenticateMeResponse> authenticateMeDelegate, Action<Guid> connectionIdHandler, Action<string> reasonSecureSessionNotEstablishedHandler)
|
|
{
|
|
SystemAuthenticationClientAuthentication systemAuthenticationClientAuthentication = new SystemAuthenticationClientAuthentication(asbSolution);
|
|
SysAuthenticatorClientCache.AddClientAuthenticator(systemAuthenticationClientAuthentication);
|
|
Guid connectionId = systemAuthenticationClientAuthentication.ConnectionId;
|
|
PublicKey consumerPublicKey = new PublicKey
|
|
{
|
|
Data = systemAuthenticationClientAuthentication.LocalPublicKey
|
|
};
|
|
ConnectRequest arg = new ConnectRequest(connectionId, consumerPublicKey, asbSolution);
|
|
ConnectResponse connectResponse = null;
|
|
try
|
|
{
|
|
connectResponse = connectDelegate?.Invoke(arg);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
string text = string.Format(CultureInfo.CurrentCulture, "Exception connecting to service during EstablishSecureSession: {0}", new object[1] { ex.Message });
|
|
ServiceTrace.LogWarning(text);
|
|
reasonSecureSessionNotEstablishedHandler?.Invoke(text);
|
|
}
|
|
if (connectResponse != null)
|
|
{
|
|
if (connectResponse.Result.Success)
|
|
{
|
|
systemAuthenticationClientAuthentication.RemotePublicKey = connectResponse.ServicePublicKey.Data;
|
|
systemAuthenticationClientAuthentication.ReasonSecureSessionNotEstablished = string.Empty;
|
|
if (systemAuthenticationClientAuthentication.ValidResponse(connectResponse, forceHmac: true))
|
|
{
|
|
byte[] initializationVector;
|
|
AuthenticateMeRequest authenticateMeRequest = new AuthenticateMeRequest(new AuthenticationData
|
|
{
|
|
Data = systemAuthenticationClientAuthentication.CalculateAuthenticationData(systemAuthenticationClientAuthentication.LocalPublicKey, systemAuthenticationClientAuthentication.RemotePublicKey, out initializationVector),
|
|
InitializationVector = initializationVector
|
|
}, clientMetadata);
|
|
systemAuthenticationClientAuthentication.Sign(authenticateMeRequest, forceHmac: true);
|
|
AuthenticateMeResponse authenticateMeResponse = authenticateMeDelegate(authenticateMeRequest);
|
|
if (authenticateMeResponse != null && authenticateMeResponse.Result.Success)
|
|
{
|
|
systemAuthenticationClientAuthentication.SecureSessionEstablished = true;
|
|
connectionIdHandler?.Invoke(connectionId);
|
|
}
|
|
else
|
|
{
|
|
ServiceTrace.LogVerbose("Service rejected the connection at the AuthenticateMe stage");
|
|
string obj = "Service rejected the connection at the AuthenticateMe stage";
|
|
if (authenticateMeResponse != null)
|
|
{
|
|
obj = ((authenticateMeResponse.Result.ErrorMessages == null || authenticateMeResponse.Result.ErrorMessages.Length == 0) ? string.Format(CultureInfo.CurrentCulture, "Service returned error {0} in response to AuthenticateMe method, cannot establish secure connection.", new object[1] { authenticateMeResponse.Result.ResultCodeAsError }) : authenticateMeResponse.Result.ErrorMessages[0]);
|
|
}
|
|
reasonSecureSessionNotEstablishedHandler?.Invoke(obj);
|
|
SysAuthenticatorClientCache.RemoveClientAuthenticator(connectionId);
|
|
connectionIdHandler?.Invoke(Guid.Empty);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (!string.IsNullOrEmpty(systemAuthenticationClientAuthentication.ReasonSecureSessionNotEstablished))
|
|
{
|
|
reasonSecureSessionNotEstablishedHandler?.Invoke("Service returned response to Connect method, but validation failed: " + systemAuthenticationClientAuthentication.ReasonSecureSessionNotEstablished);
|
|
}
|
|
else
|
|
{
|
|
reasonSecureSessionNotEstablishedHandler?.Invoke("Service returned response to Connect method, but validation data was not valid, cannot establish secure session");
|
|
}
|
|
SysAuthenticatorClientCache.RemoveClientAuthenticator(connectionId);
|
|
connectionIdHandler?.Invoke(Guid.Empty);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (connectResponse.Result.ErrorMessages != null && connectResponse.Result.ErrorMessages.Length != 0)
|
|
{
|
|
reasonSecureSessionNotEstablishedHandler?.Invoke(string.Format(CultureInfo.CurrentCulture, "Service returned error {0} in response to Connect method, cannot establish secure connection. Additional information:", new object[1] { connectResponse.Result.ResultCodeAsError }));
|
|
string[] errorMessages = connectResponse.Result.ErrorMessages;
|
|
foreach (string obj2 in errorMessages)
|
|
{
|
|
reasonSecureSessionNotEstablishedHandler?.Invoke(obj2);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
reasonSecureSessionNotEstablishedHandler?.Invoke(string.Format(CultureInfo.CurrentCulture, "Service returned error {0} in response to Connect method, cannot establish secure connection.", new object[1] { connectResponse.Result.ResultCodeAsError }));
|
|
}
|
|
SysAuthenticatorClientCache.RemoveClientAuthenticator(connectionId);
|
|
connectionIdHandler?.Invoke(Guid.Empty);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
SysAuthenticatorClientCache.RemoveClientAuthenticator(connectionId);
|
|
connectionIdHandler?.Invoke(Guid.Empty);
|
|
}
|
|
return systemAuthenticationClientAuthentication.SecureSessionEstablished;
|
|
}
|
|
|
|
public void AbortSession()
|
|
{
|
|
Reset();
|
|
base.ReasonSecureSessionNotEstablished = "Session Aborted";
|
|
}
|
|
|
|
public static void DisconnectSecureSession(Guid connectionId, Action<DisconnectRequest> disconnectDelegate)
|
|
{
|
|
SystemAuthenticationClientAuthentication clientAuthenticator = SysAuthenticatorClientCache.GetClientAuthenticator(connectionId);
|
|
if (clientAuthenticator != null)
|
|
{
|
|
byte[] initializationVector;
|
|
DisconnectRequest disconnectRequest = new DisconnectRequest(new AuthenticationData
|
|
{
|
|
Data = clientAuthenticator.EncypherWithNewInitializationVector(Encoding.UTF8.GetBytes(clientAuthenticator.ConnectionId.ToString()), out initializationVector),
|
|
InitializationVector = initializationVector
|
|
});
|
|
clientAuthenticator.Sign(disconnectRequest, forceHmac: false);
|
|
disconnectDelegate?.Invoke(disconnectRequest);
|
|
}
|
|
}
|
|
|
|
private new void Reset()
|
|
{
|
|
base.Reset();
|
|
Timeout = 10000u;
|
|
}
|
|
}
|